2014-02-03 06:43:28 -08:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2013-07-24 08:28:32 -07:00
|
|
|
|
2014-02-03 06:43:28 -08:00
|
|
|
"use strict";
|
2013-07-24 08:28:32 -07:00
|
|
|
|
2014-03-10 09:38:29 -07:00
|
|
|
let chromeGlobal = this;
|
|
|
|
|
2014-02-03 06:43:28 -08:00
|
|
|
// Encapsulate in its own scope to allows loading this frame script
|
|
|
|
// more than once.
|
|
|
|
(function () {
|
2014-03-27 11:58:02 -07:00
|
|
|
let Cu = Components.utils;
|
2014-03-04 06:38:05 -08:00
|
|
|
let { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
|
|
|
|
const DevToolsUtils = devtools.require("devtools/toolkit/DevToolsUtils.js");
|
2014-02-03 06:43:28 -08:00
|
|
|
const {DebuggerServer, ActorPool} = Cu.import("resource://gre/modules/devtools/dbg-server.jsm", {});
|
2013-07-24 08:28:32 -07:00
|
|
|
|
2014-02-03 06:43:28 -08:00
|
|
|
if (!DebuggerServer.initialized) {
|
|
|
|
DebuggerServer.init();
|
|
|
|
}
|
2013-07-24 08:28:32 -07:00
|
|
|
|
2014-02-03 06:43:28 -08:00
|
|
|
// In case of apps being loaded in parent process, DebuggerServer is already
|
|
|
|
// initialized, but child specific actors are not registered.
|
|
|
|
// Otherwise, for apps in child process, we need to load actors the first
|
|
|
|
// time we load child.js
|
|
|
|
DebuggerServer.addChildActors();
|
2013-07-24 08:28:32 -07:00
|
|
|
|
2014-04-02 12:29:40 -07:00
|
|
|
let conn;
|
|
|
|
|
2014-02-03 06:43:28 -08:00
|
|
|
let onConnect = DevToolsUtils.makeInfallible(function (msg) {
|
|
|
|
removeMessageListener("debug:connect", onConnect);
|
2013-07-24 08:28:32 -07:00
|
|
|
|
2014-02-03 06:43:28 -08:00
|
|
|
let mm = msg.target;
|
2013-07-24 08:28:32 -07:00
|
|
|
|
2014-04-02 12:29:40 -07:00
|
|
|
conn = DebuggerServer.connectToParent(msg.data.prefix, mm);
|
2013-07-24 08:28:32 -07:00
|
|
|
|
2014-03-10 09:38:29 -07:00
|
|
|
let actor = new DebuggerServer.ContentActor(conn, chromeGlobal);
|
2014-02-03 06:43:28 -08:00
|
|
|
let actorPool = new ActorPool(conn);
|
|
|
|
actorPool.addActor(actor);
|
|
|
|
conn.addActorPool(actorPool);
|
|
|
|
|
2014-03-10 09:38:12 -07:00
|
|
|
sendAsyncMessage("debug:actor", {actor: actor.grip()});
|
2014-02-03 06:43:28 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
addMessageListener("debug:connect", onConnect);
|
2014-04-02 12:29:40 -07:00
|
|
|
|
|
|
|
let onDisconnect = DevToolsUtils.makeInfallible(function (msg) {
|
|
|
|
removeMessageListener("debug:disconnect", onDisconnect);
|
|
|
|
|
|
|
|
// Call DebuggerServerConnection.close to destroy all child actors
|
|
|
|
// (It should end up calling DebuggerServerConnection.onClosed
|
|
|
|
// that would actually cleanup all actor pools)
|
|
|
|
conn.close();
|
|
|
|
conn = null;
|
|
|
|
});
|
|
|
|
addMessageListener("debug:disconnect", onDisconnect);
|
2014-02-03 06:43:28 -08:00
|
|
|
})();
|