Bug 1277951 - Use ActorClassWithSpec for WorkerActor and ServiceWorkerRegistrationActor; r=ejpbruel

This commit is contained in:
Nick Fitzgerald 2016-06-06 10:24:34 -07:00
Родитель 32fd612182
Коммит 05e8f31b35
3 изменённых файлов: 71 добавлений и 39 удалений

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

@ -5,6 +5,10 @@ var { DebuggerServer } = require("devtools/server/main");
var Services = require("Services");
const protocol = require("devtools/shared/protocol");
const { Arg, method, RetVal } = protocol;
const {
workerSpec,
serviceWorkerRegistrationSpec,
} = require("devtools/shared/specs/worker");
loader.lazyRequireGetter(this, "ChromeUtils");
@ -40,9 +44,7 @@ function matchWorkerDebugger(dbg, options) {
return true;
}
let WorkerActor = protocol.ActorClass({
typeName: "worker",
let WorkerActor = protocol.ActorClassWithSpec(workerSpec, {
initialize: function (conn, dbg) {
protocol.Actor.prototype.initialize.call(this, conn);
this._dbg = dbg;
@ -69,7 +71,7 @@ let WorkerActor = protocol.ActorClass({
return form;
},
attach: method(function () {
attach: function () {
if (this._dbg.isClosed) {
return { error: "closed" };
}
@ -91,12 +93,9 @@ let WorkerActor = protocol.ActorClass({
type: "attached",
url: this._dbg.url
};
}, {
request: {},
response: RetVal("json")
}),
},
detach: method(function () {
detach: function () {
if (!this._attached) {
return { error: "wrongState" };
}
@ -104,12 +103,9 @@ let WorkerActor = protocol.ActorClass({
this._detach();
return { type: "detached" };
}, {
request: {},
response: RetVal("json")
}),
},
connect: method(function (options) {
connect: function (options) {
if (!this._attached) {
return { error: "wrongState" };
}
@ -136,14 +132,9 @@ let WorkerActor = protocol.ActorClass({
}, (error) => {
return { error: error.toString() };
});
}, {
request: {
options: Arg(0, "json"),
},
response: RetVal("json")
}),
},
push: method(function () {
push: function () {
if (this._dbg.type !== Ci.nsIWorkerDebugger.TYPE_SERVICE) {
return { error: "wrongType" };
}
@ -152,10 +143,7 @@ let WorkerActor = protocol.ActorClass({
this._dbg.principal.originAttributes);
swm.sendPushEvent(originAttributes, registration.scope);
return { type: "pushed" };
}, {
request: {},
response: RetVal("json")
}),
},
onClose: function () {
if (this._attached) {
@ -307,9 +295,8 @@ exports.WorkerActorList = WorkerActorList;
// Lazily load the service-worker-child.js process script only once.
let _serviceWorkerProcessScriptLoaded = false;
let ServiceWorkerRegistrationActor = protocol.ActorClass({
typeName: "serviceWorkerRegistration",
let ServiceWorkerRegistrationActor =
protocol.ActorClassWithSpec(serviceWorkerRegistrationSpec, {
initialize: function (conn, registration) {
protocol.Actor.prototype.initialize.call(this, conn);
this._registration = registration;
@ -327,7 +314,7 @@ let ServiceWorkerRegistrationActor = protocol.ActorClass({
};
},
start: method(function () {
start: function () {
if (!_serviceWorkerProcessScriptLoaded) {
Services.ppmm.loadProcessScript(
"resource://devtools/server/service-worker-child.js", true);
@ -337,12 +324,9 @@ let ServiceWorkerRegistrationActor = protocol.ActorClass({
scope: this._registration.scope
});
return { type: "started" };
}, {
request: {},
response: RetVal("json")
}),
},
unregister: method(function () {
unregister: function () {
let { principal, scope } = this._registration;
let unregisterCallback = {
unregisterSucceeded: function () {},
@ -355,10 +339,7 @@ let ServiceWorkerRegistrationActor = protocol.ActorClass({
swm.propagateUnregister(principal, unregisterCallback, scope);
return { type: "unregistered" };
}, {
request: {},
response: RetVal("json")
}),
},
});
function ServiceWorkerRegistrationActorList(conn) {

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

@ -25,5 +25,6 @@ DevToolsModules(
'styles.js',
'stylesheets.js',
'webaudio.js',
'webgl.js'
'webgl.js',
'worker.js'
)

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

@ -0,0 +1,50 @@
/* 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 workerSpec = generateActorSpec({
typeName: "worker",
methods: {
attach: {
request: {},
response: RetVal("json")
},
detach: {
request: {},
response: RetVal("json")
},
connect: {
request: {
options: Arg(0, "json"),
},
response: RetVal("json")
},
push: {
request: {},
response: RetVal("json")
},
},
});
exports.workerSpec = workerSpec;
const serviceWorkerRegistrationSpec = generateActorSpec({
typeName: "serviceWorkerRegistration",
methods: {
start: {
request: {},
response: RetVal("json")
},
unregister: {
request: {},
response: RetVal("json")
},
},
});
exports.serviceWorkerRegistrationSpec = serviceWorkerRegistrationSpec;