Keep track of the URI we're keyed on in imgRequests. This makes it possible to avoid leaks. b=468160 r=bzbarsky sr=vlad

This commit is contained in:
Joe Drew 2008-12-10 20:58:28 -08:00
parent b1879ea25f
commit 0f5fffdcd6
3 changed files with 28 additions and 9 deletions

View File

@ -255,7 +255,7 @@ void imgCacheEntry::TouchWithSize(PRInt32 diff)
if (!Evicted()) {
nsCOMPtr<nsIURI> uri;
mRequest->GetURI(getter_AddRefs(uri));
mRequest->GetKeyURI(getter_AddRefs(uri));
imgLoader::CacheEntriesChanged(uri, diff);
}
}
@ -269,7 +269,7 @@ void imgCacheEntry::Touch(PRBool updateTime /* = PR_TRUE */)
if (!Evicted()) {
nsCOMPtr<nsIURI> uri;
mRequest->GetURI(getter_AddRefs(uri));
mRequest->GetKeyURI(getter_AddRefs(uri));
imgLoader::CacheEntriesChanged(uri);
}
}
@ -909,7 +909,7 @@ PRBool imgLoader::RemoveFromCache(imgCacheEntry *entry)
nsRefPtr<imgRequest> request(getter_AddRefs(entry->GetRequest()));
if (request) {
nsCOMPtr<nsIURI> key;
if (NS_SUCCEEDED(request->GetURI(getter_AddRefs(key))) && key)
if (NS_SUCCEEDED(request->GetKeyURI(getter_AddRefs(key))) && key)
ret = RemoveFromCache(key);
}
@ -1061,7 +1061,7 @@ NS_IMETHODIMP imgLoader::LoadImage(nsIURI *aURI,
newChannel->SetLoadGroup(loadGroup);
void *cacheId = NS_GetCurrentThread();
request->Init(aURI, loadGroup, newChannel, entry, cacheId, aCX);
request->Init(aURI, aURI, loadGroup, newChannel, entry, cacheId, aCX);
// create the proxy listener
ProxyListener *pl = new ProxyListener(static_cast<nsIStreamListener *>(request.get()));
@ -1198,7 +1198,7 @@ NS_IMETHODIMP imgLoader::LoadImageWithChannel(nsIChannel *channel, imgIDecoderOb
// We use originalURI here to fulfil the imgIRequest contract on GetURI.
nsCOMPtr<nsIURI> originalURI;
channel->GetOriginalURI(getter_AddRefs(originalURI));
request->Init(originalURI, channel, channel, entry, NS_GetCurrentThread(), aCX);
request->Init(originalURI, uri, channel, channel, entry, NS_GetCurrentThread(), aCX);
ProxyListener *pl = new ProxyListener(static_cast<nsIStreamListener *>(request.get()));
if (!pl)
@ -1471,7 +1471,7 @@ NS_IMETHODIMP imgCacheValidator::OnStartRequest(nsIRequest *aRequest, nsISupport
// We use originalURI here to fulfil the imgIRequest contract on GetURI.
nsCOMPtr<nsIURI> originalURI;
channel->GetOriginalURI(getter_AddRefs(originalURI));
request->Init(originalURI, channel, channel, entry, NS_GetCurrentThread(), mContext);
request->Init(originalURI, uri, channel, channel, entry, NS_GetCurrentThread(), mContext);
ProxyListener *pl = new ProxyListener(static_cast<nsIStreamListener *>(request));
if (!pl) {

View File

@ -96,6 +96,7 @@ imgRequest::~imgRequest()
}
nsresult imgRequest::Init(nsIURI *aURI,
nsIURI *aKeyURI,
nsIRequest *aRequest,
nsIChannel *aChannel,
imgCacheEntry *aCacheEntry,
@ -114,6 +115,7 @@ nsresult imgRequest::Init(nsIURI *aURI,
return NS_ERROR_OUT_OF_MEMORY;
mURI = aURI;
mKeyURI = aKeyURI;
mRequest = aRequest;
mChannel = aChannel;
mChannel->GetNotificationCallbacks(getter_AddRefs(mPrevChannelSink));
@ -323,6 +325,19 @@ nsresult imgRequest::GetURI(nsIURI **aURI)
return NS_ERROR_FAILURE;
}
nsresult imgRequest::GetKeyURI(nsIURI **aKeyURI)
{
LOG_FUNC(gImgLog, "imgRequest::GetKeyURI");
if (mKeyURI) {
*aKeyURI = mKeyURI;
NS_ADDREF(*aKeyURI);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
nsresult imgRequest::GetPrincipal(nsIPrincipal **aPrincipal)
{
LOG_FUNC(gImgLog, "imgRequest::GetPrincipal");
@ -1011,12 +1026,11 @@ imgRequest::OnChannelRedirect(nsIChannel *oldChannel, nsIChannel *newChannel, PR
mChannel = newChannel;
nsCOMPtr<nsIURI> uri;
newChannel->GetOriginalURI(getter_AddRefs(uri));
newChannel->GetOriginalURI(mKeyURI);
// If we don't still have a cache entry, we don't want to refresh the cache.
if (uri && mCacheEntry)
imgLoader::PutIntoCache(uri, mCacheEntry);
imgLoader::PutIntoCache(mKeyURI, mCacheEntry);
return rv;
}

View File

@ -89,6 +89,7 @@ public:
NS_DECL_ISUPPORTS
nsresult Init(nsIURI *aURI,
nsIURI *aKeyURI,
nsIRequest *aRequest,
nsIChannel *aChannel,
imgCacheEntry *aCacheEntry,
@ -127,6 +128,7 @@ private:
inline nsresult GetResultFromImageStatus(PRUint32 aStatus) const;
void Cancel(nsresult aStatus);
nsresult GetURI(nsIURI **aURI);
nsresult GetKeyURI(nsIURI **aURI);
nsresult GetPrincipal(nsIPrincipal **aPrincipal);
nsresult GetSecurityInfo(nsISupports **aSecurityInfo);
void RemoveFromCache();
@ -160,7 +162,10 @@ public:
private:
nsCOMPtr<nsIRequest> mRequest;
// The original URI we were loaded with.
nsCOMPtr<nsIURI> mURI;
// The URI we are keyed on in the cache.
nsCOMPtr<nsIURI> mKeyURI;
nsCOMPtr<nsIPrincipal> mPrincipal;
nsCOMPtr<imgIContainer> mImage;
nsCOMPtr<imgIDecoder> mDecoder;