Bug 1133242 - ServiceWorkerManager must use the correct principal in b2g, r=nsm

This commit is contained in:
Andrea Marchesini 2015-02-17 13:36:09 +01:00
parent c64b06e3cc
commit 7420ed16c7
2 changed files with 12 additions and 13 deletions

View File

@ -565,7 +565,8 @@ public:
MOZ_ASSERT(!swm->mSetOfScopesBeingUpdated.Contains(mRegistration->mScope)); MOZ_ASSERT(!swm->mSetOfScopesBeingUpdated.Contains(mRegistration->mScope));
swm->mSetOfScopesBeingUpdated.Put(mRegistration->mScope, true); swm->mSetOfScopesBeingUpdated.Put(mRegistration->mScope, true);
nsRefPtr<ServiceWorker> serviceWorker; nsRefPtr<ServiceWorker> serviceWorker;
rv = swm->CreateServiceWorker(mRegistration->mScriptSpec, rv = swm->CreateServiceWorker(mRegistration->mPrincipal,
mRegistration->mScriptSpec,
mRegistration->mScope, mRegistration->mScope,
getter_AddRefs(serviceWorker)); getter_AddRefs(serviceWorker));
@ -630,7 +631,8 @@ public:
nsRefPtr<ServiceWorker> serviceWorker; nsRefPtr<ServiceWorker> serviceWorker;
nsresult rv = nsresult rv =
swm->CreateServiceWorker(mRegistration->mInstallingWorker->ScriptSpec(), swm->CreateServiceWorker(mRegistration->mPrincipal,
mRegistration->mInstallingWorker->ScriptSpec(),
mRegistration->mScope, mRegistration->mScope,
getter_AddRefs(serviceWorker)); getter_AddRefs(serviceWorker));
@ -1145,7 +1147,8 @@ ServiceWorkerRegistrationInfo::Activate()
MOZ_ASSERT(mActiveWorker); MOZ_ASSERT(mActiveWorker);
nsRefPtr<ServiceWorker> serviceWorker; nsRefPtr<ServiceWorker> serviceWorker;
nsresult rv = nsresult rv =
swm->CreateServiceWorker(mActiveWorker->ScriptSpec(), swm->CreateServiceWorker(mPrincipal,
mActiveWorker->ScriptSpec(),
mScope, mScope,
getter_AddRefs(serviceWorker)); getter_AddRefs(serviceWorker));
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
@ -2185,11 +2188,13 @@ ServiceWorkerManager::GetActive(nsIDOMWindow* aWindow,
} }
NS_IMETHODIMP NS_IMETHODIMP
ServiceWorkerManager::CreateServiceWorker(const nsACString& aScriptSpec, ServiceWorkerManager::CreateServiceWorker(nsIPrincipal* aPrincipal,
const nsACString& aScriptSpec,
const nsACString& aScope, const nsACString& aScope,
ServiceWorker** aServiceWorker) ServiceWorker** aServiceWorker)
{ {
AssertIsOnMainThread(); AssertIsOnMainThread();
MOZ_ASSERT(aPrincipal);
WorkerPrivate::LoadInfo info; WorkerPrivate::LoadInfo info;
nsresult rv = NS_NewURI(getter_AddRefs(info.mBaseURI), aScriptSpec, nullptr, nullptr); nsresult rv = NS_NewURI(getter_AddRefs(info.mBaseURI), aScriptSpec, nullptr, nullptr);
@ -2204,14 +2209,7 @@ ServiceWorkerManager::CreateServiceWorker(const nsACString& aScriptSpec,
return rv; return rv;
} }
// FIXME(nsm): Create correct principal based on app-ness. info.mPrincipal = aPrincipal;
// Would it make sense to store the nsIPrincipal of the first register() in
// the ServiceWorkerRegistrationInfo and use that?
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
rv = ssm->GetNoAppCodebasePrincipal(info.mBaseURI, getter_AddRefs(info.mPrincipal));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// NOTE: this defaults the SW load context to: // NOTE: this defaults the SW load context to:
// - private browsing = false // - private browsing = false

View File

@ -406,7 +406,8 @@ private:
ServiceWorker** aServiceWorker); ServiceWorker** aServiceWorker);
NS_IMETHOD NS_IMETHOD
CreateServiceWorker(const nsACString& aScriptSpec, CreateServiceWorker(nsIPrincipal* aPrincipal,
const nsACString& aScriptSpec,
const nsACString& aScope, const nsACString& aScope,
ServiceWorker** aServiceWorker); ServiceWorker** aServiceWorker);