Bug 1153292 - part3: aboutdebugging: expose sw state from registration, notify listeners on statechange;r=bkelly draft
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 15 Sep 2016 14:47:15 +0200
changeset 420134 f7e023708f8954b978b189025fd0b06c587d6a8e
parent 420133 bd35e5e913583d4235435c106aeee79a8a478534
child 420135 83bcd044a79b616b202f87cc9a93182fc12b4c24
push id31104
push userjdescottes@mozilla.com
push dateMon, 03 Oct 2016 13:33:13 +0000
reviewersbkelly
bugs1153292
milestone52.0a1
Bug 1153292 - part3: aboutdebugging: expose sw state from registration, notify listeners on statechange;r=bkelly As it turns out, the workaround used to detect "not activated" service worker registrations works only in e10s pages. In non e10s, service worker registrations are returned even if they are not in activated state. Here we add the currently associated worker to the registration info, which will be used to determine if the service worker is activated by about debugging. MozReview-Commit-ID: ImeZcXQdBtO
dom/interfaces/base/nsIServiceWorkerManager.idl
dom/workers/ServiceWorkerInfo.cpp
--- a/dom/interfaces/base/nsIServiceWorkerManager.idl
+++ b/dom/interfaces/base/nsIServiceWorkerManager.idl
@@ -24,19 +24,29 @@ interface nsIServiceWorkerUnregisterCall
   void unregisterFailed();
 };
 
 interface nsIWorkerDebugger;
 
 [scriptable, builtinclass, uuid(76e357ed-208d-4e4c-9165-1c4059707879)]
 interface nsIServiceWorkerInfo : nsISupports
 {
+  // State values below should match the ServiceWorkerState enumeration.
+  const unsigned short STATE_INSTALLING = 0;
+  const unsigned short STATE_INSTALLED = 1;
+  const unsigned short STATE_ACTIVATING = 2;
+  const unsigned short STATE_ACTIVATED = 3;
+  const unsigned short STATE_REDUNDANT = 4;
+  const unsigned short STATE_UNKNOWN = 5;
+
   readonly attribute DOMString scriptSpec;
   readonly attribute DOMString cacheName;
 
+  readonly attribute unsigned short state;
+
   readonly attribute nsIWorkerDebugger debugger;
 
   void attachDebugger();
 
   void detachDebugger();
 };
 
 [scriptable, uuid(87e63548-d440-4b8a-b158-65ad1de0211E)]
--- a/dom/workers/ServiceWorkerInfo.cpp
+++ b/dom/workers/ServiceWorkerInfo.cpp
@@ -5,16 +5,29 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ServiceWorkerInfo.h"
 
 #include "ServiceWorkerScriptCache.h"
 
 BEGIN_WORKERS_NAMESPACE
 
+static_assert(nsIServiceWorkerInfo::STATE_INSTALLING == static_cast<uint16_t>(ServiceWorkerState::Installing),
+              "ServiceWorkerState enumeration value should match state values from nsIServiceWorkerInfo.");
+static_assert(nsIServiceWorkerInfo::STATE_INSTALLED == static_cast<uint16_t>(ServiceWorkerState::Installed),
+              "ServiceWorkerState enumeration value should match state values from nsIServiceWorkerInfo.");
+static_assert(nsIServiceWorkerInfo::STATE_ACTIVATING == static_cast<uint16_t>(ServiceWorkerState::Activating),
+              "ServiceWorkerState enumeration value should match state values from nsIServiceWorkerInfo.");
+static_assert(nsIServiceWorkerInfo::STATE_ACTIVATED == static_cast<uint16_t>(ServiceWorkerState::Activated),
+              "ServiceWorkerState enumeration value should match state values from nsIServiceWorkerInfo.");
+static_assert(nsIServiceWorkerInfo::STATE_REDUNDANT == static_cast<uint16_t>(ServiceWorkerState::Redundant),
+              "ServiceWorkerState enumeration value should match state values from nsIServiceWorkerInfo.");
+static_assert(nsIServiceWorkerInfo::STATE_UNKNOWN == static_cast<uint16_t>(ServiceWorkerState::EndGuard_),
+              "ServiceWorkerState enumeration value should match state values from nsIServiceWorkerInfo.");
+
 NS_IMPL_ISUPPORTS(ServiceWorkerInfo, nsIServiceWorkerInfo)
 
 NS_IMETHODIMP
 ServiceWorkerInfo::GetScriptSpec(nsAString& aScriptSpec)
 {
   AssertIsOnMainThread();
   CopyUTF8toUTF16(mScriptSpec, aScriptSpec);
   return NS_OK;
@@ -24,16 +37,25 @@ NS_IMETHODIMP
 ServiceWorkerInfo::GetCacheName(nsAString& aCacheName)
 {
   AssertIsOnMainThread();
   aCacheName = mCacheName;
   return NS_OK;
 }
 
 NS_IMETHODIMP
+ServiceWorkerInfo::GetState(uint16_t* aState)
+{
+  MOZ_ASSERT(aState);
+  AssertIsOnMainThread();
+  *aState = static_cast<uint16_t>(mState);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 ServiceWorkerInfo::GetDebugger(nsIWorkerDebugger** aResult)
 {
   if (NS_WARN_IF(!aResult)) {
     return NS_ERROR_FAILURE;
   }
 
   return mServiceWorkerPrivate->GetDebugger(aResult);
 }