diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index bf5c1bb5398a..a5f7b0981ebd 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -10871,10 +10871,7 @@ nsDocShell::DoChannelLoad(nsIChannel* aChannel, // If the user pressed shift-reload, then do not allow ServiceWorker // interception to occur. See step 12.1 of the SW HandleFetch algorithm. - if (mLoadType == LOAD_RELOAD_BYPASS_CACHE || - mLoadType == LOAD_RELOAD_BYPASS_PROXY || - mLoadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE || - mLoadType == LOAD_RELOAD_ALLOW_MIXED_CONTENT) { + if (IsForceReloadType(mLoadType)) { nsCOMPtr internal = do_QueryInterface(aChannel); if (internal) { internal->ForceNoIntercept(); @@ -11163,11 +11160,7 @@ nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel, nsISupports* aOwner, * for the page. Save the new cacheKey in Session History. * see bug 90098 */ - if (aChannel && - (aLoadType == LOAD_RELOAD_BYPASS_CACHE || - aLoadType == LOAD_RELOAD_BYPASS_PROXY || - aLoadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE || - aLoadType == LOAD_RELOAD_ALLOW_MIXED_CONTENT)) { + if (aChannel && IsForceReloadType(aLoadType)) { NS_ASSERTION(!updateSHistory, "We shouldn't be updating session history for forced" " reloads!"); diff --git a/docshell/base/nsDocShellLoadTypes.h b/docshell/base/nsDocShellLoadTypes.h index 273dd87b0d61..67304476dfa1 100644 --- a/docshell/base/nsDocShellLoadTypes.h +++ b/docshell/base/nsDocShellLoadTypes.h @@ -101,5 +101,17 @@ IsValidLoadType(uint32_t aLoadType) return false; } +static inline bool +IsForceReloadType(uint32_t aLoadType) { + switch (aLoadType) { + case LOAD_RELOAD_BYPASS_CACHE: + case LOAD_RELOAD_BYPASS_PROXY: + case LOAD_RELOAD_BYPASS_PROXY_AND_CACHE: + case LOAD_RELOAD_ALLOW_MIXED_CONTENT: + return true; + } + return false; +} + #endif // MOZILLA_INTERNAL_API #endif diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 8177411ac6af..dc162816c049 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -33,6 +33,7 @@ #include "mozilla/css/Loader.h" #include "mozilla/css/ImageLoader.h" #include "nsDocShell.h" +#include "nsDocShellLoadTypes.h" #include "nsIDocShellTreeItem.h" #include "nsCOMArray.h" #include "nsQueryObject.h" @@ -4730,15 +4731,13 @@ nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject) mTemplateContentsOwner->SetScriptGlobalObject(aScriptGlobalObject); } - nsCOMPtr channel = GetChannel(); - if (!mMaybeServiceWorkerControlled && channel) { - nsLoadFlags loadFlags = 0; - channel->GetLoadFlags(&loadFlags); + if (!mMaybeServiceWorkerControlled && mDocumentContainer && mScriptGlobalObject && GetChannel()) { + nsCOMPtr docShell(mDocumentContainer); + uint32_t loadType; + docShell->GetLoadType(&loadType); + // If we are shift-reloaded, don't associate with a ServiceWorker. - // TODO: This should check the nsDocShell definition of shift-reload instead - // of trying to infer it from LOAD_BYPASS_CACHE. The current code - // will probably cause problems once bug 1120715 lands. - if (loadFlags & nsIRequest::LOAD_BYPASS_CACHE) { + if (IsForceReloadType(loadType)) { NS_WARNING("Page was shift reloaded, skipping ServiceWorker control"); return; }