Bug 1059174 - Allow ServiceWorkers over http on localhost, r=nsm
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 02 Sep 2014 21:07:55 +0100
changeset 203267 cea25477ad0fa0fcadf65f8814a0d2c67d7b4fde
parent 203266 0cf223c85b3b06e63a7ff66b634454a5176986df
child 203268 73cd32cd0a0a2a70aa03f73266185f374e65e331
push id27425
push userryanvm@gmail.com
push dateWed, 03 Sep 2014 20:38:59 +0000
treeherdermozilla-central@acbdce59da2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnsm
bugs1059174
milestone35.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 1059174 - Allow ServiceWorkers over http on localhost, r=nsm
dom/workers/ServiceWorkerManager.cpp
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -571,18 +571,39 @@ ServiceWorkerManager::Register(const nsA
   // Although the spec says that the same-origin checks should also be done
   // asynchronously, we do them in sync because the Promise created by the
   // WebIDL infrastructure due to a returned error will be resolved
   // asynchronously. We aren't making any internal state changes in these
   // checks, so ordering of multiple calls is not affected.
 
   nsCOMPtr<nsIURI> documentURI = doc->GetBaseURI();
 
+  bool httpsNeeded = true;
+
   // FIXME(nsm): Bug 1003991. Disable check when devtools are open.
-  if (!Preferences::GetBool("dom.serviceWorkers.testing.enabled")) {
+  if (Preferences::GetBool("dom.serviceWorkers.testing.enabled")) {
+    httpsNeeded = false;
+  }
+
+  // No https needed for localhost.
+  if (httpsNeeded) {
+    nsAutoCString host;
+    result = documentURI->GetHost(host);
+    if (NS_WARN_IF(result.Failed())) {
+      return result.ErrorCode();
+    }
+
+    if (host.Equals("127.0.0.1") ||
+        host.Equals("localhost") ||
+        host.Equals("::1")) {
+      httpsNeeded = false;
+    }
+  }
+
+  if (httpsNeeded) {
     bool isHttps;
     result = documentURI->SchemeIs("https", &isHttps);
     if (result.Failed() || !isHttps) {
       NS_WARNING("ServiceWorker registration from insecure websites is not allowed.");
       return NS_ERROR_DOM_SECURITY_ERR;
     }
   }