diff --git a/dom/clients/manager/ClientSource.cpp b/dom/clients/manager/ClientSource.cpp index c0357b25adea..ec498691cdb9 100644 --- a/dom/clients/manager/ClientSource.cpp +++ b/dom/clients/manager/ClientSource.cpp @@ -640,7 +640,7 @@ ClientSource::Claim(const ClientClaimArgs& aArgs) auto holder = MakeRefPtr>(innerWindow->AsGlobal()); - RefPtr p = swm->MaybeClaimClient(doc, swd); + RefPtr p = swm->MaybeClaimClient(mClientInfo, swd); p->Then(mEventTarget, __func__, [outerPromise, holder] (bool aResult) { holder->Complete(); diff --git a/dom/serviceworkers/ServiceWorkerManager.cpp b/dom/serviceworkers/ServiceWorkerManager.cpp index 9604407f5ac2..1dd43b9d831e 100644 --- a/dom/serviceworkers/ServiceWorkerManager.cpp +++ b/dom/serviceworkers/ServiceWorkerManager.cpp @@ -2554,7 +2554,7 @@ ServiceWorkerManager::UpdateInternal(nsIPrincipal* aPrincipal, } already_AddRefed -ServiceWorkerManager::MaybeClaimClient(nsIDocument* aDocument, +ServiceWorkerManager::MaybeClaimClient(const ClientInfo& aClientInfo, ServiceWorkerRegistrationInfo* aWorkerRegistration) { MOZ_DIAGNOSTIC_ASSERT(aWorkerRegistration); @@ -2568,26 +2568,19 @@ ServiceWorkerManager::MaybeClaimClient(nsIDocument* aDocument, } // Same origin check - if (!aWorkerRegistration->Principal()->Equals(aDocument->NodePrincipal())) { + nsCOMPtr principal(aClientInfo.GetPrincipal()); + if (!aWorkerRegistration->Principal()->Equals(principal)) { ref = GenericPromise::CreateAndReject(NS_ERROR_DOM_SECURITY_ERR, __func__); return ref.forget(); } - Maybe 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 matchingRegistration = - GetServiceWorkerRegistrationInfo(aDocument); + GetServiceWorkerRegistrationInfo(aClientInfo); // The registration currently controlling the client RefPtr controllingRegistration; - GetClientRegistration(clientInfo.ref(), - getter_AddRefs(controllingRegistration)); + GetClientRegistration(aClientInfo, getter_AddRefs(controllingRegistration)); if (aWorkerRegistration != matchingRegistration || aWorkerRegistration == controllingRegistration) { @@ -2595,18 +2588,17 @@ ServiceWorkerManager::MaybeClaimClient(nsIDocument* aDocument, return ref.forget(); } - ref = StartControllingClient(clientInfo.ref(), aWorkerRegistration); + ref = StartControllingClient(aClientInfo, aWorkerRegistration); return ref.forget(); } already_AddRefed -ServiceWorkerManager::MaybeClaimClient(nsIDocument* aDoc, +ServiceWorkerManager::MaybeClaimClient(const ClientInfo& aClientInfo, const ServiceWorkerDescriptor& aServiceWorker) { RefPtr ref; - nsCOMPtr principal = - PrincipalInfoToPrincipal(aServiceWorker.PrincipalInfo()); + nsCOMPtr principal = aServiceWorker.GetPrincipal(); if (!principal) { ref = GenericPromise::CreateAndResolve(false, __func__); return ref.forget(); @@ -2625,7 +2617,7 @@ ServiceWorkerManager::MaybeClaimClient(nsIDocument* aDoc, return ref.forget(); } - ref = MaybeClaimClient(aDoc, registration); + ref = MaybeClaimClient(aClientInfo, registration); return ref.forget(); } diff --git a/dom/serviceworkers/ServiceWorkerManager.h b/dom/serviceworkers/ServiceWorkerManager.h index ead91b04b128..18db8b8c7633 100644 --- a/dom/serviceworkers/ServiceWorkerManager.h +++ b/dom/serviceworkers/ServiceWorkerManager.h @@ -285,11 +285,11 @@ public: JSExnType aExnType); already_AddRefed - MaybeClaimClient(nsIDocument* aDocument, + MaybeClaimClient(const ClientInfo& aClientInfo, ServiceWorkerRegistrationInfo* aWorkerRegistration); already_AddRefed - MaybeClaimClient(nsIDocument* aDoc, + MaybeClaimClient(const ClientInfo& aClientInfo, const ServiceWorkerDescriptor& aServiceWorker); void