|
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 |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
4 */ |
|
5 |
|
6 const { Cc, Ci, Cu } = require("chrome"); |
|
7 |
|
8 const { SimulatorProcess } = require("./simulator-process"); |
|
9 const { Promise: promise } = Cu.import("resource://gre/modules/Promise.jsm", {}); |
|
10 const Self = require("sdk/self"); |
|
11 const System = require("sdk/system"); |
|
12 const { Simulator } = Cu.import("resource://gre/modules/devtools/Simulator.jsm"); |
|
13 |
|
14 let process; |
|
15 |
|
16 function launch({ port }) { |
|
17 // Close already opened simulation |
|
18 if (process) { |
|
19 return close().then(launch.bind(null, { port: port })); |
|
20 } |
|
21 |
|
22 process = SimulatorProcess(); |
|
23 process.remoteDebuggerPort = port; |
|
24 process.run(); |
|
25 |
|
26 return promise.resolve(); |
|
27 } |
|
28 |
|
29 function close() { |
|
30 if (!process) { |
|
31 return promise.resolve(); |
|
32 } |
|
33 let p = process; |
|
34 process = null; |
|
35 return p.kill(); |
|
36 } |
|
37 |
|
38 |
|
39 // Load data generated at build time that |
|
40 // expose various information about the runtime we ship |
|
41 let appinfo = System.staticArgs; |
|
42 |
|
43 Simulator.register(appinfo.label, { |
|
44 appinfo: appinfo, |
|
45 launch: launch, |
|
46 close: close |
|
47 }); |
|
48 |
|
49 require("sdk/system/unload").when(function () { |
|
50 Simulator.unregister(appinfo.label); |
|
51 close(); |
|
52 }); |