Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This Source Code is subject to the terms of the Mozilla Public License | 2 * This Source Code is subject to the terms of the Mozilla Public License |
3 * version 2.0 (the "License"). You can obtain a copy of the License at | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
5 */ | 5 */ |
6 | 6 |
7 Cu.import("resource://gre/modules/Services.jsm"); | 7 Cu.import("resource://gre/modules/Services.jsm"); |
8 | 8 |
9 let {Prefs} = require("prefs"); | 9 let {Prefs} = require("prefs"); |
10 let {WindowObserver} = require("windowObserver"); | 10 let {WindowObserver} = require("windowObserver"); |
11 let {WindowWrapper} = require("windowWrapper"); | 11 let {WindowWrapper} = require("windowWrapper"); |
12 | 12 |
13 // Check whether some preferences can still be found under their old locations | 13 // Check whether some preferences can still be found under their old locations |
14 Prefs.migrate("extensions.adblockplus.ehh-selectelement_key", "selectelement_key "); | 14 Prefs.migrate("extensions.adblockplus.ehh-selectelement_key", "selectelement_key "); |
15 Prefs.migrate("extensions.adblockplus.ehh.showhelp", "showhelp"); | 15 Prefs.migrate("extensions.adblockplus.ehh.showhelp", "showhelp"); |
16 | 16 |
17 // Window types to attach to | 17 // Window types to attach to |
18 let knownWindowTypes = Object.create(null); | 18 let knownWindowTypes = new Set(["navigator:browser", "mail:3pane", "mail:message Window"]); |
Wladimir Palant
2015/04/01 19:01:14
Better: Set(["navigator:browser", "mail:3pane", "m
Sebastian Noack
2015/04/02 07:19:47
True.
| |
19 knownWindowTypes["navigator:browser"] = true; | |
20 knownWindowTypes["mail:3pane"] = true; | |
21 knownWindowTypes["mail:messageWindow"] = true; | |
22 | 19 |
23 // Use random marker class | 20 // Use random marker class |
24 let elementMarkerClass = null; | 21 let elementMarkerClass = null; |
25 { | 22 { |
26 let rnd = []; | 23 let rnd = []; |
27 let offset = "a".charCodeAt(0); | 24 let offset = "a".charCodeAt(0); |
28 for (let i = 0; i < 20; i++) | 25 for (let i = 0; i < 20; i++) |
29 rnd.push(offset + Math.random() * 26); | 26 rnd.push(offset + Math.random() * 26); |
30 | 27 |
31 elementMarkerClass = String.fromCharCode.apply(String, rnd); | 28 elementMarkerClass = String.fromCharCode.apply(String, rnd); |
(...skipping 26 matching lines...) Expand all Loading... | |
58 return; | 55 return; |
59 | 56 |
60 let overlay = event.target.responseXML.documentElement; | 57 let overlay = event.target.responseXML.documentElement; |
61 | 58 |
62 // Initialization done, we can start up now | 59 // Initialization done, we can start up now |
63 require("inspectorObserver"); | 60 require("inspectorObserver"); |
64 new WindowObserver({ | 61 new WindowObserver({ |
65 applyToWindow: function(window) | 62 applyToWindow: function(window) |
66 { | 63 { |
67 let type = window.document.documentElement.getAttribute("windowtype"); | 64 let type = window.document.documentElement.getAttribute("windowtype"); |
68 if (!(type in knownWindowTypes) || window._ehhWrapper) | 65 if (!knownWindowTypes.has(type) || window._ehhWrapper) |
69 return; | 66 return; |
70 | 67 |
71 window.document.documentElement.appendChild(overlay.cloneNode(true)); | 68 window.document.documentElement.appendChild(overlay.cloneNode(true)); |
72 | 69 |
73 let style = window.document.createProcessingInstruction("xml-stylesheet", 'class="elemhidehelper-node" href="chrome://elemhidehelper/skin/overlay.css" typ e="text/css"'); | 70 let style = window.document.createProcessingInstruction("xml-stylesheet", 'class="elemhidehelper-node" href="chrome://elemhidehelper/skin/overlay.css" typ e="text/css"'); |
74 window.document.insertBefore(style, window.document.firstChild); | 71 window.document.insertBefore(style, window.document.firstChild); |
75 | 72 |
76 window._ehhWrapper = new WindowWrapper(window); | 73 window._ehhWrapper = new WindowWrapper(window); |
77 }, | 74 }, |
78 | 75 |
79 removeFromWindow: function(window) | 76 removeFromWindow: function(window) |
80 { | 77 { |
81 if (!window._ehhWrapper) | 78 if (!window._ehhWrapper) |
82 return; | 79 return; |
83 | 80 |
84 window._ehhWrapper.shutdown(); | 81 window._ehhWrapper.shutdown(); |
85 delete window._ehhWrapper; | 82 delete window._ehhWrapper; |
86 | 83 |
87 let element = window.document.getElementById(overlay.getAttribute("id")); | 84 let element = window.document.getElementById(overlay.getAttribute("id")); |
88 if (element) | 85 if (element) |
89 element.parentNode.removeChild(element); | 86 element.parentNode.removeChild(element); |
90 | 87 |
91 for (let child = window.document.firstChild; child; child = child.nextSibl ing) | 88 for (let child = window.document.firstChild; child; child = child.nextSibl ing) |
92 if (child.nodeType == child.PROCESSING_INSTRUCTION_NODE && child.data.in dexOf("elemhidehelper-node") >= 0) | 89 if (child.nodeType == child.PROCESSING_INSTRUCTION_NODE && child.data.in dexOf("elemhidehelper-node") >= 0) |
93 child.parentNode.removeChild(child); | 90 child.parentNode.removeChild(child); |
94 } | 91 } |
95 }); | 92 }); |
96 }, false); | 93 }, false); |
97 request.send(null); | 94 request.send(null); |
LEFT | RIGHT |