mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 00:05:36 +00:00
Bug 1620194 - Remove actor-registry actor r=ochameau
Depends on D65564 Differential Revision: https://phabricator.services.mozilla.com/D65570 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
c230c0e21e
commit
22a011204c
@ -1,56 +0,0 @@
|
||||
/* 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";
|
||||
|
||||
const protocol = require("devtools/shared/protocol");
|
||||
|
||||
const {
|
||||
registerActor,
|
||||
unregisterActor,
|
||||
} = require("devtools/server/actors/utils/actor-registry-utils");
|
||||
const {
|
||||
actorActorSpec,
|
||||
actorRegistrySpec,
|
||||
} = require("devtools/shared/specs/actor-registry");
|
||||
|
||||
/**
|
||||
* The ActorActor gives you a handle to an actor you've dynamically
|
||||
* registered and allows you to unregister it.
|
||||
*/
|
||||
const ActorActor = protocol.ActorClassWithSpec(actorActorSpec, {
|
||||
initialize: function(conn, options) {
|
||||
protocol.Actor.prototype.initialize.call(this, conn);
|
||||
|
||||
this.options = options;
|
||||
},
|
||||
|
||||
unregister: function() {
|
||||
unregisterActor(this.options);
|
||||
},
|
||||
});
|
||||
|
||||
/*
|
||||
* The ActorRegistryActor allows clients to define new actors on the
|
||||
* server. This is particularly useful for addons.
|
||||
*/
|
||||
const ActorRegistryActor = protocol.ActorClassWithSpec(actorRegistrySpec, {
|
||||
initialize: function(conn) {
|
||||
protocol.Actor.prototype.initialize.call(this, conn);
|
||||
},
|
||||
|
||||
registerActor: function(sourceText, fileName, options) {
|
||||
return registerActor(sourceText, fileName, options).then(() => {
|
||||
const { constructor, type } = options;
|
||||
|
||||
return ActorActor(this.conn, {
|
||||
name: constructor,
|
||||
tab: type.tab,
|
||||
global: type.global,
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
exports.ActorRegistryActor = ActorRegistryActor;
|
@ -20,7 +20,6 @@ DIRS += [
|
||||
]
|
||||
|
||||
DevToolsModules(
|
||||
'actor-registry.js',
|
||||
'animation-type-longhand.js',
|
||||
'animation.js',
|
||||
'array-buffer.js',
|
||||
|
@ -1,94 +0,0 @@
|
||||
/* 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";
|
||||
|
||||
const { Cu, CC } = require("chrome");
|
||||
|
||||
const { DevToolsServer } = require("devtools/server/devtools-server");
|
||||
const {
|
||||
ActorRegistry,
|
||||
} = require("devtools/server/actors/utils/actor-registry");
|
||||
|
||||
/**
|
||||
* Support for actor registration. Main used by ActorRegistryActor
|
||||
* for dynamic registration of new actors.
|
||||
*
|
||||
* @param sourceText {String} Source of the actor implementation
|
||||
* @param fileName {String} URL of the actor module (for proper stack traces)
|
||||
* @param options {Object} Configuration object
|
||||
*/
|
||||
exports.registerActor = function(sourceText, fileName, options) {
|
||||
// Register in the current process
|
||||
exports.registerActorInCurrentProcess(sourceText, fileName, options);
|
||||
// Register in any child processes
|
||||
return DevToolsServer.setupInChild({
|
||||
module: "devtools/server/actors/utils/actor-registry-utils",
|
||||
setupChild: "registerActorInCurrentProcess",
|
||||
args: [sourceText, fileName, options],
|
||||
waitForEval: true,
|
||||
});
|
||||
};
|
||||
|
||||
exports.registerActorInCurrentProcess = function(
|
||||
sourceText,
|
||||
fileName,
|
||||
options
|
||||
) {
|
||||
const principal = CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")();
|
||||
const sandbox = Cu.Sandbox(principal);
|
||||
sandbox.exports = {};
|
||||
sandbox.require = require;
|
||||
|
||||
Cu.evalInSandbox(sourceText, sandbox, "1.8", fileName, 1);
|
||||
|
||||
const { prefix, constructor, type } = options;
|
||||
|
||||
if (
|
||||
type.global &&
|
||||
!ActorRegistry.globalActorFactories.hasOwnProperty(prefix)
|
||||
) {
|
||||
ActorRegistry.addGlobalActor(
|
||||
{
|
||||
constructorName: constructor,
|
||||
constructorFun: sandbox[constructor],
|
||||
},
|
||||
prefix
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
type.target &&
|
||||
!ActorRegistry.targetScopedActorFactories.hasOwnProperty(prefix)
|
||||
) {
|
||||
ActorRegistry.addTargetScopedActor(
|
||||
{
|
||||
constructorName: constructor,
|
||||
constructorFun: sandbox[constructor],
|
||||
},
|
||||
prefix
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
exports.unregisterActor = function(options) {
|
||||
// Unregister in the current process
|
||||
exports.unregisterActorInCurrentProcess(options);
|
||||
// Unregister in any child processes
|
||||
DevToolsServer.setupInChild({
|
||||
module: "devtools/server/actors/utils/actor-registry-utils",
|
||||
setupChild: "unregisterActorInCurrentProcess",
|
||||
args: [options],
|
||||
});
|
||||
};
|
||||
|
||||
exports.unregisterActorInCurrentProcess = function(options) {
|
||||
if (options.target) {
|
||||
ActorRegistry.removeTargetScopedActor(options);
|
||||
}
|
||||
|
||||
if (options.global) {
|
||||
ActorRegistry.removeGlobalActor(options);
|
||||
}
|
||||
};
|
@ -127,11 +127,6 @@ const ActorRegistry = {
|
||||
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",
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
DevToolsModules(
|
||||
'accessibility.js',
|
||||
'actor-registry-utils.js',
|
||||
'actor-registry.js',
|
||||
'breakpoint-actor-map.js',
|
||||
'css-grid-utils.js',
|
||||
|
@ -166,6 +166,5 @@ fail-if = fission
|
||||
[browser_styles_getRuleText.js]
|
||||
[browser_stylesheets_getTextEmpty.js]
|
||||
[browser_stylesheets_nested-iframes.js]
|
||||
[browser_register_actor.js]
|
||||
[browser_resource_list-remote-frames.js]
|
||||
[browser_webextension_inspected_window.js]
|
||||
|
@ -1,77 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var gClient;
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
const actorURL =
|
||||
"chrome://mochitests/content/chrome/devtools/server/tests/chrome/hello-actor.js";
|
||||
|
||||
DevToolsServer.init();
|
||||
DevToolsServer.registerAllActors();
|
||||
|
||||
gClient = new DevToolsClient(DevToolsServer.connectPipe());
|
||||
gClient
|
||||
.connect()
|
||||
.then(() => gClient.mainRoot.listTabs())
|
||||
.then(async () => {
|
||||
const options = {
|
||||
prefix: "helloActor",
|
||||
constructor: "HelloActor",
|
||||
type: { target: true },
|
||||
};
|
||||
|
||||
const registry = await gClient.mainRoot.getFront("actorRegistry");
|
||||
const actorFront = await registry.registerActor(actorURL, options);
|
||||
const tabs = await gClient.mainRoot.listTabs();
|
||||
const front = tabs.find(tab => tab.selected);
|
||||
ok(!!front.targetForm.helloActor, "Hello actor must exist");
|
||||
|
||||
// Make sure actor's state is maintained across listTabs requests.
|
||||
checkActorState(
|
||||
front.targetForm.helloActor,
|
||||
cleanupActor.bind(this, actorFront)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function cleanupActor(actorFront) {
|
||||
// Clean up
|
||||
actorFront.unregister().then(() => {
|
||||
gClient.close().then(() => {
|
||||
DevToolsServer.destroy();
|
||||
gClient = null;
|
||||
finish();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getCount(actor, callback) {
|
||||
return gClient.request(
|
||||
{
|
||||
to: actor,
|
||||
type: "count",
|
||||
},
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
||||
var checkActorState = async function(helloActor, callback) {
|
||||
let response = await getCount(helloActor);
|
||||
ok(!response.error, "No error");
|
||||
is(response.count, 1, "The counter must be valid");
|
||||
|
||||
response = await getCount(helloActor);
|
||||
ok(!response.error, "No error");
|
||||
is(response.count, 2, "The counter must be valid");
|
||||
|
||||
const tabs = await gClient.mainRoot.listTabs();
|
||||
const tabTarget = tabs.find(tab => tab.selected);
|
||||
is(tabTarget.targetForm.helloActor, helloActor, "Hello actor must be valid");
|
||||
|
||||
response = await getCount(helloActor);
|
||||
ok(!response.error, "No error");
|
||||
is(response.count, 3, "The counter must be valid");
|
||||
|
||||
callback();
|
||||
};
|
@ -1,76 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Check that you can register new actors via the ActorRegistrationActor.
|
||||
*/
|
||||
|
||||
var gClient;
|
||||
var gRegistryFront;
|
||||
var gActorFront;
|
||||
|
||||
function run_test() {
|
||||
initTestDevToolsServer();
|
||||
DevToolsServer.registerAllActors();
|
||||
gClient = new DevToolsClient(DevToolsServer.connectPipe());
|
||||
gClient.connect().then(getRegistry);
|
||||
do_test_pending();
|
||||
}
|
||||
|
||||
async function getRegistry() {
|
||||
gRegistryFront = await gClient.mainRoot.getFront("actorRegistry");
|
||||
registerNewActor();
|
||||
}
|
||||
|
||||
function registerNewActor() {
|
||||
const options = {
|
||||
prefix: "helloActor",
|
||||
constructor: "HelloActor",
|
||||
type: { global: true },
|
||||
};
|
||||
|
||||
gRegistryFront
|
||||
.registerActor("resource://test/hello-actor.js", options)
|
||||
.then(actorFront => (gActorFront = actorFront))
|
||||
.then(talkToNewActor)
|
||||
.catch(e => {
|
||||
DevToolsUtils.reportException("registerNewActor", e);
|
||||
Assert.ok(false);
|
||||
});
|
||||
}
|
||||
|
||||
function talkToNewActor() {
|
||||
gClient.mainRoot.getRoot().then(({ helloActor }) => {
|
||||
Assert.ok(!!helloActor);
|
||||
gClient.request(
|
||||
{
|
||||
to: helloActor,
|
||||
type: "hello",
|
||||
},
|
||||
response => {
|
||||
Assert.ok(!response.error);
|
||||
unregisterNewActor();
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function unregisterNewActor() {
|
||||
gActorFront
|
||||
.unregister()
|
||||
.then(testActorIsUnregistered)
|
||||
.catch(e => {
|
||||
DevToolsUtils.reportException("unregisterNewActor", e);
|
||||
Assert.ok(false);
|
||||
});
|
||||
}
|
||||
|
||||
function testActorIsUnregistered() {
|
||||
gClient.mainRoot.rootForm.then(({ helloActor }) => {
|
||||
Assert.ok(!helloActor);
|
||||
|
||||
finishClient(gClient);
|
||||
});
|
||||
}
|
@ -38,7 +38,6 @@ support-files =
|
||||
[test_addons_actor.js]
|
||||
[test_animation_name.js]
|
||||
[test_animation_type.js]
|
||||
[test_actor-registry-actor.js]
|
||||
[test_nesting-01.js]
|
||||
[test_nesting-02.js]
|
||||
[test_nesting-03.js]
|
||||
|
@ -1,77 +0,0 @@
|
||||
/* 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";
|
||||
|
||||
const { components } = require("chrome");
|
||||
const Services = require("Services");
|
||||
const {
|
||||
actorActorSpec,
|
||||
actorRegistrySpec,
|
||||
} = require("devtools/shared/specs/actor-registry");
|
||||
const {
|
||||
FrontClassWithSpec,
|
||||
registerFront,
|
||||
} = require("devtools/shared/protocol");
|
||||
|
||||
loader.lazyImporter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
class ActorActorFront extends FrontClassWithSpec(actorActorSpec) {}
|
||||
|
||||
exports.ActorActorFront = ActorActorFront;
|
||||
registerFront(ActorActorFront);
|
||||
|
||||
function request(uri) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
uri = Services.io.newURI(uri);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
|
||||
NetUtil.asyncFetch(
|
||||
{
|
||||
uri,
|
||||
loadUsingSystemPrincipal: true,
|
||||
},
|
||||
(stream, status, req) => {
|
||||
if (!components.isSuccessCode(status)) {
|
||||
reject(
|
||||
new Error(
|
||||
"Request failed with status code = " +
|
||||
status +
|
||||
" after NetUtil.asyncFetch for url = " +
|
||||
uri
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const source = NetUtil.readInputStreamToString(
|
||||
stream,
|
||||
stream.available()
|
||||
);
|
||||
stream.close();
|
||||
resolve(source);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
class ActorRegistryFront extends FrontClassWithSpec(actorRegistrySpec) {
|
||||
constructor(client) {
|
||||
super(client);
|
||||
|
||||
// Attribute name from which to retrieve the actorID out of the target actor's form
|
||||
this.formAttributeName = "actorRegistryActor";
|
||||
}
|
||||
|
||||
registerActor(uri, options) {
|
||||
return request(uri, options).then(sourceText => {
|
||||
return super.registerActor(sourceText, uri, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
exports.ActorRegistryFront = ActorRegistryFront;
|
||||
registerFront(ActorRegistryFront);
|
@ -14,7 +14,6 @@ DIRS += [
|
||||
|
||||
DevToolsModules(
|
||||
'accessibility.js',
|
||||
'actor-registry.js',
|
||||
'animation.js',
|
||||
'array-buffer.js',
|
||||
'changes.js',
|
||||
|
@ -171,7 +171,7 @@ LazyActor.prototype = {
|
||||
getConstructor() {
|
||||
const options = this._options;
|
||||
if (options.constructorFun) {
|
||||
// Actor definition registered by ActorRegistryActor or testing helpers
|
||||
// Actor definition registered by testing helpers
|
||||
return options.constructorFun;
|
||||
}
|
||||
// Lazy actor definition, where options contains all the information
|
||||
|
@ -1,39 +0,0 @@
|
||||
/* 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";
|
||||
|
||||
const { Arg, RetVal, generateActorSpec } = require("devtools/shared/protocol");
|
||||
|
||||
const actorActorSpec = generateActorSpec({
|
||||
typeName: "actorActor",
|
||||
|
||||
methods: {
|
||||
unregister: {
|
||||
request: {},
|
||||
response: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
exports.actorActorSpec = actorActorSpec;
|
||||
|
||||
const actorRegistrySpec = generateActorSpec({
|
||||
typeName: "actorRegistry",
|
||||
|
||||
methods: {
|
||||
registerActor: {
|
||||
request: {
|
||||
sourceText: Arg(0, "string"),
|
||||
filename: Arg(1, "string"),
|
||||
options: Arg(2, "json"),
|
||||
},
|
||||
|
||||
response: {
|
||||
actorActor: RetVal("actorActor"),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
exports.actorRegistrySpec = actorRegistrySpec;
|
@ -22,11 +22,6 @@ const Types = (exports.__TypesForTests = [
|
||||
spec: "devtools/shared/specs/accessibility",
|
||||
front: "devtools/shared/fronts/accessibility",
|
||||
},
|
||||
{
|
||||
types: ["actorActor", "actorRegistry"],
|
||||
spec: "devtools/shared/specs/actor-registry",
|
||||
front: "devtools/shared/fronts/actor-registry",
|
||||
},
|
||||
{
|
||||
types: ["addons"],
|
||||
spec: "devtools/shared/specs/addon/addons",
|
||||
|
@ -13,7 +13,6 @@ DIRS += [
|
||||
|
||||
DevToolsModules(
|
||||
'accessibility.js',
|
||||
'actor-registry.js',
|
||||
'animation.js',
|
||||
'array-buffer.js',
|
||||
'changes.js',
|
||||
|
Loading…
Reference in New Issue
Block a user