Skip to content

Commit

Permalink
Bug 1437080 P3 Make SetFetchCacheMode() to clear other cache flags an…
Browse files Browse the repository at this point in the history
…d assert the final value. r=valentin
  • Loading branch information
wanderview authored and MrAlex94 committed Jul 12, 2018
1 parent 7e991d5 commit d82c62b
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions netwerk/protocol/http/HttpBaseChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2765,6 +2765,25 @@ HttpBaseChannel::GetFetchCacheMode(uint32_t* aFetchCacheMode)
return NS_OK;
}

namespace {

void
SetCacheFlags(uint32_t& aLoadFlags, uint32_t aFlags)
{
// First, clear any possible cache related flags.
uint32_t allPossibleFlags = nsIRequest::INHIBIT_CACHING
| nsIRequest::LOAD_BYPASS_CACHE
| nsIRequest::VALIDATE_ALWAYS
| nsIRequest::LOAD_FROM_CACHE
| nsICachingChannel::LOAD_ONLY_FROM_CACHE;
aLoadFlags &= ~allPossibleFlags;

// Then set the new flags.
aLoadFlags |= aFlags;
}

} // anonymous namespace

NS_IMETHODIMP
HttpBaseChannel::SetFetchCacheMode(uint32_t aFetchCacheMode)
{
Expand All @@ -2779,20 +2798,20 @@ HttpBaseChannel::SetFetchCacheMode(uint32_t aFetchCacheMode)
case nsIHttpChannelInternal::FETCH_CACHE_MODE_NO_STORE:
// no-store means don't consult the cache on the way to the network, and
// don't store the response in the cache even if it's cacheable.
mLoadFlags |= INHIBIT_CACHING | LOAD_BYPASS_CACHE;
SetCacheFlags(mLoadFlags, INHIBIT_CACHING | LOAD_BYPASS_CACHE);
break;
case nsIHttpChannelInternal::FETCH_CACHE_MODE_RELOAD:
// reload means don't consult the cache on the way to the network, but
// do store the response in the cache if possible.
mLoadFlags |= LOAD_BYPASS_CACHE;
SetCacheFlags(mLoadFlags, LOAD_BYPASS_CACHE);
break;
case nsIHttpChannelInternal::FETCH_CACHE_MODE_NO_CACHE:
// no-cache means always validate what's in the cache.
mLoadFlags |= VALIDATE_ALWAYS;
SetCacheFlags(mLoadFlags, VALIDATE_ALWAYS);
break;
case nsIHttpChannelInternal::FETCH_CACHE_MODE_FORCE_CACHE:
// force-cache means don't validate unless if the response would vary.
mLoadFlags |= VALIDATE_NEVER;
SetCacheFlags(mLoadFlags, LOAD_FROM_CACHE);
break;
case nsIHttpChannelInternal::FETCH_CACHE_MODE_ONLY_IF_CACHED:
// only-if-cached means only from cache, no network, no validation, generate
Expand All @@ -2801,10 +2820,17 @@ HttpBaseChannel::SetFetchCacheMode(uint32_t aFetchCacheMode)
// the user has things in their cache without any network traffic side
// effects) are addressed in the Request constructor which enforces/requires
// same-origin request mode.
mLoadFlags |= VALIDATE_NEVER | nsICachingChannel::LOAD_ONLY_FROM_CACHE;
SetCacheFlags(mLoadFlags, LOAD_FROM_CACHE |
nsICachingChannel::LOAD_ONLY_FROM_CACHE);
break;
}

#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
uint32_t finalMode = 0;
MOZ_ALWAYS_SUCCEEDS(GetFetchCacheMode(&finalMode));
MOZ_DIAGNOSTIC_ASSERT(finalMode == aFetchCacheMode);
#endif // MOZ_DIAGNOSTIC_ASSERT_ENABLED

return NS_OK;
}

Expand Down

0 comments on commit d82c62b

Please sign in to comment.