Bug 1328293 - Show if a service worker is listening for fetch events in about:debugging. r=jdescottes
authorCatalin Badea <catalin.badea392@gmail.com>
Sun, 22 Jan 2017 09:03:00 +0200
changeset 377851 abe4ae295d864e60824018314be1ad9ca702b66a
parent 377850 69fb2fc615351bca97b998c9d70cb7e79edffd66
child 377852 b108c67ae38528b3140e342dde1a41c05ef24f4f
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1328293
milestone53.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 1328293 - Show if a service worker is listening for fetch events in about:debugging. r=jdescottes
devtools/client/aboutdebugging/components/workers/panel.js
devtools/client/aboutdebugging/components/workers/service-worker-target.js
devtools/client/locales/en-US/aboutdebugging.properties
devtools/server/actors/worker.js
dom/interfaces/base/nsIServiceWorkerManager.idl
dom/workers/ServiceWorkerInfo.cpp
--- a/devtools/client/aboutdebugging/components/workers/panel.js
+++ b/devtools/client/aboutdebugging/components/workers/panel.js
@@ -71,16 +71,17 @@ 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,
+          fetch: form.fetch,
           registrationActor: form.actor,
           active: form.active
         });
       });
 
       forms.workers.forEach(form => {
         let worker = {
           icon: WorkerIcon,
@@ -94,16 +95,18 @@ module.exports = createClass({
             if (registration) {
               // XXX: Race, sometimes a ServiceWorkerRegistrationInfo doesn't
               // have a scriptSpec, but its associated WorkerDebugger does.
               if (!registration.url) {
                 registration.name = registration.url = form.url;
               }
               registration.workerActor = form.actor;
             } else {
+              worker.fetch = form.fetch;
+
               // 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. Augment the worker as a registration worker to
               // display it in aboutdebugging.
               worker.scope = form.scope;
               worker.active = false;
               workers.service.push(worker);
             }
--- a/devtools/client/aboutdebugging/components/workers/service-worker-target.js
+++ b/devtools/client/aboutdebugging/components/workers/service-worker-target.js
@@ -20,16 +20,17 @@ const Strings = Services.strings.createB
 module.exports = createClass({
   displayName: "ServiceWorkerTarget",
 
   propTypes: {
     client: PropTypes.instanceOf(DebuggerClient).isRequired,
     debugDisabled: PropTypes.bool,
     target: PropTypes.shape({
       active: PropTypes.bool,
+      fetch: PropTypes.bool.isRequired,
       icon: PropTypes.string,
       name: PropTypes.string.isRequired,
       url: PropTypes.string,
       scope: PropTypes.string.isRequired,
       // registrationActor can be missing in e10s.
       registrationActor: PropTypes.string,
       workerActor: PropTypes.string
     }).isRequired
@@ -190,16 +191,19 @@ module.exports = createClass({
     }, Strings.GetStringFromName("unregister"));
   },
 
   render() {
     let { target } = this.props;
     let { pushSubscription } = this.state;
     let status = this.getServiceWorkerStatus();
 
+    let fetch = target.fetch ? Strings.GetStringFromName("listeningForFetchEvents") :
+      Strings.GetStringFromName("notListeningForFetchEvents");
+
     return dom.div({ className: "target-container" },
       dom.img({
         className: "target-icon",
         role: "presentation",
         src: target.icon
       }),
       dom.span({ className: `target-status target-status-${status}` },
         Strings.GetStringFromName(status)),
@@ -211,16 +215,22 @@ module.exports = createClass({
               dom.strong(null, Strings.GetStringFromName("pushService")),
               dom.span({
                 className: "service-worker-push-url",
                 title: pushSubscription.endpoint
               }, pushSubscription.endpoint)) :
             null
           ),
           dom.li({ className: "target-detail" },
+            dom.strong(null, Strings.GetStringFromName("fetch")),
+            dom.span({
+              className: "service-worker-fetch-flag",
+              title: fetch
+            }, fetch)),
+          dom.li({ className: "target-detail" },
             dom.strong(null, Strings.GetStringFromName("scope")),
             dom.span({
               className: "service-worker-scope",
               title: target.scope
             }, target.scope),
             this.renderUnregisterLink()
           )
         )
--- a/devtools/client/locales/en-US/aboutdebugging.properties
+++ b/devtools/client/locales/en-US/aboutdebugging.properties
@@ -16,16 +16,28 @@ push = Push
 # This string is displayed as a label of the button that starts a service worker.
 start = Start
 
 scope = Scope
 unregister = unregister
 
 pushService = Push Service
 
+# LOCALIZATION NOTE (fetch):
+# Fetch is an event type and should not be translated.
+fetch = Fetch
+
+# LOCALIZATION NOTE (listeningForFetchEvents):
+# This is used to display the state of the SW in regard to fetch events.
+listeningForFetchEvents = Listening for fetch events.
+
+# LOCALIZATION NOTE (notListeningForFetchEvents):
+# This is used to display the state of the SW in regard to fetch events.
+notListeningForFetchEvents = Not listening for fetch events.
+
 # LOCALIZATION NOTE (addons):
 # This string is displayed as a header of the about:debugging#addons page.
 addons = Add-ons
 
 # LOCALIZATION NOTE (addonDebugging.label):
 # This string is displayed next to a check box that enables the user to switch
 # addon debugging on/off.
 addonDebugging.label = Enable add-on debugging
--- a/devtools/server/actors/worker.js
+++ b/devtools/server/actors/worker.js
@@ -48,16 +48,20 @@ let WorkerActor = protocol.ActorClassWit
       actor: this.actorID,
       consoleActor: this._consoleActor,
       url: this._dbg.url,
       type: this._dbg.type
     };
     if (this._dbg.type === Ci.nsIWorkerDebugger.TYPE_SERVICE) {
       let registration = this._getServiceWorkerRegistrationInfo();
       form.scope = registration.scope;
+      let newestWorker = (registration.activeWorker ||
+                          registration.waitingWorker ||
+                          registration.installingWorker);
+      form.fetch = newestWorker && newestWorker.handlesFetchEvents;
     }
     return form;
   },
 
   attach() {
     if (this._dbg.isClosed) {
       return { error: "closed" };
     }
@@ -224,16 +228,17 @@ let ServiceWorkerActor = protocol.ActorC
   form() {
     if (!this._worker) {
       return null;
     }
 
     return {
       url: this._worker.scriptSpec,
       state: this._worker.state,
+      fetch: this._worker.handlesFetchEvents
     };
   },
 
   destroy() {
     protocol.Actor.prototype.destroy.call(this);
     this._worker = null;
   },
 });
@@ -282,24 +287,27 @@ protocol.ActorClassWithSpec(serviceWorke
     if (detail === "actorid") {
       return this.actorID;
     }
     let registration = this._registration;
     let installingWorker = this._installingWorker.form();
     let waitingWorker = this._waitingWorker.form();
     let activeWorker = this._activeWorker.form();
 
+    let newestWorker = (activeWorker || waitingWorker || installingWorker);
+
     let isE10s = Services.appinfo.browserTabsRemoteAutostart;
     return {
       actor: this.actorID,
       scope: registration.scope,
       url: registration.scriptSpec,
       installingWorker,
       waitingWorker,
       activeWorker,
+      fetch: newestWorker && newestWorker.fetch,
       // - 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
     };
   },
 
   destroy() {
--- a/dom/interfaces/base/nsIServiceWorkerManager.idl
+++ b/dom/interfaces/base/nsIServiceWorkerManager.idl
@@ -40,16 +40,18 @@ interface nsIServiceWorkerInfo : nsISupp
 
   readonly attribute DOMString scriptSpec;
   readonly attribute DOMString cacheName;
 
   readonly attribute unsigned short state;
 
   readonly attribute nsIWorkerDebugger debugger;
 
+  readonly attribute bool handlesFetchEvents;
+
   void attachDebugger();
 
   void detachDebugger();
 };
 
 [scriptable, uuid(87e63548-d440-4b8a-b158-65ad1de0211E)]
 interface nsIServiceWorkerRegistrationInfoListener : nsISupports
 {
--- a/dom/workers/ServiceWorkerInfo.cpp
+++ b/dom/workers/ServiceWorkerInfo.cpp
@@ -56,16 +56,25 @@ ServiceWorkerInfo::GetDebugger(nsIWorker
   if (NS_WARN_IF(!aResult)) {
     return NS_ERROR_FAILURE;
   }
 
   return mServiceWorkerPrivate->GetDebugger(aResult);
 }
 
 NS_IMETHODIMP
+ServiceWorkerInfo::GetHandlesFetchEvents(bool* aValue)
+{
+  MOZ_ASSERT(aValue);
+  AssertIsOnMainThread();
+  *aValue = HandlesFetch();
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 ServiceWorkerInfo::AttachDebugger()
 {
   return mServiceWorkerPrivate->AttachDebugger();
 }
 
 NS_IMETHODIMP
 ServiceWorkerInfo::DetachDebugger()
 {