diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 13d05e33de88..f67200535252 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -667,7 +667,10 @@ nsresult nsHttpChannel::OnBeforeConnect() { RefPtr bc; mLoadInfo->GetBrowsingContext(getter_AddRefs(bc)); - if (bc && bc->Top()->GetForceOffline()) { + // If bypassing the cache and we're forced offline + // we can just return the error here. + if (bc && bc->Top()->GetForceOffline() && + BYPASS_LOCAL_CACHE(mLoadFlags, LoadPreferCacheLoadOverBypass())) { return NS_ERROR_OFFLINE; } @@ -773,7 +776,12 @@ nsresult nsHttpChannel::MaybeUseHTTPSRRForUpgrade(bool aShouldUpgrade, return aStatus; } - if (mURI->SchemeIs("https") || aShouldUpgrade || !LoadUseHTTPSSVC()) { + RefPtr bc; + mLoadInfo->GetBrowsingContext(getter_AddRefs(bc)); + bool forceOffline = bc && bc->Top()->GetForceOffline(); + + if (mURI->SchemeIs("https") || aShouldUpgrade || !LoadUseHTTPSSVC() || + forceOffline) { return ContinueOnBeforeConnect(aShouldUpgrade, aStatus); } @@ -1190,10 +1198,19 @@ nsresult nsHttpChannel::ContinueConnect() { "CORS preflight must have been finished by the time we " "do the rest of ContinueConnect"); + RefPtr bc; + mLoadInfo->GetBrowsingContext(getter_AddRefs(bc)); + // we may or may not have a cache entry at this point if (mCacheEntry) { // read straight from the cache if possible... if (mCachedContentIsValid) { + // If we're forced offline, and set to bypass the cache, return offline. + if (bc && bc->Top()->GetForceOffline() && + BYPASS_LOCAL_CACHE(mLoadFlags, LoadPreferCacheLoadOverBypass())) { + return NS_ERROR_OFFLINE; + } + nsRunnableMethod* event = nullptr; nsresult rv; if (!LoadCachedContentIsPartial()) { @@ -1230,6 +1247,11 @@ nsresult nsHttpChannel::ContinueConnect() { return NS_ERROR_DOCUMENT_NOT_CACHED; } + // We're about to hit the network. Don't if we're forced offline. + if (bc && bc->Top()->GetForceOffline()) { + return NS_ERROR_OFFLINE; + } + // hit the net... nsresult rv = DoConnect(mTransactionSticky); mTransactionSticky = nullptr; @@ -4138,10 +4160,10 @@ nsresult nsHttpChannel::OpenCacheEntryInternal(bool isHttps) { return NS_OK; } - if (offline || (mLoadFlags & INHIBIT_CACHING) || - (bc && bc->Top()->GetForceOffline())) { + bool forceOffline = bc && bc->Top()->GetForceOffline(); + if (offline || (mLoadFlags & INHIBIT_CACHING) || forceOffline) { if (BYPASS_LOCAL_CACHE(mLoadFlags, LoadPreferCacheLoadOverBypass()) && - !offline) { + !offline && !forceOffline) { return NS_OK; } cacheEntryOpenFlags = nsICacheStorage::OPEN_READONLY;