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
This commit is contained in:
John Dai 2016-03-31 23:08:45 -07:00
parent c2298e0f56
commit 059fdf21d7
2 changed files with 23 additions and 4 deletions

View File

@ -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.

View File

@ -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<nsIURI> 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<uint64_t, 16> windows;