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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
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
4 * http://mozilla.org/MPL/2.0/.
5 */
6
7 "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.
8
9 (function(messageManager)
10 {
11 const Cc = Components.classes;
12 const Ci = Components.interfaces;
13 const Cr = Components.results;
14 const Cu = Components.utils;
15
16 let {Loader, main, unload} = Cu.import("resource://gre/modules/commonjs/toolki t/loader.js", {});
saroyanm 2016/11/24 17:46:10 Nit: Exceeding 80 chars.
Wladimir Palant 2016/12/01 09:40:49 Done.
17 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
18
19 Cu.importGlobalProperties(["atob", "btoa", "File", "URL", "URLSearchParams",
20 "TextDecoder", "TextEncoder"]);
21
22 let shutdownHandlers = [];
23 let onShutdown =
24 {
25 done: false,
26 add: function(handler)
27 {
28 if (shutdownHandlers.indexOf(handler) < 0)
29 shutdownHandlers.push(handler);
30 },
31 remove: function(handler)
32 {
33 let index = shutdownHandlers.indexOf(handler);
34 if (index >= 0)
35 shutdownHandlers.splice(index, 1);
36 }
37 };
38
39 function init()
40 {
41 let url = new URL(Components.stack.filename);
42 let params = new URLSearchParams(url.search.substr(1));
43 let info = JSON.parse(params.get("info"));
44
45 let loader = Loader({
46 paths: {
47 "": info.addonRoot + "lib/"
48 },
49 globals: {
50 Components, Cc, Ci, Cu, Cr, atob, btoa, File, URL, URLSearchParams,
51 TextDecoder, TextEncoder, onShutdown
52 },
53 modules: {
54 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
55 },
56 id: info.addonID
57 });
58 onShutdown.add(() => unload(loader, "disable"))
59
60 main(loader, "child/main");
61 }
62
63 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
64 {
65 if (onShutdown.done)
66 return;
67
68 onShutdown.done = true;
69 for (let i = shutdownHandlers.length - 1; i >= 0; i --)
70 {
71 try
72 {
73 shutdownHandlers[i]();
74 }
75 catch (e)
76 {
77 Cu.reportError(e);
78 }
79 }
80 shutdownHandlers = null;
81 }
82
83 messageManager.addMessageListener("ElemHideHelper:Shutdown", shutdown);
84 onShutdown.add(() =>
85 {
86 messageManager.removeMessageListener("ElemHideHelper:Shutdown", shutdown);
87 });
88
89 init();
90 })(this);
OLDNEW

Powered by Google App Engine
This is Rietveld