 Issue 29362609:
  Issue 2879 - Restructure existing process script, split it up into multiple modules  (Closed) 
  Base URL: https://hg.adblockplus.org/elemhidehelper
    
  
    Issue 29362609:
  Issue 2879 - Restructure existing process script, split it up into multiple modules  (Closed) 
  Base URL: https://hg.adblockplus.org/elemhidehelper| Left: | ||
| Right: | 
| LEFT | RIGHT | 
|---|---|
| 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 "use strict"; | 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 | 8 | 
| 9 (function(messageManager) | 9 (function(messageManager) | 
| 10 { | 10 { | 
| 11 const Cc = Components.classes; | 11 const Cc = Components.classes; | 
| 12 const Ci = Components.interfaces; | 12 const Ci = Components.interfaces; | 
| 13 const Cr = Components.results; | 13 const Cr = Components.results; | 
| 14 const Cu = Components.utils; | 14 const Cu = Components.utils; | 
| 15 | 15 | 
| 16 let {Loader, main, unload} = Cu.import("resource://gre/modules/commonjs/toolki t/loader.js", {}); | 16 let {Loader, main, unload} = Cu.import( | 
| 
saroyanm
2016/11/24 17:46:10
Nit: Exceeding 80 chars.
 
Wladimir Palant
2016/12/01 09:40:49
Done.
 | |
| 17 "resource://gre/modules/commonjs/toolkit/loader.js", {} | |
| 18 ); | |
| 17 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); | 19 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); | 
| 18 | 20 | 
| 19 Cu.importGlobalProperties(["atob", "btoa", "File", "URL", "URLSearchParams", | 21 Cu.importGlobalProperties(["atob", "btoa", "File", "URL", "URLSearchParams", | 
| 20 "TextDecoder", "TextEncoder"]); | 22 "TextDecoder", "TextEncoder"]); | 
| 21 | 23 | 
| 22 let shutdownHandlers = []; | 24 let shutdownHandlers = []; | 
| 23 let onShutdown = | 25 let onShutdown = | 
| 24 { | 26 { | 
| 25 done: false, | 27 done: false, | 
| 26 add: function(handler) | 28 add: function(handler) | 
| (...skipping 17 matching lines...) Expand all Loading... | |
| 44 | 46 | 
| 45 let loader = Loader({ | 47 let loader = Loader({ | 
| 46 paths: { | 48 paths: { | 
| 47 "": info.addonRoot + "lib/" | 49 "": info.addonRoot + "lib/" | 
| 48 }, | 50 }, | 
| 49 globals: { | 51 globals: { | 
| 50 Components, Cc, Ci, Cu, Cr, atob, btoa, File, URL, URLSearchParams, | 52 Components, Cc, Ci, Cu, Cr, atob, btoa, File, URL, URLSearchParams, | 
| 51 TextDecoder, TextEncoder, onShutdown | 53 TextDecoder, TextEncoder, onShutdown | 
| 52 }, | 54 }, | 
| 53 modules: { | 55 modules: { | 
| 54 info, messageManager | 56 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 }, | 57 }, | 
| 56 id: info.addonID | 58 id: info.addonID | 
| 57 }); | 59 }); | 
| 58 onShutdown.add(() => unload(loader, "disable")) | 60 onShutdown.add(() => unload(loader, "disable")) | 
| 59 | 61 | 
| 60 main(loader, "child/main"); | 62 main(loader, "child/main"); | 
| 61 } | 63 } | 
| 62 | 64 | 
| 63 function shutdown(message) | 65 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 { | 66 { | 
| 65 if (onShutdown.done) | 67 if (onShutdown.done) | 
| 66 return; | 68 return; | 
| 67 | 69 | 
| 68 onShutdown.done = true; | 70 onShutdown.done = true; | 
| 69 for (let i = shutdownHandlers.length - 1; i >= 0; i --) | 71 for (let i = shutdownHandlers.length - 1; i >= 0; i --) | 
| 70 { | 72 { | 
| 71 try | 73 try | 
| 72 { | 74 { | 
| 73 shutdownHandlers[i](); | 75 shutdownHandlers[i](); | 
| 74 } | 76 } | 
| 75 catch (e) | 77 catch (e) | 
| 76 { | 78 { | 
| 77 Cu.reportError(e); | 79 Cu.reportError(e); | 
| 78 } | 80 } | 
| 79 } | 81 } | 
| 80 shutdownHandlers = null; | 82 shutdownHandlers = null; | 
| 81 } | 83 } | 
| 82 | 84 | 
| 83 messageManager.addMessageListener("ElemHideHelper:Shutdown", shutdown); | 85 messageManager.addMessageListener("ElemHideHelper:Shutdown", shutdown); | 
| 84 onShutdown.add(() => | 86 onShutdown.add(() => | 
| 85 { | 87 { | 
| 86 messageManager.removeMessageListener("ElemHideHelper:Shutdown", shutdown); | 88 messageManager.removeMessageListener("ElemHideHelper:Shutdown", shutdown); | 
| 87 }); | 89 }); | 
| 88 | 90 | 
| 89 init(); | 91 init(); | 
| 90 })(this); | 92 })(this); | 
| LEFT | RIGHT |