2014-02-03 18:43:28 +04: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 19:28:32 +04:00
|
|
|
|
2014-02-03 18:43:28 +04:00
|
|
|
"use strict";
|
2013-07-24 19:28:32 +04:00
|
|
|
|
2016-07-07 00:17:03 +03:00
|
|
|
/* global addEventListener, addMessageListener, removeMessageListener, sendAsyncMessage */
|
2014-09-18 13:44:00 +04:00
|
|
|
|
2016-06-29 01:57:24 +03:00
|
|
|
try {
|
2016-05-17 21:25:54 +03:00
|
|
|
var chromeGlobal = this;
|
2014-03-10 20:38:29 +04:00
|
|
|
|
2016-06-29 01:57:24 +03:00
|
|
|
// Encapsulate in its own scope to allows loading this frame script more than once.
|
2016-05-17 21:25:54 +03:00
|
|
|
(function () {
|
2016-07-07 00:17:03 +03:00
|
|
|
const Cu = Components.utils;
|
|
|
|
const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
|
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
|
|
|
|
const { dumpn } = DevToolsUtils;
|
|
|
|
const { DebuggerServer, ActorPool } = require("devtools/server/main");
|
2017-05-17 21:01:30 +03:00
|
|
|
const { ContentActor } = require("devtools/server/actors/childtab");
|
2014-12-06 02:40:10 +03:00
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
if (!DebuggerServer.initialized) {
|
|
|
|
DebuggerServer.init();
|
|
|
|
}
|
2016-12-19 14:14:12 +03:00
|
|
|
// We want a special server without any root actor and only tab actors.
|
|
|
|
// We are going to spawn a ContentActor instance in the next few lines,
|
|
|
|
// it is going to act like a root actor without being one.
|
|
|
|
DebuggerServer.registerActors({ root: false, browser: false, tab: true });
|
2013-07-24 19:28:32 +04:00
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
let connections = new Map();
|
2014-04-02 23:29:40 +04:00
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
let onConnect = DevToolsUtils.makeInfallible(function (msg) {
|
|
|
|
removeMessageListener("debug:connect", onConnect);
|
2013-07-24 19:28:32 +04:00
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
let mm = msg.target;
|
|
|
|
let prefix = msg.data.prefix;
|
2013-07-24 19:28:32 +04:00
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
let conn = DebuggerServer.connectToParent(prefix, mm);
|
|
|
|
conn.parentMessageManager = mm;
|
|
|
|
connections.set(prefix, conn);
|
2013-07-24 19:28:32 +04:00
|
|
|
|
2017-05-17 21:01:30 +03:00
|
|
|
let actor = new ContentActor(conn, chromeGlobal, prefix);
|
2016-05-17 21:25:54 +03:00
|
|
|
let actorPool = new ActorPool(conn);
|
|
|
|
actorPool.addActor(actor);
|
|
|
|
conn.addActorPool(actorPool);
|
2014-02-03 18:43:28 +04:00
|
|
|
|
2017-01-12 01:21:56 +03:00
|
|
|
sendAsyncMessage("debug:actor", {actor: actor.form(), prefix: prefix});
|
2016-05-17 21:25:54 +03:00
|
|
|
});
|
2014-02-03 18:43:28 +04:00
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
addMessageListener("debug:connect", onConnect);
|
2014-04-02 23:29:40 +04:00
|
|
|
|
2016-06-29 01:57:24 +03:00
|
|
|
// Allows executing module setup helper from the parent process.
|
|
|
|
// See also: DebuggerServer.setupInChild()
|
2016-05-17 21:25:54 +03:00
|
|
|
let onSetupInChild = DevToolsUtils.makeInfallible(msg => {
|
|
|
|
let { module, setupChild, args } = msg.data;
|
2016-06-29 01:57:24 +03:00
|
|
|
let m;
|
2014-12-06 02:40:10 +03:00
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
try {
|
|
|
|
m = require(module);
|
2014-12-06 02:40:10 +03:00
|
|
|
|
2016-12-13 00:50:10 +03:00
|
|
|
if (!(setupChild in m)) {
|
2016-08-06 03:03:12 +03:00
|
|
|
dumpn(`ERROR: module '${module}' does not export '${setupChild}'`);
|
2016-05-17 21:25:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
2014-12-06 02:40:10 +03:00
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
m[setupChild].apply(m, args);
|
|
|
|
} catch (e) {
|
2016-06-29 01:57:24 +03:00
|
|
|
let errorMessage =
|
|
|
|
"Exception during actor module setup running in the child process: ";
|
|
|
|
DevToolsUtils.reportException(errorMessage + e);
|
|
|
|
dumpn(`ERROR: ${errorMessage}\n\t module: '${module}'\n\t ` +
|
|
|
|
`setupChild: '${setupChild}'\n${DevToolsUtils.safeErrorString(e)}`);
|
2016-05-17 21:25:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (msg.data.id) {
|
2016-06-29 01:57:24 +03:00
|
|
|
// Send a message back to know when it is processed
|
|
|
|
sendAsyncMessage("debug:setup-in-child-response", {id: msg.data.id});
|
2016-05-17 21:25:54 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2014-12-06 02:40:10 +03:00
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
addMessageListener("debug:setup-in-child", onSetupInChild);
|
2014-12-06 02:40:10 +03:00
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
let onDisconnect = DevToolsUtils.makeInfallible(function (msg) {
|
2016-08-19 04:00:13 +03:00
|
|
|
let prefix = msg.data.prefix;
|
|
|
|
let conn = connections.get(prefix);
|
|
|
|
if (!conn) {
|
|
|
|
// Several copies of this frame script can be running for a single frame since it
|
|
|
|
// is loaded once for each DevTools connection to the frame. If this disconnect
|
|
|
|
// request doesn't match a connection known here, ignore it.
|
|
|
|
return;
|
|
|
|
}
|
2014-04-02 23:29:40 +04:00
|
|
|
|
2016-08-19 04:00:13 +03:00
|
|
|
removeMessageListener("debug:disconnect", onDisconnect);
|
2016-06-29 01:57:24 +03:00
|
|
|
// Call DebuggerServerConnection.close to destroy all child actors. It should end up
|
|
|
|
// calling DebuggerServerConnection.onClosed that would actually cleanup all actor
|
|
|
|
// pools.
|
2016-08-19 04:00:13 +03:00
|
|
|
conn.close();
|
|
|
|
connections.delete(prefix);
|
2016-05-17 21:25:54 +03:00
|
|
|
});
|
|
|
|
addMessageListener("debug:disconnect", onDisconnect);
|
2014-09-30 00:05:22 +04:00
|
|
|
|
2016-07-07 00:17:03 +03:00
|
|
|
// In non-e10s mode, the "debug:disconnect" message isn't always received before the
|
|
|
|
// messageManager connection goes away. Watching for "unload" here ensures we close
|
|
|
|
// any connections when the frame is unloaded.
|
|
|
|
addEventListener("unload", () => {
|
|
|
|
for (let conn of connections.values()) {
|
|
|
|
conn.close();
|
|
|
|
}
|
|
|
|
connections.clear();
|
|
|
|
});
|
2016-05-17 21:25:54 +03:00
|
|
|
})();
|
|
|
|
} catch (e) {
|
2016-06-29 01:57:24 +03:00
|
|
|
dump(`Exception in app child process: ${e}\n`);
|
2014-09-18 13:44:00 +04:00
|
|
|
}
|