Bug 1190703 - Relax scope resolution assertion in ServiceWorkerContainer::Register. r=bkelly
authorNikhil Marathe <nsm.nikhil@gmail.com>
Wed, 05 Aug 2015 14:33:50 -0700
changeset 288118 65767c78adb12f5ff35f7e56b2fe573aba86d85f
parent 288117 8b893803cc40da2ea65685254dc05ed7420e9866
child 288119 15512b2f6f41e1b749a0097e3360d0ee7f9f7cfe
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1190703
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1190703 - Relax scope resolution assertion in ServiceWorkerContainer::Register. r=bkelly
dom/bindings/Errors.msg
dom/workers/ServiceWorkerContainer.cpp
--- a/dom/bindings/Errors.msg
+++ b/dom/bindings/Errors.msg
@@ -71,8 +71,9 @@ MSG_DEF(MSG_INVALID_RESPONSE_STATUSCODE_
 MSG_DEF(MSG_INVALID_REDIRECT_STATUSCODE_ERROR, 0, JSEXN_RANGEERR, "Invalid redirect status code.")
 MSG_DEF(MSG_INVALID_URL_SCHEME, 2, JSEXN_TYPEERR, "{0} URL {1} must be either http:// or https://.")
 MSG_DEF(MSG_RESPONSE_URL_IS_NULL, 0, JSEXN_TYPEERR, "Cannot set Response.finalURL when Response.url is null.")
 MSG_DEF(MSG_RESPONSE_HAS_VARY_STAR, 0, JSEXN_TYPEERR, "Invalid Response object with a 'Vary: *' header.")
 MSG_DEF(MSG_BAD_FORMDATA, 0, JSEXN_TYPEERR, "Could not parse content as FormData.")
 MSG_DEF(MSG_NO_ACTIVE_WORKER, 1, JSEXN_TYPEERR, "No active worker for scope {0}.")
 MSG_DEF(MSG_NOTIFICATION_PERMISSION_DENIED, 0, JSEXN_TYPEERR, "Permission to show Notification denied.")
 MSG_DEF(MSG_NOTIFICATION_NO_CONSTRUCTOR_IN_SERVICEWORKER, 0, JSEXN_TYPEERR, "Notification constructor cannot be used in ServiceWorkerGlobalScope. Use registration.showNotification() instead.")
+MSG_DEF(MSG_INVALID_SCOPE, 2, JSEXN_TYPEERR, "Invalid scope trying to resolve {0} with base URL {1}.")
--- a/dom/workers/ServiceWorkerContainer.cpp
+++ b/dom/workers/ServiceWorkerContainer.cpp
@@ -126,25 +126,35 @@ ServiceWorkerContainer::Register(const n
   }
 
   // In ServiceWorkerContainer.register() the scope argument is parsed against
   // different base URLs depending on whether it was passed or not.
   nsCOMPtr<nsIURI> scopeURI;
 
   // Step 4. If none passed, parse against script's URL
   if (!aOptions.mScope.WasPassed()) {
-    nsresult rv = NS_NewURI(getter_AddRefs(scopeURI), NS_LITERAL_CSTRING("./"),
-                            nullptr, scriptURI);
-    MOZ_ALWAYS_TRUE(NS_SUCCEEDED(rv));
+    NS_NAMED_LITERAL_STRING(defaultScope, "./");
+    rv = NS_NewURI(getter_AddRefs(scopeURI), defaultScope,
+                   nullptr, scriptURI);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      nsAutoCString spec;
+      scriptURI->GetSpec(spec);
+      aRv.ThrowTypeError(MSG_INVALID_SCOPE, &defaultScope, &spec);
+      return nullptr;
+    }
   } else {
     // Step 5. Parse against entry settings object's base URL.
-    nsresult rv = NS_NewURI(getter_AddRefs(scopeURI), aOptions.mScope.Value(),
-                            nullptr, window->GetDocBaseURI());
+    rv = NS_NewURI(getter_AddRefs(scopeURI), aOptions.mScope.Value(),
+                   nullptr, window->GetDocBaseURI());
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      aRv.ThrowTypeError(MSG_INVALID_URL, &aOptions.mScope.Value());
+      nsAutoCString spec;
+      if (window->GetDocBaseURI()) {
+        window->GetDocBaseURI()->GetSpec(spec);
+      }
+      aRv.ThrowTypeError(MSG_INVALID_SCOPE, &aOptions.mScope.Value(), &spec);
       return nullptr;
     }
   }
 
   aRv = swm->Register(window, scopeURI, scriptURI, getter_AddRefs(promise));
   if (aRv.Failed()) {
     return nullptr;
   }