Bug 1461181 Don't call ServiceWorkerManager::StartControllingClient() if there is no active worker. r=asuth
authorBen Kelly <ben@wanderview.com>
Mon, 21 May 2018 09:13:47 -0700
changeset 419143 d5ec7b9c344a
parent 419142 87d810949bdf
child 419144 7614c38e5c0f
push id103469
push userbkelly@mozilla.com
push date2018-05-21 16:13 +0000
treeherdermozilla-inbound@d5ec7b9c344a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1461181
milestone62.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 1461181 Don't call ServiceWorkerManager::StartControllingClient() if there is no active worker. r=asuth
dom/serviceworkers/ServiceWorkerManager.cpp
--- a/dom/serviceworkers/ServiceWorkerManager.cpp
+++ b/dom/serviceworkers/ServiceWorkerManager.cpp
@@ -307,17 +307,17 @@ ServiceWorkerManager::Init(ServiceWorker
 
   mActor = static_cast<ServiceWorkerManagerChild*>(actor);
 }
 
 RefPtr<GenericPromise>
 ServiceWorkerManager::StartControllingClient(const ClientInfo& aClientInfo,
                                              ServiceWorkerRegistrationInfo* aRegistrationInfo)
 {
-  MOZ_DIAGNOSTIC_ASSERT(aRegistrationInfo->GetActive());
+  MOZ_RELEASE_ASSERT(aRegistrationInfo->GetActive());
 
   RefPtr<GenericPromise> ref;
 
   const ServiceWorkerDescriptor& active =
     aRegistrationInfo->GetActive()->Descriptor();
 
   auto entry = mControlledClients.LookupForAdd(aClientInfo.Id());
   if (entry) {
@@ -1877,16 +1877,17 @@ ServiceWorkerManager::StartControlling(c
   nsCOMPtr<nsIURI> scope;
   nsresult rv =
     NS_NewURI(getter_AddRefs(scope), aServiceWorker.Scope(), nullptr, nullptr);
   NS_ENSURE_SUCCESS(rv, false);
 
   RefPtr<ServiceWorkerRegistrationInfo> registration =
     GetServiceWorkerRegistrationInfo(principal, scope);
   NS_ENSURE_TRUE(registration, false);
+  NS_ENSURE_TRUE(registration->GetActive(), false);
 
   StartControllingClient(aClientInfo, registration);
 
   return true;
 }
 
 void
 ServiceWorkerManager::MaybeCheckNavigationUpdate(const ClientInfo& aClientInfo)
@@ -2552,20 +2553,25 @@ ServiceWorkerManager::UpdateInternal(nsI
   queue->ScheduleJob(job);
 }
 
 already_AddRefed<GenericPromise>
 ServiceWorkerManager::MaybeClaimClient(nsIDocument* aDocument,
                                        ServiceWorkerRegistrationInfo* aWorkerRegistration)
 {
   MOZ_DIAGNOSTIC_ASSERT(aWorkerRegistration);
-  MOZ_DIAGNOSTIC_ASSERT(aWorkerRegistration->GetActive());
 
   RefPtr<GenericPromise> ref;
 
+  if (!aWorkerRegistration->GetActive()) {
+    ref = GenericPromise::CreateAndReject(NS_ERROR_DOM_INVALID_STATE_ERR,
+                                          __func__);
+    return ref.forget();
+  }
+
   // Same origin check
   if (!aWorkerRegistration->Principal()->Equals(aDocument->NodePrincipal())) {
     ref = GenericPromise::CreateAndReject(NS_ERROR_DOM_SECURITY_ERR, __func__);
     return ref.forget();
   }
 
   Maybe<ClientInfo> clientInfo(aDocument->GetClientInfo());
   if (NS_WARN_IF(clientInfo.isNothing())) {