Bug 1438211 P5 Replace direct window/worker calls with nsIGlobalObject::GetOrCreateServiceWorkerRegistration(). r=asuth
authorBen Kelly <ben@wanderview.com>
Fri, 02 Mar 2018 13:02:50 -0800
changeset 407227 98cfdc9a7826
parent 407226 ee87211590b5
child 407228 43c8c3b917ea
push id33596
push userncsoregi@mozilla.com
push dateFri, 09 Mar 2018 00:18:11 +0000
treeherdermozilla-central@31a33fc61956 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1438211
milestone60.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 1438211 P5 Replace direct window/worker calls with nsIGlobalObject::GetOrCreateServiceWorkerRegistration(). r=asuth
dom/serviceworkers/ServiceWorkerManager.cpp
dom/workers/WorkerScope.cpp
--- a/dom/serviceworkers/ServiceWorkerManager.cpp
+++ b/dom/serviceworkers/ServiceWorkerManager.cpp
@@ -462,17 +462,17 @@ class ServiceWorkerResolveWindowPromiseO
     }
 
     MOZ_ASSERT(aJob->GetType() == ServiceWorkerJob::Type::Register);
     RefPtr<ServiceWorkerRegisterJob> registerJob =
       static_cast<ServiceWorkerRegisterJob*>(aJob);
     RefPtr<ServiceWorkerRegistrationInfo> reg = registerJob->GetRegistration();
 
     RefPtr<ServiceWorkerRegistration> swr =
-      window->GetServiceWorkerRegistration(reg->Descriptor());
+      window->AsGlobal()->GetOrCreateServiceWorkerRegistration(reg->Descriptor());
 
     nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
       "ServiceWorkerResolveWindowPromiseOnRegisterCallback::JobFinished",
       [promise = Move(promise), swr = Move(swr)] () {
         promise->MaybeResolve(swr);
       });
     MOZ_ALWAYS_SUCCEEDS(
       window->EventTargetFor(TaskCategory::Other)->Dispatch(r.forget()));
@@ -1026,17 +1026,17 @@ public:
 
       rv = principal->CheckMayLoad(scopeURI, true /* report */,
                                    false /* allowIfInheritsPrincipal */);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         continue;
       }
 
       RefPtr<ServiceWorkerRegistration> swr =
-        mWindow->GetServiceWorkerRegistration(info->Descriptor());
+        mWindow->AsGlobal()->GetOrCreateServiceWorkerRegistration(info->Descriptor());
 
       array.AppendElement(swr);
     }
 
     mPromise->MaybeResolve(array);
     return NS_OK;
   }
 };
@@ -1149,17 +1149,17 @@ public:
       swm->GetServiceWorkerRegistrationInfo(principal, uri);
 
     if (!registration) {
       mPromise->MaybeResolveWithUndefined();
       return NS_OK;
     }
 
     RefPtr<ServiceWorkerRegistration> swr =
-      mWindow->GetServiceWorkerRegistration(registration->Descriptor());
+      mWindow->AsGlobal()->GetOrCreateServiceWorkerRegistration(registration->Descriptor());
     mPromise->MaybeResolve(swr);
 
     return NS_OK;
   }
 };
 
 // If we return an error code here, the ServiceWorkerContainer will
 // automatically reject the Promise.
@@ -1463,17 +1463,17 @@ ServiceWorkerManager::CheckReadyPromise(
   nsCOMPtr<nsIPrincipal> principal = doc->NodePrincipal();
   MOZ_ASSERT(principal);
 
   RefPtr<ServiceWorkerRegistrationInfo> registration =
     GetServiceWorkerRegistrationInfo(principal, aURI);
 
   if (registration && registration->GetActive()) {
     RefPtr<ServiceWorkerRegistration> swr =
-      aWindow->GetServiceWorkerRegistration(registration->Descriptor());
+      aWindow->AsGlobal()->GetOrCreateServiceWorkerRegistration(registration->Descriptor());
     aPromise->MaybeResolve(swr);
     return true;
   }
 
   return false;
 }
 
 ServiceWorkerInfo*
--- a/dom/workers/WorkerScope.cpp
+++ b/dom/workers/WorkerScope.cpp
@@ -680,19 +680,17 @@ NS_IMPL_RELEASE_INHERITED(ServiceWorkerG
 ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(WorkerPrivate* aWorkerPrivate,
                                                    const ServiceWorkerRegistrationDescriptor& aRegistrationDescriptor)
   : WorkerGlobalScope(aWorkerPrivate)
   , mScope(NS_ConvertUTF8toUTF16(aRegistrationDescriptor.Scope()))
 
   // Eagerly create the registration because we will need to receive updates
   // about the state of the registration.  We can't wait until first access
   // to start receiving these.
-  , mRegistration(ServiceWorkerRegistration::CreateForWorker(aWorkerPrivate,
-                                                             this,
-                                                             aRegistrationDescriptor))
+  , mRegistration(GetOrCreateServiceWorkerRegistration(aRegistrationDescriptor))
 {
 }
 
 ServiceWorkerGlobalScope::~ServiceWorkerGlobalScope()
 {
 }
 
 bool