Implements hook_page_build().
Adds the drupal.contextual-links library to the page for any user who has the 'access contextual links' permission.
function contextual_page_build(&$page) {
  if (!user_access('access contextual links')) {
    return;
  }
  $page['#attached']['library'][] = array(
    'contextual',
    'drupal.contextual-links',
  );
}