2014-06-24 22:12:07 -07:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
2012-04-22 02:59:09 -07:00
|
|
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07: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 02:59:09 -07:00
|
|
|
|
|
|
|
"use strict";
|
2014-05-21 04:58:18 -07:00
|
|
|
|
2012-04-22 02:59:09 -07:00
|
|
|
/**
|
|
|
|
* Toolkit glue for the remote debugging protocol, loaded into the
|
|
|
|
* debugging global.
|
|
|
|
*/
|
2014-04-17 11:45:32 -07:00
|
|
|
let { Ci, Cc, CC, Cu, Cr } = require("chrome");
|
|
|
|
let Services = require("Services");
|
2014-09-16 03:00:00 -07:00
|
|
|
let { ActorPool, RegisteredActorFactory, ObservedActorFactory } = require("devtools/server/actors/common");
|
2014-12-01 22:55:56 -08:00
|
|
|
let { LocalDebuggerTransport, ChildDebuggerTransport } =
|
2014-05-14 12:30:02 -07:00
|
|
|
require("devtools/toolkit/transport/transport");
|
2014-04-24 04:13:12 -07:00
|
|
|
let DevToolsUtils = require("devtools/toolkit/DevToolsUtils");
|
2014-05-14 12:30:02 -07:00
|
|
|
let { dumpn, dumpv, dbg_assert } = DevToolsUtils;
|
2014-04-17 10:27:03 -07:00
|
|
|
let EventEmitter = require("devtools/toolkit/event-emitter");
|
2014-07-07 03:07:00 -07:00
|
|
|
let Debugger = require("Debugger");
|
2012-04-22 02:59:09 -07:00
|
|
|
|
2014-12-01 22:55:56 -08:00
|
|
|
DevToolsUtils.defineLazyGetter(this, "DebuggerSocket", () => {
|
|
|
|
let { DebuggerSocket } = require("devtools/toolkit/security/socket");
|
|
|
|
return DebuggerSocket;
|
|
|
|
});
|
|
|
|
|
2014-01-06 12:55:00 -08: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-04-17 11:45:32 -07:00
|
|
|
this.Debugger = Debugger;
|
2014-03-13 08:01:32 -07:00
|
|
|
this.Services = Services;
|
2014-04-24 04:13:12 -07:00
|
|
|
this.ActorPool = ActorPool;
|
2014-04-17 11:45:32 -07:00
|
|
|
this.DevToolsUtils = DevToolsUtils;
|
2014-04-17 11:47:28 -07:00
|
|
|
this.dumpn = dumpn;
|
2014-05-14 12:30:02 -07:00
|
|
|
this.dumpv = dumpv;
|
2014-04-17 11:47:28 -07:00
|
|
|
this.dbg_assert = dbg_assert;
|
2014-03-04 06:38:05 -08:00
|
|
|
|
2014-01-06 12:55:00 -08:00
|
|
|
// Overload `Components` to prevent SDK loader exception on Components
|
|
|
|
// object usage
|
|
|
|
Object.defineProperty(this, "Components", {
|
|
|
|
get: function () require("chrome").components
|
|
|
|
});
|
2013-08-30 17:34:26 -07:00
|
|
|
|
2014-06-17 12:51:43 -07:00
|
|
|
if (isWorker) {
|
|
|
|
dumpn.wantLogging = true;
|
|
|
|
dumpv.wantVerbose = true;
|
|
|
|
} else {
|
|
|
|
const LOG_PREF = "devtools.debugger.log";
|
|
|
|
const VERBOSE_PREF = "devtools.debugger.log.verbose";
|
|
|
|
|
|
|
|
dumpn.wantLogging = Services.prefs.getBoolPref(LOG_PREF);
|
|
|
|
dumpv.wantVerbose =
|
|
|
|
Services.prefs.getPrefType(VERBOSE_PREF) !== Services.prefs.PREF_INVALID &&
|
|
|
|
Services.prefs.getBoolPref(VERBOSE_PREF);
|
|
|
|
}
|
2012-04-22 02:59:09 -07:00
|
|
|
|
2013-08-28 07:19:34 -07:00
|
|
|
function loadSubScript(aURL)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
|
|
|
.getService(Ci.mozIJSSubScriptLoader);
|
|
|
|
loader.loadSubScript(aURL, this);
|
|
|
|
} catch(e) {
|
2014-03-22 01:02:13 -07:00
|
|
|
let errorStr = "Error loading: " + aURL + ":\n" +
|
|
|
|
(e.fileName ? "at " + e.fileName + " : " + e.lineNumber + "\n" : "") +
|
|
|
|
e + " - " + e.stack + "\n";
|
2013-08-28 07:19:34 -07:00
|
|
|
dump(errorStr);
|
2014-05-30 07:42:55 -07:00
|
|
|
reportError(errorStr);
|
2013-08-28 07:19:34 -07:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-02 12:29:40 -07:00
|
|
|
let events = require("sdk/event/core");
|
2014-04-22 12:55:01 -07:00
|
|
|
let {defer, resolve, reject, all} = require("devtools/toolkit/deprecated-sync-thenables");
|
2014-01-06 12:55:00 -08:00
|
|
|
this.defer = defer;
|
|
|
|
this.resolve = resolve;
|
|
|
|
this.reject = reject;
|
|
|
|
this.all = all;
|
2013-04-15 14:07:00 -07:00
|
|
|
|
2013-06-06 16:06:08 -07: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 12:56:30 -07:00
|
|
|
// See DebuggerServer.setRootActor for a description.
|
|
|
|
setRootActor: function(factory) {
|
|
|
|
DebuggerServer.setRootActor(factory);
|
|
|
|
},
|
|
|
|
|
2013-06-06 16:06:08 -07:00
|
|
|
// See DebuggerServer.addGlobalActor for a description.
|
|
|
|
addGlobalActor: function(factory, name) {
|
|
|
|
DebuggerServer.addGlobalActor(factory, name);
|
|
|
|
activeGlobalActors.add(factory);
|
|
|
|
},
|
|
|
|
// See DebuggerServer.removeGlobalActor for a description.
|
|
|
|
removeGlobalActor: function(factory) {
|
|
|
|
DebuggerServer.removeGlobalActor(factory);
|
|
|
|
activeGlobalActors.delete(factory);
|
|
|
|
},
|
|
|
|
|
|
|
|
// See DebuggerServer.addTabActor for a description.
|
|
|
|
addTabActor: function(factory, name) {
|
|
|
|
DebuggerServer.addTabActor(factory, name);
|
|
|
|
activeTabActors.add(factory);
|
|
|
|
},
|
|
|
|
// See DebuggerServer.removeTabActor for a description.
|
|
|
|
removeTabActor: function(factory) {
|
|
|
|
DebuggerServer.removeTabActor(factory);
|
|
|
|
activeTabActors.delete(factory);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Destroy the module API object, unregistering any
|
|
|
|
// factories registered by the module.
|
|
|
|
destroy: function() {
|
|
|
|
for (let factory of activeTabActors) {
|
|
|
|
DebuggerServer.removeTabActor(factory);
|
|
|
|
}
|
|
|
|
activeTabActors = null;
|
|
|
|
for (let factory of activeGlobalActors) {
|
|
|
|
DebuggerServer.removeGlobalActor(factory);
|
|
|
|
}
|
|
|
|
activeGlobalActors = null;
|
|
|
|
}
|
2014-11-27 02:52:00 -08:00
|
|
|
};
|
2013-06-06 16:06:08 -07:00
|
|
|
};
|
|
|
|
|
2012-04-22 02:59:09 -07:00
|
|
|
/***
|
|
|
|
* Public API
|
|
|
|
*/
|
|
|
|
var DebuggerServer = {
|
2014-07-10 11:15:00 -07:00
|
|
|
_listeners: [],
|
2013-05-03 18:21:48 -07:00
|
|
|
_initialized: false,
|
2012-04-22 02:59:09 -07:00
|
|
|
_transportInitialized: false,
|
2012-09-19 23:36:32 -07:00
|
|
|
// Map of global actor names to actor constructors provided by extensions.
|
2013-05-03 18:21:48 -07:00
|
|
|
globalActorFactories: {},
|
2012-09-19 23:36:32 -07:00
|
|
|
// Map of tab actor names to actor constructors provided by extensions.
|
2013-05-03 18:21:48 -07:00
|
|
|
tabActorFactories: {},
|
2012-04-22 02:59:09 -07:00
|
|
|
|
2012-08-30 14:10:07 -07:00
|
|
|
LONG_STRING_LENGTH: 10000,
|
|
|
|
LONG_STRING_INITIAL_LENGTH: 1000,
|
2013-11-06 13:39:50 -08:00
|
|
|
LONG_STRING_READ_LENGTH: 65 * 1024,
|
2012-08-30 14:10:07 -07:00
|
|
|
|
2013-08-01 01:51:24 -07: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,
|
|
|
|
|
2012-04-22 02:59:09 -07:00
|
|
|
/**
|
|
|
|
* Initialize the debugger server.
|
|
|
|
*/
|
2014-12-01 22:55:56 -08:00
|
|
|
init: function DS_init() {
|
2012-04-22 02:59:09 -07:00
|
|
|
if (this.initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-01 22:55:56 -08:00
|
|
|
this.initTransport();
|
2012-09-19 23:36:32 -07:00
|
|
|
|
2013-05-03 18:21:48 -07:00
|
|
|
this._initialized = true;
|
2012-04-22 02:59:09 -07:00
|
|
|
},
|
|
|
|
|
2014-04-17 16:25:07 -07:00
|
|
|
protocol: require("devtools/server/protocol"),
|
|
|
|
|
2012-04-22 02:59:09 -07:00
|
|
|
/**
|
|
|
|
* Initialize the debugger server's transport variables. This can be
|
|
|
|
* in place of init() for cases where the jsdebugger isn't needed.
|
|
|
|
*/
|
2014-12-01 22:55:56 -08:00
|
|
|
initTransport: function DS_initTransport() {
|
2012-04-22 02:59:09 -07:00
|
|
|
if (this._transportInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._connections = {};
|
|
|
|
this._nextConnID = 0;
|
|
|
|
this._transportInitialized = true;
|
|
|
|
},
|
|
|
|
|
2013-05-03 18:21:48 -07:00
|
|
|
get initialized() this._initialized,
|
2012-09-19 23:36:32 -07:00
|
|
|
|
|
|
|
/**
|
2013-07-12 12:13:21 -07: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-19 23:36:32 -07:00
|
|
|
*/
|
2012-10-31 09:31:55 -07:00
|
|
|
destroy: function DS_destroy() {
|
2013-05-30 09:42:00 -07:00
|
|
|
if (!this._initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let connID of Object.getOwnPropertyNames(this._connections)) {
|
|
|
|
this._connections[connID].close();
|
2012-09-19 23:36:32 -07:00
|
|
|
}
|
2013-06-06 16:06:08 -07:00
|
|
|
|
|
|
|
for (let id of Object.getOwnPropertyNames(gRegisteredModules)) {
|
2014-09-16 03:00:00 -07:00
|
|
|
this.unregisterModule(id);
|
2013-06-06 16:06:08 -07:00
|
|
|
}
|
2014-11-27 02:52:00 -08:00
|
|
|
gRegisteredModules = Object.create(null);
|
2013-06-06 16:06:08 -07:00
|
|
|
|
2014-07-10 11:15:00 -07:00
|
|
|
this.closeAllListeners();
|
2013-05-30 09:42:00 -07:00
|
|
|
this.globalActorFactories = {};
|
|
|
|
this.tabActorFactories = {};
|
|
|
|
this._transportInitialized = false;
|
|
|
|
this._initialized = false;
|
2013-09-07 16:28:51 -07:00
|
|
|
|
2013-05-30 09:42:00 -07:00
|
|
|
dumpn("Debugger server is shut down.");
|
2012-09-19 23:36:32 -07:00
|
|
|
},
|
2012-04-22 02:59:09 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a subscript into the debugging global.
|
|
|
|
*
|
|
|
|
* @param aURL string A url that will be loaded as a subscript into the
|
|
|
|
* debugging global. The user must load at least one script
|
|
|
|
* that implements a createRootActor() function to create the
|
|
|
|
* server's root actor.
|
|
|
|
*/
|
2012-10-31 09:31:55 -07:00
|
|
|
addActors: function DS_addActors(aURL) {
|
2012-04-22 02:59:09 -07:00
|
|
|
loadSubScript.call(this, aURL);
|
|
|
|
},
|
|
|
|
|
2013-06-06 16:06:08 -07:00
|
|
|
/**
|
|
|
|
* Register a CommonJS module with the debugger server.
|
|
|
|
* @param id string
|
2014-09-16 03:00:00 -07: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 04:49:00 -07:00
|
|
|
* - type (a dictionary of booleans with following attribute names):
|
2014-09-16 03:00:00 -07: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-06 16:06:08 -07:00
|
|
|
*/
|
2014-09-16 03:00:00 -07:00
|
|
|
registerModule: function(id, options) {
|
2013-06-06 16:06:08 -07:00
|
|
|
if (id in gRegisteredModules) {
|
|
|
|
throw new Error("Tried to register a module twice: " + id + "\n");
|
|
|
|
}
|
|
|
|
|
2014-09-16 03:00:00 -07:00
|
|
|
if (options) {
|
|
|
|
// Lazy loaded actors
|
|
|
|
let {prefix, constructor, type} = options;
|
|
|
|
if (typeof(prefix) !== "string") {
|
|
|
|
throw new Error("Lazy actor definition for '" + id + "' requires a string 'prefix' option.");
|
|
|
|
}
|
|
|
|
if (typeof(constructor) !== "string") {
|
|
|
|
throw new Error("Lazy actor definition for '" + id + "' requires a string 'constructor' option.");
|
|
|
|
}
|
|
|
|
if (!("global" in type) && !("tab" in type)) {
|
2014-10-03 04:49:00 -07:00
|
|
|
throw new Error("Lazy actor definition for '" + id + "' requires a dictionary 'type' option whose attributes can be 'global' or 'tab'.");
|
2014-09-16 03:00:00 -07: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-06 16:06:08 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if a module id has been registered.
|
|
|
|
*/
|
|
|
|
isModuleRegistered: function(id) {
|
|
|
|
return (id in gRegisteredModules);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregister a previously-loaded CommonJS module from the debugger server.
|
|
|
|
*/
|
|
|
|
unregisterModule: function(id) {
|
|
|
|
let mod = gRegisteredModules[id];
|
|
|
|
if (!mod) {
|
|
|
|
throw new Error("Tried to unregister a module that was not previously registered.");
|
|
|
|
}
|
2014-09-16 03:00:00 -07: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-06 16:06:08 -07:00
|
|
|
delete gRegisteredModules[id];
|
|
|
|
},
|
|
|
|
|
2012-04-22 02:59:09 -07:00
|
|
|
/**
|
|
|
|
* Install Firefox-specific actors.
|
2014-03-03 11:11:00 -08: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 02:59:09 -07:00
|
|
|
*/
|
2014-01-24 02:11:00 -08:00
|
|
|
addBrowserActors: function(aWindowType = "navigator:browser", restrictPrivileges = false) {
|
|
|
|
this.chromeWindowType = aWindowType;
|
2014-05-13 12:56:30 -07:00
|
|
|
this.registerModule("devtools/server/actors/webbrowser");
|
2014-01-24 02:11:00 -08:00
|
|
|
|
|
|
|
if (!restrictPrivileges) {
|
|
|
|
this.addTabActors();
|
2014-04-29 08:52:44 -07:00
|
|
|
let { ChromeDebuggerActor } = require("devtools/server/actors/script");
|
|
|
|
this.addGlobalActor(ChromeDebuggerActor, "chromeDebugger");
|
2014-09-16 03:00:00 -07:00
|
|
|
this.registerModule("devtools/server/actors/preference", {
|
|
|
|
prefix: "preference",
|
|
|
|
constructor: "PreferenceActor",
|
|
|
|
type: { global: true }
|
|
|
|
});
|
2014-10-03 04:49:00 -07:00
|
|
|
this.registerModule("devtools/server/actors/actor-registry", {
|
|
|
|
prefix: "actorRegistry",
|
|
|
|
constructor: "ActorRegistryActor",
|
|
|
|
type: { global: true }
|
|
|
|
});
|
2014-01-24 02:11:00 -08:00
|
|
|
}
|
2013-04-25 09:46:13 -07:00
|
|
|
|
2014-09-18 02:44:00 -07:00
|
|
|
this.registerModule("devtools/server/actors/webapps", {
|
|
|
|
prefix: "webapps",
|
|
|
|
constructor: "WebappsActor",
|
|
|
|
type: { global: true }
|
|
|
|
});
|
2014-09-16 03:00:00 -07:00
|
|
|
this.registerModule("devtools/server/actors/device", {
|
|
|
|
prefix: "device",
|
|
|
|
constructor: "DeviceActor",
|
|
|
|
type: { global: true }
|
|
|
|
});
|
2012-04-22 02:59:09 -07:00
|
|
|
},
|
|
|
|
|
2013-07-24 08:28:32 -07:00
|
|
|
/**
|
|
|
|
* Install tab actors in documents loaded in content childs
|
|
|
|
*/
|
|
|
|
addChildActors: function () {
|
|
|
|
// 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 01:38:00 -07:00
|
|
|
if (!DebuggerServer.tabActorFactories.hasOwnProperty("consoleActor")) {
|
2014-03-03 11:11:00 -08:00
|
|
|
this.addTabActors();
|
|
|
|
}
|
|
|
|
// But webbrowser.js and childtab.js aren't loaded from shell.js.
|
2014-05-13 12:56:30 -07:00
|
|
|
if (!this.isModuleRegistered("devtools/server/actors/webbrowser")) {
|
|
|
|
this.registerModule("devtools/server/actors/webbrowser");
|
2013-07-24 08:28:32 -07:00
|
|
|
}
|
2014-03-10 09:38:17 -07:00
|
|
|
if (!("ContentActor" in this)) {
|
2013-07-24 08:28:32 -07:00
|
|
|
this.addActors("resource://gre/modules/devtools/server/actors/childtab.js");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-01-24 02:11:00 -08:00
|
|
|
/**
|
|
|
|
* Install tab actors.
|
|
|
|
*/
|
|
|
|
addTabActors: function() {
|
2014-09-16 03:00:00 -07:00
|
|
|
this.registerModule("devtools/server/actors/webconsole", {
|
|
|
|
prefix: "console",
|
|
|
|
constructor: "WebConsoleActor",
|
|
|
|
type: { global: true, tab: true }
|
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/inspector", {
|
|
|
|
prefix: "inspector",
|
|
|
|
constructor: "InspectorActor",
|
|
|
|
type: { global: true, tab: true }
|
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/call-watcher", {
|
|
|
|
prefix: "callWatcher",
|
|
|
|
constructor: "CallWatcherActor",
|
|
|
|
type: { tab: true }
|
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/canvas", {
|
|
|
|
prefix: "canvas",
|
|
|
|
constructor: "CanvasActor",
|
|
|
|
type: { global: true, tab: true }
|
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/webgl", {
|
|
|
|
prefix: "webgl",
|
|
|
|
constructor: "WebGLActor",
|
|
|
|
type: { global: true, tab: true }
|
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/webaudio", {
|
|
|
|
prefix: "webaudio",
|
|
|
|
constructor: "WebAudioActor",
|
|
|
|
type: { global: true, tab: true }
|
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/stylesheets", {
|
|
|
|
prefix: "styleSheets",
|
|
|
|
constructor: "StyleSheetsActor",
|
|
|
|
type: { global: true, tab: true }
|
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/styleeditor", {
|
|
|
|
prefix: "styleEditor",
|
|
|
|
constructor: "StyleEditorActor",
|
|
|
|
type: { global: true, tab: true }
|
|
|
|
});
|
|
|
|
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/tracer", {
|
|
|
|
prefix: "trace",
|
|
|
|
constructor: "TracerActor",
|
|
|
|
type: { tab: true }
|
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/memory", {
|
|
|
|
prefix: "memory",
|
|
|
|
constructor: "MemoryActor",
|
|
|
|
type: { global: true, tab: true }
|
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/framerate", {
|
|
|
|
prefix: "framerate",
|
|
|
|
constructor: "FramerateActor",
|
|
|
|
type: { global: true, tab: true }
|
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/eventlooplag", {
|
|
|
|
prefix: "eventLoopLag",
|
|
|
|
constructor: "EventLoopLagActor",
|
|
|
|
type: { global: true, tab: true }
|
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/layout", {
|
|
|
|
prefix: "reflow",
|
|
|
|
constructor: "ReflowActor",
|
|
|
|
type: { tab: true }
|
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/csscoverage", {
|
|
|
|
prefix: "cssUsage",
|
|
|
|
constructor: "CSSUsageActor",
|
|
|
|
type: { global: true, tab: true }
|
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/monitor", {
|
|
|
|
prefix: "monitor",
|
|
|
|
constructor: "MonitorActor",
|
|
|
|
type: { global: true, tab: true }
|
|
|
|
});
|
|
|
|
this.registerModule("devtools/server/actors/timeline", {
|
|
|
|
prefix: "timeline",
|
|
|
|
constructor: "TimelineActor",
|
|
|
|
type: { global: true, tab: true }
|
|
|
|
});
|
2014-03-29 10:01:37 -07:00
|
|
|
if ("nsIProfiler" in Ci) {
|
2014-09-16 03:00:00 -07:00
|
|
|
this.registerModule("devtools/server/actors/profiler", {
|
|
|
|
prefix: "profiler",
|
|
|
|
constructor: "ProfilerActor",
|
|
|
|
type: { global: true, tab: true }
|
|
|
|
});
|
2014-03-29 10:01:37 -07:00
|
|
|
}
|
2014-12-11 11:08:49 -08:00
|
|
|
this.registerModule("devtools/server/actors/animation", {
|
|
|
|
prefix: "animations",
|
|
|
|
constructor: "AnimationsActor",
|
|
|
|
type: { global: true, tab: true }
|
|
|
|
});
|
2014-01-24 02:11:00 -08:00
|
|
|
},
|
|
|
|
|
2014-04-17 10:27:03 -07:00
|
|
|
/**
|
|
|
|
* Passes a set of options to the BrowserAddonActors for the given ID.
|
|
|
|
*
|
|
|
|
* @param aId string
|
|
|
|
* The ID of the add-on to pass the options to
|
|
|
|
* @param aOptions object
|
|
|
|
* The options.
|
|
|
|
* @return a promise that will be resolved when complete.
|
|
|
|
*/
|
|
|
|
setAddonOptions: function DS_setAddonOptions(aId, aOptions) {
|
|
|
|
if (!this._initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let promises = [];
|
|
|
|
|
|
|
|
// Pass to all connections
|
|
|
|
for (let connID of Object.getOwnPropertyNames(this._connections)) {
|
|
|
|
promises.push(this._connections[connID].setAddonOptions(aId, aOptions));
|
|
|
|
}
|
|
|
|
|
|
|
|
return all(promises);
|
|
|
|
},
|
|
|
|
|
2014-07-10 11:15:00 -07:00
|
|
|
get listeningSockets() {
|
|
|
|
return this._listeners.length;
|
|
|
|
},
|
|
|
|
|
2012-04-22 02:59:09 -07:00
|
|
|
/**
|
2014-12-10 18:55:51 -08: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.
|
|
|
|
*
|
|
|
|
* See SocketListener in toolkit/devtools/security/socket.js for available
|
|
|
|
* options.
|
2012-04-22 02:59:09 -07:00
|
|
|
*
|
2014-07-10 11:15:00 -07:00
|
|
|
* @return SocketListener
|
2014-12-10 18:55:51 -08: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 02:59:09 -07:00
|
|
|
*/
|
2014-12-10 18:55:51 -08:00
|
|
|
createListener: function() {
|
2014-04-24 10:11:55 -07:00
|
|
|
if (!Services.prefs.getBoolPref("devtools.debugger.remote-enabled")) {
|
2014-12-10 18:55:51 -08:00
|
|
|
throw new Error("Can't create listener, remote debugging disabled");
|
2014-04-24 10:11:55 -07:00
|
|
|
}
|
2012-04-22 02:59:09 -07:00
|
|
|
this._checkInit();
|
2014-12-10 18:55:51 -08:00
|
|
|
return DebuggerSocket.createListener();
|
|
|
|
},
|
2012-04-22 02:59:09 -07:00
|
|
|
|
2014-12-10 18:55:51 -08:00
|
|
|
/**
|
|
|
|
* Add a SocketListener instance to the server's set of active
|
|
|
|
* SocketListeners. This is called by a SocketListener after it is opened.
|
|
|
|
*/
|
|
|
|
_addListener: function(listener) {
|
2014-07-10 11:15:00 -07:00
|
|
|
this._listeners.push(listener);
|
|
|
|
},
|
2012-04-22 02:59:09 -07:00
|
|
|
|
2014-07-10 11:15:00 -07:00
|
|
|
/**
|
|
|
|
* Remove a SocketListener instance from the server's set of active
|
|
|
|
* SocketListeners. This is called by a SocketListener after it is closed.
|
|
|
|
*/
|
|
|
|
_removeListener: function(listener) {
|
|
|
|
this._listeners = this._listeners.filter(l => l !== listener);
|
2012-04-22 02:59:09 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-07-10 11:15:00 -07:00
|
|
|
* Closes and forgets all previously opened listeners.
|
2012-09-19 23:36:32 -07:00
|
|
|
*
|
2014-07-10 11:15:00 -07:00
|
|
|
* @return boolean
|
|
|
|
* Whether any listeners were actually closed.
|
2012-04-22 02:59:09 -07:00
|
|
|
*/
|
2014-07-10 11:15:00 -07:00
|
|
|
closeAllListeners: function() {
|
|
|
|
if (!this.listeningSockets) {
|
2012-04-22 02:59:09 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-10 11:15:00 -07:00
|
|
|
for (let listener of this._listeners) {
|
|
|
|
listener.close();
|
2012-09-19 23:36:32 -07:00
|
|
|
}
|
2012-04-22 02:59:09 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-09-22 08:44:00 -07: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 02:59:09 -07:00
|
|
|
*
|
2013-07-24 08:27:26 -07:00
|
|
|
* @param aPrefix string [optional]
|
|
|
|
* If given, all actors in this connection will have names starting
|
2014-05-14 12:30:01 -07:00
|
|
|
* with |aPrefix + '/'|.
|
2012-04-22 02:59:09 -07:00
|
|
|
* @returns a client-side DebuggerTransport for communicating with
|
2013-07-24 08:27:26 -07:00
|
|
|
* the newly-created connection.
|
2012-04-22 02:59:09 -07:00
|
|
|
*/
|
2013-07-24 08:27:26 -07:00
|
|
|
connectPipe: function DS_connectPipe(aPrefix) {
|
2012-04-22 02:59:09 -07:00
|
|
|
this._checkInit();
|
|
|
|
|
2012-09-22 08:44:00 -07:00
|
|
|
let serverTransport = new LocalDebuggerTransport;
|
|
|
|
let clientTransport = new LocalDebuggerTransport(serverTransport);
|
|
|
|
serverTransport.other = clientTransport;
|
2013-07-24 08:27:26 -07:00
|
|
|
let connection = this._onConnection(serverTransport, aPrefix);
|
2013-06-03 09:05:29 -07: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 02:59:09 -07:00
|
|
|
|
2012-09-22 08:44:00 -07:00
|
|
|
return clientTransport;
|
2012-04-22 02:59:09 -07:00
|
|
|
},
|
|
|
|
|
2013-07-24 08:28:32 -07:00
|
|
|
/**
|
|
|
|
* In a content child process, create a new connection that exchanges
|
|
|
|
* nsIMessageSender messages with our parent process.
|
|
|
|
*
|
|
|
|
* @param aPrefix
|
|
|
|
* 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 12:30:01 -07:00
|
|
|
* beginning with "<prefix>/".
|
2013-07-24 08:28:32 -07:00
|
|
|
*/
|
|
|
|
connectToParent: function(aPrefix, aMessageManager) {
|
|
|
|
this._checkInit();
|
|
|
|
|
|
|
|
let transport = new ChildDebuggerTransport(aMessageManager, aPrefix);
|
|
|
|
return this._onConnection(transport, aPrefix, true);
|
|
|
|
},
|
2013-06-03 09:05:29 -07:00
|
|
|
|
2014-11-07 12:24:47 -08:00
|
|
|
connectToContent: function (aConnection, aMm) {
|
|
|
|
let deferred = defer();
|
|
|
|
|
|
|
|
let prefix = aConnection.allocID("content-process");
|
|
|
|
let actor, childTransport;
|
|
|
|
|
|
|
|
aMm.addMessageListener("debug:content-process-actor", function listener(msg) {
|
|
|
|
// Arbitrarily choose the first content process to reply
|
|
|
|
// XXX: This code needs to be updated if we use more than one content process
|
|
|
|
aMm.removeMessageListener("debug:content-process-actor", listener);
|
|
|
|
|
|
|
|
// Pipe Debugger message from/to parent/child via the message manager
|
|
|
|
childTransport = new ChildDebuggerTransport(aMm, prefix);
|
|
|
|
childTransport.hooks = {
|
|
|
|
onPacket: aConnection.send.bind(aConnection),
|
|
|
|
onClosed: function () {}
|
|
|
|
};
|
|
|
|
childTransport.ready();
|
|
|
|
|
|
|
|
aConnection.setForwarding(prefix, childTransport);
|
|
|
|
|
|
|
|
dumpn("establishing forwarding for process with prefix " + prefix);
|
|
|
|
|
|
|
|
actor = msg.json.actor;
|
|
|
|
|
|
|
|
deferred.resolve(actor);
|
|
|
|
});
|
|
|
|
|
|
|
|
aMm.sendAsyncMessage("DevTools:InitDebuggerServer", {
|
|
|
|
prefix: prefix
|
|
|
|
});
|
|
|
|
|
|
|
|
function onDisconnect() {
|
|
|
|
Services.obs.removeObserver(onMessageManagerDisconnect, "message-manager-disconnect");
|
|
|
|
events.off(aConnection, "closed", onDisconnect);
|
|
|
|
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;
|
|
|
|
aConnection.cancelForwarding(prefix);
|
|
|
|
|
|
|
|
// ... and notify the child process to clean the tab actors.
|
|
|
|
try {
|
|
|
|
aMm.sendAsyncMessage("debug:content-process-destroy");
|
|
|
|
} catch(e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let onMessageManagerDisconnect = DevToolsUtils.makeInfallible(function (subject, topic, data) {
|
|
|
|
if (subject == aMm) {
|
|
|
|
onDisconnect();
|
|
|
|
aConnection.send({ from: actor.actor, type: "tabDetached" });
|
|
|
|
}
|
|
|
|
}).bind(this);
|
|
|
|
Services.obs.addObserver(onMessageManagerDisconnect,
|
|
|
|
"message-manager-disconnect", false);
|
|
|
|
|
|
|
|
events.on(aConnection, "closed", onDisconnect);
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
},
|
|
|
|
|
2014-11-27 02:52:00 -08:00
|
|
|
/**
|
|
|
|
* Check if the caller is running in a content child process.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
* true if the caller is running in a content
|
|
|
|
*/
|
|
|
|
get isInChildProcess() !!this.parentMessageManager,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
setupInParent: function({ module, setupParent }) {
|
|
|
|
if (!this.isInChildProcess) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let { sendSyncMessage } = DebuggerServer.parentMessageManager;
|
|
|
|
|
|
|
|
return sendSyncMessage("debug:setup-in-parent", {
|
|
|
|
module: module,
|
|
|
|
setupParent: setupParent
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-04-03 05:45:25 -07:00
|
|
|
/**
|
|
|
|
* Connect to a child process.
|
|
|
|
*
|
|
|
|
* @param object aConnection
|
|
|
|
* The debugger server connection to use.
|
|
|
|
* @param nsIDOMElement aFrame
|
|
|
|
* The browser element that holds the child process.
|
|
|
|
* @param function [aOnDisconnect]
|
|
|
|
* Optional function to invoke when the child is disconnected.
|
|
|
|
* @return object
|
|
|
|
* A promise object that is resolved once the connection is
|
|
|
|
* established.
|
|
|
|
*/
|
|
|
|
connectToChild: function(aConnection, aFrame, aOnDisconnect) {
|
|
|
|
let deferred = defer();
|
2014-03-10 08:32:37 -07:00
|
|
|
|
2014-04-03 05:45:25 -07:00
|
|
|
let mm = aFrame.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader
|
|
|
|
.messageManager;
|
2014-03-10 08:32:37 -07:00
|
|
|
mm.loadFrameScript("resource://gre/modules/devtools/server/child.js", false);
|
|
|
|
|
2014-03-10 09:38:12 -07:00
|
|
|
let actor, childTransport;
|
|
|
|
let prefix = aConnection.allocID("child");
|
2014-08-27 03:19:29 -07:00
|
|
|
let childID = null;
|
2014-04-03 05:45:25 -07:00
|
|
|
let netMonitor = null;
|
2014-03-10 08:32:37 -07:00
|
|
|
|
2014-11-27 02:52:00 -08:00
|
|
|
// provides hook to actor modules that need to exchange messages
|
|
|
|
// between e10s parent and child processes
|
|
|
|
let onSetupInParent = function (msg) {
|
|
|
|
let { module, setupParent } = msg.json;
|
|
|
|
let m, fn;
|
|
|
|
|
|
|
|
try {
|
|
|
|
m = require(module);
|
|
|
|
|
|
|
|
if (!setupParent in m) {
|
|
|
|
dumpn("ERROR: module '" + module + "' does not export '" + setupParent + "'");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m[setupParent]({ mm: mm, childID: childID });
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} catch(e) {
|
|
|
|
let error_msg = "exception during actor module setup running in the parent process: ";
|
|
|
|
DevToolsUtils.reportException(error_msg + e);
|
|
|
|
dumpn("ERROR: " + error_msg + " \n\t module: '" + module + "' \n\t setupParent: '" + setupParent + "'\n" +
|
|
|
|
DevToolsUtils.safeErrorString(e));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
mm.addMessageListener("debug:setup-in-parent", onSetupInParent);
|
|
|
|
|
2014-03-10 08:32:37 -07:00
|
|
|
let onActorCreated = DevToolsUtils.makeInfallible(function (msg) {
|
|
|
|
mm.removeMessageListener("debug:actor", onActorCreated);
|
|
|
|
|
2014-08-27 03:19:29 -07:00
|
|
|
childID = msg.json.childID;
|
|
|
|
|
2014-03-10 08:32:37 -07:00
|
|
|
// Pipe Debugger message from/to parent/child via the message manager
|
|
|
|
childTransport = new ChildDebuggerTransport(mm, prefix);
|
|
|
|
childTransport.hooks = {
|
|
|
|
onPacket: aConnection.send.bind(aConnection),
|
|
|
|
onClosed: function () {}
|
|
|
|
};
|
|
|
|
childTransport.ready();
|
|
|
|
|
|
|
|
aConnection.setForwarding(prefix, childTransport);
|
|
|
|
|
|
|
|
dumpn("establishing forwarding for app with prefix " + prefix);
|
|
|
|
|
|
|
|
actor = msg.json.actor;
|
|
|
|
|
2014-05-21 06:08:24 -07:00
|
|
|
let { NetworkMonitorManager } = require("devtools/toolkit/webconsole/network-monitor");
|
2014-04-03 05:45:25 -07:00
|
|
|
netMonitor = new NetworkMonitorManager(aFrame, actor.actor);
|
|
|
|
|
2014-03-10 08:32:37 -07:00
|
|
|
deferred.resolve(actor);
|
|
|
|
}).bind(this);
|
|
|
|
mm.addMessageListener("debug:actor", onActorCreated);
|
|
|
|
|
|
|
|
let onMessageManagerDisconnect = DevToolsUtils.makeInfallible(function (subject, topic, data) {
|
|
|
|
if (subject == mm) {
|
|
|
|
Services.obs.removeObserver(onMessageManagerDisconnect, topic);
|
2014-11-27 02:52:00 -08:00
|
|
|
|
|
|
|
// provides hook to actor modules that need to exchange messages
|
|
|
|
// between e10s parent and child processes
|
|
|
|
this.emit("disconnected-from-child:" + childID, { mm: mm, childID: childID });
|
|
|
|
|
|
|
|
mm.removeMessageListener("debug:setup-in-parent", onSetupInParent);
|
|
|
|
|
2014-03-10 08:32:37 -07: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();
|
2014-04-02 12:29:40 -07:00
|
|
|
childTransport = null;
|
2014-03-10 08:32:37 -07:00
|
|
|
aConnection.cancelForwarding(prefix);
|
2014-07-29 04:57:00 -07:00
|
|
|
|
|
|
|
// ... and notify the child process to clean the tab actors.
|
2014-08-27 03:19:29 -07:00
|
|
|
mm.sendAsyncMessage("debug:disconnect", { childID: childID });
|
2014-03-10 08:32:37 -07: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) {
|
2014-03-10 09:38:17 -07:00
|
|
|
// The ContentActor within the child process doesn't necessary
|
2014-03-10 08:32:37 -07:00
|
|
|
// have to time to uninitialize itself when the app is closed/killed.
|
|
|
|
// So ensure telling the client that the related actor is detached.
|
|
|
|
aConnection.send({ from: actor.actor, type: "tabDetached" });
|
|
|
|
actor = null;
|
|
|
|
}
|
|
|
|
|
2014-04-03 05:45:25 -07:00
|
|
|
if (netMonitor) {
|
|
|
|
netMonitor.destroy();
|
|
|
|
netMonitor = null;
|
|
|
|
}
|
|
|
|
|
2014-03-10 08:32:37 -07:00
|
|
|
if (aOnDisconnect) {
|
|
|
|
aOnDisconnect(mm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).bind(this);
|
|
|
|
Services.obs.addObserver(onMessageManagerDisconnect,
|
|
|
|
"message-manager-disconnect", false);
|
|
|
|
|
2014-04-02 12:29:40 -07:00
|
|
|
events.once(aConnection, "closed", () => {
|
|
|
|
if (childTransport) {
|
|
|
|
// When the client disconnects, we have to unplug the dedicated
|
|
|
|
// ChildDebuggerTransport...
|
|
|
|
childTransport.close();
|
|
|
|
childTransport = null;
|
|
|
|
aConnection.cancelForwarding(prefix);
|
|
|
|
|
|
|
|
// ... and notify the child process to clean the tab actors.
|
2014-08-27 03:19:29 -07:00
|
|
|
mm.sendAsyncMessage("debug:disconnect", { childID: childID });
|
2014-08-27 03:19:30 -07:00
|
|
|
|
|
|
|
if (netMonitor) {
|
|
|
|
netMonitor.destroy();
|
|
|
|
netMonitor = null;
|
|
|
|
}
|
2014-04-02 12:29:40 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-03-10 09:38:12 -07:00
|
|
|
mm.sendAsyncMessage("debug:connect", { prefix: prefix });
|
2014-03-10 08:32:37 -07:00
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
},
|
|
|
|
|
2012-04-22 02:59:09 -07:00
|
|
|
/**
|
|
|
|
* Raises an exception if the server has not been properly initialized.
|
|
|
|
*/
|
2012-10-31 09:31:55 -07:00
|
|
|
_checkInit: function DS_checkInit() {
|
2012-04-22 02:59:09 -07:00
|
|
|
if (!this._transportInitialized) {
|
|
|
|
throw "DebuggerServer has not been initialized.";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.createRootActor) {
|
|
|
|
throw "Use DebuggerServer.addActors() to add a root actor implementation.";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-07-24 08:27:26 -07:00
|
|
|
* Create a new debugger connection for the given transport. Called after
|
|
|
|
* connectPipe(), from connectToParent, or from an incoming socket
|
|
|
|
* connection handler.
|
|
|
|
*
|
|
|
|
* If present, |aForwardingPrefix| is a forwarding prefix that a parent
|
|
|
|
* server is using to recognizes messages intended for this server. Ensure
|
2014-05-14 12:30:01 -07:00
|
|
|
* that all our actors have names beginning with |aForwardingPrefix + '/'|.
|
|
|
|
* In particular, the root actor's name will be |aForwardingPrefix + '/root'|.
|
2013-07-24 08:27:26 -07:00
|
|
|
*/
|
2013-07-24 08:28:32 -07:00
|
|
|
_onConnection: function DS_onConnection(aTransport, aForwardingPrefix, aNoRootActor = false) {
|
2013-07-24 08:27:26 -07:00
|
|
|
let connID;
|
|
|
|
if (aForwardingPrefix) {
|
2014-05-14 12:30:01 -07:00
|
|
|
connID = aForwardingPrefix + "/";
|
2013-07-24 08:27:26 -07:00
|
|
|
} else {
|
|
|
|
connID = "conn" + this._nextConnID++ + '.';
|
|
|
|
}
|
2012-04-22 02:59:09 -07:00
|
|
|
let conn = new DebuggerServerConnection(connID, aTransport);
|
|
|
|
this._connections[connID] = conn;
|
|
|
|
|
|
|
|
// Create a root actor for the connection and send the hello packet.
|
2013-07-24 08:28:32 -07:00
|
|
|
if (!aNoRootActor) {
|
|
|
|
conn.rootActor = this.createRootActor(conn);
|
|
|
|
if (aForwardingPrefix)
|
2014-05-14 12:30:01 -07:00
|
|
|
conn.rootActor.actorID = aForwardingPrefix + "/root";
|
2013-07-24 08:28:32 -07:00
|
|
|
else
|
|
|
|
conn.rootActor.actorID = "root";
|
|
|
|
conn.addActor(conn.rootActor);
|
|
|
|
aTransport.send(conn.rootActor.sayHello());
|
|
|
|
}
|
2012-04-22 02:59:09 -07:00
|
|
|
aTransport.ready();
|
2013-06-03 09:05:29 -07:00
|
|
|
|
2014-04-17 10:27:03 -07:00
|
|
|
this.emit("connectionchange", "opened", conn);
|
2013-06-03 09:05:29 -07:00
|
|
|
return conn;
|
2012-04-22 02:59:09 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-09-27 04:31:49 -07:00
|
|
|
* Remove the connection from the debugging server.
|
2012-04-22 02:59:09 -07:00
|
|
|
*/
|
2012-10-31 09:31:55 -07:00
|
|
|
_connectionClosed: function DS_connectionClosed(aConnection) {
|
2012-04-22 02:59:09 -07:00
|
|
|
delete this._connections[aConnection.prefix];
|
2014-04-17 10:27:03 -07:00
|
|
|
this.emit("connectionchange", "closed", aConnection);
|
2012-10-31 09:31:55 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// DebuggerServer extension API.
|
|
|
|
|
2014-05-13 12:56:30 -07:00
|
|
|
setRootActor: function DS_setRootActor(aFunction) {
|
|
|
|
this.createRootActor = aFunction;
|
|
|
|
},
|
|
|
|
|
2012-10-31 09:31:55 -07: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.
|
|
|
|
*
|
2014-09-16 03:00:00 -07:00
|
|
|
* @param aActor function, object
|
|
|
|
* In case of function:
|
2013-05-24 10:13:42 -07: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 03:00:00 -07: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 10:13:42 -07:00
|
|
|
*
|
2012-10-31 09:31:55 -07:00
|
|
|
* @param aName string [optional]
|
|
|
|
* The name of the new request type. If this is not present, the
|
|
|
|
* actorPrefix property of the constructor prototype is used.
|
|
|
|
*/
|
2014-09-16 03:00:00 -07:00
|
|
|
addTabActor: function DS_addTabActor(aActor, aName) {
|
|
|
|
let name = aName ? aName : aActor.prototype.actorPrefix;
|
2012-10-31 09:31:55 -07:00
|
|
|
if (["title", "url", "actor"].indexOf(name) != -1) {
|
|
|
|
throw Error(name + " is not allowed");
|
|
|
|
}
|
|
|
|
if (DebuggerServer.tabActorFactories.hasOwnProperty(name)) {
|
|
|
|
throw Error(name + " already exists");
|
|
|
|
}
|
2014-09-16 03:00:00 -07:00
|
|
|
DebuggerServer.tabActorFactories[name] = new RegisteredActorFactory(aActor, name);
|
2012-10-31 09:31:55 -07: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 04:49:00 -07:00
|
|
|
* When unregistering an existing tab actor remove related tab factory
|
|
|
|
* as well as all existing instances of the actor.
|
2012-10-31 09:31:55 -07:00
|
|
|
*
|
2014-09-16 03:00:00 -07:00
|
|
|
* @param aActor function, object
|
|
|
|
* In case of function:
|
2012-10-31 09:31:55 -07:00
|
|
|
* The constructor function for this request type.
|
2014-09-16 03:00:00 -07:00
|
|
|
* In case of object:
|
|
|
|
* Same object being given to related addTabActor call.
|
2012-10-31 09:31:55 -07:00
|
|
|
*/
|
2014-09-16 03:00:00 -07:00
|
|
|
removeTabActor: function DS_removeTabActor(aActor) {
|
2012-10-31 09:31:55 -07:00
|
|
|
for (let name in DebuggerServer.tabActorFactories) {
|
|
|
|
let handler = DebuggerServer.tabActorFactories[name];
|
2014-09-16 03:00:00 -07:00
|
|
|
if ((handler.name && handler.name == aActor.name) ||
|
|
|
|
(handler.id && handler.id == aActor.id)) {
|
2012-10-31 09:31:55 -07:00
|
|
|
delete DebuggerServer.tabActorFactories[name];
|
2014-10-03 04:49:00 -07:00
|
|
|
for (let connID of Object.getOwnPropertyNames(this._connections)) {
|
|
|
|
this._connections[connID].rootActor.removeActorByName(name);
|
|
|
|
}
|
2012-10-31 09:31:55 -07: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.
|
|
|
|
*
|
2014-09-16 03:00:00 -07:00
|
|
|
* @param aActor function, object
|
|
|
|
* In case of function:
|
2013-05-24 10:13:42 -07: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 03:00:00 -07: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 10:13:42 -07:00
|
|
|
*
|
2012-10-31 09:31:55 -07:00
|
|
|
* @param aName string [optional]
|
|
|
|
* The name of the new request type. If this is not present, the
|
|
|
|
* actorPrefix property of the constructor prototype is used.
|
|
|
|
*/
|
2014-09-16 03:00:00 -07:00
|
|
|
addGlobalActor: function DS_addGlobalActor(aActor, aName) {
|
|
|
|
let name = aName ? aName : aActor.prototype.actorPrefix;
|
2012-10-31 09:31:55 -07:00
|
|
|
if (["from", "tabs", "selected"].indexOf(name) != -1) {
|
|
|
|
throw Error(name + " is not allowed");
|
|
|
|
}
|
|
|
|
if (DebuggerServer.globalActorFactories.hasOwnProperty(name)) {
|
|
|
|
throw Error(name + " already exists");
|
|
|
|
}
|
2014-09-16 03:00:00 -07:00
|
|
|
DebuggerServer.globalActorFactories[name] = new RegisteredActorFactory(aActor, name);
|
2012-10-31 09:31:55 -07: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 04:49:00 -07:00
|
|
|
* When unregistering an existing global actor remove related global factory
|
|
|
|
* as well as all existing instances of the actor.
|
2012-10-31 09:31:55 -07:00
|
|
|
*
|
2014-09-16 03:00:00 -07:00
|
|
|
* @param aActor function, object
|
|
|
|
* In case of function:
|
2012-10-31 09:31:55 -07:00
|
|
|
* The constructor function for this request type.
|
2014-09-16 03:00:00 -07:00
|
|
|
* In case of object:
|
|
|
|
* Same object being given to related addGlobalActor call.
|
2012-10-31 09:31:55 -07:00
|
|
|
*/
|
2014-09-16 03:00:00 -07:00
|
|
|
removeGlobalActor: function DS_removeGlobalActor(aActor) {
|
2012-10-31 09:31:55 -07:00
|
|
|
for (let name in DebuggerServer.globalActorFactories) {
|
|
|
|
let handler = DebuggerServer.globalActorFactories[name];
|
2014-09-16 03:00:00 -07:00
|
|
|
if ((handler.name && handler.name == aActor.name) ||
|
|
|
|
(handler.id && handler.id == aActor.id)) {
|
2012-10-31 09:31:55 -07:00
|
|
|
delete DebuggerServer.globalActorFactories[name];
|
2014-10-03 04:49:00 -07:00
|
|
|
for (let connID of Object.getOwnPropertyNames(this._connections)) {
|
|
|
|
this._connections[connID].rootActor.removeActorByName(name);
|
|
|
|
}
|
2012-10-31 09:31:55 -07:00
|
|
|
}
|
|
|
|
}
|
2012-04-22 02:59:09 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-17 10:27:03 -07:00
|
|
|
EventEmitter.decorate(DebuggerServer);
|
|
|
|
|
2013-08-30 17:34:26 -07:00
|
|
|
if (this.exports) {
|
|
|
|
exports.DebuggerServer = DebuggerServer;
|
|
|
|
}
|
2014-01-06 12:55:00 -08:00
|
|
|
// Needed on B2G (See header note)
|
|
|
|
this.DebuggerServer = DebuggerServer;
|
2012-10-31 09:31:55 -07:00
|
|
|
|
2014-07-07 03:07:00 -07: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.
|
|
|
|
let includes = ["Components", "Ci", "Cu", "require", "Services", "DebuggerServer",
|
|
|
|
"ActorPool", "DevToolsUtils"];
|
|
|
|
includes.forEach(name => {
|
|
|
|
DebuggerServer[name] = this[name];
|
|
|
|
});
|
|
|
|
|
2014-04-24 04:13:12 -07:00
|
|
|
// Export ActorPool for requirers of main.js
|
2013-08-30 17:34:26 -07:00
|
|
|
if (this.exports) {
|
|
|
|
exports.ActorPool = ActorPool;
|
|
|
|
}
|
2012-04-22 02:59:09 -07: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.
|
|
|
|
*
|
|
|
|
* @param aPrefix string
|
|
|
|
* All actor IDs created by this connection should be prefixed
|
|
|
|
* with aPrefix.
|
|
|
|
* @param aTransport transport
|
|
|
|
* Packet transport for the debugging protocol.
|
|
|
|
*/
|
|
|
|
function DebuggerServerConnection(aPrefix, aTransport)
|
|
|
|
{
|
|
|
|
this._prefix = aPrefix;
|
|
|
|
this._transport = aTransport;
|
|
|
|
this._transport.hooks = this;
|
|
|
|
this._nextID = 1;
|
|
|
|
|
|
|
|
this._actorPool = new ActorPool(this);
|
|
|
|
this._extraPools = [];
|
2013-07-24 08:27:26 -07:00
|
|
|
|
2013-08-08 22:28:41 -07: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.
|
|
|
|
this._actorResponses = new Map;
|
|
|
|
|
2013-07-24 08:27:26 -07: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 12:30:01 -07:00
|
|
|
* packets to the server whose actors' names all begin with P + "/".
|
2013-07-24 08:27:26 -07:00
|
|
|
*/
|
|
|
|
this._forwardingPrefixes = new Map;
|
2012-04-22 02:59:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DebuggerServerConnection.prototype = {
|
|
|
|
_prefix: null,
|
|
|
|
get prefix() { return this._prefix },
|
|
|
|
|
|
|
|
_transport: null,
|
|
|
|
get transport() { return this._transport },
|
|
|
|
|
2013-05-30 09:42:00 -07:00
|
|
|
close: function() {
|
|
|
|
this._transport.close();
|
|
|
|
},
|
|
|
|
|
2012-04-22 02:59:09 -07:00
|
|
|
send: function DSC_send(aPacket) {
|
|
|
|
this.transport.send(aPacket);
|
|
|
|
},
|
|
|
|
|
2014-05-14 12:30:02 -07:00
|
|
|
/**
|
|
|
|
* Used when sending a bulk reply from an actor.
|
|
|
|
* @see DebuggerTransport.prototype.startBulkSend
|
|
|
|
*/
|
|
|
|
startBulkSend: function(header) {
|
|
|
|
return this.transport.startBulkSend(header);
|
|
|
|
},
|
|
|
|
|
2012-04-22 02:59:09 -07:00
|
|
|
allocID: function DSC_allocID(aPrefix) {
|
|
|
|
return this.prefix + (aPrefix || '') + this._nextID++;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a map of actor IDs to the connection.
|
|
|
|
*/
|
|
|
|
addActorPool: function DSC_addActorPool(aActorPool) {
|
|
|
|
this._extraPools.push(aActorPool);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a previously-added pool of actors to the connection.
|
2012-12-17 12:06:13 -08:00
|
|
|
*
|
|
|
|
* @param ActorPool aActorPool
|
|
|
|
* The ActorPool instance you want to remove.
|
2014-04-08 00:23:00 -07:00
|
|
|
* @param boolean aNoCleanup [optional]
|
|
|
|
* True if you don't want to disconnect each actor from the pool, false
|
2012-12-17 12:06:13 -08:00
|
|
|
* otherwise.
|
2012-04-22 02:59:09 -07:00
|
|
|
*/
|
2014-04-08 00:23:00 -07:00
|
|
|
removeActorPool: function DSC_removeActorPool(aActorPool, aNoCleanup) {
|
2012-08-24 00:41:02 -07:00
|
|
|
let index = this._extraPools.lastIndexOf(aActorPool);
|
|
|
|
if (index > -1) {
|
2012-12-17 12:06:13 -08:00
|
|
|
let pool = this._extraPools.splice(index, 1);
|
2014-04-08 00:23:00 -07:00
|
|
|
if (!aNoCleanup) {
|
2012-12-17 12:06:13 -08:00
|
|
|
pool.map(function(p) { p.cleanup(); });
|
|
|
|
}
|
2012-08-24 00:41:02 -07:00
|
|
|
}
|
2012-04-22 02:59:09 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an actor to the default actor pool for this connection.
|
|
|
|
*/
|
|
|
|
addActor: function DSC_addActor(aActor) {
|
|
|
|
this._actorPool.addActor(aActor);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an actor to the default actor pool for this connection.
|
|
|
|
*/
|
|
|
|
removeActor: function DSC_removeActor(aActor) {
|
|
|
|
this._actorPool.removeActor(aActor);
|
|
|
|
},
|
|
|
|
|
2013-06-06 12:29:27 -07:00
|
|
|
/**
|
|
|
|
* Match the api expected by the protocol library.
|
|
|
|
*/
|
|
|
|
unmanage: function(aActor) {
|
|
|
|
return this.removeActor(aActor);
|
|
|
|
},
|
|
|
|
|
2012-04-22 02:59:09 -07:00
|
|
|
/**
|
|
|
|
* Look up an actor implementation for an actorID. Will search
|
|
|
|
* all the actor pools registered with the connection.
|
|
|
|
*
|
|
|
|
* @param aActorID string
|
|
|
|
* Actor ID to look up.
|
|
|
|
*/
|
|
|
|
getActor: function DSC_getActor(aActorID) {
|
2013-06-06 12:29:27 -07:00
|
|
|
let pool = this.poolFor(aActorID);
|
|
|
|
if (pool) {
|
|
|
|
return pool.get(aActorID);
|
2012-04-22 02:59:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aActorID === "root") {
|
|
|
|
return this.rootActor;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2014-05-14 12:30:02 -07:00
|
|
|
_getOrCreateActor: function(actorID) {
|
|
|
|
let actor = this.getActor(actorID);
|
|
|
|
if (!actor) {
|
|
|
|
this.transport.send({ from: actorID ? actorID : "root",
|
|
|
|
error: "noSuchActor",
|
|
|
|
message: "No such actor for ID: " + actorID });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-16 03:00:00 -07:00
|
|
|
// Dynamically-loaded actors have to be created lazily.
|
|
|
|
if (actor instanceof ObservedActorFactory) {
|
2014-05-14 12:30:02 -07:00
|
|
|
try {
|
2014-09-16 03:00:00 -07:00
|
|
|
actor= actor.createActor();
|
2014-05-14 12:30:02 -07:00
|
|
|
} catch (e) {
|
|
|
|
this.transport.send(this._unknownError(
|
|
|
|
"Error occurred while creating actor '" + actor.name,
|
|
|
|
e));
|
|
|
|
}
|
2014-09-16 03:00:00 -07:00
|
|
|
} else if (typeof(actor) !== "object") {
|
|
|
|
// 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 12:30:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return actor;
|
|
|
|
},
|
|
|
|
|
2013-06-06 12:29:27 -07:00
|
|
|
poolFor: function DSC_actorPool(aActorID) {
|
|
|
|
if (this._actorPool && this._actorPool.has(aActorID)) {
|
|
|
|
return this._actorPool;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let pool of this._extraPools) {
|
|
|
|
if (pool.has(aActorID)) {
|
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2013-04-15 14:07:00 -07:00
|
|
|
_unknownError: function DSC__unknownError(aPrefix, aError) {
|
2014-03-04 06:38:05 -08:00
|
|
|
let errorString = aPrefix + ": " + DevToolsUtils.safeErrorString(aError);
|
2014-05-30 07:42:55 -07:00
|
|
|
reportError(errorString);
|
2013-04-15 14:07:00 -07:00
|
|
|
dumpn(errorString);
|
|
|
|
return {
|
|
|
|
error: "unknownError",
|
2013-08-20 11:15:15 -07:00
|
|
|
message: errorString
|
2013-04-15 14:07:00 -07:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2014-05-14 12:30:02 -07:00
|
|
|
_queueResponse: function(from, type, response) {
|
|
|
|
let pendingResponse = this._actorResponses.get(from) || resolve(null);
|
|
|
|
let responsePromise = pendingResponse.then(() => {
|
|
|
|
return response;
|
|
|
|
}).then(aResponse => {
|
|
|
|
if (!aResponse.from) {
|
|
|
|
aResponse.from = from;
|
|
|
|
}
|
|
|
|
this.transport.send(aResponse);
|
|
|
|
}).then(null, (e) => {
|
|
|
|
let errorPacket = this._unknownError(
|
|
|
|
"error occurred while processing '" + type,
|
|
|
|
e);
|
|
|
|
errorPacket.from = from;
|
|
|
|
this.transport.send(errorPacket);
|
|
|
|
});
|
|
|
|
|
|
|
|
this._actorResponses.set(from, responsePromise);
|
|
|
|
},
|
|
|
|
|
2014-04-17 10:27:03 -07:00
|
|
|
/**
|
|
|
|
* Passes a set of options to the BrowserAddonActors for the given ID.
|
|
|
|
*
|
|
|
|
* @param aId string
|
|
|
|
* The ID of the add-on to pass the options to
|
|
|
|
* @param aOptions object
|
|
|
|
* The options.
|
|
|
|
* @return a promise that will be resolved when complete.
|
|
|
|
*/
|
|
|
|
setAddonOptions: function DSC_setAddonOptions(aId, aOptions) {
|
|
|
|
let addonList = this.rootActor._parameters.addonList;
|
|
|
|
if (!addonList) {
|
|
|
|
return resolve();
|
|
|
|
}
|
|
|
|
return addonList.getList().then((addonActors) => {
|
|
|
|
for (let actor of addonActors) {
|
|
|
|
if (actor.id != aId) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
actor.setOptions(aOptions);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-07-24 08:27:26 -07: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.
|
|
|
|
*
|
|
|
|
* If we receive a packet for an actor whose name begins with |aPrefix|
|
2014-05-14 12:30:01 -07:00
|
|
|
* followed by '/', then we will forward that packet to |aTransport|.
|
2013-07-24 08:27:26 -07:00
|
|
|
*
|
|
|
|
* This overrides any prior forwarding for |aPrefix|.
|
|
|
|
*
|
|
|
|
* @param aPrefix string
|
2014-05-14 12:30:01 -07:00
|
|
|
* The actor name prefix, not including the '/'.
|
2013-07-24 08:27:26 -07:00
|
|
|
* @param aTransport object
|
|
|
|
* A packet transport to which we should forward packets to actors
|
2014-05-14 12:30:01 -07:00
|
|
|
* whose names begin with |(aPrefix + '/').|
|
2013-07-24 08:27:26 -07:00
|
|
|
*/
|
|
|
|
setForwarding: function(aPrefix, aTransport) {
|
|
|
|
this._forwardingPrefixes.set(aPrefix, aTransport);
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop forwarding messages to actors whose names begin with
|
2014-05-14 12:30:01 -07:00
|
|
|
* |aPrefix+'/'|. Such messages will now elicit 'noSuchActor' errors.
|
2013-07-24 08:27:26 -07:00
|
|
|
*/
|
|
|
|
cancelForwarding: function(aPrefix) {
|
|
|
|
this._forwardingPrefixes.delete(aPrefix);
|
|
|
|
},
|
|
|
|
|
2014-07-28 04:56:12 -07:00
|
|
|
sendActorEvent: function (actorID, eventName, event = {}) {
|
2014-07-07 06:40:00 -07:00
|
|
|
event.from = actorID;
|
|
|
|
event.type = eventName;
|
|
|
|
this.send(event);
|
|
|
|
},
|
|
|
|
|
2012-04-22 02:59:09 -07:00
|
|
|
// Transport hooks.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by DebuggerTransport to dispatch incoming packets as appropriate.
|
|
|
|
*
|
|
|
|
* @param aPacket object
|
|
|
|
* The incoming packet.
|
|
|
|
*/
|
|
|
|
onPacket: function DSC_onPacket(aPacket) {
|
2013-07-24 08:27:26 -07: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) {
|
2014-05-14 12:30:01 -07:00
|
|
|
let separator = aPacket.to.indexOf('/');
|
|
|
|
if (separator >= 0) {
|
|
|
|
let forwardTo = this._forwardingPrefixes.get(aPacket.to.substring(0, separator));
|
2013-07-24 08:27:26 -07:00
|
|
|
if (forwardTo) {
|
|
|
|
forwardTo.send(aPacket);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 12:30:02 -07:00
|
|
|
let actor = this._getOrCreateActor(aPacket.to);
|
2012-04-22 02:59:09 -07:00
|
|
|
if (!actor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var ret = null;
|
2014-01-06 09:27:10 -08:00
|
|
|
|
|
|
|
// handle "requestTypes" RDP request.
|
|
|
|
if (aPacket.type == "requestTypes") {
|
|
|
|
ret = { from: actor.actorID, requestTypes: Object.keys(actor.requestTypes) };
|
|
|
|
} else if (actor.requestTypes && actor.requestTypes[aPacket.type]) {
|
|
|
|
// Dispatch the request to the actor.
|
2012-04-22 02:59:09 -07:00
|
|
|
try {
|
2013-06-06 12:29:27 -07:00
|
|
|
this.currentPacket = aPacket;
|
|
|
|
ret = actor.requestTypes[aPacket.type].bind(actor)(aPacket, this);
|
2012-04-22 02:59:09 -07:00
|
|
|
} catch(e) {
|
2013-04-15 14:07:00 -07:00
|
|
|
this.transport.send(this._unknownError(
|
|
|
|
"error occurred while processing '" + aPacket.type,
|
|
|
|
e));
|
2013-06-06 12:29:27 -07:00
|
|
|
} finally {
|
2013-10-27 11:03:20 -07:00
|
|
|
this.currentPacket = undefined;
|
2012-04-22 02:59:09 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = { error: "unrecognizedPacketType",
|
2014-05-14 12:30:02 -07:00
|
|
|
message: ("Actor " + actor.actorID +
|
|
|
|
" does not recognize the packet type " +
|
|
|
|
aPacket.type) };
|
|
|
|
}
|
|
|
|
|
|
|
|
// There will not be a return value if a bulk reply is sent.
|
|
|
|
if (ret) {
|
|
|
|
this._queueResponse(aPacket.to, aPacket.type, ret);
|
2012-04-22 02:59:09 -07:00
|
|
|
}
|
2014-05-14 12:30:02 -07: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 05:19:00 -07:00
|
|
|
* This object also emits "progress" events for each chunk
|
|
|
|
* that is copied. See stream-utils.js.
|
2014-05-14 12:30:02 -07:00
|
|
|
*/
|
|
|
|
onBulkPacket: function(packet) {
|
|
|
|
let { actor: actorKey, type, length } = packet;
|
2012-04-22 02:59:09 -07:00
|
|
|
|
2014-05-14 12:30:02 -07:00
|
|
|
let actor = this._getOrCreateActor(actorKey);
|
|
|
|
if (!actor) {
|
2012-04-22 02:59:09 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-14 12:30:02 -07:00
|
|
|
// Dispatch the request to the actor.
|
|
|
|
let ret;
|
|
|
|
if (actor.requestTypes && actor.requestTypes[type]) {
|
|
|
|
try {
|
|
|
|
ret = actor.requestTypes[type].call(actor, packet);
|
|
|
|
} catch(e) {
|
|
|
|
this.transport.send(this._unknownError(
|
|
|
|
"error occurred while processing bulk packet '" + type, e));
|
|
|
|
packet.done.reject(e);
|
2013-08-08 22:28:41 -07:00
|
|
|
}
|
2014-05-14 12:30:02 -07: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-08 22:28:41 -07:00
|
|
|
|
2014-05-14 12:30:02 -07: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 02:59:09 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by DebuggerTransport when the underlying stream is closed.
|
|
|
|
*
|
|
|
|
* @param aStatus nsresult
|
|
|
|
* The status code that corresponds to the reason for closing
|
|
|
|
* the stream.
|
|
|
|
*/
|
|
|
|
onClosed: function DSC_onClosed(aStatus) {
|
|
|
|
dumpn("Cleaning up connection.");
|
2014-04-02 12:29:40 -07:00
|
|
|
if (!this._actorPool) {
|
|
|
|
// Ignore this call if the connection is already closed.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
events.emit(this, "closed", aStatus);
|
2012-04-22 02:59:09 -07:00
|
|
|
|
|
|
|
this._actorPool.cleanup();
|
|
|
|
this._actorPool = null;
|
|
|
|
this._extraPools.map(function(p) { p.cleanup(); });
|
|
|
|
this._extraPools = null;
|
|
|
|
|
|
|
|
DebuggerServer._connectionClosed(this);
|
2012-11-01 08:34:10 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Debugging helper for inspecting the state of the actor pools.
|
|
|
|
*/
|
|
|
|
_dumpPools: function DSC_dumpPools() {
|
|
|
|
dumpn("/-------------------- dumping pools:");
|
|
|
|
if (this._actorPool) {
|
|
|
|
dumpn("--------------------- actorPool actors: " +
|
|
|
|
uneval(Object.keys(this._actorPool._actors)));
|
|
|
|
}
|
|
|
|
for each (let pool in this._extraPools)
|
|
|
|
dumpn("--------------------- extraPool actors: " +
|
|
|
|
uneval(Object.keys(pool._actors)));
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Debugging helper for inspecting the state of an actor pool.
|
|
|
|
*/
|
|
|
|
_dumpPool: function DSC_dumpPools(aPool) {
|
|
|
|
dumpn("/-------------------- dumping pool:");
|
|
|
|
dumpn("--------------------- actorPool actors: " +
|
|
|
|
uneval(Object.keys(aPool._actors)));
|
2012-04-22 02:59:09 -07:00
|
|
|
}
|
|
|
|
};
|