2012-05-21 15:12:37 +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/. */
|
2012-04-22 13:59:09 +04:00
|
|
|
|
|
|
|
"use strict";
|
2014-05-21 15:58:18 +04:00
|
|
|
|
2012-04-22 13:59:09 +04:00
|
|
|
/**
|
|
|
|
* Toolkit glue for the remote debugging protocol, loaded into the
|
|
|
|
* debugging global.
|
|
|
|
*/
|
2015-09-15 21:19:45 +03:00
|
|
|
var { Ci, Cc, CC, Cu, Cr } = require("chrome");
|
|
|
|
var Services = require("Services");
|
|
|
|
var { ActorPool, OriginalLocation, RegisteredActorFactory,
|
2015-03-11 17:15:40 +03:00
|
|
|
ObservedActorFactory } = require("devtools/server/actors/common");
|
2015-09-15 21:19:45 +03:00
|
|
|
var { LocalDebuggerTransport, ChildDebuggerTransport, WorkerDebuggerTransport } =
|
2015-09-21 20:04:18 +03:00
|
|
|
require("devtools/shared/transport/transport");
|
|
|
|
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
|
2015-11-16 18:22:49 +03:00
|
|
|
var { dumpn, dumpv } = DevToolsUtils;
|
2016-08-06 00:41:01 +03:00
|
|
|
var flags = require("devtools/shared/flags");
|
2015-09-21 20:04:18 +03:00
|
|
|
var EventEmitter = require("devtools/shared/event-emitter");
|
2015-09-15 21:19:45 +03:00
|
|
|
var Promise = require("promise");
|
2016-06-29 03:42:30 +03:00
|
|
|
var SyncPromise = require("devtools/shared/deprecated-sync-thenables");
|
2012-04-22 13:59:09 +04:00
|
|
|
|
2014-12-02 09:55:56 +03:00
|
|
|
DevToolsUtils.defineLazyGetter(this, "DebuggerSocket", () => {
|
2015-09-21 20:04:18 +03:00
|
|
|
let { DebuggerSocket } = require("devtools/shared/security/socket");
|
2014-12-02 09:55:56 +03:00
|
|
|
return DebuggerSocket;
|
|
|
|
});
|
2015-01-26 21:47:13 +03:00
|
|
|
DevToolsUtils.defineLazyGetter(this, "Authentication", () => {
|
2015-09-21 20:04:18 +03:00
|
|
|
return require("devtools/shared/security/auth");
|
2015-01-26 21:47:13 +03:00
|
|
|
});
|
2015-11-19 20:51:21 +03:00
|
|
|
DevToolsUtils.defineLazyGetter(this, "generateUUID", () => {
|
2016-06-29 03:42:30 +03:00
|
|
|
let { generateUUID } = Cc["@mozilla.org/uuid-generator;1"]
|
|
|
|
.getService(Ci.nsIUUIDGenerator);
|
2015-11-19 20:51:21 +03:00
|
|
|
return generateUUID;
|
|
|
|
});
|
2014-12-02 09:55:56 +03:00
|
|
|
|
2014-01-07 00:55:00 +04:00
|
|
|
// On B2G, `this` != Global scope, so `Ci` won't be binded on `this`
|
|
|
|
// (i.e. this.Ci is undefined) Then later, when using loadSubScript,
|
|
|
|
// Ci,... won't be defined for sub scripts.
|
|
|
|
this.Ci = Ci;
|
|
|
|
this.Cc = Cc;
|
|
|
|
this.CC = CC;
|
|
|
|
this.Cu = Cu;
|
|
|
|
this.Cr = Cr;
|
2014-03-13 19:01:32 +04:00
|
|
|
this.Services = Services;
|
2014-04-24 15:13:12 +04:00
|
|
|
this.ActorPool = ActorPool;
|
2014-04-17 22:45:32 +04:00
|
|
|
this.DevToolsUtils = DevToolsUtils;
|
2014-04-17 22:47:28 +04:00
|
|
|
this.dumpn = dumpn;
|
2014-05-14 23:30:02 +04:00
|
|
|
this.dumpv = dumpv;
|
2014-03-04 18:38:05 +04:00
|
|
|
|
2014-01-07 00:55:00 +04:00
|
|
|
// Overload `Components` to prevent SDK loader exception on Components
|
|
|
|
// object usage
|
|
|
|
Object.defineProperty(this, "Components", {
|
2016-06-29 03:42:30 +03:00
|
|
|
get() {
|
2015-05-28 18:54:00 +03:00
|
|
|
return require("chrome").components;
|
|
|
|
}
|
2014-01-07 00:55:00 +04:00
|
|
|
});
|
2013-08-31 04:34:26 +04:00
|
|
|
|
2014-06-17 23:51:43 +04:00
|
|
|
if (isWorker) {
|
2016-08-06 00:41:01 +03:00
|
|
|
flags.wantLogging = true;
|
|
|
|
flags.wantVerbose = true;
|
2014-06-17 23:51:43 +04:00
|
|
|
} else {
|
|
|
|
const LOG_PREF = "devtools.debugger.log";
|
|
|
|
const VERBOSE_PREF = "devtools.debugger.log.verbose";
|
|
|
|
|
2016-08-06 00:41:01 +03:00
|
|
|
flags.wantLogging = Services.prefs.getBoolPref(LOG_PREF);
|
|
|
|
flags.wantVerbose =
|
2014-06-17 23:51:43 +04:00
|
|
|
Services.prefs.getPrefType(VERBOSE_PREF) !== Services.prefs.PREF_INVALID &&
|
|
|
|
Services.prefs.getBoolPref(VERBOSE_PREF);
|
|
|
|
}
|
2012-04-22 13:59:09 +04:00
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
function loadSubScript(url) {
|
2013-08-28 18:19:34 +04:00
|
|
|
try {
|
|
|
|
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
2016-06-29 03:42:30 +03:00
|
|
|
.getService(Ci.mozIJSSubScriptLoader);
|
|
|
|
loader.loadSubScript(url, this);
|
2016-05-17 21:25:54 +03:00
|
|
|
} catch (e) {
|
2016-06-29 03:42:30 +03:00
|
|
|
let errorStr = "Error loading: " + url + ":\n" +
|
2014-03-22 12:02:13 +04:00
|
|
|
(e.fileName ? "at " + e.fileName + " : " + e.lineNumber + "\n" : "") +
|
|
|
|
e + " - " + e.stack + "\n";
|
2013-08-28 18:19:34 +04:00
|
|
|
dump(errorStr);
|
2014-05-30 18:42:55 +04:00
|
|
|
reportError(errorStr);
|
2013-08-28 18:19:34 +04:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 18:48:00 +03:00
|
|
|
loader.lazyRequireGetter(this, "events", "sdk/event/core");
|
|
|
|
|
2013-06-07 03:06:08 +04:00
|
|
|
var gRegisteredModules = Object.create(null);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The ModuleAPI object is passed to modules loaded using the
|
|
|
|
* DebuggerServer.registerModule() API. Modules can use this
|
|
|
|
* object to register actor factories.
|
|
|
|
* Factories registered through the module API will be removed
|
|
|
|
* when the module is unregistered or when the server is
|
|
|
|
* destroyed.
|
|
|
|
*/
|
|
|
|
function ModuleAPI() {
|
|
|
|
let activeTabActors = new Set();
|
|
|
|
let activeGlobalActors = new Set();
|
|
|
|
|
|
|
|
return {
|
2014-05-13 23:56:30 +04:00
|
|
|
// See DebuggerServer.setRootActor for a description.
|
2016-06-29 03:42:30 +03:00
|
|
|
setRootActor(factory) {
|
2014-05-13 23:56:30 +04:00
|
|
|
DebuggerServer.setRootActor(factory);
|
|
|
|
},
|
|
|
|
|
2013-06-07 03:06:08 +04:00
|
|
|
// See DebuggerServer.addGlobalActor for a description.
|
2016-06-29 03:42:30 +03:00
|
|
|
addGlobalActor(factory, name) {
|
2013-06-07 03:06:08 +04:00
|
|
|
DebuggerServer.addGlobalActor(factory, name);
|
|
|
|
activeGlobalActors.add(factory);
|
|
|
|
},
|
|
|
|
// See DebuggerServer.removeGlobalActor for a description.
|
2016-06-29 03:42:30 +03:00
|
|
|
removeGlobalActor(factory) {
|
2013-06-07 03:06:08 +04:00
|
|
|
DebuggerServer.removeGlobalActor(factory);
|
|
|
|
activeGlobalActors.delete(factory);
|
|
|
|
},
|
|
|
|
|
|
|
|
// See DebuggerServer.addTabActor for a description.
|
2016-06-29 03:42:30 +03:00
|
|
|
addTabActor(factory, name) {
|
2013-06-07 03:06:08 +04:00
|
|
|
DebuggerServer.addTabActor(factory, name);
|
|
|
|
activeTabActors.add(factory);
|
|
|
|
},
|
|
|
|
// See DebuggerServer.removeTabActor for a description.
|
2016-06-29 03:42:30 +03:00
|
|
|
removeTabActor(factory) {
|
2013-06-07 03:06:08 +04:00
|
|
|
DebuggerServer.removeTabActor(factory);
|
|
|
|
activeTabActors.delete(factory);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Destroy the module API object, unregistering any
|
|
|
|
// factories registered by the module.
|
2016-06-29 03:42:30 +03:00
|
|
|
destroy() {
|
2013-06-07 03:06:08 +04:00
|
|
|
for (let factory of activeTabActors) {
|
|
|
|
DebuggerServer.removeTabActor(factory);
|
|
|
|
}
|
|
|
|
activeTabActors = null;
|
|
|
|
for (let factory of activeGlobalActors) {
|
|
|
|
DebuggerServer.removeGlobalActor(factory);
|
|
|
|
}
|
|
|
|
activeGlobalActors = null;
|
|
|
|
}
|
2014-11-27 13:52:00 +03:00
|
|
|
};
|
2016-05-17 21:25:54 +03:00
|
|
|
}
|
2013-06-07 03:06:08 +04:00
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
/** *
|
2012-04-22 13:59:09 +04:00
|
|
|
* Public API
|
|
|
|
*/
|
|
|
|
var DebuggerServer = {
|
2014-07-10 22:15:00 +04:00
|
|
|
_listeners: [],
|
2013-05-04 05:21:48 +04:00
|
|
|
_initialized: false,
|
2012-09-20 10:36:32 +04:00
|
|
|
// Map of global actor names to actor constructors provided by extensions.
|
2013-05-04 05:21:48 +04:00
|
|
|
globalActorFactories: {},
|
2012-09-20 10:36:32 +04:00
|
|
|
// Map of tab actor names to actor constructors provided by extensions.
|
2013-05-04 05:21:48 +04:00
|
|
|
tabActorFactories: {},
|
2012-04-22 13:59:09 +04:00
|
|
|
|
2012-08-31 01:10:07 +04:00
|
|
|
LONG_STRING_LENGTH: 10000,
|
|
|
|
LONG_STRING_INITIAL_LENGTH: 1000,
|
2013-11-07 01:39:50 +04:00
|
|
|
LONG_STRING_READ_LENGTH: 65 * 1024,
|
2012-08-31 01:10:07 +04:00
|
|
|
|
2013-08-01 12:51:24 +04:00
|
|
|
/**
|
|
|
|
* The windowtype of the chrome window to use for actors that use the global
|
|
|
|
* window (i.e the global style editor). Set this to your main window type,
|
|
|
|
* for example "navigator:browser".
|
|
|
|
*/
|
|
|
|
chromeWindowType: null,
|
|
|
|
|
2015-03-04 07:47:00 +03:00
|
|
|
/**
|
|
|
|
* Allow debugging chrome of (parent or child) processes.
|
|
|
|
*/
|
|
|
|
allowChromeProcess: false,
|
|
|
|
|
2012-04-22 13:59:09 +04:00
|
|
|
/**
|
|
|
|
* Initialize the debugger server.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
init() {
|
2012-04-22 13:59:09 +04:00
|
|
|
if (this.initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-06 03:54:19 +03:00
|
|
|
this._connections = {};
|
|
|
|
this._nextConnID = 0;
|
2012-09-20 10:36:32 +04:00
|
|
|
|
2013-05-04 05:21:48 +04:00
|
|
|
this._initialized = true;
|
2012-04-22 13:59:09 +04:00
|
|
|
},
|
|
|
|
|
2015-05-28 18:54:00 +03:00
|
|
|
get protocol() {
|
2016-05-06 10:19:00 +03:00
|
|
|
return require("devtools/shared/protocol");
|
2015-05-28 18:54:00 +03:00
|
|
|
},
|
2014-04-18 03:25:07 +04:00
|
|
|
|
2015-05-28 18:54:00 +03:00
|
|
|
get initialized() {
|
|
|
|
return this._initialized;
|
|
|
|
},
|
2012-09-20 10:36:32 +04:00
|
|
|
|
|
|
|
/**
|
2013-07-12 23:13:21 +04:00
|
|
|
* Performs cleanup tasks before shutting down the debugger server. Such tasks
|
|
|
|
* include clearing any actor constructors added at runtime. This method
|
|
|
|
* should be called whenever a debugger server is no longer useful, to avoid
|
|
|
|
* memory leaks. After this method returns, the debugger server must be
|
|
|
|
* initialized again before use.
|
2012-09-20 10:36:32 +04:00
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
destroy() {
|
2013-05-30 20:42:00 +04:00
|
|
|
if (!this._initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let connID of Object.getOwnPropertyNames(this._connections)) {
|
|
|
|
this._connections[connID].close();
|
2012-09-20 10:36:32 +04:00
|
|
|
}
|
2013-06-07 03:06:08 +04:00
|
|
|
|
|
|
|
for (let id of Object.getOwnPropertyNames(gRegisteredModules)) {
|
2014-09-16 14:00:00 +04:00
|
|
|
this.unregisterModule(id);
|
2013-06-07 03:06:08 +04:00
|
|
|
}
|
2014-11-27 13:52:00 +03:00
|
|
|
gRegisteredModules = Object.create(null);
|
2013-06-07 03:06:08 +04:00
|
|
|
|
2014-07-10 22:15:00 +04:00
|
|
|
this.closeAllListeners();
|
2013-05-30 20:42:00 +04:00
|
|
|
this.globalActorFactories = {};
|
|
|
|
this.tabActorFactories = {};
|
|
|
|
this._initialized = false;
|
2013-09-08 03:28:51 +04:00
|
|
|
|
2013-05-30 20:42:00 +04:00
|
|
|
dumpn("Debugger server is shut down.");
|
2012-09-20 10:36:32 +04:00
|
|
|
},
|
2012-04-22 13:59:09 +04:00
|
|
|
|
2015-01-06 02:41:29 +03:00
|
|
|
/**
|
|
|
|
* Raises an exception if the server has not been properly initialized.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
_checkInit() {
|
2015-01-06 03:54:19 +03:00
|
|
|
if (!this._initialized) {
|
2016-06-29 03:42:30 +03:00
|
|
|
throw new Error("DebuggerServer has not been initialized.");
|
2015-01-06 02:41:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.createRootActor) {
|
2016-06-29 03:42:30 +03:00
|
|
|
throw new Error("Use DebuggerServer.addActors() to add a root actor " +
|
|
|
|
"implementation.");
|
2015-01-06 02:41:29 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-04-22 13:59:09 +04:00
|
|
|
/**
|
|
|
|
* Load a subscript into the debugging global.
|
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param url string A url that will be loaded as a subscript into the
|
2012-04-22 13:59:09 +04:00
|
|
|
* debugging global. The user must load at least one script
|
|
|
|
* that implements a createRootActor() function to create the
|
|
|
|
* server's root actor.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
addActors(url) {
|
|
|
|
loadSubScript.call(this, url);
|
2012-04-22 13:59:09 +04:00
|
|
|
},
|
|
|
|
|
2013-06-07 03:06:08 +04:00
|
|
|
/**
|
|
|
|
* Register a CommonJS module with the debugger server.
|
|
|
|
* @param id string
|
2014-09-16 14:00:00 +04:00
|
|
|
* The ID of a CommonJS module. This module must export 'register'
|
|
|
|
* and 'unregister' functions if no `options` argument is given.
|
|
|
|
* If `options` is set, the actor is going to be registered
|
|
|
|
* immediately, but loaded only when a client starts sending packets
|
|
|
|
* to an actor with the same id.
|
|
|
|
*
|
|
|
|
* @param options object (optional)
|
|
|
|
* This parameter is still optional, but not providing it is
|
|
|
|
* deprecated and will result in eagerly loading the actor module
|
|
|
|
* with the memory overhead that entails.
|
|
|
|
* An object with 3 mandatory attributes:
|
|
|
|
* - prefix (string):
|
|
|
|
* The prefix of an actor is used to compute:
|
|
|
|
* - the `actorID` of each new actor instance (ex: prefix1).
|
|
|
|
* (See ActorPool.addActor)
|
|
|
|
* - the actor name in the listTabs request. Sending a listTabs
|
|
|
|
* request to the root actor returns actor IDs. IDs are in
|
|
|
|
* dictionaries, with actor names as keys and actor IDs as values.
|
|
|
|
* The actor name is the prefix to which the "Actor" string is
|
|
|
|
* appended. So for an actor with the `console` prefix, the actor
|
|
|
|
* name will be `consoleActor`.
|
|
|
|
* - constructor (string):
|
|
|
|
* the name of the exported symbol to be used as the actor
|
|
|
|
* constructor.
|
2014-10-03 15:49:00 +04:00
|
|
|
* - type (a dictionary of booleans with following attribute names):
|
2014-09-16 14:00:00 +04:00
|
|
|
* - "global"
|
|
|
|
* registers a global actor instance, if true.
|
|
|
|
* A global actor has the root actor as its parent.
|
|
|
|
* - "tab"
|
|
|
|
* registers a tab actor instance, if true.
|
|
|
|
* A new actor will be created for each tab and each app.
|
2013-06-07 03:06:08 +04:00
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
registerModule(id, options) {
|
2013-06-07 03:06:08 +04:00
|
|
|
if (id in gRegisteredModules) {
|
|
|
|
throw new Error("Tried to register a module twice: " + id + "\n");
|
|
|
|
}
|
|
|
|
|
2014-09-16 14:00:00 +04:00
|
|
|
if (options) {
|
|
|
|
// Lazy loaded actors
|
|
|
|
let {prefix, constructor, type} = options;
|
2016-05-17 21:25:54 +03:00
|
|
|
if (typeof (prefix) !== "string") {
|
2016-06-29 03:42:30 +03:00
|
|
|
throw new Error(`Lazy actor definition for '${id}' requires a string ` +
|
|
|
|
`'prefix' option.`);
|
2014-09-16 14:00:00 +04:00
|
|
|
}
|
2016-05-17 21:25:54 +03:00
|
|
|
if (typeof (constructor) !== "string") {
|
2016-06-29 03:42:30 +03:00
|
|
|
throw new Error(`Lazy actor definition for '${id}' requires a string ` +
|
|
|
|
`'constructor' option.`);
|
2014-09-16 14:00:00 +04:00
|
|
|
}
|
|
|
|
if (!("global" in type) && !("tab" in type)) {
|
2016-06-29 03:42:30 +03:00
|
|
|
throw new Error(`Lazy actor definition for '${id}' requires a dictionary ` +
|
|
|
|
`'type' option whose attributes can be 'global' or 'tab'.`);
|
2014-09-16 14:00:00 +04:00
|
|
|
}
|
|
|
|
let name = prefix + "Actor";
|
|
|
|
let mod = {
|
|
|
|
id: id,
|
|
|
|
prefix: prefix,
|
|
|
|
constructorName: constructor,
|
|
|
|
type: type,
|
|
|
|
globalActor: type.global,
|
|
|
|
tabActor: type.tab
|
|
|
|
};
|
|
|
|
gRegisteredModules[id] = mod;
|
|
|
|
if (mod.tabActor) {
|
|
|
|
this.addTabActor(mod, name);
|
|
|
|
}
|
|
|
|
if (mod.globalActor) {
|
|
|
|
this.addGlobalActor(mod, name);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Deprecated actors being loaded at startup
|
|
|
|
let moduleAPI = ModuleAPI();
|
|
|
|
let mod = require(id);
|
|
|
|
mod.register(moduleAPI);
|
|
|
|
gRegisteredModules[id] = {
|
|
|
|
module: mod,
|
|
|
|
api: moduleAPI
|
|
|
|
};
|
|
|
|
}
|
2013-06-07 03:06:08 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if a module id has been registered.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
isModuleRegistered(id) {
|
2013-06-07 03:06:08 +04:00
|
|
|
return (id in gRegisteredModules);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregister a previously-loaded CommonJS module from the debugger server.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
unregisterModule(id) {
|
2013-06-07 03:06:08 +04:00
|
|
|
let mod = gRegisteredModules[id];
|
|
|
|
if (!mod) {
|
|
|
|
throw new Error("Tried to unregister a module that was not previously registered.");
|
|
|
|
}
|
2014-09-16 14:00:00 +04:00
|
|
|
|
|
|
|
// Lazy actors
|
|
|
|
if (mod.tabActor) {
|
|
|
|
this.removeTabActor(mod);
|
|
|
|
}
|
|
|
|
if (mod.globalActor) {
|
|
|
|
this.removeGlobalActor(mod);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mod.module) {
|
|
|
|
// Deprecated non-lazy module API
|
|
|
|
mod.module.unregister(mod.api);
|
|
|
|
mod.api.destroy();
|
|
|
|
}
|
|
|
|
|
2013-06-07 03:06:08 +04:00
|
|
|
delete gRegisteredModules[id];
|
|
|
|
},
|
|
|
|
|
2012-04-22 13:59:09 +04:00
|
|
|
/**
|
|
|
|
* Install Firefox-specific actors.
|
2014-03-03 23:11:00 +04:00
|
|
|
*
|
|
|
|
* /!\ Be careful when adding a new actor, especially global actors.
|
|
|
|
* Any new global actor will be exposed and returned by the root actor.
|
|
|
|
*
|
|
|
|
* That's the reason why tab actors aren't loaded on demand via
|
|
|
|
* restrictPrivileges=true, to prevent exposing them on b2g parent process's
|
|
|
|
* root actor.
|
2012-04-22 13:59:09 +04:00
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
addBrowserActors(windowType = "navigator:browser", restrictPrivileges = false) {
|
|
|
|
this.chromeWindowType = windowType;
|
2014-05-13 23:56:30 +04:00
|
|
|
this.registerModule("devtools/server/actors/webbrowser");
|
2014-01-24 14:11:00 +04:00
|
|
|
|
|
|
|
if (!restrictPrivileges) {
|
|
|
|
this.addTabActors();
|
2014-09-16 14:00:00 +04:00
|
|
|
this.registerModule("devtools/server/actors/preference", {
|
|
|
|
prefix: "preference",
|
|
|
|
constructor: "PreferenceActor",
|
|
|
|
type: { global: true }
|
|
|
|
});
|
2014-10-03 15:49:00 +04:00
|
|
|
this.registerModule("devtools/server/actors/actor-registry", {
|
|
|
|
prefix: "actorRegistry",
|
|
|
|
constructor: "ActorRegistryActor",
|
|
|
|
type: { global: true }
|
|
|
|
});
|
2014-01-24 14:11:00 +04:00
|
|
|
}
|
2015-11-19 20:51:22 +03:00
|
|
|
if (Services.prefs.getBoolPref("dom.mozSettings.enabled")) {
|
2015-01-22 19:21:00 +03:00
|
|
|
this.registerModule("devtools/server/actors/settings", {
|
|
|
|
prefix: "settings",
|
|
|
|
constructor: "SettingsActor",
|
|
|
|
type: { global: true }
|
|
|
|
});
|
|
|
|
}
|
2016-05-20 19:36:04 +03:00
|
|
|
this.registerModule("devtools/server/actors/addons", {
|
|
|
|
prefix: "addons",
|
|
|
|
constructor: "AddonsActor",
|
|
|
|
type: { global: true }
|
|
|
|
});
|
2014-09-16 14:00:00 +04:00
|
|
|
this.registerModule("devtools/server/actors/device", {
|
|
|
|
prefix: "device",
|
|
|
|
constructor: "DeviceActor",
|
|
|
|
type: { global: true }
|
|
|
|
});
|
2015-01-31 18:36:00 +03:00
|
|
|
this.registerModule("devtools/server/actors/director-registry", {
|
|
|
|
prefix: "directorRegistry",
|
|
|
|
constructor: "DirectorRegistryActor",
|
|
|
|
type: { global: true }
|
|
|
|
});
|
2015-09-26 01:35:02 +03:00
|
|
|
this.registerModule("devtools/server/actors/heap-snapshot-file", {
|
|
|
|
prefix: "heapSnapshotFile",
|
|
|
|
constructor: "HeapSnapshotFileActor",
|
|
|
|
type: { global: true }
|
|
|
|
});
|
2012-04-22 13:59:09 +04:00
|
|
|
},
|
|
|
|
|
2013-07-24 19:28:32 +04:00
|
|
|
/**
|
|
|
|
* Install tab actors in documents loaded in content childs
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
addChildActors() {
|
2013-07-24 19:28:32 +04:00
|
|
|
// In case of apps being loaded in parent process, DebuggerServer is already
|
|
|
|
// initialized and browser actors are already loaded,
|
|
|
|
// but childtab.js hasn't been loaded yet.
|
2014-04-23 12:38:00 +04:00
|
|
|
if (!DebuggerServer.tabActorFactories.hasOwnProperty("consoleActor")) {
|
2014-03-03 23:11:00 +04:00
|
|
|
this.addTabActors();
|
|
|
|
}
|
|
|
|
// But webbrowser.js and childtab.js aren't loaded from shell.js.
|
2014-05-13 23:56:30 +04:00
|
|
|
if (!this.isModuleRegistered("devtools/server/actors/webbrowser")) {
|
|
|
|
this.registerModule("devtools/server/actors/webbrowser");
|
2013-07-24 19:28:32 +04:00
|
|
|
}
|
2014-03-10 20:38:17 +04:00
|
|
|
if (!("ContentActor" in this)) {
|
2015-10-14 02:18:43 +03:00
|
|
|
this.addActors("resource://devtools/server/actors/childtab.js");
|
2013-07-24 19:28:32 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-01-24 14:11:00 +04:00
|
|
|
/**
|
|
|
|
* Install tab actors.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
addTabActors() {
|
2014-09-16 14:00:00 +04:00
|
|
|
this.registerModule("devtools/server/actors/webconsole", {
|
|
|
|
prefix: "console",
|
|
|
|
constructor: "WebConsoleActor",
|
2015-03-04 07:47:00 +03:00
|
|
|
type: { tab: true }
|
2014-09-16 14:00:00 +04:00
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/inspector", {
|
|
|
|
prefix: "inspector",
|
|
|
|
constructor: "InspectorActor",
|
2015-03-04 07:47:00 +03:00
|
|
|
type: { tab: true }
|
2014-09-16 14:00:00 +04:00
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/call-watcher", {
|
|
|
|
prefix: "callWatcher",
|
|
|
|
constructor: "CallWatcherActor",
|
|
|
|
type: { tab: true }
|
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/canvas", {
|
|
|
|
prefix: "canvas",
|
|
|
|
constructor: "CanvasActor",
|
2015-03-04 07:47:00 +03:00
|
|
|
type: { tab: true }
|
2014-09-16 14:00:00 +04:00
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/webgl", {
|
|
|
|
prefix: "webgl",
|
|
|
|
constructor: "WebGLActor",
|
2015-03-04 07:47:00 +03:00
|
|
|
type: { tab: true }
|
2014-09-16 14:00:00 +04:00
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/webaudio", {
|
|
|
|
prefix: "webaudio",
|
|
|
|
constructor: "WebAudioActor",
|
2015-03-04 07:47:00 +03:00
|
|
|
type: { tab: true }
|
2014-09-16 14:00:00 +04:00
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/stylesheets", {
|
|
|
|
prefix: "styleSheets",
|
|
|
|
constructor: "StyleSheetsActor",
|
2015-03-04 07:47:00 +03:00
|
|
|
type: { tab: true }
|
2014-09-16 14:00:00 +04:00
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/styleeditor", {
|
|
|
|
prefix: "styleEditor",
|
|
|
|
constructor: "StyleEditorActor",
|
2015-03-04 07:47:00 +03:00
|
|
|
type: { tab: true }
|
2014-09-16 14:00:00 +04:00
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/storage", {
|
|
|
|
prefix: "storage",
|
|
|
|
constructor: "StorageActor",
|
|
|
|
type: { tab: true }
|
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/gcli", {
|
|
|
|
prefix: "gcli",
|
|
|
|
constructor: "GcliActor",
|
|
|
|
type: { tab: true }
|
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/memory", {
|
|
|
|
prefix: "memory",
|
|
|
|
constructor: "MemoryActor",
|
2015-03-04 07:47:00 +03:00
|
|
|
type: { tab: true }
|
2014-09-16 14:00:00 +04:00
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/framerate", {
|
|
|
|
prefix: "framerate",
|
|
|
|
constructor: "FramerateActor",
|
2015-03-04 07:47:00 +03:00
|
|
|
type: { tab: true }
|
2014-09-16 14:00:00 +04:00
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/eventlooplag", {
|
|
|
|
prefix: "eventLoopLag",
|
|
|
|
constructor: "EventLoopLagActor",
|
2015-03-04 07:47:00 +03:00
|
|
|
type: { tab: true }
|
2014-09-16 14:00:00 +04:00
|
|
|
});
|
2016-11-01 05:51:58 +03:00
|
|
|
this.registerModule("devtools/server/actors/reflow", {
|
2014-09-16 14:00:00 +04:00
|
|
|
prefix: "reflow",
|
|
|
|
constructor: "ReflowActor",
|
|
|
|
type: { tab: true }
|
|
|
|
});
|
2016-05-26 18:48:00 +03:00
|
|
|
this.registerModule("devtools/server/actors/css-properties", {
|
|
|
|
prefix: "cssProperties",
|
|
|
|
constructor: "CssPropertiesActor",
|
|
|
|
type: { tab: true }
|
|
|
|
});
|
2014-09-16 14:00:00 +04:00
|
|
|
this.registerModule("devtools/server/actors/csscoverage", {
|
|
|
|
prefix: "cssUsage",
|
|
|
|
constructor: "CSSUsageActor",
|
2015-03-04 07:47:00 +03:00
|
|
|
type: { tab: true }
|
2014-09-16 14:00:00 +04:00
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/monitor", {
|
|
|
|
prefix: "monitor",
|
|
|
|
constructor: "MonitorActor",
|
2015-03-04 07:47:00 +03:00
|
|
|
type: { tab: true }
|
2014-09-16 14:00:00 +04:00
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/timeline", {
|
|
|
|
prefix: "timeline",
|
|
|
|
constructor: "TimelineActor",
|
2015-03-04 07:47:00 +03:00
|
|
|
type: { tab: true }
|
2014-09-16 14:00:00 +04:00
|
|
|
});
|
2015-01-31 18:36:00 +03:00
|
|
|
this.registerModule("devtools/server/actors/director-manager", {
|
|
|
|
prefix: "directorManager",
|
|
|
|
constructor: "DirectorManagerActor",
|
|
|
|
type: { global: false, tab: true }
|
|
|
|
});
|
2014-03-29 21:01:37 +04:00
|
|
|
if ("nsIProfiler" in Ci) {
|
2014-09-16 14:00:00 +04:00
|
|
|
this.registerModule("devtools/server/actors/profiler", {
|
|
|
|
prefix: "profiler",
|
|
|
|
constructor: "ProfilerActor",
|
2015-03-04 07:47:00 +03:00
|
|
|
type: { tab: true }
|
2014-09-16 14:00:00 +04:00
|
|
|
});
|
2015-08-13 04:42:54 +03:00
|
|
|
this.registerModule("devtools/server/actors/performance", {
|
|
|
|
prefix: "performance",
|
|
|
|
constructor: "PerformanceActor",
|
|
|
|
type: { tab: true }
|
|
|
|
});
|
2014-03-29 21:01:37 +04:00
|
|
|
}
|
2014-12-11 22:08:49 +03:00
|
|
|
this.registerModule("devtools/server/actors/animation", {
|
|
|
|
prefix: "animations",
|
|
|
|
constructor: "AnimationsActor",
|
2015-03-04 07:47:00 +03:00
|
|
|
type: { tab: true }
|
2014-12-11 22:08:49 +03:00
|
|
|
});
|
2015-06-03 00:52:46 +03:00
|
|
|
this.registerModule("devtools/server/actors/promises", {
|
|
|
|
prefix: "promises",
|
|
|
|
constructor: "PromisesActor",
|
2015-08-25 08:59:59 +03:00
|
|
|
type: { tab: true }
|
2015-06-03 00:52:46 +03:00
|
|
|
});
|
2015-08-01 01:40:08 +03:00
|
|
|
this.registerModule("devtools/server/actors/performance-entries", {
|
|
|
|
prefix: "performanceEntries",
|
|
|
|
constructor: "PerformanceEntriesActor",
|
|
|
|
type: { tab: true }
|
|
|
|
});
|
2016-08-17 00:03:09 +03:00
|
|
|
this.registerModule("devtools/server/actors/emulation", {
|
|
|
|
prefix: "emulation",
|
|
|
|
constructor: "EmulationActor",
|
|
|
|
type: { tab: true }
|
|
|
|
});
|
2014-01-24 14:11:00 +04:00
|
|
|
},
|
|
|
|
|
2014-04-17 21:27:03 +04:00
|
|
|
/**
|
|
|
|
* Passes a set of options to the BrowserAddonActors for the given ID.
|
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param id string
|
2014-04-17 21:27:03 +04:00
|
|
|
* The ID of the add-on to pass the options to
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param options object
|
2014-04-17 21:27:03 +04:00
|
|
|
* The options.
|
|
|
|
* @return a promise that will be resolved when complete.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
setAddonOptions(id, options) {
|
2014-04-17 21:27:03 +04:00
|
|
|
if (!this._initialized) {
|
2016-06-29 03:42:30 +03:00
|
|
|
return Promise.resolve();
|
2014-04-17 21:27:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
let promises = [];
|
|
|
|
|
|
|
|
// Pass to all connections
|
|
|
|
for (let connID of Object.getOwnPropertyNames(this._connections)) {
|
2016-06-29 03:42:30 +03:00
|
|
|
promises.push(this._connections[connID].setAddonOptions(id, options));
|
2014-04-17 21:27:03 +04:00
|
|
|
}
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
return SyncPromise.all(promises);
|
2014-04-17 21:27:03 +04:00
|
|
|
},
|
|
|
|
|
2014-07-10 22:15:00 +04:00
|
|
|
get listeningSockets() {
|
|
|
|
return this._listeners.length;
|
|
|
|
},
|
|
|
|
|
2012-04-22 13:59:09 +04:00
|
|
|
/**
|
2014-12-11 05:55:51 +03:00
|
|
|
* Creates a socket listener for remote debugger connections.
|
|
|
|
*
|
|
|
|
* After calling this, set some socket options, such as the port / path to
|
|
|
|
* listen on, and then call |open| on the listener.
|
|
|
|
*
|
2015-09-21 20:07:31 +03:00
|
|
|
* See SocketListener in devtools/shared/security/socket.js for available
|
2014-12-11 05:55:51 +03:00
|
|
|
* options.
|
2012-04-22 13:59:09 +04:00
|
|
|
*
|
2014-07-10 22:15:00 +04:00
|
|
|
* @return SocketListener
|
2014-12-11 05:55:51 +03:00
|
|
|
* A SocketListener instance that is waiting to be configured and
|
|
|
|
* opened is returned. This single listener can be closed at any
|
|
|
|
* later time by calling |close| on the SocketListener. If remote
|
|
|
|
* connections are disabled, an error is thrown.
|
2012-04-22 13:59:09 +04:00
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
createListener() {
|
2014-04-24 21:11:55 +04:00
|
|
|
if (!Services.prefs.getBoolPref("devtools.debugger.remote-enabled")) {
|
2014-12-11 05:55:51 +03:00
|
|
|
throw new Error("Can't create listener, remote debugging disabled");
|
2014-04-24 21:11:55 +04:00
|
|
|
}
|
2012-04-22 13:59:09 +04:00
|
|
|
this._checkInit();
|
2014-12-11 05:55:51 +03:00
|
|
|
return DebuggerSocket.createListener();
|
|
|
|
},
|
2012-04-22 13:59:09 +04:00
|
|
|
|
2014-12-11 05:55:51 +03:00
|
|
|
/**
|
|
|
|
* Add a SocketListener instance to the server's set of active
|
|
|
|
* SocketListeners. This is called by a SocketListener after it is opened.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
_addListener(listener) {
|
2014-07-10 22:15:00 +04:00
|
|
|
this._listeners.push(listener);
|
|
|
|
},
|
2012-04-22 13:59:09 +04:00
|
|
|
|
2014-07-10 22:15:00 +04:00
|
|
|
/**
|
|
|
|
* Remove a SocketListener instance from the server's set of active
|
|
|
|
* SocketListeners. This is called by a SocketListener after it is closed.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
_removeListener(listener) {
|
2014-07-10 22:15:00 +04:00
|
|
|
this._listeners = this._listeners.filter(l => l !== listener);
|
2012-04-22 13:59:09 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-07-10 22:15:00 +04:00
|
|
|
* Closes and forgets all previously opened listeners.
|
2012-09-20 10:36:32 +04:00
|
|
|
*
|
2014-07-10 22:15:00 +04:00
|
|
|
* @return boolean
|
|
|
|
* Whether any listeners were actually closed.
|
2012-04-22 13:59:09 +04:00
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
closeAllListeners() {
|
2014-07-10 22:15:00 +04:00
|
|
|
if (!this.listeningSockets) {
|
2012-04-22 13:59:09 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-10 22:15:00 +04:00
|
|
|
for (let listener of this._listeners) {
|
|
|
|
listener.close();
|
2012-09-20 10:36:32 +04:00
|
|
|
}
|
2012-04-22 13:59:09 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-09-22 19:44:00 +04:00
|
|
|
* Creates a new connection to the local debugger speaking over a fake
|
|
|
|
* transport. This connection results in straightforward calls to the onPacket
|
|
|
|
* handlers of each side.
|
2012-04-22 13:59:09 +04:00
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param prefix string [optional]
|
2013-07-24 19:27:26 +04:00
|
|
|
* If given, all actors in this connection will have names starting
|
2016-06-29 03:42:30 +03:00
|
|
|
* with |prefix + '/'|.
|
2012-04-22 13:59:09 +04:00
|
|
|
* @returns a client-side DebuggerTransport for communicating with
|
2013-07-24 19:27:26 +04:00
|
|
|
* the newly-created connection.
|
2012-04-22 13:59:09 +04:00
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
connectPipe(prefix) {
|
2012-04-22 13:59:09 +04:00
|
|
|
this._checkInit();
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
let serverTransport = new LocalDebuggerTransport();
|
2012-09-22 19:44:00 +04:00
|
|
|
let clientTransport = new LocalDebuggerTransport(serverTransport);
|
|
|
|
serverTransport.other = clientTransport;
|
2016-06-29 03:42:30 +03:00
|
|
|
let connection = this._onConnection(serverTransport, prefix);
|
2013-06-03 20:05:29 +04:00
|
|
|
|
|
|
|
// I'm putting this here because I trust you.
|
|
|
|
//
|
|
|
|
// There are times, when using a local connection, when you're going
|
|
|
|
// to be tempted to just get direct access to the server. Resist that
|
|
|
|
// temptation! If you succumb to that temptation, you will make the
|
|
|
|
// fine developers that work on Fennec and Firefox OS sad. They're
|
|
|
|
// professionals, they'll try to act like they understand, but deep
|
|
|
|
// down you'll know that you hurt them.
|
|
|
|
//
|
|
|
|
// This reference allows you to give in to that temptation. There are
|
|
|
|
// times this makes sense: tests, for example, and while porting a
|
|
|
|
// previously local-only codebase to the remote protocol.
|
|
|
|
//
|
|
|
|
// But every time you use this, you will feel the shame of having
|
|
|
|
// used a property that starts with a '_'.
|
|
|
|
clientTransport._serverConnection = connection;
|
2012-04-22 13:59:09 +04:00
|
|
|
|
2012-09-22 19:44:00 +04:00
|
|
|
return clientTransport;
|
2012-04-22 13:59:09 +04:00
|
|
|
},
|
|
|
|
|
2013-07-24 19:28:32 +04:00
|
|
|
/**
|
|
|
|
* In a content child process, create a new connection that exchanges
|
|
|
|
* nsIMessageSender messages with our parent process.
|
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param prefix
|
2013-07-24 19:28:32 +04:00
|
|
|
* The prefix we should use in our nsIMessageSender message names and
|
|
|
|
* actor names. This connection will use messages named
|
|
|
|
* "debug:<prefix>:packet", and all its actors will have names
|
2014-05-14 23:30:01 +04:00
|
|
|
* beginning with "<prefix>/".
|
2013-07-24 19:28:32 +04:00
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
connectToParent(prefix, scopeOrManager) {
|
2013-07-24 19:28:32 +04:00
|
|
|
this._checkInit();
|
|
|
|
|
2015-06-17 11:56:58 +03:00
|
|
|
let transport = isWorker ?
|
2016-06-29 03:42:30 +03:00
|
|
|
new WorkerDebuggerTransport(scopeOrManager, prefix) :
|
|
|
|
new ChildDebuggerTransport(scopeOrManager, prefix);
|
2015-06-17 11:56:58 +03:00
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
return this._onConnection(transport, prefix, true);
|
2013-07-24 19:28:32 +04:00
|
|
|
},
|
2013-06-03 20:05:29 +04:00
|
|
|
|
2016-11-04 18:05:15 +03:00
|
|
|
connectToContent(connection, mm, onDestroy) {
|
2016-06-29 03:42:30 +03:00
|
|
|
let deferred = SyncPromise.defer();
|
2014-11-07 23:24:47 +03:00
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
let prefix = connection.allocID("content-process");
|
2014-11-07 23:24:47 +03:00
|
|
|
let actor, childTransport;
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
mm.addMessageListener("debug:content-process-actor", function listener(msg) {
|
2014-11-07 23:24:47 +03:00
|
|
|
// Arbitrarily choose the first content process to reply
|
|
|
|
// XXX: This code needs to be updated if we use more than one content process
|
2016-06-29 03:42:30 +03:00
|
|
|
mm.removeMessageListener("debug:content-process-actor", listener);
|
2014-11-07 23:24:47 +03:00
|
|
|
|
|
|
|
// Pipe Debugger message from/to parent/child via the message manager
|
2016-06-29 03:42:30 +03:00
|
|
|
childTransport = new ChildDebuggerTransport(mm, prefix);
|
2014-11-07 23:24:47 +03:00
|
|
|
childTransport.hooks = {
|
2016-06-29 03:42:30 +03:00
|
|
|
onPacket: connection.send.bind(connection),
|
|
|
|
onClosed() {}
|
2014-11-07 23:24:47 +03:00
|
|
|
};
|
|
|
|
childTransport.ready();
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
connection.setForwarding(prefix, childTransport);
|
2014-11-07 23:24:47 +03:00
|
|
|
|
|
|
|
dumpn("establishing forwarding for process with prefix " + prefix);
|
|
|
|
|
|
|
|
actor = msg.json.actor;
|
|
|
|
|
|
|
|
deferred.resolve(actor);
|
|
|
|
});
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
mm.sendAsyncMessage("DevTools:InitDebuggerServer", {
|
2014-11-07 23:24:47 +03:00
|
|
|
prefix: prefix
|
|
|
|
});
|
|
|
|
|
2015-02-27 08:35:26 +03:00
|
|
|
function onClose() {
|
|
|
|
Services.obs.removeObserver(onMessageManagerClose, "message-manager-close");
|
2016-06-29 03:42:30 +03:00
|
|
|
events.off(connection, "closed", onClose);
|
2014-11-07 23:24:47 +03:00
|
|
|
if (childTransport) {
|
|
|
|
// If we have a child transport, the actor has already
|
|
|
|
// been created. We need to stop using this message manager.
|
|
|
|
childTransport.close();
|
|
|
|
childTransport = null;
|
2016-06-29 03:42:30 +03:00
|
|
|
connection.cancelForwarding(prefix);
|
2014-11-07 23:24:47 +03:00
|
|
|
|
|
|
|
// ... and notify the child process to clean the tab actors.
|
|
|
|
try {
|
2016-06-29 03:42:30 +03:00
|
|
|
mm.sendAsyncMessage("debug:content-process-destroy");
|
|
|
|
} catch (e) {
|
|
|
|
// Nothing to do
|
|
|
|
}
|
2014-11-07 23:24:47 +03:00
|
|
|
}
|
2016-11-04 18:05:15 +03:00
|
|
|
|
|
|
|
if (onDestroy) {
|
|
|
|
onDestroy(mm);
|
|
|
|
}
|
2014-11-07 23:24:47 +03:00
|
|
|
}
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
let onMessageManagerClose = DevToolsUtils.makeInfallible((subject, topic, data) => {
|
|
|
|
if (subject == mm) {
|
2015-02-27 08:35:26 +03:00
|
|
|
onClose();
|
2016-06-29 03:42:30 +03:00
|
|
|
connection.send({ from: actor.actor, type: "tabDetached" });
|
2014-11-07 23:24:47 +03:00
|
|
|
}
|
2016-06-29 03:42:30 +03:00
|
|
|
});
|
2015-02-27 08:35:26 +03:00
|
|
|
Services.obs.addObserver(onMessageManagerClose,
|
|
|
|
"message-manager-close", false);
|
2014-11-07 23:24:47 +03:00
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
events.on(connection, "closed", onClose);
|
2014-11-07 23:24:47 +03:00
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
},
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
connectToWorker(connection, dbg, id, options) {
|
2015-06-17 11:56:58 +03:00
|
|
|
return new Promise((resolve, reject) => {
|
2015-06-17 18:22:18 +03:00
|
|
|
// Step 1: Ensure the worker debugger is initialized.
|
2016-06-29 03:42:30 +03:00
|
|
|
if (!dbg.isInitialized) {
|
|
|
|
dbg.initialize("resource://devtools/server/worker.js");
|
2015-06-17 18:22:18 +03:00
|
|
|
|
|
|
|
// Create a listener for rpc requests from the worker debugger. Only do
|
|
|
|
// this once, when the worker debugger is first initialized, rather than
|
|
|
|
// for each connection.
|
|
|
|
let listener = {
|
|
|
|
onClose: () => {
|
2016-06-29 03:42:30 +03:00
|
|
|
dbg.removeListener(listener);
|
2015-06-17 18:22:18 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onMessage: (message) => {
|
2016-06-29 03:42:30 +03:00
|
|
|
message = JSON.parse(message);
|
|
|
|
if (message.type !== "rpc") {
|
2015-06-17 18:22:18 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Promise.resolve().then(() => {
|
|
|
|
let method = {
|
|
|
|
"fetch": DevToolsUtils.fetch,
|
2016-06-29 03:42:30 +03:00
|
|
|
}[message.method];
|
2015-06-17 18:22:18 +03:00
|
|
|
if (!method) {
|
2016-06-29 03:42:30 +03:00
|
|
|
throw Error("Unknown method: " + message.method);
|
2015-06-17 18:22:18 +03:00
|
|
|
}
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
return method.apply(undefined, message.params);
|
2015-06-17 18:22:18 +03:00
|
|
|
}).then((value) => {
|
2016-06-29 03:42:30 +03:00
|
|
|
dbg.postMessage(JSON.stringify({
|
2015-06-17 18:22:18 +03:00
|
|
|
type: "rpc",
|
|
|
|
result: value,
|
|
|
|
error: null,
|
2016-06-29 03:42:30 +03:00
|
|
|
id: message.id
|
2015-06-17 18:22:18 +03:00
|
|
|
}));
|
|
|
|
}, (reason) => {
|
2016-06-29 03:42:30 +03:00
|
|
|
dbg.postMessage(JSON.stringify({
|
2015-06-17 18:22:18 +03:00
|
|
|
type: "rpc",
|
|
|
|
result: null,
|
|
|
|
error: reason,
|
2016-06-29 03:42:30 +03:00
|
|
|
id: message.id
|
2015-06-17 18:22:18 +03:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
dbg.addListener(listener);
|
2015-06-17 18:22:18 +03:00
|
|
|
}
|
2015-06-17 11:56:58 +03:00
|
|
|
|
|
|
|
// Step 2: Send a connect request to the worker debugger.
|
2016-06-29 03:42:30 +03:00
|
|
|
dbg.postMessage(JSON.stringify({
|
2015-06-17 11:56:58 +03:00
|
|
|
type: "connect",
|
2016-06-29 03:42:30 +03:00
|
|
|
id,
|
|
|
|
options,
|
2015-06-17 11:56:58 +03:00
|
|
|
}));
|
|
|
|
|
|
|
|
// Steps 3-5 are performed on the worker thread (see worker.js).
|
|
|
|
|
2015-10-26 19:13:11 +03:00
|
|
|
// Step 6: Wait for a connection response from the worker debugger.
|
2015-06-17 11:56:58 +03:00
|
|
|
let listener = {
|
|
|
|
onClose: () => {
|
2016-06-29 03:42:30 +03:00
|
|
|
dbg.removeListener(listener);
|
2015-06-17 11:56:58 +03:00
|
|
|
|
|
|
|
reject("closed");
|
|
|
|
},
|
|
|
|
|
|
|
|
onMessage: (message) => {
|
2016-06-29 03:42:30 +03:00
|
|
|
message = JSON.parse(message);
|
|
|
|
if (message.type !== "connected" || message.id !== id) {
|
2015-06-17 11:56:58 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
// The initial connection message has been received, don't
|
2015-10-26 19:13:11 +03:00
|
|
|
// need to listen any longer
|
2016-06-29 03:42:30 +03:00
|
|
|
dbg.removeListener(listener);
|
2015-06-17 11:56:58 +03:00
|
|
|
|
|
|
|
// Step 7: Create a transport for the connection to the worker.
|
2016-06-29 03:42:30 +03:00
|
|
|
let transport = new WorkerDebuggerTransport(dbg, id);
|
2015-06-17 11:56:58 +03:00
|
|
|
transport.ready();
|
|
|
|
transport.hooks = {
|
|
|
|
onClosed: () => {
|
2016-06-29 03:42:30 +03:00
|
|
|
if (!dbg.isClosed) {
|
2016-08-08 08:53:37 +03:00
|
|
|
// If the worker happens to be shutting down while we are trying
|
|
|
|
// to close the connection, there is a small interval during
|
|
|
|
// which no more runnables can be dispatched to the worker, but
|
|
|
|
// the worker debugger has not yet been closed. In that case,
|
|
|
|
// the call to postMessage below will fail. The onClosed hook on
|
|
|
|
// DebuggerTransport is not supposed to throw exceptions, so we
|
|
|
|
// need to make sure to catch these early.
|
|
|
|
try {
|
|
|
|
dbg.postMessage(JSON.stringify({
|
|
|
|
type: "disconnect",
|
|
|
|
id,
|
|
|
|
}));
|
|
|
|
} catch (e) {
|
|
|
|
// We can safely ignore these exceptions. The only time the
|
|
|
|
// call to postMessage can fail is if the worker is either
|
|
|
|
// shutting down, or has finished shutting down. In both
|
|
|
|
// cases, there is nothing to clean up, so we don't care
|
|
|
|
// whether this message arrives or not.
|
|
|
|
}
|
2015-06-17 11:56:58 +03:00
|
|
|
}
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
connection.cancelForwarding(id);
|
2015-06-17 11:56:58 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onPacket: (packet) => {
|
|
|
|
// Ensure that any packets received from the server on the worker
|
|
|
|
// thread are forwarded to the client on the main thread, as if
|
|
|
|
// they had been sent by the server on the main thread.
|
2016-06-29 03:42:30 +03:00
|
|
|
connection.send(packet);
|
2015-06-17 11:56:58 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Ensure that any packets received from the client on the main thread
|
|
|
|
// to actors on the worker thread are forwarded to the server on the
|
|
|
|
// worker thread.
|
2016-06-29 03:42:30 +03:00
|
|
|
connection.setForwarding(id, transport);
|
2015-06-17 11:56:58 +03:00
|
|
|
|
|
|
|
resolve({
|
2016-06-29 03:42:30 +03:00
|
|
|
threadActor: message.threadActor,
|
|
|
|
consoleActor: message.consoleActor,
|
2015-06-17 11:56:58 +03:00
|
|
|
transport: transport
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2016-06-29 03:42:30 +03:00
|
|
|
dbg.addListener(listener);
|
2015-06-17 11:56:58 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-11-27 13:52:00 +03:00
|
|
|
/**
|
2016-07-07 00:17:03 +03:00
|
|
|
* Check if the server is running in the child process.
|
2014-11-27 13:52:00 +03:00
|
|
|
*/
|
2016-07-07 00:17:03 +03:00
|
|
|
get isInChildProcess() {
|
|
|
|
return Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
|
|
|
},
|
2014-11-27 13:52:00 +03:00
|
|
|
|
2014-12-06 02:40:10 +03:00
|
|
|
/**
|
|
|
|
* In a chrome parent process, ask all content child processes
|
|
|
|
* to execute a given module setup helper.
|
|
|
|
*
|
|
|
|
* @param module
|
|
|
|
* The module to be required
|
|
|
|
* @param setupChild
|
|
|
|
* The name of the setup helper exported by the above module
|
|
|
|
* (setup helper signature: function ({mm}) { ... })
|
2015-11-19 20:51:21 +03:00
|
|
|
* @param waitForEval (optional)
|
|
|
|
* If true, the returned promise only resolves once code in child
|
|
|
|
* is evaluated
|
2014-12-06 02:40:10 +03:00
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
setupInChild({ module, setupChild, args, waitForEval }) {
|
2016-07-07 00:17:03 +03:00
|
|
|
if (this._childMessageManagers.size == 0) {
|
2015-11-19 20:51:21 +03:00
|
|
|
return Promise.resolve();
|
2014-12-06 02:40:10 +03:00
|
|
|
}
|
2015-11-19 20:51:21 +03:00
|
|
|
let deferred = Promise.defer();
|
|
|
|
|
|
|
|
// If waitForEval is set, pass a unique id and expect child.js to send
|
|
|
|
// a message back once the code in child is evaluated.
|
2016-05-17 21:25:54 +03:00
|
|
|
if (typeof (waitForEval) != "boolean") {
|
2015-11-19 20:51:21 +03:00
|
|
|
waitForEval = false;
|
|
|
|
}
|
|
|
|
let count = this._childMessageManagers.size;
|
|
|
|
let id = waitForEval ? generateUUID().toString() : null;
|
2014-12-06 02:40:10 +03:00
|
|
|
|
2015-08-03 17:52:42 +03:00
|
|
|
this._childMessageManagers.forEach(mm => {
|
2015-11-19 20:51:21 +03:00
|
|
|
if (waitForEval) {
|
|
|
|
// Listen for the end of each child execution
|
|
|
|
let evalListener = msg => {
|
|
|
|
if (msg.data.id !== id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mm.removeMessageListener("debug:setup-in-child-response", evalListener);
|
|
|
|
if (--count === 0) {
|
|
|
|
deferred.resolve();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
mm.addMessageListener("debug:setup-in-child-response", evalListener);
|
|
|
|
}
|
2015-08-03 17:52:42 +03:00
|
|
|
mm.sendAsyncMessage("debug:setup-in-child", {
|
|
|
|
module: module,
|
|
|
|
setupChild: setupChild,
|
|
|
|
args: args,
|
2015-11-19 20:51:21 +03:00
|
|
|
id: id,
|
2015-08-03 17:52:42 +03:00
|
|
|
});
|
2014-12-06 02:40:10 +03:00
|
|
|
});
|
2015-11-19 20:51:21 +03:00
|
|
|
|
|
|
|
if (waitForEval) {
|
|
|
|
return deferred.promise;
|
|
|
|
}
|
2016-06-29 03:42:30 +03:00
|
|
|
return Promise.resolve();
|
2014-12-06 02:40:10 +03:00
|
|
|
},
|
|
|
|
|
2014-11-27 13:52:00 +03:00
|
|
|
/**
|
2015-08-03 17:52:42 +03:00
|
|
|
* Live list of all currenctly attached child's message managers.
|
2014-11-27 13:52:00 +03:00
|
|
|
*/
|
2015-08-03 17:52:42 +03:00
|
|
|
_childMessageManagers: new Set(),
|
2014-11-27 13:52:00 +03:00
|
|
|
|
2014-04-03 16:45:25 +04:00
|
|
|
/**
|
|
|
|
* Connect to a child process.
|
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param object connection
|
2014-04-03 16:45:25 +04:00
|
|
|
* The debugger server connection to use.
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param nsIDOMElement frame
|
2014-04-03 16:45:25 +04:00
|
|
|
* The browser element that holds the child process.
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param function [onDestroy]
|
2015-04-18 10:39:07 +03:00
|
|
|
* Optional function to invoke when the child process closes
|
|
|
|
* or the connection shuts down. (Need to forget about the
|
|
|
|
* related TabActor)
|
2014-04-03 16:45:25 +04:00
|
|
|
* @return object
|
|
|
|
* A promise object that is resolved once the connection is
|
|
|
|
* established.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
connectToChild(connection, frame, onDestroy) {
|
|
|
|
let deferred = SyncPromise.defer();
|
2014-03-10 19:32:37 +04:00
|
|
|
|
2016-06-07 02:28:26 +03:00
|
|
|
// Get messageManager from XUL browser (which might be a specialized tunnel for RDM)
|
|
|
|
// or else fallback to asking the frameLoader itself.
|
|
|
|
let mm = frame.messageManager || frame.frameLoader.messageManager;
|
2015-10-14 02:18:43 +03:00
|
|
|
mm.loadFrameScript("resource://devtools/server/child.js", false);
|
2016-06-29 04:10:55 +03:00
|
|
|
|
|
|
|
let trackMessageManager = () => {
|
|
|
|
frame.addEventListener("DevTools:BrowserSwap", onBrowserSwap);
|
|
|
|
mm.addMessageListener("debug:setup-in-parent", onSetupInParent);
|
|
|
|
if (!actor) {
|
|
|
|
mm.addMessageListener("debug:actor", onActorCreated);
|
|
|
|
}
|
|
|
|
DebuggerServer._childMessageManagers.add(mm);
|
|
|
|
};
|
|
|
|
|
|
|
|
let untrackMessageManager = () => {
|
|
|
|
frame.removeEventListener("DevTools:BrowserSwap", onBrowserSwap);
|
|
|
|
mm.removeMessageListener("debug:setup-in-parent", onSetupInParent);
|
|
|
|
if (!actor) {
|
|
|
|
mm.removeMessageListener("debug:actor", onActorCreated);
|
|
|
|
}
|
|
|
|
DebuggerServer._childMessageManagers.delete(mm);
|
|
|
|
};
|
2014-03-10 19:32:37 +04:00
|
|
|
|
2014-03-10 20:38:12 +04:00
|
|
|
let actor, childTransport;
|
2016-06-29 03:42:30 +03:00
|
|
|
let prefix = connection.allocID("child");
|
2016-08-06 00:00:36 +03:00
|
|
|
// Compute the same prefix that's used by DebuggerServerConnection
|
|
|
|
let connPrefix = prefix + "/";
|
2014-03-10 19:32:37 +04:00
|
|
|
|
2014-11-27 13:52:00 +03:00
|
|
|
// provides hook to actor modules that need to exchange messages
|
|
|
|
// between e10s parent and child processes
|
2016-08-06 03:03:12 +03:00
|
|
|
let parentModules = [];
|
2014-11-27 13:52:00 +03:00
|
|
|
let onSetupInParent = function (msg) {
|
2015-11-02 19:18:58 +03:00
|
|
|
// We may have multiple connectToChild instance running for the same tab
|
2016-08-06 00:00:36 +03:00
|
|
|
// and need to filter the messages.
|
|
|
|
if (msg.json.prefix != connPrefix) {
|
2016-06-29 03:42:30 +03:00
|
|
|
return false;
|
2015-11-02 19:18:58 +03:00
|
|
|
}
|
|
|
|
|
2014-11-27 13:52:00 +03:00
|
|
|
let { module, setupParent } = msg.json;
|
2016-06-29 03:42:30 +03:00
|
|
|
let m;
|
2014-11-27 13:52:00 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
m = require(module);
|
|
|
|
|
|
|
|
if (!setupParent in m) {
|
2016-08-06 03:03:12 +03:00
|
|
|
dumpn(`ERROR: module '${module}' does not export '${setupParent}'`);
|
2014-11-27 13:52:00 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-06 03:03:12 +03:00
|
|
|
parentModules.push(m[setupParent]({ mm, prefix: connPrefix }));
|
2014-11-27 13:52:00 +03:00
|
|
|
|
|
|
|
return true;
|
2016-05-17 21:25:54 +03:00
|
|
|
} catch (e) {
|
2016-06-29 03:42:30 +03:00
|
|
|
let errorMessage =
|
|
|
|
"Exception during actor module setup running in the parent process: ";
|
|
|
|
DevToolsUtils.reportException(errorMessage + e);
|
|
|
|
dumpn(`ERROR: ${errorMessage}\n\t module: '${module}'\n\t ` +
|
|
|
|
`setupParent: '${setupParent}'\n${DevToolsUtils.safeErrorString(e)}`);
|
2014-11-27 13:52:00 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-10 19:32:37 +04:00
|
|
|
let onActorCreated = DevToolsUtils.makeInfallible(function (msg) {
|
2015-04-18 10:39:07 +03:00
|
|
|
if (msg.json.prefix != prefix) {
|
|
|
|
return;
|
|
|
|
}
|
2014-03-10 19:32:37 +04:00
|
|
|
mm.removeMessageListener("debug:actor", onActorCreated);
|
|
|
|
|
|
|
|
// Pipe Debugger message from/to parent/child via the message manager
|
|
|
|
childTransport = new ChildDebuggerTransport(mm, prefix);
|
|
|
|
childTransport.hooks = {
|
2016-06-29 03:42:30 +03:00
|
|
|
onPacket: connection.send.bind(connection),
|
|
|
|
onClosed() {}
|
2014-03-10 19:32:37 +04:00
|
|
|
};
|
|
|
|
childTransport.ready();
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
connection.setForwarding(prefix, childTransport);
|
2014-03-10 19:32:37 +04:00
|
|
|
|
|
|
|
dumpn("establishing forwarding for app with prefix " + prefix);
|
|
|
|
|
|
|
|
actor = msg.json.actor;
|
|
|
|
deferred.resolve(actor);
|
|
|
|
}).bind(this);
|
2016-06-29 04:10:55 +03:00
|
|
|
|
|
|
|
// Listen for browser frame swap
|
|
|
|
let onBrowserSwap = ({ detail: newFrame }) => {
|
|
|
|
// Remove listeners from old frame and mm
|
|
|
|
untrackMessageManager();
|
|
|
|
// Update frame and mm to point to the new browser frame
|
|
|
|
frame = newFrame;
|
|
|
|
// Get messageManager from XUL browser (which might be a specialized tunnel for RDM)
|
|
|
|
// or else fallback to asking the frameLoader itself.
|
|
|
|
mm = frame.messageManager || frame.frameLoader.messageManager;
|
|
|
|
// Add listeners to new frame and mm
|
|
|
|
trackMessageManager();
|
|
|
|
|
2016-08-06 03:03:12 +03:00
|
|
|
// provides hook to actor modules that need to exchange messages
|
|
|
|
// between e10s parent and child processes
|
|
|
|
parentModules.forEach(mod => {
|
|
|
|
if (mod.onBrowserSwap) {
|
|
|
|
mod.onBrowserSwap(mm);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-29 04:10:55 +03:00
|
|
|
if (childTransport) {
|
|
|
|
childTransport.swapBrowser(mm);
|
|
|
|
}
|
|
|
|
};
|
2014-03-10 19:32:37 +04:00
|
|
|
|
2015-04-18 10:39:07 +03:00
|
|
|
let destroy = DevToolsUtils.makeInfallible(function () {
|
|
|
|
// provides hook to actor modules that need to exchange messages
|
|
|
|
// between e10s parent and child processes
|
2016-08-06 03:03:12 +03:00
|
|
|
parentModules.forEach(mod => {
|
|
|
|
if (mod.onDisconnected) {
|
|
|
|
mod.onDisconnected();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// TODO: Remove this deprecated path once it's no longer needed by add-ons.
|
2016-08-06 00:00:36 +03:00
|
|
|
DebuggerServer.emit("disconnected-from-child:" + connPrefix,
|
|
|
|
{ mm, prefix: connPrefix });
|
2014-03-10 19:32:37 +04:00
|
|
|
|
2014-04-02 23:29:40 +04:00
|
|
|
if (childTransport) {
|
2015-04-18 10:39:07 +03:00
|
|
|
// If we have a child transport, the actor has already
|
|
|
|
// been created. We need to stop using this message manager.
|
2014-04-02 23:29:40 +04:00
|
|
|
childTransport.close();
|
|
|
|
childTransport = null;
|
2016-06-29 03:42:30 +03:00
|
|
|
connection.cancelForwarding(prefix);
|
2014-04-02 23:29:40 +04:00
|
|
|
|
|
|
|
// ... and notify the child process to clean the tab actors.
|
2015-10-22 18:06:16 +03:00
|
|
|
try {
|
|
|
|
// Bug 1169643: Ignore any exception as the child process
|
|
|
|
// may already be destroyed by now.
|
2016-06-29 03:42:30 +03:00
|
|
|
mm.sendAsyncMessage("debug:disconnect", { prefix });
|
|
|
|
} catch (e) {
|
|
|
|
// Nothing to do
|
|
|
|
}
|
2015-04-18 10:39:07 +03:00
|
|
|
} else {
|
|
|
|
// Otherwise, the app has been closed before the actor
|
|
|
|
// had a chance to be created, so we are not able to create
|
|
|
|
// the actor.
|
|
|
|
deferred.resolve(null);
|
|
|
|
}
|
|
|
|
if (actor) {
|
|
|
|
// The ContentActor within the child process doesn't necessary
|
|
|
|
// have time to uninitialize itself when the app is closed/killed.
|
|
|
|
// So ensure telling the client that the related actor is detached.
|
2016-06-29 03:42:30 +03:00
|
|
|
connection.send({ from: actor.actor, type: "tabDetached" });
|
2015-04-18 10:39:07 +03:00
|
|
|
actor = null;
|
|
|
|
}
|
2014-08-27 14:19:30 +04:00
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
if (onDestroy) {
|
|
|
|
onDestroy(mm);
|
2015-04-18 10:39:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup all listeners
|
2016-06-29 04:10:55 +03:00
|
|
|
untrackMessageManager();
|
2015-04-18 10:39:07 +03:00
|
|
|
Services.obs.removeObserver(onMessageManagerClose, "message-manager-close");
|
2016-06-29 03:42:30 +03:00
|
|
|
events.off(connection, "closed", destroy);
|
2014-04-02 23:29:40 +04:00
|
|
|
});
|
|
|
|
|
2016-06-29 04:10:55 +03:00
|
|
|
// Listen for various messages and frame events
|
|
|
|
trackMessageManager();
|
|
|
|
|
2015-04-18 10:39:07 +03:00
|
|
|
// Listen for app process exit
|
|
|
|
let onMessageManagerClose = function (subject, topic, data) {
|
|
|
|
if (subject == mm) {
|
|
|
|
destroy();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Services.obs.addObserver(onMessageManagerClose,
|
|
|
|
"message-manager-close", false);
|
|
|
|
|
|
|
|
// Listen for connection close to cleanup things
|
|
|
|
// when user unplug the device or we lose the connection somehow.
|
2016-06-29 03:42:30 +03:00
|
|
|
events.on(connection, "closed", destroy);
|
2015-04-18 10:39:07 +03:00
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
mm.sendAsyncMessage("debug:connect", { prefix });
|
2014-03-10 19:32:37 +04:00
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
},
|
|
|
|
|
2012-04-22 13:59:09 +04:00
|
|
|
/**
|
2013-07-24 19:27:26 +04:00
|
|
|
* Create a new debugger connection for the given transport. Called after
|
|
|
|
* connectPipe(), from connectToParent, or from an incoming socket
|
|
|
|
* connection handler.
|
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* If present, |forwardingPrefix| is a forwarding prefix that a parent
|
2013-07-24 19:27:26 +04:00
|
|
|
* server is using to recognizes messages intended for this server. Ensure
|
2016-06-29 03:42:30 +03:00
|
|
|
* that all our actors have names beginning with |forwardingPrefix + '/'|.
|
|
|
|
* In particular, the root actor's name will be |forwardingPrefix + '/root'|.
|
2013-07-24 19:27:26 +04:00
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
_onConnection(transport, forwardingPrefix, noRootActor = false) {
|
2013-07-24 19:27:26 +04:00
|
|
|
let connID;
|
2016-06-29 03:42:30 +03:00
|
|
|
if (forwardingPrefix) {
|
|
|
|
connID = forwardingPrefix + "/";
|
2013-07-24 19:27:26 +04:00
|
|
|
} else {
|
2015-03-03 11:44:25 +03:00
|
|
|
// Multiple servers can be started at the same time, and when that's the
|
|
|
|
// case, they are loaded in separate devtools loaders.
|
|
|
|
// So, use the current loader ID to prefix the connection ID and make it
|
|
|
|
// unique.
|
2016-05-17 21:25:54 +03:00
|
|
|
connID = "server" + loader.id + ".conn" + this._nextConnID++ + ".";
|
2013-07-24 19:27:26 +04:00
|
|
|
}
|
2015-03-03 11:44:25 +03:00
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
let conn = new DebuggerServerConnection(connID, transport);
|
2012-04-22 13:59:09 +04:00
|
|
|
this._connections[connID] = conn;
|
|
|
|
|
|
|
|
// Create a root actor for the connection and send the hello packet.
|
2016-06-29 03:42:30 +03:00
|
|
|
if (!noRootActor) {
|
2013-07-24 19:28:32 +04:00
|
|
|
conn.rootActor = this.createRootActor(conn);
|
2016-06-29 03:42:30 +03:00
|
|
|
if (forwardingPrefix) {
|
|
|
|
conn.rootActor.actorID = forwardingPrefix + "/root";
|
|
|
|
} else {
|
2013-07-24 19:28:32 +04:00
|
|
|
conn.rootActor.actorID = "root";
|
2016-06-29 03:42:30 +03:00
|
|
|
}
|
2013-07-24 19:28:32 +04:00
|
|
|
conn.addActor(conn.rootActor);
|
2016-06-29 03:42:30 +03:00
|
|
|
transport.send(conn.rootActor.sayHello());
|
2013-07-24 19:28:32 +04:00
|
|
|
}
|
2016-06-29 03:42:30 +03:00
|
|
|
transport.ready();
|
2013-06-03 20:05:29 +04:00
|
|
|
|
2014-04-17 21:27:03 +04:00
|
|
|
this.emit("connectionchange", "opened", conn);
|
2013-06-03 20:05:29 +04:00
|
|
|
return conn;
|
2012-04-22 13:59:09 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-09-27 15:31:49 +04:00
|
|
|
* Remove the connection from the debugging server.
|
2012-04-22 13:59:09 +04:00
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
_connectionClosed(connection) {
|
|
|
|
delete this._connections[connection.prefix];
|
|
|
|
this.emit("connectionchange", "closed", connection);
|
2012-10-31 20:31:55 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
// DebuggerServer extension API.
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
setRootActor(actorFactory) {
|
|
|
|
this.createRootActor = actorFactory;
|
2014-05-13 23:56:30 +04:00
|
|
|
},
|
|
|
|
|
2012-10-31 20:31:55 +04:00
|
|
|
/**
|
|
|
|
* Registers handlers for new tab-scoped request types defined dynamically.
|
|
|
|
* This is used for example by add-ons to augment the functionality of the tab
|
|
|
|
* actor. Note that the name or actorPrefix of the request type is not allowed
|
|
|
|
* to clash with existing protocol packet properties, like 'title', 'url' or
|
|
|
|
* 'actor', since that would break the protocol.
|
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param actor function, object
|
2014-09-16 14:00:00 +04:00
|
|
|
* In case of function:
|
2013-05-24 21:13:42 +04:00
|
|
|
* The constructor function for this request type. This expects to be
|
|
|
|
* called as a constructor (i.e. with 'new'), and passed two
|
|
|
|
* arguments: the DebuggerServerConnection, and the BrowserTabActor
|
|
|
|
* with which it will be associated.
|
2014-09-16 14:00:00 +04:00
|
|
|
* Only used for deprecated eagerly loaded actors.
|
|
|
|
* In case of object:
|
|
|
|
* First argument of RegisteredActorFactory constructor.
|
|
|
|
* See the it's definition for more info.
|
2013-05-24 21:13:42 +04:00
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param name string [optional]
|
2012-10-31 20:31:55 +04:00
|
|
|
* The name of the new request type. If this is not present, the
|
|
|
|
* actorPrefix property of the constructor prototype is used.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
addTabActor(actor, name = actor.prototype.actorPrefix) {
|
2012-10-31 20:31:55 +04:00
|
|
|
if (["title", "url", "actor"].indexOf(name) != -1) {
|
|
|
|
throw Error(name + " is not allowed");
|
|
|
|
}
|
|
|
|
if (DebuggerServer.tabActorFactories.hasOwnProperty(name)) {
|
|
|
|
throw Error(name + " already exists");
|
|
|
|
}
|
2016-06-29 03:42:30 +03:00
|
|
|
DebuggerServer.tabActorFactories[name] = new RegisteredActorFactory(actor, name);
|
2012-10-31 20:31:55 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregisters the handler for the specified tab-scoped request type.
|
|
|
|
* This may be used for example by add-ons when shutting down or upgrading.
|
2014-10-03 15:49:00 +04:00
|
|
|
* When unregistering an existing tab actor remove related tab factory
|
|
|
|
* as well as all existing instances of the actor.
|
2012-10-31 20:31:55 +04:00
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param actor function, object
|
2014-09-16 14:00:00 +04:00
|
|
|
* In case of function:
|
2012-10-31 20:31:55 +04:00
|
|
|
* The constructor function for this request type.
|
2014-09-16 14:00:00 +04:00
|
|
|
* In case of object:
|
|
|
|
* Same object being given to related addTabActor call.
|
2012-10-31 20:31:55 +04:00
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
removeTabActor(actor) {
|
2012-10-31 20:31:55 +04:00
|
|
|
for (let name in DebuggerServer.tabActorFactories) {
|
|
|
|
let handler = DebuggerServer.tabActorFactories[name];
|
2016-06-29 03:42:30 +03:00
|
|
|
if ((handler.name && handler.name == actor.name) ||
|
|
|
|
(handler.id && handler.id == actor.id)) {
|
2012-10-31 20:31:55 +04:00
|
|
|
delete DebuggerServer.tabActorFactories[name];
|
2014-10-03 15:49:00 +04:00
|
|
|
for (let connID of Object.getOwnPropertyNames(this._connections)) {
|
2015-11-19 20:51:21 +03:00
|
|
|
// DebuggerServerConnection in child process don't have rootActor
|
|
|
|
if (this._connections[connID].rootActor) {
|
|
|
|
this._connections[connID].rootActor.removeActorByName(name);
|
|
|
|
}
|
2014-10-03 15:49:00 +04:00
|
|
|
}
|
2012-10-31 20:31:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers handlers for new browser-scoped request types defined
|
|
|
|
* dynamically. This is used for example by add-ons to augment the
|
|
|
|
* functionality of the root actor. Note that the name or actorPrefix of the
|
|
|
|
* request type is not allowed to clash with existing protocol packet
|
|
|
|
* properties, like 'from', 'tabs' or 'selected', since that would break the
|
|
|
|
* protocol.
|
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param actor function, object
|
2014-09-16 14:00:00 +04:00
|
|
|
* In case of function:
|
2013-05-24 21:13:42 +04:00
|
|
|
* The constructor function for this request type. This expects to be
|
|
|
|
* called as a constructor (i.e. with 'new'), and passed two
|
|
|
|
* arguments: the DebuggerServerConnection, and the BrowserRootActor
|
|
|
|
* with which it will be associated.
|
2014-09-16 14:00:00 +04:00
|
|
|
* Only used for deprecated eagerly loaded actors.
|
|
|
|
* In case of object:
|
|
|
|
* First argument of RegisteredActorFactory constructor.
|
|
|
|
* See the it's definition for more info.
|
2013-05-24 21:13:42 +04:00
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param name string [optional]
|
2012-10-31 20:31:55 +04:00
|
|
|
* The name of the new request type. If this is not present, the
|
|
|
|
* actorPrefix property of the constructor prototype is used.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
addGlobalActor(actor, name = actor.prototype.actorPrefix) {
|
2012-10-31 20:31:55 +04:00
|
|
|
if (["from", "tabs", "selected"].indexOf(name) != -1) {
|
|
|
|
throw Error(name + " is not allowed");
|
|
|
|
}
|
|
|
|
if (DebuggerServer.globalActorFactories.hasOwnProperty(name)) {
|
|
|
|
throw Error(name + " already exists");
|
|
|
|
}
|
2016-06-29 03:42:30 +03:00
|
|
|
DebuggerServer.globalActorFactories[name] = new RegisteredActorFactory(actor, name);
|
2012-10-31 20:31:55 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregisters the handler for the specified browser-scoped request type.
|
|
|
|
* This may be used for example by add-ons when shutting down or upgrading.
|
2014-10-03 15:49:00 +04:00
|
|
|
* When unregistering an existing global actor remove related global factory
|
|
|
|
* as well as all existing instances of the actor.
|
2012-10-31 20:31:55 +04:00
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param actor function, object
|
2014-09-16 14:00:00 +04:00
|
|
|
* In case of function:
|
2012-10-31 20:31:55 +04:00
|
|
|
* The constructor function for this request type.
|
2014-09-16 14:00:00 +04:00
|
|
|
* In case of object:
|
|
|
|
* Same object being given to related addGlobalActor call.
|
2012-10-31 20:31:55 +04:00
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
removeGlobalActor(actor) {
|
2012-10-31 20:31:55 +04:00
|
|
|
for (let name in DebuggerServer.globalActorFactories) {
|
|
|
|
let handler = DebuggerServer.globalActorFactories[name];
|
2016-06-29 03:42:30 +03:00
|
|
|
if ((handler.name && handler.name == actor.name) ||
|
|
|
|
(handler.id && handler.id == actor.id)) {
|
2012-10-31 20:31:55 +04:00
|
|
|
delete DebuggerServer.globalActorFactories[name];
|
2014-10-03 15:49:00 +04:00
|
|
|
for (let connID of Object.getOwnPropertyNames(this._connections)) {
|
|
|
|
this._connections[connID].rootActor.removeActorByName(name);
|
|
|
|
}
|
2012-10-31 20:31:55 +04:00
|
|
|
}
|
|
|
|
}
|
2016-07-07 00:17:03 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ⚠ TESTING ONLY! ⚠ Searches all active connections for an actor matching an ID.
|
|
|
|
* This is helpful for some tests which depend on reaching into the server to check some
|
|
|
|
* properties of an actor.
|
|
|
|
*/
|
|
|
|
_searchAllConnectionsForActor(actorID) {
|
|
|
|
for (let connID of Object.getOwnPropertyNames(this._connections)) {
|
|
|
|
let actor = this._connections[connID].getActor(actorID);
|
|
|
|
if (actor) {
|
|
|
|
return actor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
2012-04-22 13:59:09 +04:00
|
|
|
};
|
|
|
|
|
2015-01-26 21:47:13 +03:00
|
|
|
// Expose these to save callers the trouble of importing DebuggerSocket
|
|
|
|
DevToolsUtils.defineLazyGetter(DebuggerServer, "Authenticators", () => {
|
|
|
|
return Authentication.Authenticators;
|
|
|
|
});
|
|
|
|
DevToolsUtils.defineLazyGetter(DebuggerServer, "AuthenticationResult", () => {
|
|
|
|
return Authentication.AuthenticationResult;
|
|
|
|
});
|
|
|
|
|
2014-04-17 21:27:03 +04:00
|
|
|
EventEmitter.decorate(DebuggerServer);
|
|
|
|
|
2013-08-31 04:34:26 +04:00
|
|
|
if (this.exports) {
|
|
|
|
exports.DebuggerServer = DebuggerServer;
|
2015-03-11 17:15:40 +03:00
|
|
|
exports.ActorPool = ActorPool;
|
|
|
|
exports.OriginalLocation = OriginalLocation;
|
2013-08-31 04:34:26 +04:00
|
|
|
}
|
2015-03-11 17:15:40 +03:00
|
|
|
|
2014-01-07 00:55:00 +04:00
|
|
|
// Needed on B2G (See header note)
|
|
|
|
this.DebuggerServer = DebuggerServer;
|
2015-03-11 17:15:40 +03:00
|
|
|
this.ActorPool = ActorPool;
|
|
|
|
this.OriginalLocation = OriginalLocation;
|
2012-10-31 20:31:55 +04:00
|
|
|
|
2014-07-07 14:07:00 +04:00
|
|
|
// When using DebuggerServer.addActors, some symbols are expected to be in
|
|
|
|
// the scope of the added actor even before the corresponding modules are
|
|
|
|
// loaded, so let's explicitly bind the expected symbols here.
|
2015-09-15 21:19:45 +03:00
|
|
|
var includes = ["Components", "Ci", "Cu", "require", "Services", "DebuggerServer",
|
2014-07-07 14:07:00 +04:00
|
|
|
"ActorPool", "DevToolsUtils"];
|
|
|
|
includes.forEach(name => {
|
|
|
|
DebuggerServer[name] = this[name];
|
|
|
|
});
|
|
|
|
|
2012-04-22 13:59:09 +04:00
|
|
|
/**
|
|
|
|
* Creates a DebuggerServerConnection.
|
|
|
|
*
|
|
|
|
* Represents a connection to this debugging global from a client.
|
|
|
|
* Manages a set of actors and actor pools, allocates actor ids, and
|
|
|
|
* handles incoming requests.
|
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param prefix string
|
2012-04-22 13:59:09 +04:00
|
|
|
* All actor IDs created by this connection should be prefixed
|
2016-06-29 03:42:30 +03:00
|
|
|
* with prefix.
|
|
|
|
* @param transport transport
|
2012-04-22 13:59:09 +04:00
|
|
|
* Packet transport for the debugging protocol.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
function DebuggerServerConnection(prefix, transport) {
|
|
|
|
this._prefix = prefix;
|
|
|
|
this._transport = transport;
|
2012-04-22 13:59:09 +04:00
|
|
|
this._transport.hooks = this;
|
|
|
|
this._nextID = 1;
|
|
|
|
|
|
|
|
this._actorPool = new ActorPool(this);
|
2015-01-06 03:26:27 +03:00
|
|
|
this._extraPools = [this._actorPool];
|
2013-07-24 19:27:26 +04:00
|
|
|
|
2013-08-09 09:28:41 +04:00
|
|
|
// Responses to a given actor must be returned the the client
|
|
|
|
// in the same order as the requests that they're replying to, but
|
|
|
|
// Implementations might finish serving requests in a different
|
|
|
|
// order. To keep things in order we generate a promise for each
|
|
|
|
// request, chained to the promise for the request before it.
|
|
|
|
// This map stores the latest request promise in the chain, keyed
|
|
|
|
// by an actor ID string.
|
2016-06-29 03:42:30 +03:00
|
|
|
this._actorResponses = new Map();
|
2013-08-09 09:28:41 +04:00
|
|
|
|
2013-07-24 19:27:26 +04:00
|
|
|
/*
|
|
|
|
* We can forward packets to other servers, if the actors on that server
|
|
|
|
* all use a distinct prefix on their names. This is a map from prefixes
|
|
|
|
* to transports: it maps a prefix P to a transport T if T conveys
|
2014-05-14 23:30:01 +04:00
|
|
|
* packets to the server whose actors' names all begin with P + "/".
|
2013-07-24 19:27:26 +04:00
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
this._forwardingPrefixes = new Map();
|
2012-04-22 13:59:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DebuggerServerConnection.prototype = {
|
|
|
|
_prefix: null,
|
2016-06-29 03:42:30 +03:00
|
|
|
get prefix() {
|
|
|
|
return this._prefix;
|
|
|
|
},
|
2012-04-22 13:59:09 +04:00
|
|
|
|
|
|
|
_transport: null,
|
2016-06-29 03:42:30 +03:00
|
|
|
get transport() {
|
|
|
|
return this._transport;
|
|
|
|
},
|
2012-04-22 13:59:09 +04:00
|
|
|
|
2015-08-03 17:52:42 +03:00
|
|
|
/**
|
|
|
|
* Message manager used to communicate with the parent process,
|
|
|
|
* set by child.js. Is only defined for connections instantiated
|
|
|
|
* within a child process.
|
|
|
|
*/
|
|
|
|
parentMessageManager: null,
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
close() {
|
2016-07-07 00:17:03 +03:00
|
|
|
if (this._transport) {
|
|
|
|
this._transport.close();
|
|
|
|
}
|
2013-05-30 20:42:00 +04:00
|
|
|
},
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
send(packet) {
|
|
|
|
this.transport.send(packet);
|
2012-04-22 13:59:09 +04:00
|
|
|
},
|
|
|
|
|
2014-05-14 23:30:02 +04:00
|
|
|
/**
|
|
|
|
* Used when sending a bulk reply from an actor.
|
|
|
|
* @see DebuggerTransport.prototype.startBulkSend
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
startBulkSend(header) {
|
2014-05-14 23:30:02 +04:00
|
|
|
return this.transport.startBulkSend(header);
|
|
|
|
},
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
allocID(prefix) {
|
|
|
|
return this.prefix + (prefix || "") + this._nextID++;
|
2012-04-22 13:59:09 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a map of actor IDs to the connection.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
addActorPool(actorPool) {
|
|
|
|
this._extraPools.push(actorPool);
|
2012-04-22 13:59:09 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a previously-added pool of actors to the connection.
|
2012-12-18 00:06:13 +04:00
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param ActorPool actorPool
|
2012-12-18 00:06:13 +04:00
|
|
|
* The ActorPool instance you want to remove.
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param boolean noCleanup [optional]
|
2016-11-12 03:24:58 +03:00
|
|
|
* True if you don't want to destroy each actor from the pool, false
|
2012-12-18 00:06:13 +04:00
|
|
|
* otherwise.
|
2012-04-22 13:59:09 +04:00
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
removeActorPool(actorPool, noCleanup) {
|
2016-08-08 08:53:37 +03:00
|
|
|
// When a connection is closed, it removes each of its actor pools. When an
|
2016-11-12 03:24:58 +03:00
|
|
|
// actor pool is removed, it calls the destroy method on each of its
|
2016-08-08 08:53:37 +03:00
|
|
|
// actors. Some actors, such as ThreadActor, manage their own actor pools.
|
2016-11-12 03:24:58 +03:00
|
|
|
// When the destroy method is called on these actors, they manually
|
2016-08-08 08:53:37 +03:00
|
|
|
// remove their actor pools. Consequently, this method is reentrant.
|
|
|
|
//
|
|
|
|
// In addition, some actors, such as ThreadActor, perform asynchronous work
|
|
|
|
// (in the case of ThreadActor, because they need to resume), before they
|
|
|
|
// remove each of their actor pools. Since we don't wait for this work to
|
|
|
|
// be completed, we can end up in this function recursively after the
|
|
|
|
// connection already set this._extraPools to null.
|
|
|
|
//
|
2016-11-12 03:24:58 +03:00
|
|
|
// This is a bug: if the destroy method can perform asynchronous work,
|
2016-08-08 08:53:37 +03:00
|
|
|
// then we should wait for that work to be completed before setting this.
|
|
|
|
// _extraPools to null. As a temporary solution, it should be acceptable
|
|
|
|
// to just return early (if this._extraPools has been set to null, all
|
|
|
|
// actors pools for this connection should already have been removed).
|
|
|
|
if (this._extraPools === null) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-29 03:42:30 +03:00
|
|
|
let index = this._extraPools.lastIndexOf(actorPool);
|
2012-08-24 11:41:02 +04:00
|
|
|
if (index > -1) {
|
2012-12-18 00:06:13 +04:00
|
|
|
let pool = this._extraPools.splice(index, 1);
|
2016-06-29 03:42:30 +03:00
|
|
|
if (!noCleanup) {
|
|
|
|
pool.forEach(p => p.destroy());
|
2012-12-18 00:06:13 +04:00
|
|
|
}
|
2012-08-24 11:41:02 +04:00
|
|
|
}
|
2012-04-22 13:59:09 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an actor to the default actor pool for this connection.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
addActor(actor) {
|
|
|
|
this._actorPool.addActor(actor);
|
2012-04-22 13:59:09 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an actor to the default actor pool for this connection.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
removeActor(actor) {
|
|
|
|
this._actorPool.removeActor(actor);
|
2012-04-22 13:59:09 +04:00
|
|
|
},
|
|
|
|
|
2013-06-06 23:29:27 +04:00
|
|
|
/**
|
|
|
|
* Match the api expected by the protocol library.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
unmanage(actor) {
|
|
|
|
return this.removeActor(actor);
|
2013-06-06 23:29:27 +04:00
|
|
|
},
|
|
|
|
|
2012-04-22 13:59:09 +04:00
|
|
|
/**
|
|
|
|
* Look up an actor implementation for an actorID. Will search
|
|
|
|
* all the actor pools registered with the connection.
|
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param actorID string
|
2012-04-22 13:59:09 +04:00
|
|
|
* Actor ID to look up.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
getActor(actorID) {
|
|
|
|
let pool = this.poolFor(actorID);
|
2013-06-06 23:29:27 +04:00
|
|
|
if (pool) {
|
2016-06-29 03:42:30 +03:00
|
|
|
return pool.get(actorID);
|
2012-04-22 13:59:09 +04:00
|
|
|
}
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
if (actorID === "root") {
|
2012-04-22 13:59:09 +04:00
|
|
|
return this.rootActor;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
_getOrCreateActor(actorID) {
|
2014-05-14 23:30:02 +04:00
|
|
|
let actor = this.getActor(actorID);
|
|
|
|
if (!actor) {
|
|
|
|
this.transport.send({ from: actorID ? actorID : "root",
|
|
|
|
error: "noSuchActor",
|
|
|
|
message: "No such actor for ID: " + actorID });
|
2016-06-29 03:42:30 +03:00
|
|
|
return null;
|
2014-05-14 23:30:02 +04:00
|
|
|
}
|
|
|
|
|
2014-09-16 14:00:00 +04:00
|
|
|
// Dynamically-loaded actors have to be created lazily.
|
|
|
|
if (actor instanceof ObservedActorFactory) {
|
2014-05-14 23:30:02 +04:00
|
|
|
try {
|
2016-05-17 21:25:54 +03:00
|
|
|
actor = actor.createActor();
|
2014-05-14 23:30:02 +04:00
|
|
|
} catch (e) {
|
|
|
|
this.transport.send(this._unknownError(
|
|
|
|
"Error occurred while creating actor '" + actor.name,
|
|
|
|
e));
|
|
|
|
}
|
2016-05-17 21:25:54 +03:00
|
|
|
} else if (typeof (actor) !== "object") {
|
2014-09-16 14:00:00 +04:00
|
|
|
// ActorPools should now contain only actor instances (i.e. objects)
|
|
|
|
// or ObservedActorFactory instances.
|
|
|
|
throw new Error("Unexpected actor constructor/function in ActorPool " +
|
|
|
|
"for actorID=" + actorID + ".");
|
2014-05-14 23:30:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return actor;
|
|
|
|
},
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
poolFor(actorID) {
|
2013-06-06 23:29:27 +04:00
|
|
|
for (let pool of this._extraPools) {
|
2016-06-29 03:42:30 +03:00
|
|
|
if (pool.has(actorID)) {
|
2013-06-06 23:29:27 +04:00
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
_unknownError(prefix, error) {
|
|
|
|
let errorString = prefix + ": " + DevToolsUtils.safeErrorString(error);
|
2014-05-30 18:42:55 +04:00
|
|
|
reportError(errorString);
|
2013-04-16 01:07:00 +04:00
|
|
|
dumpn(errorString);
|
|
|
|
return {
|
|
|
|
error: "unknownError",
|
2013-08-20 22:15:15 +04:00
|
|
|
message: errorString
|
2013-04-16 01:07:00 +04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
_queueResponse: function (from, type, responseOrPromise) {
|
|
|
|
let pendingResponse = this._actorResponses.get(from) || SyncPromise.resolve(null);
|
2014-05-14 23:30:02 +04:00
|
|
|
let responsePromise = pendingResponse.then(() => {
|
2016-06-29 03:42:30 +03:00
|
|
|
return responseOrPromise;
|
|
|
|
}).then(response => {
|
|
|
|
if (!response.from) {
|
|
|
|
response.from = from;
|
2014-05-14 23:30:02 +04:00
|
|
|
}
|
2016-06-29 03:42:30 +03:00
|
|
|
this.transport.send(response);
|
2014-05-14 23:30:02 +04:00
|
|
|
}).then(null, (e) => {
|
|
|
|
let errorPacket = this._unknownError(
|
2016-06-29 03:42:30 +03:00
|
|
|
"error occurred while processing '" + type, e);
|
2014-05-14 23:30:02 +04:00
|
|
|
errorPacket.from = from;
|
|
|
|
this.transport.send(errorPacket);
|
|
|
|
});
|
|
|
|
|
|
|
|
this._actorResponses.set(from, responsePromise);
|
|
|
|
},
|
|
|
|
|
2014-04-17 21:27:03 +04:00
|
|
|
/**
|
|
|
|
* Passes a set of options to the BrowserAddonActors for the given ID.
|
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param id string
|
2014-04-17 21:27:03 +04:00
|
|
|
* The ID of the add-on to pass the options to
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param options object
|
2014-04-17 21:27:03 +04:00
|
|
|
* The options.
|
|
|
|
* @return a promise that will be resolved when complete.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
setAddonOptions(id, options) {
|
2014-04-17 21:27:03 +04:00
|
|
|
let addonList = this.rootActor._parameters.addonList;
|
|
|
|
if (!addonList) {
|
2016-06-29 03:42:30 +03:00
|
|
|
return SyncPromise.resolve();
|
2014-04-17 21:27:03 +04:00
|
|
|
}
|
|
|
|
return addonList.getList().then((addonActors) => {
|
|
|
|
for (let actor of addonActors) {
|
2016-06-29 03:42:30 +03:00
|
|
|
if (actor.id != id) {
|
2014-04-17 21:27:03 +04:00
|
|
|
continue;
|
|
|
|
}
|
2016-06-29 03:42:30 +03:00
|
|
|
actor.setOptions(options);
|
2014-04-17 21:27:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-07-24 19:27:26 +04:00
|
|
|
/* Forwarding packets to other transports based on actor name prefixes. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Arrange to forward packets to another server. This is how we
|
|
|
|
* forward debugging connections to child processes.
|
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* If we receive a packet for an actor whose name begins with |prefix|
|
|
|
|
* followed by '/', then we will forward that packet to |transport|.
|
2013-07-24 19:27:26 +04:00
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* This overrides any prior forwarding for |prefix|.
|
2013-07-24 19:27:26 +04:00
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param prefix string
|
2014-05-14 23:30:01 +04:00
|
|
|
* The actor name prefix, not including the '/'.
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param transport object
|
2013-07-24 19:27:26 +04:00
|
|
|
* A packet transport to which we should forward packets to actors
|
2016-06-29 03:42:30 +03:00
|
|
|
* whose names begin with |(prefix + '/').|
|
2013-07-24 19:27:26 +04:00
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
setForwarding(prefix, transport) {
|
|
|
|
this._forwardingPrefixes.set(prefix, transport);
|
2013-07-24 19:27:26 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop forwarding messages to actors whose names begin with
|
2016-06-29 03:42:30 +03:00
|
|
|
* |prefix+'/'|. Such messages will now elicit 'noSuchActor' errors.
|
2013-07-24 19:27:26 +04:00
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
cancelForwarding(prefix) {
|
|
|
|
this._forwardingPrefixes.delete(prefix);
|
2016-07-07 00:17:03 +03:00
|
|
|
|
|
|
|
// Notify the client that forwarding in now cancelled for this prefix.
|
|
|
|
// There could be requests in progress that the client should abort rather leaving
|
|
|
|
// handing indefinitely.
|
|
|
|
if (this.rootActor) {
|
|
|
|
this.send(this.rootActor.forwardingCancelled(prefix));
|
|
|
|
}
|
2013-07-24 19:27:26 +04:00
|
|
|
},
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
sendActorEvent(actorID, eventName, event = {}) {
|
2014-07-07 17:40:00 +04:00
|
|
|
event.from = actorID;
|
|
|
|
event.type = eventName;
|
|
|
|
this.send(event);
|
|
|
|
},
|
|
|
|
|
2012-04-22 13:59:09 +04:00
|
|
|
// Transport hooks.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by DebuggerTransport to dispatch incoming packets as appropriate.
|
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param packet object
|
2012-04-22 13:59:09 +04:00
|
|
|
* The incoming packet.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
onPacket(packet) {
|
2013-07-24 19:27:26 +04:00
|
|
|
// If the actor's name begins with a prefix we've been asked to
|
|
|
|
// forward, do so.
|
|
|
|
//
|
|
|
|
// Note that the presence of a prefix alone doesn't indicate that
|
|
|
|
// forwarding is needed: in DebuggerServerConnection instances in child
|
|
|
|
// processes, every actor has a prefixed name.
|
|
|
|
if (this._forwardingPrefixes.size > 0) {
|
2016-06-29 03:42:30 +03:00
|
|
|
let to = packet.to;
|
2016-05-17 21:25:54 +03:00
|
|
|
let separator = to.lastIndexOf("/");
|
2015-06-17 11:56:58 +03:00
|
|
|
while (separator >= 0) {
|
|
|
|
to = to.substring(0, separator);
|
2016-06-29 03:42:30 +03:00
|
|
|
let forwardTo = this._forwardingPrefixes.get(packet.to.substring(0, separator));
|
2013-07-24 19:27:26 +04:00
|
|
|
if (forwardTo) {
|
2016-06-29 03:42:30 +03:00
|
|
|
forwardTo.send(packet);
|
2013-07-24 19:27:26 +04:00
|
|
|
return;
|
|
|
|
}
|
2016-05-17 21:25:54 +03:00
|
|
|
separator = to.lastIndexOf("/");
|
2013-07-24 19:27:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
let actor = this._getOrCreateActor(packet.to);
|
2012-04-22 13:59:09 +04:00
|
|
|
if (!actor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
let ret = null;
|
2014-01-06 21:27:10 +04:00
|
|
|
|
|
|
|
// handle "requestTypes" RDP request.
|
2016-06-29 03:42:30 +03:00
|
|
|
if (packet.type == "requestTypes") {
|
2014-01-06 21:27:10 +04:00
|
|
|
ret = { from: actor.actorID, requestTypes: Object.keys(actor.requestTypes) };
|
2016-06-29 03:42:30 +03:00
|
|
|
} else if (actor.requestTypes && actor.requestTypes[packet.type]) {
|
2014-01-06 21:27:10 +04:00
|
|
|
// Dispatch the request to the actor.
|
2012-04-22 13:59:09 +04:00
|
|
|
try {
|
2016-06-29 03:42:30 +03:00
|
|
|
this.currentPacket = packet;
|
|
|
|
ret = actor.requestTypes[packet.type].bind(actor)(packet, this);
|
2016-05-17 21:25:54 +03:00
|
|
|
} catch (e) {
|
2013-04-16 01:07:00 +04:00
|
|
|
this.transport.send(this._unknownError(
|
2016-06-29 03:42:30 +03:00
|
|
|
"error occurred while processing '" + packet.type,
|
2013-04-16 01:07:00 +04:00
|
|
|
e));
|
2013-06-06 23:29:27 +04:00
|
|
|
} finally {
|
2013-10-27 22:03:20 +04:00
|
|
|
this.currentPacket = undefined;
|
2012-04-22 13:59:09 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = { error: "unrecognizedPacketType",
|
2014-05-14 23:30:02 +04:00
|
|
|
message: ("Actor " + actor.actorID +
|
|
|
|
" does not recognize the packet type " +
|
2016-06-29 03:42:30 +03:00
|
|
|
packet.type) };
|
2014-05-14 23:30:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// There will not be a return value if a bulk reply is sent.
|
|
|
|
if (ret) {
|
2016-06-29 03:42:30 +03:00
|
|
|
this._queueResponse(packet.to, packet.type, ret);
|
2012-04-22 13:59:09 +04:00
|
|
|
}
|
2014-05-14 23:30:02 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by the DebuggerTransport to dispatch incoming bulk packets as
|
|
|
|
* appropriate.
|
|
|
|
*
|
|
|
|
* @param packet object
|
|
|
|
* The incoming packet, which contains:
|
|
|
|
* * actor: Name of actor that will receive the packet
|
|
|
|
* * type: Name of actor's method that should be called on receipt
|
|
|
|
* * length: Size of the data to be read
|
|
|
|
* * stream: This input stream should only be used directly if you can
|
|
|
|
* ensure that you will read exactly |length| bytes and will
|
|
|
|
* not close the stream when reading is complete
|
|
|
|
* * done: If you use the stream directly (instead of |copyTo|
|
|
|
|
* below), you must signal completion by resolving /
|
|
|
|
* rejecting this deferred. If it's rejected, the transport
|
|
|
|
* will be closed. If an Error is supplied as a rejection
|
|
|
|
* value, it will be logged via |dumpn|. If you do use
|
|
|
|
* |copyTo|, resolving is taken care of for you when copying
|
|
|
|
* completes.
|
|
|
|
* * copyTo: A helper function for getting your data out of the stream
|
|
|
|
* that meets the stream handling requirements above, and has
|
|
|
|
* the following signature:
|
|
|
|
* @param output nsIAsyncOutputStream
|
|
|
|
* The stream to copy to.
|
|
|
|
* @return Promise
|
|
|
|
* The promise is resolved when copying completes or rejected
|
|
|
|
* if any (unexpected) errors occur.
|
2014-06-26 16:19:00 +04:00
|
|
|
* This object also emits "progress" events for each chunk
|
|
|
|
* that is copied. See stream-utils.js.
|
2014-05-14 23:30:02 +04:00
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
onBulkPacket(packet) {
|
|
|
|
let { actor: actorKey, type } = packet;
|
2012-04-22 13:59:09 +04:00
|
|
|
|
2014-05-14 23:30:02 +04:00
|
|
|
let actor = this._getOrCreateActor(actorKey);
|
|
|
|
if (!actor) {
|
2012-04-22 13:59:09 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-14 23:30:02 +04:00
|
|
|
// Dispatch the request to the actor.
|
|
|
|
let ret;
|
|
|
|
if (actor.requestTypes && actor.requestTypes[type]) {
|
|
|
|
try {
|
|
|
|
ret = actor.requestTypes[type].call(actor, packet);
|
2016-05-17 21:25:54 +03:00
|
|
|
} catch (e) {
|
2014-05-14 23:30:02 +04:00
|
|
|
this.transport.send(this._unknownError(
|
|
|
|
"error occurred while processing bulk packet '" + type, e));
|
|
|
|
packet.done.reject(e);
|
2013-08-09 09:28:41 +04:00
|
|
|
}
|
2014-05-14 23:30:02 +04:00
|
|
|
} else {
|
|
|
|
let message = "Actor " + actorKey +
|
|
|
|
" does not recognize the bulk packet type " + type;
|
|
|
|
ret = { error: "unrecognizedPacketType",
|
|
|
|
message: message };
|
|
|
|
packet.done.reject(new Error(message));
|
|
|
|
}
|
2013-08-09 09:28:41 +04:00
|
|
|
|
2014-05-14 23:30:02 +04:00
|
|
|
// If there is a JSON response, queue it for sending back to the client.
|
|
|
|
if (ret) {
|
|
|
|
this._queueResponse(actorKey, type, ret);
|
|
|
|
}
|
2012-04-22 13:59:09 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by DebuggerTransport when the underlying stream is closed.
|
|
|
|
*
|
2016-06-29 03:42:30 +03:00
|
|
|
* @param status nsresult
|
2012-04-22 13:59:09 +04:00
|
|
|
* The status code that corresponds to the reason for closing
|
|
|
|
* the stream.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
onClosed(status) {
|
2012-04-22 13:59:09 +04:00
|
|
|
dumpn("Cleaning up connection.");
|
2014-04-02 23:29:40 +04:00
|
|
|
if (!this._actorPool) {
|
|
|
|
// Ignore this call if the connection is already closed.
|
|
|
|
return;
|
|
|
|
}
|
2015-11-19 20:51:21 +03:00
|
|
|
this._actorPool = null;
|
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
events.emit(this, "closed", status);
|
2012-04-22 13:59:09 +04:00
|
|
|
|
2016-06-29 03:42:30 +03:00
|
|
|
this._extraPools.forEach(p => p.destroy());
|
2012-04-22 13:59:09 +04:00
|
|
|
this._extraPools = null;
|
|
|
|
|
2015-04-18 10:39:07 +03:00
|
|
|
this.rootActor = null;
|
|
|
|
this._transport = null;
|
2012-04-22 13:59:09 +04:00
|
|
|
DebuggerServer._connectionClosed(this);
|
2012-11-01 19:34:10 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Debugging helper for inspecting the state of the actor pools.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
_dumpPools() {
|
2012-11-01 19:34:10 +04:00
|
|
|
dumpn("/-------------------- dumping pools:");
|
|
|
|
if (this._actorPool) {
|
|
|
|
dumpn("--------------------- actorPool actors: " +
|
|
|
|
uneval(Object.keys(this._actorPool._actors)));
|
|
|
|
}
|
2015-05-28 18:54:00 +03:00
|
|
|
for (let pool of this._extraPools) {
|
2015-01-06 03:26:27 +03:00
|
|
|
if (pool !== this._actorPool) {
|
|
|
|
dumpn("--------------------- extraPool actors: " +
|
|
|
|
uneval(Object.keys(pool._actors)));
|
|
|
|
}
|
|
|
|
}
|
2012-11-01 19:34:10 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Debugging helper for inspecting the state of an actor pool.
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
_dumpPool(pool) {
|
2012-11-01 19:34:10 +04:00
|
|
|
dumpn("/-------------------- dumping pool:");
|
|
|
|
dumpn("--------------------- actorPool actors: " +
|
2016-06-29 03:42:30 +03:00
|
|
|
uneval(Object.keys(pool._actors)));
|
2015-08-03 17:52:42 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* In a content child process, ask the DebuggerServer in the parent process
|
|
|
|
* to execute a given module setup helper.
|
|
|
|
*
|
|
|
|
* @param module
|
|
|
|
* The module to be required
|
|
|
|
* @param setupParent
|
|
|
|
* The name of the setup helper exported by the above module
|
|
|
|
* (setup helper signature: function ({mm}) { ... })
|
|
|
|
* @return boolean
|
|
|
|
* true if the setup helper returned successfully
|
|
|
|
*/
|
2016-06-29 03:42:30 +03:00
|
|
|
setupInParent({ module, setupParent }) {
|
2015-08-03 17:52:42 +03:00
|
|
|
if (!this.parentMessageManager) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let { sendSyncMessage } = this.parentMessageManager;
|
|
|
|
|
|
|
|
return sendSyncMessage("debug:setup-in-parent", {
|
2015-11-02 19:18:58 +03:00
|
|
|
prefix: this.prefix,
|
2015-08-03 17:52:42 +03:00
|
|
|
module: module,
|
|
|
|
setupParent: setupParent
|
|
|
|
});
|
|
|
|
},
|
2012-04-22 13:59:09 +04:00
|
|
|
};
|