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: "use strict"; michael@0: michael@0: let chromeGlobal = this; michael@0: michael@0: // Encapsulate in its own scope to allows loading this frame script michael@0: // more than once. michael@0: (function () { michael@0: let Cu = Components.utils; michael@0: let { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); michael@0: const DevToolsUtils = devtools.require("devtools/toolkit/DevToolsUtils.js"); michael@0: const {DebuggerServer, ActorPool} = Cu.import("resource://gre/modules/devtools/dbg-server.jsm", {}); michael@0: michael@0: if (!DebuggerServer.initialized) { michael@0: DebuggerServer.init(); michael@0: } michael@0: michael@0: // In case of apps being loaded in parent process, DebuggerServer is already michael@0: // initialized, but child specific actors are not registered. michael@0: // Otherwise, for apps in child process, we need to load actors the first michael@0: // time we load child.js michael@0: DebuggerServer.addChildActors(); michael@0: michael@0: let conn; michael@0: michael@0: let onConnect = DevToolsUtils.makeInfallible(function (msg) { michael@0: removeMessageListener("debug:connect", onConnect); michael@0: michael@0: let mm = msg.target; michael@0: michael@0: conn = DebuggerServer.connectToParent(msg.data.prefix, mm); michael@0: michael@0: let actor = new DebuggerServer.ContentActor(conn, chromeGlobal); michael@0: let actorPool = new ActorPool(conn); michael@0: actorPool.addActor(actor); michael@0: conn.addActorPool(actorPool); michael@0: michael@0: sendAsyncMessage("debug:actor", {actor: actor.grip()}); michael@0: }); michael@0: michael@0: addMessageListener("debug:connect", onConnect); michael@0: michael@0: let onDisconnect = DevToolsUtils.makeInfallible(function (msg) { michael@0: removeMessageListener("debug:disconnect", onDisconnect); michael@0: michael@0: // Call DebuggerServerConnection.close to destroy all child actors michael@0: // (It should end up calling DebuggerServerConnection.onClosed michael@0: // that would actually cleanup all actor pools) michael@0: conn.close(); michael@0: conn = null; michael@0: }); michael@0: addMessageListener("debug:disconnect", onDisconnect); michael@0: })();