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

Unified Diff: lib/child/bootstrap.js

Issue 29362609: Issue 2879 - Restructure existing process script, split it up into multiple modules (Closed) Base URL: https://hg.adblockplus.org/elemhidehelper
Patch Set: Created Nov. 17, 2016, 8:36 a.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/child/bootstrap.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/lib/child/bootstrap.js
@@ -0,0 +1,90 @@
+/*
+ * This Source Code is subject to the terms of the Mozilla Public License
+ * version 2.0 (the "License"). You can obtain a copy of the License at
+ * http://mozilla.org/MPL/2.0/.
+ */
+
+"use strict";
Wladimir Palant 2016/11/17 08:42:58 This is very close to lib/child/bootstrap.js we us
saroyanm 2016/11/22 14:58:31 Acknowledged.
+
+(function(messageManager)
+{
+ const Cc = Components.classes;
+ const Ci = Components.interfaces;
+ const Cr = Components.results;
+ const Cu = Components.utils;
+
+ let {Loader, main, unload} = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {});
saroyanm 2016/11/24 17:46:10 Nit: Exceeding 80 chars.
Wladimir Palant 2016/12/01 09:40:49 Done.
+ let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
+
+ Cu.importGlobalProperties(["atob", "btoa", "File", "URL", "URLSearchParams",
+ "TextDecoder", "TextEncoder"]);
+
+ let shutdownHandlers = [];
+ let onShutdown =
+ {
+ done: false,
+ add: function(handler)
+ {
+ if (shutdownHandlers.indexOf(handler) < 0)
+ shutdownHandlers.push(handler);
+ },
+ remove: function(handler)
+ {
+ let index = shutdownHandlers.indexOf(handler);
+ if (index >= 0)
+ shutdownHandlers.splice(index, 1);
+ }
+ };
+
+ function init()
+ {
+ let url = new URL(Components.stack.filename);
+ let params = new URLSearchParams(url.search.substr(1));
+ let info = JSON.parse(params.get("info"));
+
+ let loader = Loader({
+ paths: {
+ "": info.addonRoot + "lib/"
+ },
+ globals: {
+ Components, Cc, Ci, Cu, Cr, atob, btoa, File, URL, URLSearchParams,
+ TextDecoder, TextEncoder, onShutdown
+ },
+ modules: {
+ info, messageManager
saroyanm 2016/11/22 14:58:31 In AdblockPlus we are defining the modules: module
Wladimir Palant 2016/11/24 14:16:29 Why? This short notation is available starting wit
saroyanm 2016/11/24 17:46:10 Oh, I was referring actually to your initial comme
+ },
+ id: info.addonID
+ });
+ onShutdown.add(() => unload(loader, "disable"))
+
+ main(loader, "child/main");
+ }
+
+ function shutdown(message)
saroyanm 2016/11/22 14:58:31 message parameter is not being used, probably can
Wladimir Palant 2016/11/24 14:16:29 It sure can be but it is still being passed in so
+ {
+ if (onShutdown.done)
+ return;
+
+ onShutdown.done = true;
+ for (let i = shutdownHandlers.length - 1; i >= 0; i --)
+ {
+ try
+ {
+ shutdownHandlers[i]();
+ }
+ catch (e)
+ {
+ Cu.reportError(e);
+ }
+ }
+ shutdownHandlers = null;
+ }
+
+ messageManager.addMessageListener("ElemHideHelper:Shutdown", shutdown);
+ onShutdown.add(() =>
+ {
+ messageManager.removeMessageListener("ElemHideHelper:Shutdown", shutdown);
+ });
+
+ init();
+})(this);

Powered by Google App Engine
This is Rietveld