зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1277673 - Decouple the ActorActorFront and ActorRegistryFront from the ActorActor and ActorRegistryActor respectively; r=ejpbruel
This commit is contained in:
Родитель
6fcf81b996
Коммит
84bd208e23
|
@ -12,7 +12,7 @@ Services.scriptloader.loadSubScript(
|
|||
|
||||
var {getInplaceEditorForSpan: inplaceEditor} = require("devtools/client/shared/inplace-editor");
|
||||
var clipboard = require("sdk/clipboard");
|
||||
var {ActorRegistryFront} = require("devtools/server/actors/actor-registry");
|
||||
var {ActorRegistryFront} = require("devtools/shared/fronts/actor-registry");
|
||||
|
||||
// If a test times out we want to see the complete log and not just the last few
|
||||
// lines.
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
let deferred = promise.defer();
|
||||
client.listTabs(deferred.resolve);
|
||||
let response = yield deferred.promise;
|
||||
let { ActorRegistryFront } = require("devtools/server/actors/actor-registry");
|
||||
let { ActorRegistryFront } = require("devtools/shared/fronts/actor-registry");
|
||||
let registryFront = ActorRegistryFront(client, response);
|
||||
|
||||
// Then ask to register our test-actor to retrieve its front
|
||||
|
|
|
@ -11,50 +11,34 @@ const { Cu, CC, components } = require("chrome");
|
|||
const Services = require("Services");
|
||||
const { DebuggerServer } = require("devtools/server/main");
|
||||
const { registerActor, unregisterActor } = require("devtools/server/actors/utils/actor-registry-utils");
|
||||
|
||||
loader.lazyImporter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm");
|
||||
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.ActorClass({
|
||||
typeName: "actorActor",
|
||||
|
||||
const ActorActor = protocol.ActorClassWithSpec(actorActorSpec, {
|
||||
initialize: function (conn, options) {
|
||||
protocol.Actor.prototype.initialize.call(this, conn);
|
||||
|
||||
this.options = options;
|
||||
},
|
||||
|
||||
unregister: method(function () {
|
||||
unregister: function () {
|
||||
unregisterActor(this.options);
|
||||
}, {
|
||||
request: {},
|
||||
response: {}
|
||||
})
|
||||
});
|
||||
|
||||
const ActorActorFront = protocol.FrontClass(ActorActor, {
|
||||
initialize: function (client, form) {
|
||||
protocol.Front.prototype.initialize.call(this, client, form);
|
||||
}
|
||||
});
|
||||
|
||||
exports.ActorActorFront = ActorActorFront;
|
||||
|
||||
/*
|
||||
* The ActorRegistryActor allows clients to define new actors on the
|
||||
* server. This is particularly useful for addons.
|
||||
*/
|
||||
const ActorRegistryActor = protocol.ActorClass({
|
||||
typeName: "actorRegistry",
|
||||
|
||||
const ActorRegistryActor = protocol.ActorClassWithSpec(actorRegistrySpec, {
|
||||
initialize: function (conn) {
|
||||
protocol.Actor.prototype.initialize.call(this, conn);
|
||||
},
|
||||
|
||||
registerActor: method(function (sourceText, fileName, options) {
|
||||
registerActor: function (sourceText, fileName, options) {
|
||||
return registerActor(sourceText, fileName, options).then(() => {
|
||||
let { constructor, type } = options;
|
||||
|
||||
|
@ -64,63 +48,7 @@ const ActorRegistryActor = protocol.ActorClass({
|
|||
global: type.global
|
||||
});
|
||||
});
|
||||
}, {
|
||||
request: {
|
||||
sourceText: Arg(0, "string"),
|
||||
filename: Arg(1, "string"),
|
||||
options: Arg(2, "json")
|
||||
},
|
||||
|
||||
response: {
|
||||
actorActor: RetVal("actorActor")
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
exports.ActorRegistryActor = ActorRegistryActor;
|
||||
|
||||
function request(uri) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
uri = Services.io.newURI(uri, null, null);
|
||||
} 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;
|
||||
}
|
||||
|
||||
let source = NetUtil.readInputStreamToString(stream, stream.available());
|
||||
stream.close();
|
||||
resolve(source);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const ActorRegistryFront = protocol.FrontClass(ActorRegistryActor, {
|
||||
initialize: function (client, form) {
|
||||
protocol.Front.prototype.initialize.call(this, client,
|
||||
{ actor: form.actorRegistryActor });
|
||||
|
||||
this.manage(this);
|
||||
},
|
||||
|
||||
registerActor: custom(function (uri, options) {
|
||||
return request(uri, options)
|
||||
.then(sourceText => {
|
||||
return this._registerActor(sourceText, uri, options);
|
||||
});
|
||||
}, {
|
||||
impl: "_registerActor"
|
||||
})
|
||||
});
|
||||
exports.ActorRegistryFront = ActorRegistryFront;
|
||||
|
|
|
@ -2,7 +2,7 @@ var gClient;
|
|||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
var {ActorRegistryFront} = require("devtools/server/actors/actor-registry");
|
||||
var {ActorRegistryFront} = require("devtools/shared/fronts/actor-registry");
|
||||
var actorURL = "chrome://mochitests/content/chrome/devtools/server/tests/mochitest/hello-actor.js";
|
||||
|
||||
if (!DebuggerServer.initialized) {
|
||||
|
|
|
@ -10,7 +10,7 @@ var gRegistryFront;
|
|||
var gActorFront;
|
||||
var gOldPref;
|
||||
|
||||
const { ActorRegistryFront } = require("devtools/server/actors/actor-registry");
|
||||
const { ActorRegistryFront } = require("devtools/shared/fronts/actor-registry");
|
||||
|
||||
function run_test()
|
||||
{
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/* 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 protocol = require("devtools/shared/protocol");
|
||||
const { custom } = protocol;
|
||||
|
||||
loader.lazyImporter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
const ActorActorFront = protocol.FrontClassWithSpec(actorActorSpec, {
|
||||
initialize: function (client, form) {
|
||||
protocol.Front.prototype.initialize.call(this, client, form);
|
||||
}
|
||||
});
|
||||
|
||||
exports.ActorActorFront = ActorActorFront;
|
||||
|
||||
function request(uri) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
uri = Services.io.newURI(uri, null, null);
|
||||
} 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;
|
||||
}
|
||||
|
||||
let source = NetUtil.readInputStreamToString(stream, stream.available());
|
||||
stream.close();
|
||||
resolve(source);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const ActorRegistryFront = protocol.FrontClassWithSpec(actorRegistrySpec, {
|
||||
initialize: function (client, form) {
|
||||
protocol.Front.prototype.initialize.call(this, client,
|
||||
{ actor: form.actorRegistryActor });
|
||||
|
||||
this.manage(this);
|
||||
},
|
||||
|
||||
registerActor: custom(function (uri, options) {
|
||||
return request(uri, options)
|
||||
.then(sourceText => {
|
||||
return this._registerActor(sourceText, uri, options);
|
||||
});
|
||||
}, {
|
||||
impl: "_registerActor"
|
||||
})
|
||||
});
|
||||
|
||||
exports.ActorRegistryFront = ActorRegistryFront;
|
|
@ -5,6 +5,7 @@
|
|||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
DevToolsModules(
|
||||
'actor-registry.js',
|
||||
'addons.js',
|
||||
'animation.js',
|
||||
'call-watcher.js',
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/* 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;
|
|
@ -5,6 +5,7 @@
|
|||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
DevToolsModules(
|
||||
'actor-registry.js',
|
||||
'addons.js',
|
||||
'animation.js',
|
||||
'call-watcher.js',
|
||||
|
|
Загрузка…
Ссылка в новой задаче