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-06-29 01:57:24 +03:00
|
|
|
/* global 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 () {
|
|
|
|
let Cu = Components.utils;
|
|
|
|
let { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
|
|
|
|
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
|
|
|
|
const { dumpn } = DevToolsUtils;
|
|
|
|
const { DebuggerServer, ActorPool } = require("devtools/server/main");
|
2014-12-06 02:40:10 +03:00
|
|
|
|
2016-06-29 01:57:24 +03:00
|
|
|
// Note that this frame script may be evaluated in non-e10s build. In such case,
|
|
|
|
// DebuggerServer is already going to be initialized.
|
2016-05-17 21:25:54 +03:00
|
|
|
if (!DebuggerServer.initialized) {
|
|
|
|
DebuggerServer.init();
|
|
|
|
DebuggerServer.isInChildProcess = true;
|
|
|
|
}
|
2013-07-24 19:28:32 +04:00
|
|
|
|
2016-06-29 01:57:24 +03: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.
|
2016-05-17 21:25:54 +03:00
|
|
|
DebuggerServer.addChildActors();
|
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
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
let actor = new DebuggerServer.ContentActor(conn, chromeGlobal, prefix);
|
|
|
|
let actorPool = new ActorPool(conn);
|
|
|
|
actorPool.addActor(actor);
|
|
|
|
conn.addActorPool(actorPool);
|
2014-02-03 18:43:28 +04:00
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
sendAsyncMessage("debug:actor", {actor: actor.form(), prefix: prefix});
|
|
|
|
});
|
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-05-17 21:25:54 +03:00
|
|
|
if (!setupChild in m) {
|
2016-06-29 01:57:24 +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) {
|
|
|
|
removeMessageListener("debug:disconnect", onDisconnect);
|
2014-04-02 23:29:40 +04:00
|
|
|
|
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-05-17 21:25:54 +03:00
|
|
|
let prefix = msg.data.prefix;
|
|
|
|
let conn = connections.get(prefix);
|
|
|
|
if (conn) {
|
|
|
|
conn.close();
|
|
|
|
connections.delete(prefix);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
addMessageListener("debug:disconnect", onDisconnect);
|
2014-09-30 00:05:22 +04:00
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
let onInspect = DevToolsUtils.makeInfallible(function (msg) {
|
2016-06-29 01:57:24 +03:00
|
|
|
// Store the node to be inspected in a global variable (gInspectingNode). Later
|
|
|
|
// we'll fetch this variable again using the findInspectingNode request over the
|
|
|
|
// remote debugging protocol.
|
2016-05-17 21:25:54 +03:00
|
|
|
let inspector = require("devtools/server/actors/inspector");
|
|
|
|
inspector.setInspectingNode(msg.objects.node);
|
|
|
|
});
|
|
|
|
addMessageListener("debug:inspect", onInspect);
|
|
|
|
})();
|
|
|
|
} 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
|
|
|
}
|