From 059fdf21d790b0ffab0b58f2361fc8573e4a6e6c Mon Sep 17 00:00:00 2001 From: John Dai Date: Thu, 31 Mar 2016 23:08:45 -0700 Subject: [PATCH] Bug 1220757 - Add report to console when service worker register fails due to mismatching scope path.r=bkelly MozReview-Commit-ID: 9hRBzWtSAd2 --HG-- extra : rebase_source : 8552934879813ac2bd6ca828b3a2ec99b35893df --- dom/locales/en-US/chrome/dom/dom.properties | 2 ++ dom/workers/ServiceWorkerManager.cpp | 25 +++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/dom/locales/en-US/chrome/dom/dom.properties b/dom/locales/en-US/chrome/dom/dom.properties index 82f5cde5edf6..cacaaf3af843 100644 --- a/dom/locales/en-US/chrome/dom/dom.properties +++ b/dom/locales/en-US/chrome/dom/dom.properties @@ -187,6 +187,8 @@ InterceptionCanceledWithURL=Failed to load '%S'. A ServiceWorker canceled the lo InterceptionRejectedResponseWithURL=Failed to load '%1$S'. A ServiceWorker passed a promise to FetchEvent.respondWith() that rejected with '%2$S'. # LOCALIZATION NOTE: Do not translate "ServiceWorker", "promise", "FetchEvent.respondWith()", or "Response". %1$S is a URL. %2$S is an error string. InterceptedNonResponseWithURL=Failed to load '%1$S'. A ServiceWorker passed a promise to FetchEvent.respondWith() that resolved with non-Response value '%2$S'. +# LOCALIZATION NOTE: Do not translate "ServiceWorker", "Service-Worker-Allowed" or "HTTP". %1$S and %2$S are URLs. +ServiceWorkerScopePathMismatch=Failed to register a ServiceWorker: The path of the provided scope '%1$S' is not under the max scope allowed '%2$S'. Adjust the scope, move the Service Worker script, or use the Service-Worker-Allowed HTTP header to allow the scope. ExecCommandCutCopyDeniedNotInputDriven=document.execCommand('cut'/'copy') was denied because it was not called from inside a short running user-generated event handler. ManifestShouldBeObject=Manifest should be an object. ManifestScopeURLInvalid=The scope URL is invalid. diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp index 396a9052ddc4..1553a23fc3b5 100644 --- a/dom/workers/ServiceWorkerManager.cpp +++ b/dom/workers/ServiceWorkerManager.cpp @@ -1457,7 +1457,20 @@ public: } if (!StringBeginsWith(mRegistration->mScope, maxPrefix)) { - NS_WARNING("By default a service worker's scope is restricted to at or below it's script's location."); + nsXPIDLString message; + NS_ConvertUTF8toUTF16 reportScope(mRegistration->mScope); + NS_ConvertUTF8toUTF16 reportMaxPrefix(maxPrefix); + const char16_t* params[] = { reportScope.get(), reportMaxPrefix.get() }; + + rv = nsContentUtils::FormatLocalizedString(nsContentUtils::eDOM_PROPERTIES, + "ServiceWorkerScopePathMismatch", + params, message); + NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to format localized string"); + swm->ReportToAllClients(mScope, + message, + EmptyString(), + EmptyString(), 0, 0, + nsIScriptError::errorFlag); Fail(NS_ERROR_DOM_SECURITY_ERR); return; } @@ -2711,9 +2724,13 @@ ServiceWorkerManager::ReportToAllClients(const nsCString& aScope, uint32_t aFlags) { nsCOMPtr uri; - nsresult rv = NS_NewURI(getter_AddRefs(uri), aFilename); - if (NS_WARN_IF(NS_FAILED(rv))) { - return; + nsresult rv; + + if (!aFilename.IsEmpty()) { + rv = NS_NewURI(getter_AddRefs(uri), aFilename); + if (NS_WARN_IF(NS_FAILED(rv))) { + return; + } } AutoTArray windows;