Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / ui / accessibility / extensions / longdesc / background.js
blob81e7fca089551670b7bb57e248675f55fbc87ca1
1 /* Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. */
5 var ariaDescribedAt = '';
6 var longDesc = '';
8 /**
9 * This is called when the extension is first loaded, so that it can be
10 * immediately used in all already-open tabs. It's not needed for any
11 * new tabs that open after that, the content script will be automatically
12 * injected into any new tab.
14 chrome.windows.getAll({'populate': true}, function(windows) {
15 for (var i = 0; i < windows.length; i++) {
16 var tabs = windows[i].tabs;
17 for (var j = 0; j < tabs.length; j++) {
18 try {
19 chrome.tabs.insertCSS(
20 tabs[j].id,
21 {file: 'border.css'},
22 function(result) {
23 chrome.runtime.lastError;
24 });
25 } catch (x) {
27 try {
28 chrome.tabs.executeScript(
29 tabs[j].id,
30 {file: 'lastRightClick.js'},
31 function(result) {
32 chrome.runtime.lastError;
33 });
34 } catch (x) {
38 });
40 /**
41 * Add context menu item when the extension is installed.
43 chrome.contextMenus.create({
44 "title": chrome.i18n.getMessage('longdesc_context_menu_item'),
45 "contexts": ["all"],
46 "id": "moreInfo",
47 "onclick": contextMenuClicked,
48 "enabled": false
49 });
51 /**
52 * Add listener for messages from content script.
53 * Enable/disable the context menu item.
55 chrome.runtime.onMessage.addListener(
56 function (request, sender, sendResponse) {
57 if (request.enabled) {
58 ariaDescribedAt = request.ariaDescribedAt;
59 longDesc = request.longDesc;
61 chrome.contextMenus.update('moreInfo', {
62 "enabled": request.enabled
63 });
64 });
66 /**
67 * Event handler for when a context menu item is clicked.
68 * aria-describedat is given a higher priority.
69 * No need to strip the URL of leading/trailing white space
70 * because Chrome takes care of this.
72 * @param info
73 * @param tab
75 function contextMenuClicked(info, tab) {
76 if (ariaDescribedAt !== '') {
77 chrome.tabs.create({url: ariaDescribedAt});
78 } else if (longDesc !== '') {
79 chrome.tabs.create({url: longDesc});