Bug 1153292 - part5: create ServiceWorkerActor;r=janx

MozReview-Commit-ID: CdlqUHHW1O1

--HG--
extra : rebase_source : d27c8063dd690aded44ef3e9bf7ed4ddba838a89
This commit is contained in:
Julian Descottes 2016-09-27 20:52:50 +02:00
Родитель 1a25f252c3
Коммит 61c6c5d259
3 изменённых файлов: 71 добавлений и 43 удалений

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

@ -60,22 +60,13 @@ module.exports = createClass({
getWorkerForms(this.props.client).then(forms => { getWorkerForms(this.props.client).then(forms => {
forms.registrations.forEach(form => { forms.registrations.forEach(form => {
// - In e10s: only active registrations are available, but if the worker is in
// activating state it won't be available as the activeWorker. Registrations with
// no worker are actually registrations with a hidden activating worker.
// - In non-e10s: registrations always have at least one worker, if it is an
// active worker, the registration is active.
let hasWorker = form.activeWorker || form.waitingWorker || form.installingWorker;
let isE10s = Services.appinfo.browserTabsRemoteAutostart;
let active = form.activeWorker || (isE10s && !hasWorker);
workers.service.push({ workers.service.push({
icon: WorkerIcon, icon: WorkerIcon,
name: form.url, name: form.url,
url: form.url, url: form.url,
scope: form.scope, scope: form.scope,
registrationActor: form.actor, registrationActor: form.actor,
active active: form.active
}); });
}); });
@ -99,17 +90,11 @@ module.exports = createClass({
} else { } else {
// If a service worker registration could not be found, this means we are in // If a service worker registration could not be found, this means we are in
// e10s, and registrations are not forwarded to other processes until they // e10s, and registrations are not forwarded to other processes until they
// reach the activated state. Add a temporary registration to display it in // reach the activated state. Augment the worker as a registration worker to
// aboutdebugging. // display it in aboutdebugging.
workers.service.push({ worker.scope = form.scope;
icon: WorkerIcon, worker.active = false;
name: form.url, workers.service.push(worker);
url: form.url,
scope: form.scope,
registrationActor: null,
workerActor: form.actor,
active: false
});
} }
break; break;
case Ci.nsIWorkerDebugger.TYPE_SHARED: case Ci.nsIWorkerDebugger.TYPE_SHARED:

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

@ -14,6 +14,7 @@ const {
workerSpec, workerSpec,
pushSubscriptionSpec, pushSubscriptionSpec,
serviceWorkerRegistrationSpec, serviceWorkerRegistrationSpec,
serviceWorkerSpec,
} = require("devtools/shared/specs/worker"); } = require("devtools/shared/specs/worker");
loader.lazyRequireGetter(this, "ChromeUtils"); loader.lazyRequireGetter(this, "ChromeUtils");
@ -339,6 +340,29 @@ let PushSubscriptionActor = protocol.ActorClassWithSpec(pushSubscriptionSpec, {
}, },
}); });
let ServiceWorkerActor = protocol.ActorClassWithSpec(serviceWorkerSpec, {
initialize(conn, worker) {
protocol.Actor.prototype.initialize.call(this, conn);
this._worker = worker;
},
form() {
if (!this._worker) {
return null;
}
return {
url: this._worker.scriptSpec,
state: this._worker.state,
};
},
destroy() {
protocol.Actor.prototype.destroy.call(this);
this._worker = null;
},
});
// Lazily load the service-worker-child.js process script only once. // Lazily load the service-worker-child.js process script only once.
let _serviceWorkerProcessScriptLoaded = false; let _serviceWorkerProcessScriptLoaded = false;
@ -357,30 +381,25 @@ protocol.ActorClassWithSpec(serviceWorkerRegistrationSpec, {
this._registration = registration; this._registration = registration;
this._pushSubscriptionActor = null; this._pushSubscriptionActor = null;
this._registration.addListener(this); this._registration.addListener(this);
let {installingWorker, waitingWorker, activeWorker} = registration;
this._installingWorker = new ServiceWorkerActor(conn, installingWorker);
this._waitingWorker = new ServiceWorkerActor(conn, waitingWorker);
this._activeWorker = new ServiceWorkerActor(conn, activeWorker);
Services.obs.addObserver(this, PushService.subscriptionModifiedTopic, false); Services.obs.addObserver(this, PushService.subscriptionModifiedTopic, false);
}, },
get installingWorkerForm() { onChange() {
return this._getWorkerForm(this._registration.installingWorker); this._installingWorker.destroy();
}, this._waitingWorker.destroy();
this._activeWorker.destroy();
get activeWorkerForm() { let {installingWorker, waitingWorker, activeWorker} = this._registration;
return this._getWorkerForm(this._registration.activeWorker); this._installingWorker = new ServiceWorkerActor(this._conn, installingWorker);
}, this._waitingWorker = new ServiceWorkerActor(this._conn, waitingWorker);
this._activeWorker = new ServiceWorkerActor(this._conn, activeWorker);
get waitingWorkerForm() {
return this._getWorkerForm(this._registration.waitingWorker);
},
_getWorkerForm: function (worker) {
if (!worker) {
return null;
}
return { url: worker.scriptSpec, state: worker.state };
},
onChange: function () {
events.emit(this, "registration-changed"); events.emit(this, "registration-changed");
}, },
@ -389,13 +408,22 @@ protocol.ActorClassWithSpec(serviceWorkerRegistrationSpec, {
return this.actorID; return this.actorID;
} }
let registration = this._registration; let registration = this._registration;
let installingWorker = this._installingWorker.form();
let waitingWorker = this._waitingWorker.form();
let activeWorker = this._activeWorker.form();
let isE10s = Services.appinfo.browserTabsRemoteAutostart;
return { return {
actor: this.actorID, actor: this.actorID,
scope: registration.scope, scope: registration.scope,
url: registration.scriptSpec, url: registration.scriptSpec,
installingWorker: this.installingWorkerForm, installingWorker,
activeWorker: this.activeWorkerForm, waitingWorker,
waitingWorker: this.waitingWorkerForm, activeWorker,
// - In e10s: only active registrations are available.
// - In non-e10s: registrations always have at least one worker, if the worker is
// active, the registration is active.
active: isE10s ? true : !!activeWorker
}; };
}, },
@ -408,6 +436,14 @@ protocol.ActorClassWithSpec(serviceWorkerRegistrationSpec, {
this._pushSubscriptionActor.destroy(); this._pushSubscriptionActor.destroy();
} }
this._pushSubscriptionActor = null; this._pushSubscriptionActor = null;
this._installingWorker.destroy();
this._waitingWorker.destroy();
this._activeWorker.destroy();
this._installingWorker = null;
this._waitingWorker = null;
this._activeWorker = null;
}, },
disconnect() { disconnect() {

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

@ -69,3 +69,10 @@ const serviceWorkerRegistrationSpec = generateActorSpec({
}); });
exports.serviceWorkerRegistrationSpec = serviceWorkerRegistrationSpec; exports.serviceWorkerRegistrationSpec = serviceWorkerRegistrationSpec;
const serviceWorkerSpec = generateActorSpec({
typeName: "serviceWorker",
});
exports.serviceWorkerSpec = serviceWorkerSpec;