michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: const { Cc, Ci, Cu } = require("chrome"); michael@0: michael@0: const { SimulatorProcess } = require("./simulator-process"); michael@0: const { Promise: promise } = Cu.import("resource://gre/modules/Promise.jsm", {}); michael@0: const Self = require("sdk/self"); michael@0: const System = require("sdk/system"); michael@0: const { Simulator } = Cu.import("resource://gre/modules/devtools/Simulator.jsm"); michael@0: michael@0: let process; michael@0: michael@0: function launch({ port }) { michael@0: // Close already opened simulation michael@0: if (process) { michael@0: return close().then(launch.bind(null, { port: port })); michael@0: } michael@0: michael@0: process = SimulatorProcess(); michael@0: process.remoteDebuggerPort = port; michael@0: process.run(); michael@0: michael@0: return promise.resolve(); michael@0: } michael@0: michael@0: function close() { michael@0: if (!process) { michael@0: return promise.resolve(); michael@0: } michael@0: let p = process; michael@0: process = null; michael@0: return p.kill(); michael@0: } michael@0: michael@0: michael@0: // Load data generated at build time that michael@0: // expose various information about the runtime we ship michael@0: let appinfo = System.staticArgs; michael@0: michael@0: Simulator.register(appinfo.label, { michael@0: appinfo: appinfo, michael@0: launch: launch, michael@0: close: close michael@0: }); michael@0: michael@0: require("sdk/system/unload").when(function () { michael@0: Simulator.unregister(appinfo.label); michael@0: close(); michael@0: });