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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/main.js
===================================================================
--- a/lib/main.js
+++ b/lib/main.js
@@ -17,25 +17,63 @@
/**
* @fileOverview Starts up Adblock Plus
*/
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
+bootstrapChildProcesses();
registerPublicAPI();
require("filterListener");
require("contentPolicy");
require("synchronizer");
require("notification");
require("sync");
require("messageResponder");
require("ui");
+function bootstrapChildProcesses()
+{
+ let info = require("info");
+
+ // Huge hack: we cannot opt out of individual compatibility shims (see
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1167802). So the about
+ // protocol shim will override our handler in the content process. Prevent
+ // this by making sure it isn't messaged.
+ try
+ {
+ let {AboutProtocolParent} = Cu.import("resource://gre/modules/RemoteAddonsParent.jsm", {});
+ if (AboutProtocolParent && typeof AboutProtocolParent.registerFactory == "function")
+ {
+ let origRegisterFactory = AboutProtocolParent.registerFactory;
+ AboutProtocolParent.registerFactory = function(addon, ...args)
+ {
+ if (addon != info.addonID)
+ origRegisterFactory.call(this, addon, ...args);
+ }
+ onShutdown.add(() => AboutProtocolParent.registerFactory = origRegisterFactory);
+ }
+ }
+ catch(e) {}
+
+ let processScript = info.addonRoot + "lib/child/bootstrap.js?" + Math.random();
+ let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"]
+ .getService(Ci.nsIProcessScriptLoader)
+ .QueryInterface(Ci.nsIMessageBroadcaster);
+ messageManager.loadProcessScript(processScript, true);
+ messageManager.broadcastAsyncMessage("AdblockPlus:Info", info);
+
+ onShutdown.add(() => {
+ messageManager.broadcastAsyncMessage("AdblockPlus:Shutdown", processScript);
+ messageManager.removeDelayedProcessScript(processScript);
+ });
+}
+
function registerPublicAPI()
{
let {addonRoot} = require("info");
let uri = Services.io.newURI(addonRoot + "lib/Public.jsm", null, null);
if (uri instanceof Ci.nsIMutable)
uri.mutable = false;

Powered by Google App Engine
This is Rietveld