Bug 1907304 - Check forceOffline BC flag _after_ opening the cache r=necko-reviewers,sekim,kershaw,jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D219292
This commit is contained in:
Valentin Gosu 2024-09-17 14:14:58 +00:00
Родитель d97141c765
Коммит dc6b3a7d90
1 изменённых файлов: 27 добавлений и 5 удалений

Просмотреть файл

@ -667,7 +667,10 @@ nsresult nsHttpChannel::OnBeforeConnect() {
RefPtr<mozilla::dom::BrowsingContext> 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<mozilla::dom::BrowsingContext> 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<mozilla::dom::BrowsingContext> 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<nsHttpChannel>* 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;