Bug 1153292 - part5: aboutdebugging: rely on activeWorker to decide if registration is activated;r=janx
MozReview-Commit-ID: 2NkeIDJZb5X
--- a/devtools/client/aboutdebugging/components/workers/panel.js
+++ b/devtools/client/aboutdebugging/components/workers/panel.js
@@ -57,17 +57,18 @@ module.exports = createClass({
getWorkerForms(this.props.client).then(forms => {
forms.registrations.forEach(form => {
workers.service.push({
icon: WorkerIcon,
name: form.url,
url: form.url,
scope: form.scope,
- registrationActor: form.actor
+ registrationActor: form.actor,
+ activated: !!form.activeWorker
});
});
forms.workers.forEach(form => {
let worker = {
icon: WorkerIcon,
name: form.url,
url: form.url,
@@ -90,17 +91,18 @@ module.exports = createClass({
}
if (!registrationFound) {
let serviceWorker = {
icon: WorkerIcon,
name: form.url,
url: form.url,
scope: form.scope,
registrationActor: null,
- workerActor: form.actor
+ workerActor: form.actor,
+ activated: false
};
workers.service.push(serviceWorker);
}
break;
case Ci.nsIWorkerDebugger.TYPE_SHARED:
workers.shared.push(worker);
break;
default:
--- a/devtools/client/aboutdebugging/components/workers/service-worker-target.js
+++ b/devtools/client/aboutdebugging/components/workers/service-worker-target.js
@@ -1,17 +1,16 @@
/* 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/. */
/* eslint-env browser */
"use strict";
-const { Ci } = require("chrome");
const { createClass, DOM: dom } =
require("devtools/client/shared/vendor/react");
const { debugWorker } = require("../../modules/worker");
const Services = require("Services");
const Strings = Services.strings.createBundle(
"chrome://devtools/locale/aboutdebugging.properties");
@@ -27,20 +26,19 @@ module.exports = createClass({
componentDidMount() {
let { client } = this.props;
client.addListener("push-subscription-modified",
this.onPushSubscriptionModified);
this.updatePushSubscription();
},
componentDidUpdate(oldProps, oldState) {
- let oldRegistrationActor = oldProps.target && oldProps.target.registrationActor;
- let registrationActor = this.props.target && this.props.target.registrationActor;
-
- if (!oldRegistrationActor && registrationActor) {
+ let wasActivated = oldProps.target.activated;
+ let isActivated = this.props.target.activated;
+ if (!wasActivated && isActivated) {
// Component just reached registration stage and should refresh push information.
this.updatePushSubscription();
}
},
componentWillUnmount() {
let { client } = this.props;
client.removeListener("push-subscription-modified", this.onPushSubscriptionModified);
@@ -112,17 +110,17 @@ module.exports = createClass({
},
isRunning() {
// We know the target is running if it has a worker actor.
return !!this.props.target.workerActor;
},
isActivated() {
- return !!this.props.target.registrationActor;
+ return this.props.target.activated;
},
getServiceWorkerStatus() {
if (this.isActivated() && this.isRunning()) {
return "running";
} else if (this.isActivated()) {
return "stopped";
}
--- a/devtools/server/actors/worker.js
+++ b/devtools/server/actors/worker.js
@@ -354,25 +354,48 @@ protocol.ActorClass(serviceWorkerRegistr
initialize(conn, registration) {
protocol.Actor.prototype.initialize.call(this, conn);
this._conn = conn;
this._registration = registration;
this._pushSubscriptionActor = null;
Services.obs.addObserver(this, PushService.subscriptionModifiedTopic, false);
},
+ get installingWorkerForm() {
+ return this._getWorkerForm(this._registration.installingWorker);
+ },
+
+ get activeWorkerForm() {
+ return this._getWorkerForm(this._registration.activeWorker);
+ },
+
+ get waitingWorkerForm() {
+ return this._getWorkerForm(this._registration.waitingWorker);
+ },
+
+ _getWorkerForm: function (worker) {
+ if (!worker) {
+ return null;
+ }
+
+ return { url: worker.scriptSpec, state: worker.state };
+ },
+
form(detail) {
if (detail === "actorid") {
return this.actorID;
}
let registration = this._registration;
return {
actor: this.actorID,
scope: registration.scope,
- url: registration.scriptSpec
+ url: registration.scriptSpec,
+ installingWorker: this.installingWorkerForm,
+ activeWorker: this.activeWorkerForm,
+ waitingWorker: this.waitingWorkerForm,
};
},
destroy() {
protocol.Actor.prototype.destroy.call(this);
Services.obs.removeObserver(this, PushService.subscriptionModifiedTopic, false);
this._registration = null;
if (this._pushSubscriptionActor) {
@@ -458,16 +481,17 @@ protocol.ActorClass(serviceWorkerRegistr
function ServiceWorkerRegistrationActorList(conn) {
this._conn = conn;
this._actors = new Map();
this._onListChanged = null;
this._mustNotify = false;
this.onRegister = this.onRegister.bind(this);
this.onUnregister = this.onUnregister.bind(this);
+ this.onStateChanged = this.onStateChanged.bind(this);
}
ServiceWorkerRegistrationActorList.prototype = {
getList() {
// Create a set of registrations.
let registrations = new Set();
let array = swm.getAllRegistrations();
for (let index = 0; index < array.length; ++index) {
@@ -535,12 +559,16 @@ ServiceWorkerRegistrationActorList.proto
},
onRegister(registration) {
this._notifyListChanged();
},
onUnregister(registration) {
this._notifyListChanged();
- }
+ },
+
+ onStateChanged(registration) {
+ this._notifyListChanged();
+ },
};
exports.ServiceWorkerRegistrationActorList = ServiceWorkerRegistrationActorList;