author | Honza Bambas <honzab.moz@firemni.cz> |
Mon, 08 Jan 2018 07:26:00 +0200 | |
changeset 450010 | 5a503850a497e892b8e4036bb7155194e6db3254 |
parent 450009 | cf08f8b8d13bc8df6cacc40e0833d3199880464e |
child 450011 | 31fb2dec46ba0b687836b5ed10a5435890be22e5 |
push id | 8527 |
push user | Callek@gmail.com |
push date | Thu, 11 Jan 2018 21:05:50 +0000 |
treeherder | mozilla-beta@95342d212a7a [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | michal |
bugs | 1423550 |
milestone | 59.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
netwerk/protocol/http/nsHttpChannel.cpp | file | annotate | diff | comparison | revisions | |
netwerk/protocol/http/nsHttpChannel.h | file | annotate | diff | comparison | revisions |
--- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -3694,69 +3694,79 @@ IsSubRangeRequest(nsHttpRequestHead &aRe return false; } return !byteRange.EqualsLiteral("bytes=0-"); } nsresult nsHttpChannel::OpenCacheEntry(bool isHttps) { - // Handle correctly mCacheEntriesToWaitFor - AutoCacheWaitFlags waitFlags(this); - // Drop this flag here mConcurrentCacheAccess = 0; - nsresult rv; - mLoadedFromApplicationCache = false; mHasQueryString = HasQueryString(mRequestHead.ParsedMethod(), mURI); LOG(("nsHttpChannel::OpenCacheEntry [this=%p]", this)); // make sure we're not abusing this function NS_PRECONDITION(!mCacheEntry, "cache entry already open"); - nsAutoCString cacheKey; - nsAutoCString extension; - if (mRequestHead.IsPost()) { // If the post id is already set then this is an attempt to replay // a post transaction via the cache. Otherwise, we need a unique // post id for this transaction. if (mPostID == 0) mPostID = gHttpHandler->GenerateUniqueID(); } else if (!mRequestHead.IsGet() && !mRequestHead.IsHead()) { // don't use the cache for other types of requests return NS_OK; } + // Pick up an application cache from the notification + // callbacks if available and if we are not an intercepted channel. + if (!mApplicationCache && mInheritApplicationCache) { + nsCOMPtr<nsIApplicationCacheContainer> appCacheContainer; + GetCallback(appCacheContainer); + + if (appCacheContainer) { + appCacheContainer->GetApplicationCache(getter_AddRefs(mApplicationCache)); + } + } + + return OpenCacheEntryInternal(isHttps, mApplicationCache, true); +} + +nsresult +nsHttpChannel::OpenCacheEntryInternal(bool isHttps, + nsIApplicationCache *applicationCache, + bool allowApplicationCache) +{ + MOZ_ASSERT_IF(!allowApplicationCache, !applicationCache); + + nsresult rv; + if (mResuming) { // We don't support caching for requests initiated // via nsIResumableChannel. return NS_OK; } // Don't cache byte range requests which are subranges, only cache 0- // byte range requests. - if (IsSubRangeRequest(mRequestHead)) + if (IsSubRangeRequest(mRequestHead)) { return NS_OK; - - // Pick up an application cache from the notification - // callbacks if available and if we are not an intercepted channel. - if (!mApplicationCache && - mInheritApplicationCache) { - nsCOMPtr<nsIApplicationCacheContainer> appCacheContainer; - GetCallback(appCacheContainer); - - if (appCacheContainer) { - appCacheContainer->GetApplicationCache(getter_AddRefs(mApplicationCache)); - } - } + } + + // Handle correctly mCacheEntriesToWaitFor + AutoCacheWaitFlags waitFlags(this); + + nsAutoCString cacheKey; + nsAutoCString extension; nsCOMPtr<nsICacheStorageService> cacheStorageService(services::GetCacheStorageService()); if (!cacheStorageService) { return NS_ERROR_NOT_AVAILABLE; } nsCOMPtr<nsICacheStorage> cacheStorage; nsCOMPtr<nsIURI> openURI; @@ -3788,48 +3798,49 @@ nsHttpChannel::OpenCacheEntry(bool isHtt if (offline || (mLoadFlags & INHIBIT_CACHING)) { if (BYPASS_LOCAL_CACHE(mLoadFlags) && !offline) { goto bypassCacheEntryOpen; } cacheEntryOpenFlags = nsICacheStorage::OPEN_READONLY; mCacheEntryIsReadOnly = true; } - else if (BYPASS_LOCAL_CACHE(mLoadFlags) && !mApplicationCache) { + else if (BYPASS_LOCAL_CACHE(mLoadFlags) && !applicationCache) { cacheEntryOpenFlags = nsICacheStorage::OPEN_TRUNCATE; } else { cacheEntryOpenFlags = nsICacheStorage::OPEN_NORMALLY | nsICacheStorage::CHECK_MULTITHREADED; } // Remember the request is a custom conditional request so that we can // process any 304 response correctly. mCustomConditionalRequest = mRequestHead.HasHeader(nsHttp::If_Modified_Since) || mRequestHead.HasHeader(nsHttp::If_None_Match) || mRequestHead.HasHeader(nsHttp::If_Unmodified_Since) || mRequestHead.HasHeader(nsHttp::If_Match) || mRequestHead.HasHeader(nsHttp::If_Range); - if (!mPostID && mApplicationCache) { + if (!mPostID && applicationCache) { rv = cacheStorageService->AppCacheStorage(info, - mApplicationCache, + applicationCache, getter_AddRefs(cacheStorage)); } else if (mLoadFlags & INHIBIT_PERSISTENT_CACHING) { rv = cacheStorageService->MemoryCacheStorage(info, // ? choose app cache as well... getter_AddRefs(cacheStorage)); } else if (mPinCacheContent) { rv = cacheStorageService->PinningCacheStorage(info, getter_AddRefs(cacheStorage)); } else { - bool lookupAppCache = !mPostID && (mChooseApplicationCache || - (mLoadFlags & LOAD_CHECK_OFFLINE_CACHE)); + bool lookupAppCache = (mChooseApplicationCache || (mLoadFlags & LOAD_CHECK_OFFLINE_CACHE)) && + !mPostID && + MOZ_LIKELY(allowApplicationCache); // Try to race only if we use disk cache storage and we don't lookup // app cache first maybeRCWN = !lookupAppCache; rv = cacheStorageService->DiskCacheStorage( info, lookupAppCache, getter_AddRefs(cacheStorage)); } NS_ENSURE_SUCCESS(rv, rv); @@ -3887,17 +3898,17 @@ nsHttpChannel::OpenCacheEntry(bool isHtt nsITimer::TYPE_ONE_SHOT); } NS_ENSURE_SUCCESS(rv, rv); waitFlags.Keep(WAIT_FOR_CACHE_ENTRY); bypassCacheEntryOpen: - if (!mApplicationCacheForWrite) + if (!mApplicationCacheForWrite || !allowApplicationCache) return NS_OK; // If there is an app cache to write to, open the entry right now in parallel. // make sure we're not abusing this function NS_PRECONDITION(!mOfflineCacheEntry, "cache entry already open"); if (offline) { @@ -4547,16 +4558,34 @@ nsHttpChannel::OnOfflineCacheEntryAvaila // for the whole origin (or a parent directory). if (!IsInSubpathOfAppCacheManifest(mApplicationCache, namespaceSpec)) { return NS_OK; } rv = namespaceEntry->GetData(mFallbackKey); NS_ENSURE_SUCCESS(rv, rv); } + + if (namespaceType & + nsIApplicationCacheNamespace::NAMESPACE_BYPASS) { + + LOG(("nsHttpChannel::OnOfflineCacheEntryAvailable this=%p, URL matches NETWORK," + " looking for a regular cache entry", this)); + + bool isHttps = false; + rv = mURI->SchemeIs("https", &isHttps); + NS_ENSURE_SUCCESS(rv, rv); + + rv = OpenCacheEntryInternal(isHttps, nullptr, false /* don't allow appcache lookups */); + if (NS_FAILED(rv)) { + // Don't let this fail when cache entry can't be synchronously open. + // We want to go forward even without a regular cache entry. + return NS_OK; + } + } } return NS_OK; } nsresult nsHttpChannel::OnOfflineCacheEntryForWritingAvailable(nsICacheEntry *aEntry, nsIApplicationCache* aAppCache,
--- a/netwerk/protocol/http/nsHttpChannel.h +++ b/netwerk/protocol/http/nsHttpChannel.h @@ -202,16 +202,19 @@ public: public: /* internal necko use only */ uint32_t GetRequestTime() const { return mRequestTime; } MOZ_MUST_USE nsresult OpenCacheEntry(bool usingSSL); + MOZ_MUST_USE nsresult OpenCacheEntryInternal(bool isHttps, + nsIApplicationCache *applicationCache, + bool noAppCache); MOZ_MUST_USE nsresult ContinueConnect(); // If the load is mixed-content, build and send an HSTS priming request. MOZ_MUST_USE nsresult TryHSTSPriming(); MOZ_MUST_USE nsresult StartRedirectChannelToURI(nsIURI *, uint32_t); // This allows cache entry to be marked as foreign even after channel itself