Bug 449198 - http-on-examine-response isn't fired when a response comes from the cache; r=bzbarsky sr=cbiesinger

This commit is contained in:
Michal Novotny 2009-02-12 05:16:00 +01:00
Родитель 267b906de5
Коммит d871725e78
4 изменённых файлов: 44 добавлений и 5 удалений

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

@ -158,5 +158,12 @@ interface nsIHttpProtocolHandler : nsIProxiedProtocolHandler
*/ */
#define NS_HTTP_ON_EXAMINE_MERGED_RESPONSE_TOPIC "http-on-examine-merged-response" #define NS_HTTP_ON_EXAMINE_MERGED_RESPONSE_TOPIC "http-on-examine-merged-response"
/**
* The observer of this topic is notified before data is read from the cache.
* The notification is sent if and only if there is no network communication
* at all.
*/
#define NS_HTTP_ON_EXAMINE_CACHED_RESPONSE_TOPIC "http-on-examine-cached-response"
%} %}

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

@ -255,11 +255,19 @@ nsHttpChannel::Init(nsIURI *uri,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
nsresult nsresult
nsHttpChannel::AsyncCall(nsAsyncCallback funcPtr) nsHttpChannel::AsyncCall(nsAsyncCallback funcPtr,
nsRunnableMethod<nsHttpChannel> **retval)
{ {
nsCOMPtr<nsIRunnable> event = nsresult rv;
nsRefPtr<nsRunnableMethod<nsHttpChannel> > event =
new nsRunnableMethod<nsHttpChannel>(this, funcPtr); new nsRunnableMethod<nsHttpChannel>(this, funcPtr);
return NS_DispatchToCurrentThread(event); rv = NS_DispatchToCurrentThread(event);
if (NS_SUCCEEDED(rv) && retval) {
*retval = event;
}
return rv;
} }
PRBool PRBool
@ -341,7 +349,15 @@ nsHttpChannel::Connect(PRBool firstTime)
// read straight from the cache if possible... // read straight from the cache if possible...
if (mCachedContentIsValid) { if (mCachedContentIsValid) {
return ReadFromCache(); nsRunnableMethod<nsHttpChannel> *event = nsnull;
if (!mCachedContentIsPartial) {
AsyncCall(&nsHttpChannel::AsyncOnExamineCachedResponse, &event);
}
rv = ReadFromCache();
if (NS_FAILED(rv) && event) {
event->Revoke();
}
return rv;
} }
else if (mLoadFlags & LOAD_ONLY_FROM_CACHE) { else if (mLoadFlags & LOAD_ONLY_FROM_CACHE) {
// the cache contains the requested resource, but it must be // the cache contains the requested resource, but it must be
@ -5591,3 +5607,8 @@ nsHttpChannel::DetermineStoragePolicy()
return policy; return policy;
} }
void
nsHttpChannel::AsyncOnExamineCachedResponse()
{
gHttpHandler->OnExamineCachedResponse(this);
}

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

@ -153,7 +153,10 @@ private:
} }
// AsyncCall may be used to call a member function asynchronously. // AsyncCall may be used to call a member function asynchronously.
nsresult AsyncCall(nsAsyncCallback funcPtr); // retval isn't refcounted and is set only when event was successfully
// posted, the event is returned for the purpose of cancelling when needed
nsresult AsyncCall(nsAsyncCallback funcPtr,
nsRunnableMethod<nsHttpChannel> **retval = nsnull);
PRBool RequestIsConditional(); PRBool RequestIsConditional();
nsresult Connect(PRBool firstTime = PR_TRUE); nsresult Connect(PRBool firstTime = PR_TRUE);
@ -205,6 +208,7 @@ private:
nsresult InstallOfflineCacheListener(); nsresult InstallOfflineCacheListener();
void MaybeInvalidateCacheEntryForSubsequentGet(); void MaybeInvalidateCacheEntryForSubsequentGet();
nsCacheStoragePolicy DetermineStoragePolicy(); nsCacheStoragePolicy DetermineStoragePolicy();
void AsyncOnExamineCachedResponse();
// Handle the bogus Content-Encoding Apache sometimes sends // Handle the bogus Content-Encoding Apache sometimes sends
void ClearBogusContentEncodingIfNeeded(); void ClearBogusContentEncodingIfNeeded();

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

@ -195,6 +195,13 @@ public:
// channel's and the global redirect observers. // channel's and the global redirect observers.
nsresult OnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan, nsresult OnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan,
PRUint32 flags); PRUint32 flags);
// Called by the channel when the response is read from the cache without
// communicating with the server.
void OnExamineCachedResponse(nsIHttpChannel *chan)
{
NotifyObservers(chan, NS_HTTP_ON_EXAMINE_CACHED_RESPONSE_TOPIC);
}
private: private:
// //