Bug 1473513 - move ActorRegistry module to server/actors/utils; r=ochameau

Summary: Depends on D6477

Reviewers: ochameau

Reviewed By: ochameau

Bug #: 1473513

Differential Revision: https://phabricator.services.mozilla.com/D6479

--HG--
rename : devtools/server/actor-registry.js => devtools/server/actors/utils/actor-registry.js
extra : rebase_source : ae52db7b028b4d866d8a363eae9ae7c124714458
This commit is contained in:
yulia 2018-09-26 10:09:15 +02:00
Родитель 29af71d6af
Коммит 72f9e83eb1
20 изменённых файлов: 430 добавлений и 18 удалений

Просмотреть файл

@ -16,7 +16,7 @@ Services.prefs.setBoolPref("devtools.debugger.log", false);
var { BrowserToolboxProcess } = ChromeUtils.import("resource://devtools/client/framework/ToolboxProcess.jsm", {});
var { DebuggerServer } = require("devtools/server/main");
var { ActorRegistry } = require("devtools/server/actor-registry");
var { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
var { DebuggerClient } = require("devtools/shared/client/debugger-client");
var ObjectClient = require("devtools/shared/client/object-client");
var { AddonManager } = ChromeUtils.import("resource://gre/modules/AddonManager.jsm", {});

Просмотреть файл

@ -755,7 +755,7 @@ async function registerActorInContentProcess(url, options) {
return ContentTask.spawn(gBrowser.selectedBrowser, { url, options }, args => {
// eslint-disable-next-line no-shadow
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
const { ActorRegistry } = require("devtools/server/actor-registry");
const { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
ActorRegistry.registerModule(args.url, args.options);
});
}

Просмотреть файл

@ -30,7 +30,7 @@ ActorRegistry.registerModule("devtools/server/actors/addon/addons", {
});
```
If you are adding a new built-in actor, you should be registering it using `ActorRegistry.registerModule` in `addBrowserActors` or `addTargetScopedActors` in `/devtools/server/actor-registry.js`.
If you are adding a new built-in actor, you should be registering it using `ActorRegistry.registerModule` in `addBrowserActors` or `addTargetScopedActors` in `/devtools/server/actors/utils/actor-registry.js`.
## A note about lazy registration

Просмотреть файл

@ -51,7 +51,7 @@ The actor implementation would go somewhere like
// You also need to export the actor class in your module for discovery.
exports.HelloActor = HelloActor;
To activate your actor, register it in the `addBrowserActors` method in `server/actor-registry.js`.
To activate your actor, register it in the `addBrowserActors` method in `server/actors/utils/actor-registry.js`.
The registration code would look something like this:
this.registerModule("devtools/server/actors/hello-world", {

Просмотреть файл

@ -23,7 +23,7 @@
var { Ci, Cu, Cr, Cc } = require("chrome");
var Services = require("Services");
const ChromeUtils = require("ChromeUtils");
var { ActorRegistry } = require("devtools/server/actor-registry");
var { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
var { assert } = DevToolsUtils;
var { TabSources } = require("devtools/server/actors/utils/TabSources");

Просмотреть файл

@ -7,7 +7,7 @@
const { Cu, CC } = require("chrome");
const { DebuggerServer } = require("devtools/server/main");
const { ActorRegistry } = require("devtools/server/actor-registry");
const { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
/**
* Support for actor registration. Main used by ActorRegistryActor

Просмотреть файл

@ -0,0 +1,412 @@
/* 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/. */
"use strict";
var Services = require("Services");
var { Ci } = require("chrome");
var gRegisteredModules = Object.create(null);
const ActorRegistry = {
// Map of global actor names to actor constructors.
globalActorFactories: {},
// Map of target-scoped actor names to actor constructors.
targetScopedActorFactories: {},
init(connections) {
this._connections = connections;
},
/**
* Register a CommonJS module with the debugger server.
* @param id string
* The ID of a CommonJS module.
* 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
* 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.
* - type (a dictionary of booleans with following attribute names):
* - "global"
* registers a global actor instance, if true.
* A global actor has the root actor as its parent.
* - "target"
* registers a target-scoped actor instance, if true.
* A new actor will be created for each target, such as a tab.
*/
registerModule(id, options) {
if (id in gRegisteredModules) {
return;
}
if (!options) {
throw new Error("ActorRegistry.registerModule requires an options argument");
}
const {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) && !("target" in type)) {
throw new Error(`Lazy actor definition for '${id}' requires a dictionary ` +
`'type' option whose attributes can be 'global' or 'target'.`);
}
const name = prefix + "Actor";
const mod = {
id,
prefix,
constructorName: constructor,
type,
globalActor: type.global,
targetScopedActor: type.target
};
gRegisteredModules[id] = mod;
if (mod.targetScopedActor) {
this.addTargetScopedActor(mod, name);
}
if (mod.globalActor) {
this.addGlobalActor(mod, name);
}
},
/**
* Unregister a previously-loaded CommonJS module from the debugger server.
*/
unregisterModule(id) {
const mod = gRegisteredModules[id];
if (!mod) {
throw new Error("Tried to unregister a module that was not previously registered.");
}
// Lazy actors
if (mod.targetScopedActor) {
this.removeTargetScopedActor(mod);
}
if (mod.globalActor) {
this.removeGlobalActor(mod);
}
delete gRegisteredModules[id];
},
/**
* Install Firefox-specific actors.
*
* /!\ Be careful when adding a new actor, especially global actors.
* Any new global actor will be exposed and returned by the root actor.
*/
addBrowserActors() {
this.registerModule("devtools/server/actors/preference", {
prefix: "preference",
constructor: "PreferenceActor",
type: { global: true }
});
this.registerModule("devtools/server/actors/actor-registry", {
prefix: "actorRegistry",
constructor: "ActorRegistryActor",
type: { global: true }
});
this.registerModule("devtools/server/actors/addon/addons", {
prefix: "addons",
constructor: "AddonsActor",
type: { global: true }
});
this.registerModule("devtools/server/actors/device", {
prefix: "device",
constructor: "DeviceActor",
type: { global: true }
});
this.registerModule("devtools/server/actors/heap-snapshot-file", {
prefix: "heapSnapshotFile",
constructor: "HeapSnapshotFileActor",
type: { global: true }
});
// Always register this as a global module, even while there is a pref turning
// on and off the other performance actor. This actor shouldn't conflict with
// the other one. These are also lazily loaded so there shouldn't be a performance
// impact.
this.registerModule("devtools/server/actors/perf", {
prefix: "perf",
constructor: "PerfActor",
type: { global: true }
});
},
/**
* Install target-scoped actors.
*/
addTargetScopedActors() {
this.registerModule("devtools/server/actors/webconsole", {
prefix: "console",
constructor: "WebConsoleActor",
type: { target: true }
});
this.registerModule("devtools/server/actors/inspector/inspector", {
prefix: "inspector",
constructor: "InspectorActor",
type: { target: true }
});
this.registerModule("devtools/server/actors/canvas", {
prefix: "canvas",
constructor: "CanvasActor",
type: { target: true }
});
this.registerModule("devtools/server/actors/webgl", {
prefix: "webgl",
constructor: "WebGLActor",
type: { target: true }
});
this.registerModule("devtools/server/actors/webaudio", {
prefix: "webaudio",
constructor: "WebAudioActor",
type: { target: true }
});
this.registerModule("devtools/server/actors/stylesheets", {
prefix: "styleSheets",
constructor: "StyleSheetsActor",
type: { target: true }
});
this.registerModule("devtools/server/actors/storage", {
prefix: "storage",
constructor: "StorageActor",
type: { target: true }
});
this.registerModule("devtools/server/actors/memory", {
prefix: "memory",
constructor: "MemoryActor",
type: { target: true }
});
this.registerModule("devtools/server/actors/framerate", {
prefix: "framerate",
constructor: "FramerateActor",
type: { target: true }
});
this.registerModule("devtools/server/actors/reflow", {
prefix: "reflow",
constructor: "ReflowActor",
type: { target: true }
});
this.registerModule("devtools/server/actors/css-properties", {
prefix: "cssProperties",
constructor: "CssPropertiesActor",
type: { target: true }
});
this.registerModule("devtools/server/actors/csscoverage", {
prefix: "cssUsage",
constructor: "CSSUsageActor",
type: { target: true }
});
this.registerModule("devtools/server/actors/timeline", {
prefix: "timeline",
constructor: "TimelineActor",
type: { target: true }
});
if ("nsIProfiler" in Ci &&
!Services.prefs.getBoolPref("devtools.performance.new-panel-enabled", false)) {
this.registerModule("devtools/server/actors/performance", {
prefix: "performance",
constructor: "PerformanceActor",
type: { target: true }
});
}
this.registerModule("devtools/server/actors/animation", {
prefix: "animations",
constructor: "AnimationsActor",
type: { target: true }
});
this.registerModule("devtools/server/actors/promises", {
prefix: "promises",
constructor: "PromisesActor",
type: { target: true }
});
this.registerModule("devtools/server/actors/emulation", {
prefix: "emulation",
constructor: "EmulationActor",
type: { target: true }
});
this.registerModule("devtools/server/actors/addon/webextension-inspected-window", {
prefix: "webExtensionInspectedWindow",
constructor: "WebExtensionInspectedWindowActor",
type: { target: true }
});
this.registerModule("devtools/server/actors/accessibility", {
prefix: "accessibility",
constructor: "AccessibilityActor",
type: { target: true }
});
this.registerModule("devtools/server/actors/screenshot", {
prefix: "screenshot",
constructor: "ScreenshotActor",
type: { target: true }
});
},
/**
* Registers handlers for new target-scoped request types defined dynamically.
*
* 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.
*
* @param options object
* - constructorName: (required)
* name of actor constructor, which is also used when removing the actor.
* One of the following:
* - id:
* module ID that contains the actor
* - constructorFun:
* a function to construct the actor
* @param name string
* The name of the new request type.
*/
addTargetScopedActor(options, name) {
if (!name) {
throw Error("addTargetScopedActor requires the `name` argument");
}
if (["title", "url", "actor"].includes(name)) {
throw Error(name + " is not allowed");
}
if (this.targetScopedActorFactories.hasOwnProperty(name)) {
throw Error(name + " already exists");
}
this.targetScopedActorFactories[name] = { options, name };
},
/**
* Unregisters the handler for the specified target-scoped request type.
*
* When unregistering an existing target-scoped actor, we remove the actor factory as
* well as all existing instances of the actor.
*
* @param actor object, string
* In case of object:
* The `actor` object being given to related addTargetScopedActor call.
* In case of string:
* The `name` string being given to related addTargetScopedActor call.
*/
removeTargetScopedActor(actorOrName) {
let name;
if (typeof actorOrName == "string") {
name = actorOrName;
} else {
const actor = actorOrName;
for (const factoryName in this.targetScopedActorFactories) {
const handler = this.targetScopedActorFactories[factoryName];
if ((handler.options.constructorName == actor.name) ||
(handler.options.id == actor.id)) {
name = factoryName;
break;
}
}
}
if (!name) {
return;
}
delete this.targetScopedActorFactories[name];
for (const connID of Object.getOwnPropertyNames(this._connections)) {
// DebuggerServerConnection in child process don't have rootActor
if (this._connections[connID].rootActor) {
this._connections[connID].rootActor.removeActorByName(name);
}
}
},
/**
* Registers handlers for new browser-scoped request types defined dynamically.
*
* 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.
*
* @param options object
* - constructorName: (required)
* name of actor constructor, which is also used when removing the actor.
* One of the following:
* - id:
* module ID that contains the actor
* - constructorFun:
* a function to construct the actor
* @param name string
* The name of the new request type.
*/
addGlobalActor(options, name) {
if (!name) {
throw Error("addGlobalActor requires the `name` argument");
}
if (["from", "tabs", "selected"].includes(name)) {
throw Error(name + " is not allowed");
}
if (this.globalActorFactories.hasOwnProperty(name)) {
throw Error(name + " already exists");
}
this.globalActorFactories[name] = { options, name };
},
/**
* Unregisters the handler for the specified browser-scoped request type.
*
* When unregistering an existing global actor, we remove the actor factory as well as
* all existing instances of the actor.
*
* @param actor object, string
* In case of object:
* The `actor` object being given to related addGlobalActor call.
* In case of string:
* The `name` string being given to related addGlobalActor call.
*/
removeGlobalActor(actorOrName) {
let name;
if (typeof actorOrName == "string") {
name = actorOrName;
} else {
const actor = actorOrName;
for (const factoryName in this.globalActorFactories) {
const handler = this.globalActorFactories[factoryName];
if ((handler.options.constructorName == actor.name) ||
(handler.options.id == actor.id)) {
name = factoryName;
break;
}
}
}
if (!name) {
return;
}
delete this.globalActorFactories[name];
for (const connID of Object.getOwnPropertyNames(this._connections)) {
// DebuggerServerConnection in child process don't have rootActor
if (this._connections[connID].rootActor) {
this._connections[connID].rootActor.removeActorByName(name);
}
}
},
destroy() {
for (const id of Object.getOwnPropertyNames(gRegisteredModules)) {
this.unregisterModule(id);
}
gRegisteredModules = Object.create(null);
this.globalActorFactories = {};
this.targetScopedActorFactories = {};
},
};
exports.ActorRegistry = ActorRegistry;

Просмотреть файл

@ -6,6 +6,7 @@
DevToolsModules(
'actor-registry-utils.js',
'actor-registry.js',
'audionodes.json',
'automation-timeline.js',
'breakpoint-actor-map.js',

Просмотреть файл

@ -9,7 +9,7 @@
var { Ci } = require("chrome");
var Services = require("Services");
var { DebuggerServer } = require("devtools/server/main");
var { ActorRegistry } = require("devtools/server/actor-registry");
var { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
loader.lazyRequireGetter(this, "RootActor", "devtools/server/actors/root", true);

Просмотреть файл

@ -11,7 +11,7 @@
var { Ci, Cc } = require("chrome");
var Services = require("Services");
var { Pool } = require("devtools/shared/protocol");
var { ActorRegistry } = require("devtools/server/actor-registry");
var { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
var { dumpn } = DevToolsUtils;

Просмотреть файл

@ -20,7 +20,6 @@ MOCHITEST_CHROME_MANIFESTS += ['tests/mochitest/chrome.ini']
XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini']
DevToolsModules(
'actor-registry.js',
'main.js',
)

Просмотреть файл

@ -12,7 +12,7 @@ Services.scriptloader.loadSubScript(
this);
const {DebuggerClient} = require("devtools/shared/client/debugger-client");
const { ActorRegistry } = require("devtools/server/actor-registry");
const { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
const {DebuggerServer} = require("devtools/server/main");
const PATH = "browser/devtools/server/tests/browser/";

Просмотреть файл

@ -47,7 +47,7 @@ function runTests() {
/* eslint-disable no-shadow */
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
const { DebuggerServer } = require("devtools/server/main");
const { ActorRegistry } = require("devtools/server/actor-registry");
const { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
/* eslint-enable no-shadow */
DebuggerServer.init();

Просмотреть файл

@ -31,7 +31,7 @@ Services.prefs.setBoolPref("devtools.debugger.log", true);
Services.prefs.setBoolPref("devtools.debugger.remote-enabled", true);
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
const { ActorRegistry } = require("devtools/server/actor-registry");
const { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
const { DebuggerServer } = require("devtools/server/main");
const { DebuggerServer: WorkerDebuggerServer } = worker.require("devtools/server/main");
const { DebuggerClient } = require("devtools/shared/client/debugger-client");

Просмотреть файл

@ -7,7 +7,7 @@ const { LazyPool, createExtraActors } = require("devtools/shared/protocol/lazy-p
const { RootActor } = require("devtools/server/actors/root");
const { ThreadActor } = require("devtools/server/actors/thread");
const { DebuggerServer } = require("devtools/server/main");
const { ActorRegistry } = require("devtools/server/actor-registry");
const { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
const { TabSources } = require("devtools/server/actors/utils/TabSources");
const makeDebugger = require("devtools/server/actors/utils/make-debugger");

Просмотреть файл

@ -6,7 +6,7 @@ const { LazyPool, createExtraActors } = require("devtools/shared/protocol/lazy-p
const { RootActor } = require("devtools/server/actors/root");
const { ThreadActor } = require("devtools/server/actors/thread");
const { DebuggerServer } = require("devtools/server/main");
const { ActorRegistry } = require("devtools/server/actor-registry");
const { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
const promise = require("promise");
var gTestGlobals = [];

Просмотреть файл

@ -25,7 +25,7 @@ const Services = require("Services");
// Enable remote debugging for the relevant tests.
Services.prefs.setBoolPref("devtools.debugger.remote-enabled", true);
const { ActorRegistry } = require("devtools/server/actor-registry");
const { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
const { DebuggerServer } = require("devtools/server/main");
const { DebuggerClient } = require("devtools/shared/client/debugger-client");

Просмотреть файл

@ -3,7 +3,7 @@
"use strict";
const { RootActor } = require("devtools/server/actors/root");
const { ActorRegistry } = require("devtools/server/actor-registry");
const { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
/**
* Root actor that doesn't have the bulk trait.

Просмотреть файл

@ -6,7 +6,7 @@ const { LazyPool, createExtraActors } = require("devtools/shared/protocol/lazy-p
const { RootActor } = require("devtools/server/actors/root");
const { ThreadActor } = require("devtools/server/actors/thread");
const { DebuggerServer } = require("devtools/server/main");
const { ActorRegistry } = require("devtools/server/actor-registry");
const { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
var gTestGlobals = [];
DebuggerServer.addTestGlobal = function(global) {

Просмотреть файл

@ -34,7 +34,7 @@ module.exports = async function() {
`function () {
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
const { ActorRegistry } = require("devtools/server/actor-registry");
const { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
ActorRegistry.registerModule("chrome://damp/content/tests/server/actor.js", {
prefix: "dampTest",
constructor: "DampTestActor",