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

Side by Side Diff: lib/main.js

Issue 29329246: Issue 3108 - Inject our about: module into all processes (Closed)
Patch Set: Created Oct. 16, 2015, 12:02 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
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** 18 /**
19 * @fileOverview Starts up Adblock Plus 19 * @fileOverview Starts up Adblock Plus
20 */ 20 */
21 21
22 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 22 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
23 Cu.import("resource://gre/modules/Services.jsm"); 23 Cu.import("resource://gre/modules/Services.jsm");
24 24
25 bootstrapChildProcesses();
25 registerPublicAPI(); 26 registerPublicAPI();
26 require("filterListener"); 27 require("filterListener");
27 require("contentPolicy"); 28 require("contentPolicy");
28 require("synchronizer"); 29 require("synchronizer");
29 require("notification"); 30 require("notification");
30 require("sync"); 31 require("sync");
31 require("messageResponder"); 32 require("messageResponder");
32 require("ui"); 33 require("ui");
33 34
35 function bootstrapChildProcesses()
36 {
37 let info = require("info");
38
39 // Huge hack: we cannot opt out of individual compatibility shims (see
40 // https://bugzilla.mozilla.org/show_bug.cgi?id=1167802). So the about
41 // protocol shim will override our handler in the content process. Prevent
42 // this by making sure it isn't messaged.
43 try
44 {
45 let {AboutProtocolParent} = Cu.import("resource://gre/modules/RemoteAddonsPa rent.jsm", {});
46 if (AboutProtocolParent && typeof AboutProtocolParent.registerFactory == "fu nction")
47 {
48 let origRegisterFactory = AboutProtocolParent.registerFactory;
49 AboutProtocolParent.registerFactory = function(addon, ...args)
50 {
51 if (addon != info.addonID)
52 origRegisterFactory.call(this, addon, ...args);
53 }
54 onShutdown.add(() => AboutProtocolParent.registerFactory = origRegisterFac tory);
55 }
56 }
57 catch(e) {}
58
59 let processScript = info.addonRoot + "lib/child/bootstrap.js?" + Math.random() ;
60 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"]
61 .getService(Ci.nsIProcessScriptLoader)
62 .QueryInterface(Ci.nsIMessageBroadcaster);
63 messageManager.loadProcessScript(processScript, true);
64 messageManager.broadcastAsyncMessage("AdblockPlus:Info", info);
65
66 onShutdown.add(() => {
67 messageManager.broadcastAsyncMessage("AdblockPlus:Shutdown", processScript);
68 messageManager.removeDelayedProcessScript(processScript);
69 });
70 }
71
34 function registerPublicAPI() 72 function registerPublicAPI()
35 { 73 {
36 let {addonRoot} = require("info"); 74 let {addonRoot} = require("info");
37 75
38 let uri = Services.io.newURI(addonRoot + "lib/Public.jsm", null, null); 76 let uri = Services.io.newURI(addonRoot + "lib/Public.jsm", null, null);
39 if (uri instanceof Ci.nsIMutable) 77 if (uri instanceof Ci.nsIMutable)
40 uri.mutable = false; 78 uri.mutable = false;
41 79
42 let classID = Components.ID("5e447bce-1dd2-11b2-b151-ec21c2b6a135"); 80 let classID = Components.ID("5e447bce-1dd2-11b2-b151-ec21c2b6a135");
43 let contractID = "@adblockplus.org/abp/public;1"; 81 let contractID = "@adblockplus.org/abp/public;1";
(...skipping 10 matching lines...) Expand all
54 92
55 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); 93 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
56 registrar.registerFactory(classID, "Adblock Plus public API URL", contractID, factory); 94 registrar.registerFactory(classID, "Adblock Plus public API URL", contractID, factory);
57 95
58 onShutdown.add(function() 96 onShutdown.add(function()
59 { 97 {
60 registrar.unregisterFactory(classID, factory); 98 registrar.unregisterFactory(classID, factory);
61 Cu.unload(uri.spec); 99 Cu.unload(uri.spec);
62 }); 100 });
63 } 101 }
OLDNEW

Powered by Google App Engine
This is Rietveld