Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / ui / accessibility / extensions / longdesc / lastRightClick.js
blobebe6b0daff129107f50ea7295071c28cf0989a55
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 borderColor;
6 var borderStyle;
7 var borderWidth;
9 chrome.storage.onChanged.addListener(function(changes, namespace) {
10 if (changes.addBorder.newValue) {
11 addBorders();
12 } else {
13 removeBorders();
15 });
17 chrome.storage.sync.get("addBorder", function(item) {
18 if (item.addBorder) {
19 addBorders();
21 });
23 document.addEventListener('contextmenu', function(element) {
24 updateContextMenuItem(element);
25 }, false);
27 document.addEventListener('mouseover', function(element) {
28 updateContextMenuItem(element);
29 }, false);
31 document.addEventListener('focus', function(element) {
32 updateContextMenuItem(element);
33 });
35 /**
36 * Sends a message to the backgrond script notifying it to
37 * enable or disable the context menu item.
39 * @param element
41 function updateContextMenuItem(element) {
42 var longDesc = '';
43 var ariaDescribedAt = '';
45 if (element.target.hasAttribute("longdesc")) {
46 longDesc = element.target.getAttribute("longdesc");
47 var link = document.createElement("a");
48 link.href = longDesc;
49 longDesc = link.href;
52 if (element.target.hasAttribute("aria-describedat")) {
53 ariaDescribedAt = element.target.getAttribute("aria-describedat");
56 if (longDesc !== '' || ariaDescribedAt !== '') {
57 chrome.runtime.sendMessage({
58 ariaDescribedAt: ariaDescribedAt,
59 longDesc: longDesc,
60 enabled: true
61 });
62 } else {
63 chrome.runtime.sendMessage({
64 enabled: false
65 });
69 /**
70 * Modify border to make the HTML element more visible.
72 function addBorders() {
73 document.body.setAttribute('showlongdescborders', '');
76 /**
77 * Revert back to the original border styling.
79 function removeBorders() {
80 document.body.removeAttribute('showlongdescborders', '');