OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
5 const Cc = Components.classes; | 5 const Cc = Components.classes; |
6 const Ci = Components.interfaces; | 6 const Ci = Components.interfaces; |
7 const Cr = Components.results; | 7 const Cr = Components.results; |
8 const Cu = Components.utils; | 8 const Cu = Components.utils; |
9 | 9 |
10 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); | 10 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); |
11 | 11 |
12 Cu.importGlobalProperties(["atob", "btoa", "File", "URL", | 12 Cu.importGlobalProperties(["atob", "btoa", "File", "URL", |
13 "TextDecoder", "TextEncoder", "XMLHttpRequest"]); | 13 "TextDecoder", "TextEncoder", "XMLHttpRequest"]); |
14 | 14 |
15 let addonData = null; | 15 let addonData = null; |
16 | 16 |
17 function startup(params, reason) | 17 function startup(params, reason) |
18 { | 18 { |
19 addonData = params; | 19 addonData = params; |
20 | 20 |
21 {%- if hasChromeRequires %} | 21 {%- if hasChromeRequires %} |
22 Services.obs.addObserver(RequireObserver, "{{metadata.get('general', 'basename
')}}-require", true); | 22 Services.obs.addObserver(RequireObserver, "{{metadata.get('general', 'basename
')}}-require", true); |
23 onShutdown.add(function() | 23 onShutdown.add(function() |
24 { | 24 { |
25 Services.obs.removeObserver(RequireObserver, "{{metadata.get('general', 'bas
ename')}}-require"); | 25 Services.obs.removeObserver(RequireObserver, "{{metadata.get('general', 'bas
ename')}}-require"); |
26 }); | 26 }); |
27 {%- set hasShutdownHandlers = True %} | 27 {%- set hasShutdownHandlers = True %} |
28 {%- endif %} | 28 {%- endif %} |
29 | 29 |
| 30 {%- if hasWebExtension %} |
| 31 let port = params.webExtension.startup().then(({browser}) => |
| 32 { |
| 33 return new Promise((resolve, reject) => |
| 34 { |
| 35 browser.runtime.onConnect.addListener(resolve); |
| 36 }); |
| 37 }); |
| 38 require.scopes.webextension = {exports: port}; |
| 39 {%- endif %} |
| 40 |
30 require("main"); | 41 require("main"); |
31 } | 42 } |
32 | 43 |
33 function shutdown(params, reason) | 44 function shutdown(params, reason) |
34 { | 45 { |
35 {%- if chromeWindows %} | 46 {%- if chromeWindows %} |
36 let windowNames = {{chromeWindows|json}}; | 47 let windowNames = {{chromeWindows|json}}; |
37 for (let i = 0; i < windowNames.length; i++) | 48 for (let i = 0; i < windowNames.length; i++) |
38 { | 49 { |
39 let enumerator = Services.wm.getEnumerator(windowNames[i]); | 50 let enumerator = Services.wm.getEnumerator(windowNames[i]); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 { | 187 { |
177 if (topic == "{{metadata.get('general', 'basename')}}-require") | 188 if (topic == "{{metadata.get('general', 'basename')}}-require") |
178 { | 189 { |
179 subject.wrappedJSObject.exports = require(data); | 190 subject.wrappedJSObject.exports = require(data); |
180 } | 191 } |
181 }, | 192 }, |
182 | 193 |
183 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse
rver]) | 194 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse
rver]) |
184 }; | 195 }; |
185 {%- endif %} | 196 {%- endif %} |
OLD | NEW |