1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/child.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +let chromeGlobal = this; 1.11 + 1.12 +// Encapsulate in its own scope to allows loading this frame script 1.13 +// more than once. 1.14 +(function () { 1.15 + let Cu = Components.utils; 1.16 + let { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); 1.17 + const DevToolsUtils = devtools.require("devtools/toolkit/DevToolsUtils.js"); 1.18 + const {DebuggerServer, ActorPool} = Cu.import("resource://gre/modules/devtools/dbg-server.jsm", {}); 1.19 + 1.20 + if (!DebuggerServer.initialized) { 1.21 + DebuggerServer.init(); 1.22 + } 1.23 + 1.24 + // In case of apps being loaded in parent process, DebuggerServer is already 1.25 + // initialized, but child specific actors are not registered. 1.26 + // Otherwise, for apps in child process, we need to load actors the first 1.27 + // time we load child.js 1.28 + DebuggerServer.addChildActors(); 1.29 + 1.30 + let conn; 1.31 + 1.32 + let onConnect = DevToolsUtils.makeInfallible(function (msg) { 1.33 + removeMessageListener("debug:connect", onConnect); 1.34 + 1.35 + let mm = msg.target; 1.36 + 1.37 + conn = DebuggerServer.connectToParent(msg.data.prefix, mm); 1.38 + 1.39 + let actor = new DebuggerServer.ContentActor(conn, chromeGlobal); 1.40 + let actorPool = new ActorPool(conn); 1.41 + actorPool.addActor(actor); 1.42 + conn.addActorPool(actorPool); 1.43 + 1.44 + sendAsyncMessage("debug:actor", {actor: actor.grip()}); 1.45 + }); 1.46 + 1.47 + addMessageListener("debug:connect", onConnect); 1.48 + 1.49 + let onDisconnect = DevToolsUtils.makeInfallible(function (msg) { 1.50 + removeMessageListener("debug:disconnect", onDisconnect); 1.51 + 1.52 + // Call DebuggerServerConnection.close to destroy all child actors 1.53 + // (It should end up calling DebuggerServerConnection.onClosed 1.54 + // that would actually cleanup all actor pools) 1.55 + conn.close(); 1.56 + conn = null; 1.57 + }); 1.58 + addMessageListener("debug:disconnect", onDisconnect); 1.59 +})();