Bug 1119026 - Respect skip serviceworker flag. r=baku,bkelly
authorNikhil Marathe <nsm.nikhil@gmail.com>
Wed, 24 Dec 2014 02:08:41 -0800
changeset 251446 7ad380221ba64af0f0e6ae07f768d4a7232cca27
parent 251445 9959a5e91de9c8e5cc176391a2cc430bd34d2082
child 251447 c84bcdd07ff8efc19869320dd0344e2394b89f8f
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, bkelly
bugs1119026
milestone38.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 1119026 - Respect skip serviceworker flag. r=baku,bkelly
dom/fetch/Fetch.cpp
dom/fetch/FetchDriver.cpp
dom/fetch/InternalRequest.h
--- a/dom/fetch/Fetch.cpp
+++ b/dom/fetch/Fetch.cpp
@@ -236,16 +236,21 @@ FetchRequest(nsIGlobalObject* aGlobal, c
     fetch->SetReferrerPolicy(doc->GetReferrerPolicy());
     aRv = fetch->Fetch(resolver);
     if (NS_WARN_IF(aRv.Failed())) {
       return nullptr;
     }
   } else {
     WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
     MOZ_ASSERT(worker);
+
+    if (worker->IsServiceWorker()) {
+      r->SetSkipServiceWorker();
+    }
+
     nsRefPtr<MainThreadFetchRunnable> run = new MainThreadFetchRunnable(worker, p, r);
     if (NS_FAILED(NS_DispatchToMainThread(run))) {
       NS_WARNING("MainThreadFetchRunnable dispatch failed!");
     }
   }
 
   return p.forget();
 }
--- a/dom/fetch/FetchDriver.cpp
+++ b/dom/fetch/FetchDriver.cpp
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/FetchDriver.h"
 
 #include "nsIInputStream.h"
 #include "nsIOutputStream.h"
 #include "nsIHttpChannel.h"
+#include "nsIHttpChannelInternal.h"
 #include "nsIHttpHeaderVisitor.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIThreadRetargetableRequest.h"
 #include "nsIUploadChannel2.h"
 
 #include "nsContentPolicyUtils.h"
 #include "nsCORSListenerProxy.h"
 #include "nsDataHandler.h"
@@ -445,16 +446,24 @@ FetchDriver::HttpFetch(bool aCORSFlag, b
       mRequest->GetMethod(method);
       rv = uploadChan->ExplicitSetUploadStream(bodyStream, contentType, -1, method, false /* aStreamHasHeaders */);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return FailWithNetworkError();
       }
     }
   }
 
+  // Set skip serviceworker flag.
+  // While the spec also gates on the client being a ServiceWorker, we can't
+  // infer that here. Instead we rely on callers to set the flag correctly.
+  if (mRequest->SkipServiceWorker()) {
+    nsCOMPtr<nsIHttpChannelInternal> internalChan = do_QueryInterface(httpChan);
+    internalChan->ForceNoIntercept();
+  }
+
   // Set up a CORS proxy that will handle the various requirements of the CORS
   // protocol. It handles the preflight cache and CORS response headers.
   // If the request is allowed, it will start our original request
   // and our observer will be notified. On failure, our observer is notified
   // directly.
   nsRefPtr<nsCORSListenerProxy> corsListener =
     new nsCORSListenerProxy(this, mPrincipal, useCredentials);
   rv = corsListener->Init(chan, true /* allow data uri */);
--- a/dom/fetch/InternalRequest.h
+++ b/dom/fetch/InternalRequest.h
@@ -175,16 +175,28 @@ public:
 
     MOZ_ASSERT(validReferrer);
 #endif
 
     mReferrer.Assign(aReferrer);
   }
 
   bool
+  SkipServiceWorker() const
+  {
+    return mSkipServiceWorker;
+  }
+
+  void
+  SetSkipServiceWorker()
+  {
+    mSkipServiceWorker = true;
+  }
+
+  bool
   IsSynchronous() const
   {
     return mSynchronous;
   }
 
   RequestMode
   Mode() const
   {