Bug 1510654 - Return ServiceWorker fronts for installing, active and waiting workers;r=ochameau,ladybenko
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 10 Jan 2019 17:26:48 +0000
changeset 510410 247e6818b26264099735ce8a0c972940d15940c9
parent 510409 a2289d2698b76d737be4c5b9c4c8fb89cbbd86d6
child 510411 08b043c4ef1b2a1a90b213ab407bd0f2fc497259
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau, ladybenko
bugs1510654
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1510654 - Return ServiceWorker fronts for installing, active and waiting workers;r=ochameau,ladybenko Depends on D15376 Differential Revision: https://phabricator.services.mozilla.com/D15377
devtools/server/actors/worker/service-worker.js
devtools/shared/fronts/worker/service-worker.js
--- a/devtools/server/actors/worker/service-worker.js
+++ b/devtools/server/actors/worker/service-worker.js
@@ -62,16 +62,17 @@ const ServiceWorkerActor = protocol.Acto
   },
 
   form() {
     if (!this._worker) {
       return null;
     }
 
     return {
+      actor: this.actorID,
       url: this._worker.scriptSpec,
       state: this._worker.state,
       fetch: this._worker.handlesFetchEvents,
     };
   },
 
   destroy() {
     protocol.Actor.prototype.destroy.call(this);
@@ -93,34 +94,24 @@ protocol.ActorClassWithSpec(serviceWorke
    */
   initialize(conn, registration) {
     protocol.Actor.prototype.initialize.call(this, conn);
     this._conn = conn;
     this._registration = registration;
     this._pushSubscriptionActor = null;
     this._registration.addListener(this);
 
-    const {installingWorker, waitingWorker, activeWorker} = registration;
-    this._installingWorker = new ServiceWorkerActor(conn, installingWorker);
-    this._waitingWorker = new ServiceWorkerActor(conn, waitingWorker);
-    this._activeWorker = new ServiceWorkerActor(conn, activeWorker);
+    this._createServiceWorkerActors();
 
     Services.obs.addObserver(this, PushService.subscriptionModifiedTopic);
   },
 
   onChange() {
-    this._installingWorker.destroy();
-    this._waitingWorker.destroy();
-    this._activeWorker.destroy();
-
-    const {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);
-
+    this._destroyServiceWorkerActors();
+    this._createServiceWorkerActors();
     this.emit("registration-changed");
   },
 
   form(detail) {
     if (detail === "actorid") {
       return this.actorID;
     }
     const registration = this._registration;
@@ -152,19 +143,17 @@ protocol.ActorClassWithSpec(serviceWorke
     Services.obs.removeObserver(this, PushService.subscriptionModifiedTopic);
     this._registration.removeListener(this);
     this._registration = null;
     if (this._pushSubscriptionActor) {
       this._pushSubscriptionActor.destroy();
     }
     this._pushSubscriptionActor = null;
 
-    this._installingWorker.destroy();
-    this._waitingWorker.destroy();
-    this._activeWorker.destroy();
+    this._destroyServiceWorkerActors();
 
     this._installingWorker = null;
     this._waitingWorker = null;
     this._activeWorker = null;
   },
 
   /**
    * Standard observer interface to listen to push messages and changes.
@@ -243,11 +232,31 @@ protocol.ActorClassWithSpec(serviceWorke
           }
           pushSubscriptionActor = new PushSubscriptionActor(this._conn, subscription);
           this._pushSubscriptionActor = pushSubscriptionActor;
           resolve(pushSubscriptionActor);
         }
       );
     });
   },
+
+  _destroyServiceWorkerActors() {
+    this._installingWorker.destroy();
+    this._waitingWorker.destroy();
+    this._activeWorker.destroy();
+  },
+
+  _createServiceWorkerActors() {
+    const {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);
+
+    // Add the ServiceWorker actors as children of this ServiceWorkerRegistration actor,
+    // assigning them valid actorIDs.
+    this.manage(this._installingWorker);
+    this.manage(this._waitingWorker);
+    this.manage(this._activeWorker);
+  },
 });
 
 exports.ServiceWorkerRegistrationActor = ServiceWorkerRegistrationActor;
--- a/devtools/shared/fronts/worker/service-worker.js
+++ b/devtools/shared/fronts/worker/service-worker.js
@@ -3,17 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
 const {
   pushSubscriptionSpec,
   serviceWorkerRegistrationSpec,
   serviceWorkerSpec,
 } = require("devtools/shared/specs/worker/service-worker");
-const { FrontClassWithSpec, registerFront } = require("devtools/shared/protocol");
+const { FrontClassWithSpec, registerFront, types } = require("devtools/shared/protocol");
 
 class PushSubscriptionFront extends FrontClassWithSpec(pushSubscriptionSpec) {
   get endpoint() {
     return this._form.endpoint;
   }
 
   get pushCount() {
     return this._form.pushCount;
@@ -61,24 +61,66 @@ class ServiceWorkerRegistrationFront ext
   get type() {
     return this._form.type;
   }
 
   get url() {
     return this._form.url;
   }
 
+  get activeWorker() {
+    return this._getServiceWorker("activeWorker");
+  }
+
+  get installingWorker() {
+    return this._getServiceWorker("installingWorker");
+  }
+
+  get waitingWorker() {
+    return this._getServiceWorker("waitingWorker");
+  }
+
+  _getServiceWorker(type) {
+    const workerForm = this._form[type];
+    if (!workerForm) {
+      return null;
+    }
+    return types.getType("serviceWorker").read(workerForm, this);
+  }
+
   form(form, detail) {
     if (detail === "actorid") {
       this.actorID = form;
       return;
     }
 
     this.actorID = form.actor;
     this._form = form;
   }
 }
 exports.ServiceWorkerRegistrationFront = ServiceWorkerRegistrationFront;
 registerFront(ServiceWorkerRegistrationFront);
 
-class ServiceWorkerFront extends FrontClassWithSpec(serviceWorkerSpec) {}
+class ServiceWorkerFront extends FrontClassWithSpec(serviceWorkerSpec) {
+  get fetch() {
+    return this._form.fetch;
+  }
+
+  get url() {
+    return this._form.url;
+  }
+
+  get state() {
+    return this._form.state;
+  }
+
+  form(form, detail) {
+    if (detail === "actorid") {
+      this.actorID = form;
+      return;
+    }
+
+    this.actorID = form.actor;
+    this._form = form;
+  }
+}
 exports.ServiceWorkerFront = ServiceWorkerFront;
 registerFront(ServiceWorkerFront);