From c5913f35b9bc59e8408bb0cb8086e8045c01ec05 Mon Sep 17 00:00:00 2001 From: Jose Antonio Olivera Ortega Date: Fri, 29 May 2015 18:17:33 +0200 Subject: [PATCH] Bug 1169210 - Can't call content service worker from chrome. r=nsm --HG-- extra : rebase_source : a49c90113ea72dad97d70906479870c5b50f29ad --- dom/workers/ServiceWorkerManager.cpp | 56 ++++++++++++++++------------ 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp index 77a117b93879..bdf13f6ea0dc 100644 --- a/dom/workers/ServiceWorkerManager.cpp +++ b/dom/workers/ServiceWorkerManager.cpp @@ -1049,21 +1049,22 @@ ServiceWorkerManager::Register(nsIDOMWindow* aWindow, { AssertIsOnMainThread(); - // XXXnsm Don't allow chrome callers for now, we don't support chrome - // ServiceWorkers. - MOZ_ASSERT(!nsContentUtils::IsCallerChrome()); - nsCOMPtr window = do_QueryInterface(aWindow); - - nsCOMPtr outerWindow = window->GetOuterWindow(); - bool serviceWorkersTestingEnabled = - outerWindow->GetServiceWorkersTestingEnabled(); + MOZ_ASSERT(window); nsCOMPtr doc = window->GetExtantDoc(); if (!doc) { return NS_ERROR_FAILURE; } + // Don't allow service workers to register when the *document* is chrome for + // now. + MOZ_ASSERT(!nsContentUtils::IsSystemPrincipal(doc->NodePrincipal())); + + nsCOMPtr outerWindow = window->GetOuterWindow(); + bool serviceWorkersTestingEnabled = + outerWindow->GetServiceWorkersTestingEnabled(); + nsCOMPtr documentURI = doc->GetBaseURI(); bool authenticatedOrigin = false; @@ -1474,15 +1475,18 @@ ServiceWorkerManager::GetRegistrations(nsIDOMWindow* aWindow, AssertIsOnMainThread(); MOZ_ASSERT(aWindow); - // XXXnsm Don't allow chrome callers for now, we don't support chrome - // ServiceWorkers. - MOZ_ASSERT(!nsContentUtils::IsCallerChrome()); - nsCOMPtr window = do_QueryInterface(aWindow); - if (!window) { + MOZ_ASSERT(window); + + nsCOMPtr doc = window->GetExtantDoc(); + if (!doc) { return NS_ERROR_FAILURE; } + // Don't allow service workers to register when the *document* is chrome for + // now. + MOZ_ASSERT(!nsContentUtils::IsSystemPrincipal(doc->NodePrincipal())); + nsCOMPtr sgo = do_QueryInterface(window); ErrorResult result; nsRefPtr promise = Promise::Create(sgo, result); @@ -1575,15 +1579,18 @@ ServiceWorkerManager::GetRegistration(nsIDOMWindow* aWindow, AssertIsOnMainThread(); MOZ_ASSERT(aWindow); - // XXXnsm Don't allow chrome callers for now, we don't support chrome - // ServiceWorkers. - MOZ_ASSERT(!nsContentUtils::IsCallerChrome()); - nsCOMPtr window = do_QueryInterface(aWindow); - if (!window) { + MOZ_ASSERT(window); + + nsCOMPtr doc = window->GetExtantDoc(); + if (!doc) { return NS_ERROR_FAILURE; } + // Don't allow service workers to register when the *document* is chrome for + // now. + MOZ_ASSERT(!nsContentUtils::IsSystemPrincipal(doc->NodePrincipal())); + nsCOMPtr sgo = do_QueryInterface(window); ErrorResult result; nsRefPtr promise = Promise::Create(sgo, result); @@ -1784,15 +1791,18 @@ ServiceWorkerManager::GetReadyPromise(nsIDOMWindow* aWindow, AssertIsOnMainThread(); MOZ_ASSERT(aWindow); - // XXXnsm Don't allow chrome callers for now, we don't support chrome - // ServiceWorkers. - MOZ_ASSERT(!nsContentUtils::IsCallerChrome()); - nsCOMPtr window = do_QueryInterface(aWindow); - if (!window) { + MOZ_ASSERT(window); + + nsCOMPtr doc = window->GetExtantDoc(); + if (!doc) { return NS_ERROR_FAILURE; } + // Don't allow service workers to register when the *document* is chrome for + // now. + MOZ_ASSERT(!nsContentUtils::IsSystemPrincipal(doc->NodePrincipal())); + MOZ_ASSERT(!mPendingReadyPromises.Contains(window)); nsCOMPtr sgo = do_QueryInterface(window);