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
--- 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);
}