b2g/simulator/lib/main.js

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial