Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/main.js

Issue 6520005931827200: Issue 2259 - Removed non-standard JavaScript code from Element Hiding Helper (Closed)
Patch Set: Use a Set instead an object Created April 2, 2015, 7:19 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/inspectorObserver.js ('k') | lib/windowWrapper.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 = 18 let knownWindowTypes = new Set(["navigator:browser", "mail:3pane", "mail:message Window"]);
19 {
20 "navigator:browser": true,
21 "mail:3pane": true,
22 "mail:messageWindow": true,
23 __proto__: null
24 };
25 19
26 // Use random marker class 20 // Use random marker class
27 let elementMarkerClass = null; 21 let elementMarkerClass = null;
28 { 22 {
29 let rnd = []; 23 let rnd = [];
30 let offset = "a".charCodeAt(0); 24 let offset = "a".charCodeAt(0);
31 for (let i = 0; i < 20; i++) 25 for (let i = 0; i < 20; i++)
32 rnd.push(offset + Math.random() * 26); 26 rnd.push(offset + Math.random() * 26);
33 27
34 elementMarkerClass = String.fromCharCode.apply(String, rnd); 28 elementMarkerClass = String.fromCharCode.apply(String, rnd);
35 } 29 }
36 exports.elementMarkerClass = elementMarkerClass; 30 exports.elementMarkerClass = elementMarkerClass;
37 31
38 // Load CSS asynchronously 32 // Load CSS asynchronously
39 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.ns IXMLHttpRequest); 33 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.ns IXMLHttpRequest);
40 request.open("GET", "chrome://elemhidehelper/content/elementmarker.css"); 34 request.open("GET", "chrome://elemhidehelper/content/elementmarker.css");
41 request.overrideMimeType("text/plain"); 35 request.overrideMimeType("text/plain");
42 request.addEventListener("load", function(event) 36 request.addEventListener("load", function(event)
43 { 37 {
44 if (onShutdown.done) 38 if (onShutdown.done)
45 return; 39 return;
46 40
47 let data = event.target.responseText.replace(/%%CLASS%%/g, elementMarkerClass) ; 41 let data = event.target.responseText.replace(/%%CLASS%%/g, elementMarkerClass) ;
48 let styleService = Cc["@mozilla.org/content/style-sheet-service;1"].getService (Ci.nsIStyleSheetService); 42 let styleService = Cc["@mozilla.org/content/style-sheet-service;1"].getService (Ci.nsIStyleSheetService);
49 let styleURI = Services.io.newURI("data:text/css," + encodeURIComponent(data), null, null); 43 let styleURI = Services.io.newURI("data:text/css," + encodeURIComponent(data), null, null);
50 styleService.loadAndRegisterSheet(styleURI, Ci.nsIStyleSheetService.USER_SHEET ); 44 styleService.loadAndRegisterSheet(styleURI, Ci.nsIStyleSheetService.USER_SHEET );
51 onShutdown.add(function() styleService.unregisterSheet(styleURI, Ci.nsIStyleSh eetService.USER_SHEET)); 45 onShutdown.add(() => styleService.unregisterSheet(styleURI, Ci.nsIStyleSheetSe rvice.USER_SHEET));
52 }, false); 46 }, false);
53 request.send(null); 47 request.send(null);
54 48
55 // Load overlay asynchonously and start attaching to windows once done 49 // Load overlay asynchonously and start attaching to windows once done
56 request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIJSX MLHttpRequest); 50 request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIJSX MLHttpRequest);
57 request.open("GET", "chrome://elemhidehelper/content/overlay.xul"); 51 request.open("GET", "chrome://elemhidehelper/content/overlay.xul");
58 request.addEventListener("load", function(event) 52 request.addEventListener("load", function(event)
59 { 53 {
60 if (onShutdown.done) 54 if (onShutdown.done)
61 return; 55 return;
62 56
63 let overlay = event.target.responseXML.documentElement; 57 let overlay = event.target.responseXML.documentElement;
64 58
65 // Initialization done, we can start up now 59 // Initialization done, we can start up now
66 require("inspectorObserver"); 60 require("inspectorObserver");
67 new WindowObserver({ 61 new WindowObserver({
68 applyToWindow: function(window) 62 applyToWindow: function(window)
69 { 63 {
70 let type = window.document.documentElement.getAttribute("windowtype"); 64 let type = window.document.documentElement.getAttribute("windowtype");
71 if (!(type in knownWindowTypes) || window._ehhWrapper) 65 if (!knownWindowTypes.has(type) || window._ehhWrapper)
72 return; 66 return;
73 67
74 window.document.documentElement.appendChild(overlay.cloneNode(true)); 68 window.document.documentElement.appendChild(overlay.cloneNode(true));
75 69
76 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"');
77 window.document.insertBefore(style, window.document.firstChild); 71 window.document.insertBefore(style, window.document.firstChild);
78 72
79 window._ehhWrapper = new WindowWrapper(window); 73 window._ehhWrapper = new WindowWrapper(window);
80 }, 74 },
81 75
82 removeFromWindow: function(window) 76 removeFromWindow: function(window)
83 { 77 {
84 if (!window._ehhWrapper) 78 if (!window._ehhWrapper)
85 return; 79 return;
86 80
87 window._ehhWrapper.shutdown(); 81 window._ehhWrapper.shutdown();
88 delete window._ehhWrapper; 82 delete window._ehhWrapper;
89 83
90 let element = window.document.getElementById(overlay.getAttribute("id")); 84 let element = window.document.getElementById(overlay.getAttribute("id"));
91 if (element) 85 if (element)
92 element.parentNode.removeChild(element); 86 element.parentNode.removeChild(element);
93 87
94 for (let child = window.document.firstChild; child; child = child.nextSibl ing) 88 for (let child = window.document.firstChild; child; child = child.nextSibl ing)
95 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)
96 child.parentNode.removeChild(child); 90 child.parentNode.removeChild(child);
97 } 91 }
98 }); 92 });
99 }, false); 93 }, false);
100 request.send(null); 94 request.send(null);
OLDNEW
« no previous file with comments | « lib/inspectorObserver.js ('k') | lib/windowWrapper.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld