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
parent 194202d83d
commit 0adb622172
4 changed files with 44 additions and 5 deletions

View File

@ -158,5 +158,12 @@ interface nsIHttpProtocolHandler : nsIProxiedProtocolHandler
*/
#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"
%}

View File

@ -255,11 +255,19 @@ nsHttpChannel::Init(nsIURI *uri,
//-----------------------------------------------------------------------------
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);
return NS_DispatchToCurrentThread(event);
rv = NS_DispatchToCurrentThread(event);
if (NS_SUCCEEDED(rv) && retval) {
*retval = event;
}
return rv;
}
PRBool
@ -341,7 +349,15 @@ nsHttpChannel::Connect(PRBool firstTime)
// read straight from the cache if possible...
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) {
// the cache contains the requested resource, but it must be
@ -5591,3 +5607,8 @@ nsHttpChannel::DetermineStoragePolicy()
return policy;
}
void
nsHttpChannel::AsyncOnExamineCachedResponse()
{
gHttpHandler->OnExamineCachedResponse(this);
}

View File

@ -153,7 +153,10 @@ private:
}
// 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();
nsresult Connect(PRBool firstTime = PR_TRUE);
@ -205,6 +208,7 @@ private:
nsresult InstallOfflineCacheListener();
void MaybeInvalidateCacheEntryForSubsequentGet();
nsCacheStoragePolicy DetermineStoragePolicy();
void AsyncOnExamineCachedResponse();
// Handle the bogus Content-Encoding Apache sometimes sends
void ClearBogusContentEncodingIfNeeded();

View File

@ -195,6 +195,13 @@ public:
// channel's and the global redirect observers.
nsresult OnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan,
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:
//