|
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/. */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 let chromeGlobal = this; |
|
8 |
|
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", {}); |
|
16 |
|
17 if (!DebuggerServer.initialized) { |
|
18 DebuggerServer.init(); |
|
19 } |
|
20 |
|
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(); |
|
26 |
|
27 let conn; |
|
28 |
|
29 let onConnect = DevToolsUtils.makeInfallible(function (msg) { |
|
30 removeMessageListener("debug:connect", onConnect); |
|
31 |
|
32 let mm = msg.target; |
|
33 |
|
34 conn = DebuggerServer.connectToParent(msg.data.prefix, mm); |
|
35 |
|
36 let actor = new DebuggerServer.ContentActor(conn, chromeGlobal); |
|
37 let actorPool = new ActorPool(conn); |
|
38 actorPool.addActor(actor); |
|
39 conn.addActorPool(actorPool); |
|
40 |
|
41 sendAsyncMessage("debug:actor", {actor: actor.grip()}); |
|
42 }); |
|
43 |
|
44 addMessageListener("debug:connect", onConnect); |
|
45 |
|
46 let onDisconnect = DevToolsUtils.makeInfallible(function (msg) { |
|
47 removeMessageListener("debug:disconnect", onDisconnect); |
|
48 |
|
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 })(); |