Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 let chromeGlobal = this;
9 // Encapsulate in its own scope to allows loading this frame script
10 // more than once.
11 (function () {
12 let Cu = Components.utils;
13 let { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
14 const DevToolsUtils = devtools.require("devtools/toolkit/DevToolsUtils.js");
15 const {DebuggerServer, ActorPool} = Cu.import("resource://gre/modules/devtools/dbg-server.jsm", {});
17 if (!DebuggerServer.initialized) {
18 DebuggerServer.init();
19 }
21 // In case of apps being loaded in parent process, DebuggerServer is already
22 // initialized, but child specific actors are not registered.
23 // Otherwise, for apps in child process, we need to load actors the first
24 // time we load child.js
25 DebuggerServer.addChildActors();
27 let conn;
29 let onConnect = DevToolsUtils.makeInfallible(function (msg) {
30 removeMessageListener("debug:connect", onConnect);
32 let mm = msg.target;
34 conn = DebuggerServer.connectToParent(msg.data.prefix, mm);
36 let actor = new DebuggerServer.ContentActor(conn, chromeGlobal);
37 let actorPool = new ActorPool(conn);
38 actorPool.addActor(actor);
39 conn.addActorPool(actorPool);
41 sendAsyncMessage("debug:actor", {actor: actor.grip()});
42 });
44 addMessageListener("debug:connect", onConnect);
46 let onDisconnect = DevToolsUtils.makeInfallible(function (msg) {
47 removeMessageListener("debug:disconnect", onDisconnect);
49 // Call DebuggerServerConnection.close to destroy all child actors
50 // (It should end up calling DebuggerServerConnection.onClosed
51 // that would actually cleanup all actor pools)
52 conn.close();
53 conn = null;
54 });
55 addMessageListener("debug:disconnect", onDisconnect);
56 })();