Bug 1462069 P1 Make ServiceWorkerManager::MaybeClaimClient() take a ClientInfo instead of nsIDocument. r=baku
☠☠ backed out by dab096c54952 ☠ ☠
authorBen Kelly <ben@wanderview.com>
Fri, 01 Jun 2018 13:39:57 -0700
changeset 475167 457cb3f8a0d903fbe86289995db5a8c57fa92687
parent 475166 ec66aff745a89871345694ea00c349976c89d8f0
child 475168 999be9379af38700878f3331391bd2cbaf8c5ed6
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1462069
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 1462069 P1 Make ServiceWorkerManager::MaybeClaimClient() take a ClientInfo instead of nsIDocument. r=baku
dom/clients/manager/ClientSource.cpp
dom/serviceworkers/ServiceWorkerManager.cpp
dom/serviceworkers/ServiceWorkerManager.h
--- a/dom/clients/manager/ClientSource.cpp
+++ b/dom/clients/manager/ClientSource.cpp
@@ -635,17 +635,17 @@ ClientSource::Claim(const ClientClaimArg
   }
 
   RefPtr<ClientOpPromise::Private> outerPromise =
     new ClientOpPromise::Private(__func__);
 
   auto holder =
     MakeRefPtr<DOMMozPromiseRequestHolder<GenericPromise>>(innerWindow->AsGlobal());
 
-  RefPtr<GenericPromise> p = swm->MaybeClaimClient(doc, swd);
+  RefPtr<GenericPromise> p = swm->MaybeClaimClient(mClientInfo, swd);
   p->Then(mEventTarget, __func__,
     [outerPromise, holder] (bool aResult) {
       holder->Complete();
       outerPromise->Resolve(NS_OK, __func__);
     }, [outerPromise, holder] (nsresult aResult) {
       holder->Complete();
       outerPromise->Reject(aResult, __func__);
     })->Track(*holder);
--- a/dom/serviceworkers/ServiceWorkerManager.cpp
+++ b/dom/serviceworkers/ServiceWorkerManager.cpp
@@ -2549,69 +2549,61 @@ ServiceWorkerManager::UpdateInternal(nsI
 
   RefPtr<UpdateJobCallback> cb = new UpdateJobCallback(aCallback);
   job->AppendResultCallback(cb);
 
   queue->ScheduleJob(job);
 }
 
 already_AddRefed<GenericPromise>
-ServiceWorkerManager::MaybeClaimClient(nsIDocument* aDocument,
+ServiceWorkerManager::MaybeClaimClient(const ClientInfo& aClientInfo,
                                        ServiceWorkerRegistrationInfo* aWorkerRegistration)
 {
   MOZ_DIAGNOSTIC_ASSERT(aWorkerRegistration);
 
   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())) {
+  nsCOMPtr<nsIPrincipal> principal(aClientInfo.GetPrincipal());
+  if (!aWorkerRegistration->Principal()->Equals(principal)) {
     ref = GenericPromise::CreateAndReject(NS_ERROR_DOM_SECURITY_ERR, __func__);
     return ref.forget();
   }
 
-  Maybe<ClientInfo> clientInfo(aDocument->GetClientInfo());
-  if (NS_WARN_IF(clientInfo.isNothing())) {
-    ref = GenericPromise::CreateAndReject(NS_ERROR_DOM_INVALID_STATE_ERR,
-                                          __func__);
-    return ref.forget();
-  }
-
   // The registration that should be controlling the client
   RefPtr<ServiceWorkerRegistrationInfo> matchingRegistration =
-    GetServiceWorkerRegistrationInfo(aDocument);
+    GetServiceWorkerRegistrationInfo(aClientInfo);
 
   // The registration currently controlling the client
   RefPtr<ServiceWorkerRegistrationInfo> controllingRegistration;
-  GetClientRegistration(clientInfo.ref(),
-                        getter_AddRefs(controllingRegistration));
+  GetClientRegistration(aClientInfo, getter_AddRefs(controllingRegistration));
 
   if (aWorkerRegistration != matchingRegistration ||
       aWorkerRegistration == controllingRegistration) {
     ref = GenericPromise::CreateAndResolve(true, __func__);
     return ref.forget();
   }
 
-  ref = StartControllingClient(clientInfo.ref(), aWorkerRegistration);
+  ref = StartControllingClient(aClientInfo, aWorkerRegistration);
   return ref.forget();
 }
 
 already_AddRefed<GenericPromise>
-ServiceWorkerManager::MaybeClaimClient(nsIDocument* aDoc,
+ServiceWorkerManager::MaybeClaimClient(const ClientInfo& aClientInfo,
                                        const ServiceWorkerDescriptor& aServiceWorker)
 {
   RefPtr<GenericPromise> ref;
 
-  nsCOMPtr<nsIPrincipal> principal =
-    PrincipalInfoToPrincipal(aServiceWorker.PrincipalInfo());
+  nsCOMPtr<nsIPrincipal> principal = aServiceWorker.GetPrincipal();
   if (!principal) {
     ref = GenericPromise::CreateAndResolve(false, __func__);
     return ref.forget();
   }
 
   RefPtr<ServiceWorkerRegistrationInfo> registration =
     GetRegistration(principal, aServiceWorker.Scope());
 
@@ -2620,17 +2612,17 @@ ServiceWorkerManager::MaybeClaimClient(n
   // not propagated to this process yet.  For now, simply note that we
   // are done.  The fix for this is to move the SWM to the parent process
   // so there are no consistency errors.
   if (NS_WARN_IF(!registration) || NS_WARN_IF(!registration->GetActive())) {
     ref = GenericPromise::CreateAndResolve(false, __func__);
     return ref.forget();
   }
 
-  ref = MaybeClaimClient(aDoc, registration);
+  ref = MaybeClaimClient(aClientInfo, registration);
   return ref.forget();
 }
 
 void
 ServiceWorkerManager::SetSkipWaitingFlag(nsIPrincipal* aPrincipal,
                                          const nsCString& aScope,
                                          uint64_t aServiceWorkerID)
 {
--- a/dom/serviceworkers/ServiceWorkerManager.h
+++ b/dom/serviceworkers/ServiceWorkerManager.h
@@ -280,21 +280,21 @@ public:
               const nsString& aFilename,
               const nsString& aLine,
               uint32_t aLineNumber,
               uint32_t aColumnNumber,
               uint32_t aFlags,
               JSExnType aExnType);
 
   already_AddRefed<GenericPromise>
-  MaybeClaimClient(nsIDocument* aDocument,
+  MaybeClaimClient(const ClientInfo& aClientInfo,
                    ServiceWorkerRegistrationInfo* aWorkerRegistration);
 
   already_AddRefed<GenericPromise>
-  MaybeClaimClient(nsIDocument* aDoc,
+  MaybeClaimClient(const ClientInfo& aClientInfo,
                    const ServiceWorkerDescriptor& aServiceWorker);
 
   void
   SetSkipWaitingFlag(nsIPrincipal* aPrincipal, const nsCString& aScope,
                      uint64_t aServiceWorkerID);
 
   static already_AddRefed<ServiceWorkerManager>
   GetInstance();