OLD | NEW |
(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"; |
| 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", {}); |
| 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 |
| 55 }, |
| 56 id: info.addonID |
| 57 }); |
| 58 onShutdown.add(() => unload(loader, "disable")) |
| 59 |
| 60 main(loader, "child/main"); |
| 61 } |
| 62 |
| 63 function shutdown(message) |
| 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); |
OLD | NEW |