зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1153292 - part5: create ServiceWorkerActor;r=janx
MozReview-Commit-ID: CdlqUHHW1O1 --HG-- extra : rebase_source : d27c8063dd690aded44ef3e9bf7ed4ddba838a89
This commit is contained in:
Родитель
1a25f252c3
Коммит
61c6c5d259
|
@ -60,22 +60,13 @@ module.exports = createClass({
|
|||
|
||||
getWorkerForms(this.props.client).then(forms => {
|
||||
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({
|
||||
icon: WorkerIcon,
|
||||
name: form.url,
|
||||
url: form.url,
|
||||
scope: form.scope,
|
||||
registrationActor: form.actor,
|
||||
active
|
||||
active: form.active
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -99,17 +90,11 @@ module.exports = createClass({
|
|||
} else {
|
||||
// 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
|
||||
// reach the activated state. Add a temporary registration to display it in
|
||||
// aboutdebugging.
|
||||
workers.service.push({
|
||||
icon: WorkerIcon,
|
||||
name: form.url,
|
||||
url: form.url,
|
||||
scope: form.scope,
|
||||
registrationActor: null,
|
||||
workerActor: form.actor,
|
||||
active: false
|
||||
});
|
||||
// reach the activated state. Augment the worker as a registration worker to
|
||||
// display it in aboutdebugging.
|
||||
worker.scope = form.scope;
|
||||
worker.active = false;
|
||||
workers.service.push(worker);
|
||||
}
|
||||
break;
|
||||
case Ci.nsIWorkerDebugger.TYPE_SHARED:
|
||||
|
|
|
@ -14,6 +14,7 @@ const {
|
|||
workerSpec,
|
||||
pushSubscriptionSpec,
|
||||
serviceWorkerRegistrationSpec,
|
||||
serviceWorkerSpec,
|
||||
} = require("devtools/shared/specs/worker");
|
||||
|
||||
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.
|
||||
let _serviceWorkerProcessScriptLoaded = false;
|
||||
|
||||
|
@ -357,30 +381,25 @@ protocol.ActorClassWithSpec(serviceWorkerRegistrationSpec, {
|
|||
this._registration = registration;
|
||||
this._pushSubscriptionActor = null;
|
||||
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);
|
||||
},
|
||||
|
||||
get installingWorkerForm() {
|
||||
return this._getWorkerForm(this._registration.installingWorker);
|
||||
},
|
||||
onChange() {
|
||||
this._installingWorker.destroy();
|
||||
this._waitingWorker.destroy();
|
||||
this._activeWorker.destroy();
|
||||
|
||||
get activeWorkerForm() {
|
||||
return this._getWorkerForm(this._registration.activeWorker);
|
||||
},
|
||||
let {installingWorker, waitingWorker, activeWorker} = this._registration;
|
||||
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");
|
||||
},
|
||||
|
||||
|
@ -389,13 +408,22 @@ protocol.ActorClassWithSpec(serviceWorkerRegistrationSpec, {
|
|||
return this.actorID;
|
||||
}
|
||||
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 {
|
||||
actor: this.actorID,
|
||||
scope: registration.scope,
|
||||
url: registration.scriptSpec,
|
||||
installingWorker: this.installingWorkerForm,
|
||||
activeWorker: this.activeWorkerForm,
|
||||
waitingWorker: this.waitingWorkerForm,
|
||||
installingWorker,
|
||||
waitingWorker,
|
||||
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 = null;
|
||||
|
||||
this._installingWorker.destroy();
|
||||
this._waitingWorker.destroy();
|
||||
this._activeWorker.destroy();
|
||||
|
||||
this._installingWorker = null;
|
||||
this._waitingWorker = null;
|
||||
this._activeWorker = null;
|
||||
},
|
||||
|
||||
disconnect() {
|
||||
|
|
|
@ -69,3 +69,10 @@ const serviceWorkerRegistrationSpec = generateActorSpec({
|
|||
});
|
||||
|
||||
exports.serviceWorkerRegistrationSpec = serviceWorkerRegistrationSpec;
|
||||
|
||||
const serviceWorkerSpec = generateActorSpec({
|
||||
typeName: "serviceWorker",
|
||||
});
|
||||
|
||||
exports.serviceWorkerSpec = serviceWorkerSpec;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче