| 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( | 
|  | 17     "resource://gre/modules/commonjs/toolkit/loader.js", {} | 
|  | 18   ); | 
|  | 19   let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); | 
|  | 20 | 
|  | 21   Cu.importGlobalProperties(["atob", "btoa", "File", "URL", "URLSearchParams", | 
|  | 22       "TextDecoder", "TextEncoder"]); | 
|  | 23 | 
|  | 24   let shutdownHandlers = []; | 
|  | 25   let onShutdown = | 
|  | 26   { | 
|  | 27     done: false, | 
|  | 28     add: function(handler) | 
|  | 29     { | 
|  | 30       if (shutdownHandlers.indexOf(handler) < 0) | 
|  | 31         shutdownHandlers.push(handler); | 
|  | 32     }, | 
|  | 33     remove: function(handler) | 
|  | 34     { | 
|  | 35       let index = shutdownHandlers.indexOf(handler); | 
|  | 36       if (index >= 0) | 
|  | 37         shutdownHandlers.splice(index, 1); | 
|  | 38     } | 
|  | 39   }; | 
|  | 40 | 
|  | 41   function init() | 
|  | 42   { | 
|  | 43     let url = new URL(Components.stack.filename); | 
|  | 44     let params = new URLSearchParams(url.search.substr(1)); | 
|  | 45     let info = JSON.parse(params.get("info")); | 
|  | 46 | 
|  | 47     let loader = Loader({ | 
|  | 48       paths: { | 
|  | 49         "": info.addonRoot + "lib/" | 
|  | 50       }, | 
|  | 51       globals: { | 
|  | 52         Components, Cc, Ci, Cu, Cr, atob, btoa, File, URL, URLSearchParams, | 
|  | 53         TextDecoder, TextEncoder, onShutdown | 
|  | 54       }, | 
|  | 55       modules: { | 
|  | 56         info, messageManager | 
|  | 57       }, | 
|  | 58       id: info.addonID | 
|  | 59     }); | 
|  | 60     onShutdown.add(() => unload(loader, "disable")) | 
|  | 61 | 
|  | 62     main(loader, "child/main"); | 
|  | 63   } | 
|  | 64 | 
|  | 65   function shutdown(message) | 
|  | 66   { | 
|  | 67     if (onShutdown.done) | 
|  | 68       return; | 
|  | 69 | 
|  | 70     onShutdown.done = true; | 
|  | 71     for (let i = shutdownHandlers.length - 1; i >= 0; i --) | 
|  | 72     { | 
|  | 73       try | 
|  | 74       { | 
|  | 75         shutdownHandlers[i](); | 
|  | 76       } | 
|  | 77       catch (e) | 
|  | 78       { | 
|  | 79         Cu.reportError(e); | 
|  | 80       } | 
|  | 81     } | 
|  | 82     shutdownHandlers = null; | 
|  | 83   } | 
|  | 84 | 
|  | 85   messageManager.addMessageListener("ElemHideHelper:Shutdown", shutdown); | 
|  | 86   onShutdown.add(() => | 
|  | 87   { | 
|  | 88     messageManager.removeMessageListener("ElemHideHelper:Shutdown", shutdown); | 
|  | 89   }); | 
|  | 90 | 
|  | 91   init(); | 
|  | 92 })(this); | 
| OLD | NEW | 
|---|