toolkit/devtools/server/child.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 "use strict";
michael@0 6
michael@0 7 let chromeGlobal = this;
michael@0 8
michael@0 9 // Encapsulate in its own scope to allows loading this frame script
michael@0 10 // more than once.
michael@0 11 (function () {
michael@0 12 let Cu = Components.utils;
michael@0 13 let { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
michael@0 14 const DevToolsUtils = devtools.require("devtools/toolkit/DevToolsUtils.js");
michael@0 15 const {DebuggerServer, ActorPool} = Cu.import("resource://gre/modules/devtools/dbg-server.jsm", {});
michael@0 16
michael@0 17 if (!DebuggerServer.initialized) {
michael@0 18 DebuggerServer.init();
michael@0 19 }
michael@0 20
michael@0 21 // In case of apps being loaded in parent process, DebuggerServer is already
michael@0 22 // initialized, but child specific actors are not registered.
michael@0 23 // Otherwise, for apps in child process, we need to load actors the first
michael@0 24 // time we load child.js
michael@0 25 DebuggerServer.addChildActors();
michael@0 26
michael@0 27 let conn;
michael@0 28
michael@0 29 let onConnect = DevToolsUtils.makeInfallible(function (msg) {
michael@0 30 removeMessageListener("debug:connect", onConnect);
michael@0 31
michael@0 32 let mm = msg.target;
michael@0 33
michael@0 34 conn = DebuggerServer.connectToParent(msg.data.prefix, mm);
michael@0 35
michael@0 36 let actor = new DebuggerServer.ContentActor(conn, chromeGlobal);
michael@0 37 let actorPool = new ActorPool(conn);
michael@0 38 actorPool.addActor(actor);
michael@0 39 conn.addActorPool(actorPool);
michael@0 40
michael@0 41 sendAsyncMessage("debug:actor", {actor: actor.grip()});
michael@0 42 });
michael@0 43
michael@0 44 addMessageListener("debug:connect", onConnect);
michael@0 45
michael@0 46 let onDisconnect = DevToolsUtils.makeInfallible(function (msg) {
michael@0 47 removeMessageListener("debug:disconnect", onDisconnect);
michael@0 48
michael@0 49 // Call DebuggerServerConnection.close to destroy all child actors
michael@0 50 // (It should end up calling DebuggerServerConnection.onClosed
michael@0 51 // that would actually cleanup all actor pools)
michael@0 52 conn.close();
michael@0 53 conn = null;
michael@0 54 });
michael@0 55 addMessageListener("debug:disconnect", onDisconnect);
michael@0 56 })();

mercurial