Bug 1179772 Make Cache API honor devtools SW testing flag in SW itself. r=ehsan
authorBen Kelly <ben@wanderview.com>
Thu, 02 Jul 2015 11:47:10 -0700
changeset 270182 d7e196b07cee220dc7812063709812587fe67193
parent 270181 942d48fd522a66dbb901b7d2a06c48d82cbfcb7b
child 270183 97c7e83acb6b42afe27901e6df9a96971bc12739
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-esr52@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1179772
milestone42.0a1
Bug 1179772 Make Cache API honor devtools SW testing flag in SW itself. r=ehsan
dom/cache/CacheStorage.cpp
--- a/dom/cache/CacheStorage.cpp
+++ b/dom/cache/CacheStorage.cpp
@@ -199,19 +199,33 @@ CacheStorage::CreateOnWorker(Namespace a
   if (!feature) {
     NS_WARNING("Worker thread is shutting down.");
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
   const PrincipalInfo& principalInfo = aWorkerPrivate->GetPrincipalInfo();
 
+  // We have a number of cases where we want to skip the https scheme
+  // validation:
+  //
+  // 1) Any worker when dom.caches.testing.enabled pref is true.
+  // 2) Any worker when dom.serviceWorkers.testing.enabled pref is true.  This
+  //    is mainly because most sites using SWs will expect Cache to work if
+  //    SWs are enabled.
+  // 3) If the window that created this worker has the devtools SW testing
+  //    option enabled.  Same reasoning as (2).
+  // 4) If the worker itself is a ServiceWorker, then we always skip the
+  //    origin checks.  The ServiceWorker has its own trusted origin checks
+  //    that are better than ours.  In addition, we don't have information
+  //    about the window any more, so we can't do our own checks.
   bool testingEnabled = aWorkerPrivate->DOMCachesTestingEnabled() ||
                         aWorkerPrivate->ServiceWorkersTestingEnabled() ||
-                        aWorkerPrivate->ServiceWorkersTestingInWindow();
+                        aWorkerPrivate->ServiceWorkersTestingInWindow() ||
+                        aWorkerPrivate->IsServiceWorker();
 
   if (!IsTrusted(principalInfo, testingEnabled)) {
     NS_WARNING("CacheStorage not supported on untrusted origins.");
     nsRefPtr<CacheStorage> ref = new CacheStorage(NS_ERROR_DOM_SECURITY_ERR);
     return ref.forget();
   }
 
   nsRefPtr<CacheStorage> ref = new CacheStorage(aNamespace, aGlobal,