diff --git a/dom/fetch/Fetch.cpp b/dom/fetch/Fetch.cpp index d7a96fd35ae..1a875a2af18 100644 --- a/dom/fetch/Fetch.cpp +++ b/dom/fetch/Fetch.cpp @@ -241,6 +241,11 @@ FetchRequest(nsIGlobalObject* aGlobal, const RequestOrUSVString& aInput, } else { WorkerPrivate* worker = GetCurrentThreadWorkerPrivate(); MOZ_ASSERT(worker); + + if (worker->IsServiceWorker()) { + r->SetSkipServiceWorker(); + } + nsRefPtr run = new MainThreadFetchRunnable(worker, p, r); if (NS_FAILED(NS_DispatchToMainThread(run))) { NS_WARNING("MainThreadFetchRunnable dispatch failed!"); diff --git a/dom/fetch/FetchDriver.cpp b/dom/fetch/FetchDriver.cpp index f8109db0f45..31462cf3b33 100644 --- a/dom/fetch/FetchDriver.cpp +++ b/dom/fetch/FetchDriver.cpp @@ -8,6 +8,7 @@ #include "nsIInputStream.h" #include "nsIOutputStream.h" #include "nsIHttpChannel.h" +#include "nsIHttpChannelInternal.h" #include "nsIHttpHeaderVisitor.h" #include "nsIScriptSecurityManager.h" #include "nsIThreadRetargetableRequest.h" @@ -450,6 +451,14 @@ FetchDriver::HttpFetch(bool aCORSFlag, bool aCORSPreflightFlag, bool aAuthentica } } + // 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 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 diff --git a/dom/fetch/InternalRequest.h b/dom/fetch/InternalRequest.h index 2fa4324d256..6e19fc1d9d2 100644 --- a/dom/fetch/InternalRequest.h +++ b/dom/fetch/InternalRequest.h @@ -179,6 +179,18 @@ public: mReferrer.Assign(aReferrer); } + bool + SkipServiceWorker() const + { + return mSkipServiceWorker; + } + + void + SetSkipServiceWorker() + { + mSkipServiceWorker = true; + } + bool IsSynchronous() const {