diff --git a/mozilla/netwerk/base/public/nsICachingChannel.idl b/mozilla/netwerk/base/public/nsICachingChannel.idl index 5644b09c4de..24ca955be86 100644 --- a/mozilla/netwerk/base/public/nsICachingChannel.idl +++ b/mozilla/netwerk/base/public/nsICachingChannel.idl @@ -93,6 +93,13 @@ interface nsICachingChannel : nsISupports * an error if cacheAsFile is false. */ readonly attribute nsIFile cacheFile; + + /** + * TRUE if this channel's data is being loaded from the cache. This value + * is undefined before the channel fires its OnStartRequest notification + * and after the channel fires its OnStopRequest notification. + */ + boolean isFromCache(); }; %{C++ diff --git a/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp b/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp index edffbad1924..aeeefe6abc7 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp @@ -68,6 +68,7 @@ nsHttpChannel::nsHttpChannel() , mFromCacheOnly(PR_FALSE) , mCachedContentIsValid(PR_FALSE) , mResponseHeadersModified(PR_FALSE) + , mCanceled(PR_FALSE) { LOG(("Creating nsHttpChannel @%x\n", this)); @@ -1751,6 +1752,7 @@ NS_IMETHODIMP nsHttpChannel::Cancel(nsresult status) { LOG(("nsHttpChannel::Cancel [this=%x status=%x]\n", this, status)); + mCanceled = PR_TRUE; mStatus = status; if (mTransaction) mTransaction->Cancel(status); @@ -2387,8 +2389,14 @@ nsHttpChannel::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult st mListenerContext = 0; } - if (mCacheEntry) - CloseCacheEntry(status); + if (mCacheEntry) { + // we don't want to discard the cache entry if canceled and + // reading from the cache. + if (mCanceled && (request == mCacheReadRequest)) + CloseCacheEntry(NS_OK); + else + CloseCacheEntry(status); + } if (mLoadGroup) mLoadGroup->RemoveRequest(this, nsnull, status); @@ -2571,6 +2579,13 @@ nsHttpChannel::GetCacheFile(nsIFile **cacheFile) return mCacheEntry->GetFile(cacheFile); } +NS_IMETHODIMP +nsHttpChannel::IsFromCache(PRBool *value) +{ + *value = (mCacheReadRequest != nsnull); + return NS_OK; +} + //----------------------------------------------------------------------------- // nsHttpChannel::nsICacheListener //----------------------------------------------------------------------------- diff --git a/mozilla/netwerk/protocol/http/src/nsHttpChannel.h b/mozilla/netwerk/protocol/http/src/nsHttpChannel.h index ecf1286c6ab..6e260d68a8e 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpChannel.h +++ b/mozilla/netwerk/protocol/http/src/nsHttpChannel.h @@ -171,6 +171,7 @@ private: PRPackedBool mFromCacheOnly; PRPackedBool mCachedContentIsValid; PRPackedBool mResponseHeadersModified; + PRPackedBool mCanceled; }; #endif // nsHttpChannel_h__