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

Side by Side Diff: lib/main.js

Issue 29363476: Issue 2879 - Move element selection into the content process (Closed) Base URL: https://hg.adblockplus.org/elemhidehelper
Patch Set: Addressed comments and marked extension as E10S-compatible Created Nov. 24, 2016, 2 p.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/child/utils.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 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); 7 let {Services} = 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 = new Set(["navigator:browser", "mail:3pane", "mail:message Window"]); 18 let knownWindowTypes = new Set(["navigator:browser", "mail:3pane", "mail:message Window"]);
19 19
20 // Use random marker class 20 // Use random marker class
21 let elementMarkerClass = null; 21 let elementMarkerClass = null;
22 { 22 {
23 let rnd = []; 23 let rnd = [];
24 let offset = "a".charCodeAt(0); 24 let offset = "a".charCodeAt(0);
25 for (let i = 0; i < 20; i++) 25 for (let i = 0; i < 20; i++)
26 rnd.push(offset + Math.random() * 26); 26 rnd.push(offset + Math.random() * 26);
27 27
28 elementMarkerClass = String.fromCharCode.apply(String, rnd); 28 elementMarkerClass = String.fromCharCode.apply(String, rnd);
29 } 29 }
30 exports.elementMarkerClass = elementMarkerClass;
31 30
32 // Load CSS asynchronously 31 // Load CSS asynchronously
33 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.ns IXMLHttpRequest); 32 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.ns IXMLHttpRequest);
34 request.open("GET", "chrome://elemhidehelper/content/elementmarker.css"); 33 request.open("GET", "chrome://elemhidehelper/content/elementmarker.css");
35 request.overrideMimeType("text/plain"); 34 request.overrideMimeType("text/plain");
36 request.addEventListener("load", function(event) 35 request.addEventListener("load", function(event)
37 { 36 {
38 if (onShutdown.done) 37 if (onShutdown.done)
39 return; 38 return;
40 39
41 let data = event.target.responseText.replace(/%%CLASS%%/g, elementMarkerClass) ; 40 let data = event.target.responseText.replace(/%%CLASS%%/g, elementMarkerClass) ;
42 let styleService = Cc["@mozilla.org/content/style-sheet-service;1"].getService (Ci.nsIStyleSheetService); 41 let styleService = Cc["@mozilla.org/content/style-sheet-service;1"].getService (Ci.nsIStyleSheetService);
43 let styleURI = Services.io.newURI("data:text/css," + encodeURIComponent(data), null, null); 42 let styleURI = Services.io.newURI("data:text/css," + encodeURIComponent(data), null, null);
44 styleService.loadAndRegisterSheet(styleURI, Ci.nsIStyleSheetService.USER_SHEET ); 43 styleService.loadAndRegisterSheet(styleURI, Ci.nsIStyleSheetService.USER_SHEET );
45 onShutdown.add(() => styleService.unregisterSheet(styleURI, Ci.nsIStyleSheetSe rvice.USER_SHEET)); 44 onShutdown.add(() => styleService.unregisterSheet(styleURI, Ci.nsIStyleSheetSe rvice.USER_SHEET));
46 }, false); 45 }, false);
47 request.send(null); 46 request.send(null);
48 47
49 // Load our process script 48 // Load our process script
50 let info = require("info"); 49 let info = require("info");
50 info.elementMarkerClass = elementMarkerClass;
51
51 let processScript = info.addonRoot + "lib/child/bootstrap.js?" + 52 let processScript = info.addonRoot + "lib/child/bootstrap.js?" +
52 elementMarkerClass + "&" + 53 elementMarkerClass + "&" +
53 "info=" + encodeURIComponent(JSON.stringify(info)); 54 "info=" + encodeURIComponent(JSON.stringify(info));
54 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"] 55 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"]
55 .getService(Ci.nsIProcessScriptLoader); 56 .getService(Ci.nsIProcessScriptLoader);
56 messageManager.loadProcessScript(processScript, true); 57 messageManager.loadProcessScript(processScript, true);
57 onShutdown.add(() => { 58 onShutdown.add(() => {
58 messageManager.removeDelayedProcessScript(processScript); 59 messageManager.removeDelayedProcessScript(processScript);
59 messageManager.QueryInterface(Ci.nsIMessageBroadcaster) 60 messageManager.QueryInterface(Ci.nsIMessageBroadcaster)
60 .broadcastAsyncMessage("ElemHideHelper:Shutdown"); 61 .broadcastAsyncMessage("ElemHideHelper:Shutdown");
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 if (element) 101 if (element)
101 element.parentNode.removeChild(element); 102 element.parentNode.removeChild(element);
102 103
103 for (let child = window.document.firstChild; child; child = child.nextSibl ing) 104 for (let child = window.document.firstChild; child; child = child.nextSibl ing)
104 if (child.nodeType == child.PROCESSING_INSTRUCTION_NODE && child.data.in dexOf("elemhidehelper-node") >= 0) 105 if (child.nodeType == child.PROCESSING_INSTRUCTION_NODE && child.data.in dexOf("elemhidehelper-node") >= 0)
105 child.parentNode.removeChild(child); 106 child.parentNode.removeChild(child);
106 } 107 }
107 }); 108 });
108 }, false); 109 }, false);
109 request.send(null); 110 request.send(null);
OLDNEW
« no previous file with comments | « lib/child/utils.js ('k') | lib/windowWrapper.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld