Bug 1595964 Part 2 - Expose evaluating worker in service worker registration front, r=jdescottes.
authorBrian Hackett <bhackett1024@gmail.com>
Sat, 07 Dec 2019 18:18:09 +0000
changeset 568125 18ddd988d27b6491258f332be6e9dcf3549e6791
parent 568124 cdbe253ae87be4702f637adcc71d91fd97b33d3c
child 568126 efaae247045d3a0d42b5c50325e38ecd3b21c14b
push id12493
push userffxbld-merge
push dateMon, 06 Jan 2020 15:38:57 +0000
treeherdermozilla-beta@63ae456b848d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1595964
milestone73.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 1595964 Part 2 - Expose evaluating worker in service worker registration front, r=jdescottes. Depends on D54286 Differential Revision: https://phabricator.services.mozilla.com/D54288
devtools/server/actors/worker/service-worker-registration.js
devtools/server/actors/worker/service-worker.js
devtools/shared/fronts/root.js
devtools/shared/fronts/worker/service-worker-registration.js
--- a/devtools/server/actors/worker/service-worker-registration.js
+++ b/devtools/server/actors/worker/service-worker-registration.js
@@ -66,30 +66,33 @@ const ServiceWorkerRegistrationActor = p
     onChange() {
       this._destroyServiceWorkerActors();
       this._createServiceWorkerActors();
       this.emit("registration-changed");
     },
 
     form() {
       const registration = this._registration;
+      const evaluatingWorker = this._evaluatingWorker.form();
       const installingWorker = this._installingWorker.form();
       const waitingWorker = this._waitingWorker.form();
       const activeWorker = this._activeWorker.form();
 
-      const newestWorker = activeWorker || waitingWorker || installingWorker;
+      const newestWorker =
+        activeWorker || waitingWorker || installingWorker || evaluatingWorker;
 
       const isParentInterceptEnabled = swm.isParentInterceptEnabled();
       const isMultiE10sWithOldImplementation =
         Services.appinfo.browserTabsRemoteAutostart &&
         !isParentInterceptEnabled;
       return {
         actor: this.actorID,
         scope: registration.scope,
         url: registration.scriptSpec,
+        evaluatingWorker,
         installingWorker,
         waitingWorker,
         activeWorker,
         fetch: newestWorker && newestWorker.fetch,
         // - In old multi e10s: only active registrations are available.
         // - In non-e10s or new implementaion: check if we have an active worker
         active: isMultiE10sWithOldImplementation ? true : !!activeWorker,
         lastUpdateTime: registration.lastUpdateTime,
@@ -116,16 +119,17 @@ const ServiceWorkerRegistrationActor = p
       this._registration = null;
       if (this._pushSubscriptionActor) {
         this._pushSubscriptionActor.destroy();
       }
       this._pushSubscriptionActor = null;
 
       this._destroyServiceWorkerActors();
 
+      this._evaluatingWorker = null;
       this._installingWorker = null;
       this._waitingWorker = null;
       this._activeWorker = null;
     },
 
     /**
      * Standard observer interface to listen to push messages and changes.
      */
@@ -292,37 +296,44 @@ const ServiceWorkerRegistrationActor = p
             this._pushSubscriptionActor = pushSubscriptionActor;
             resolve(pushSubscriptionActor);
           }
         );
       });
     },
 
     _destroyServiceWorkerActors() {
+      this._evaluatingWorker.destroy();
       this._installingWorker.destroy();
       this._waitingWorker.destroy();
       this._activeWorker.destroy();
     },
 
     _createServiceWorkerActors() {
       const {
+        evaluatingWorker,
         installingWorker,
         waitingWorker,
         activeWorker,
       } = this._registration;
 
+      this._evaluatingWorker = new ServiceWorkerActor(
+        this._conn,
+        evaluatingWorker
+      );
       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._evaluatingWorker);
       this.manage(this._installingWorker);
       this.manage(this._waitingWorker);
       this.manage(this._activeWorker);
     },
   }
 );
 
 exports.ServiceWorkerRegistrationActor = ServiceWorkerRegistrationActor;
--- a/devtools/server/actors/worker/service-worker.js
+++ b/devtools/server/actors/worker/service-worker.js
@@ -1,35 +1,42 @@
 /* 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 { Ci } = require("chrome");
 const protocol = require("devtools/shared/protocol");
 const {
   serviceWorkerSpec,
 } = require("devtools/shared/specs/worker/service-worker");
 
 const ServiceWorkerActor = protocol.ActorClassWithSpec(serviceWorkerSpec, {
   initialize(conn, worker) {
     protocol.Actor.prototype.initialize.call(this, conn);
     this._worker = worker;
   },
 
   form() {
     if (!this._worker) {
       return null;
     }
 
+    // handlesFetchEvents is not available if the worker's main script is in the
+    // evaluating state.
+    const isEvaluating =
+      this._worker.state == Ci.nsIServiceWorkerInfo.STATE_PARSED;
+    const fetch = isEvaluating ? undefined : this._worker.handlesFetchEvents;
+
     return {
       actor: this.actorID,
       url: this._worker.scriptSpec,
       state: this._worker.state,
-      fetch: this._worker.handlesFetchEvents,
+      fetch,
       id: this._worker.id,
     };
   },
 
   destroy() {
     protocol.Actor.prototype.destroy.call(this);
     this._worker = null;
   },
--- a/devtools/shared/fronts/root.js
+++ b/devtools/shared/fronts/root.js
@@ -101,18 +101,24 @@ class RootFront extends FrontClassWithSp
 
     const result = {
       service: [],
       shared: [],
       other: [],
     };
 
     registrations.forEach(front => {
-      const { activeWorker, waitingWorker, installingWorker } = front;
-      const newestWorker = activeWorker || waitingWorker || installingWorker;
+      const {
+        activeWorker,
+        waitingWorker,
+        installingWorker,
+        evaluatingWorker,
+      } = front;
+      const newestWorker =
+        activeWorker || waitingWorker || installingWorker || evaluatingWorker;
 
       // All the information is simply mirrored from the registration front.
       // However since registering workers will fetch similar information from the worker
       // target front and will not have a service worker registration front, consumers
       // should not read meta data directly on the registration front instance.
       result.service.push({
         active: front.active,
         fetch: front.fetch,
@@ -160,18 +166,20 @@ class RootFront extends FrontClassWithSp
             if (!r.newestWorkerId || !isParentInterceptEnabled) {
               return r.scope === front.scope;
             }
 
             return r.newestWorkerId === front.id;
           });
 
           if (registration) {
-            // XXX: Race, sometimes a ServiceWorkerRegistrationInfo doesn't
-            // have a scriptSpec, but its associated WorkerDebugger does.
+            // Before bug 1595964, URLs were not available for registrations
+            // whose worker's main script is being evaluated. Now, URLs are
+            // always available, and this test deals with older servers.
+            // @backward-compatibility: remove in Firefox 75
             if (!registration.url) {
               registration.name = registration.url = front.url;
             }
             registration.workerTargetFront = front;
           } else {
             // If we are missing the registration, augment the worker front with
             // fields expected on service worker registration fronts so that it
             // can be displayed in UIs handling on service worker registrations.
--- a/devtools/shared/fronts/worker/service-worker-registration.js
+++ b/devtools/shared/fronts/worker/service-worker-registration.js
@@ -38,16 +38,20 @@ class ServiceWorkerRegistrationFront ext
   get type() {
     return this._form.type;
   }
 
   get url() {
     return this._form.url;
   }
 
+  get evaluatingWorker() {
+    return this._getServiceWorker("evaluatingWorker");
+  }
+
   get activeWorker() {
     return this._getServiceWorker("activeWorker");
   }
 
   get installingWorker() {
     return this._getServiceWorker("installingWorker");
   }