fixes bug 328903 "Image requests need to cancel properly" r=biesi sr=bzbarsky

git-svn-id: svn://10.0.0.236/trunk@192217 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
darin%meer.net
2006-03-11 20:32:47 +00:00
parent 9b1e02ab08
commit a7e9ed4e7f
3 changed files with 36 additions and 36 deletions

View File

@@ -502,7 +502,13 @@ NS_IMETHODIMP imgLoader::LoadImage(nsIURI *aURI,
imgCache::Put(aURI, request, getter_AddRefs(entry));
}
request->Init(newChannel, entry, cacheId, aCX);
// Create a loadgroup for this new channel. This way if the channel
// is redirected, we'll have a way to cancel the resulting channel.
nsCOMPtr<nsILoadGroup> loadGroup =
do_CreateInstance(NS_LOADGROUP_CONTRACTID);
newChannel->SetLoadGroup(loadGroup);
request->Init(aURI, loadGroup, entry, cacheId, aCX);
// create the proxy listener
ProxyListener *pl = new ProxyListener(NS_STATIC_CAST(nsIStreamListener *, request));
@@ -648,7 +654,12 @@ NS_IMETHODIMP imgLoader::LoadImageWithChannel(nsIChannel *channel, imgIDecoderOb
imgCache::Put(uri, request, getter_AddRefs(entry));
request->Init(channel, entry, activeQ.get(), aCX);
// XXX(darin): I'm not sure that using the original URI is correct here.
// Perhaps we should use the same URI that indexes the cache? Or, perhaps
// the cache should use the original URI? See bug 89419.
nsCOMPtr<nsIURI> originalURI;
channel->GetOriginalURI(getter_AddRefs(originalURI));
request->Init(originalURI, channel, entry, activeQ.get(), aCX);
ProxyListener *pl = new ProxyListener(NS_STATIC_CAST(nsIStreamListener *, request));
if (!pl) {
@@ -981,7 +992,12 @@ NS_IMETHODIMP imgCacheValidator::OnStartRequest(nsIRequest *aRequest, nsISupport
imgCache::Put(uri, request, getter_AddRefs(entry));
request->Init(channel, entry, activeQ.get(), mContext);
// XXX(darin): I'm not sure that using the original URI is correct here.
// Perhaps we should use the same URI that indexes the cache? Or, perhaps
// the cache should use the original URI? See bug 89419.
nsCOMPtr<nsIURI> originalURI;
channel->GetOriginalURI(getter_AddRefs(originalURI));
request->Init(originalURI, channel, entry, activeQ.get(), mContext);
ProxyListener *pl = new ProxyListener(NS_STATIC_CAST(nsIStreamListener *, request));
if (!pl) {

View File

@@ -91,21 +91,24 @@ imgRequest::~imgRequest()
/* destructor code */
}
nsresult imgRequest::Init(nsIChannel *aChannel,
nsresult imgRequest::Init(nsIURI *aURI,
nsIRequest *aRequest,
nsICacheEntryDescriptor *aCacheEntry,
void *aCacheId,
void *aLoadId)
{
LOG_FUNC(gImgLog, "imgRequest::Init");
NS_ASSERTION(!mImage, "imgRequest::Init -- Multiple calls to init");
NS_ASSERTION(aChannel, "imgRequest::Init -- No channel");
NS_ASSERTION(!mImage, "Multiple calls to init");
NS_ASSERTION(aURI, "No uri");
NS_ASSERTION(aRequest, "No request");
mProperties = do_CreateInstance("@mozilla.org/properties;1");
if (!mProperties)
return NS_ERROR_OUT_OF_MEMORY;
mChannel = aChannel;
mURI = aURI;
mRequest = aRequest;
/* set our loading flag to true here.
Setting it here lets checks to see if the load is in progress
@@ -172,7 +175,7 @@ nsresult imgRequest::RemoveProxy(imgRequestProxy *proxy, nsresult aStatus, PRBoo
This way, if a proxy is destroyed without calling cancel on it, it won't leak
and won't leave a bad pointer in mObservers.
*/
if (mChannel && mLoading && NS_FAILED(aStatus)) {
if (mRequest && mLoading && NS_FAILED(aStatus)) {
LOG_MSG(gImgLog, "imgRequest::RemoveProxy", "load in progress. canceling");
mImageStatus |= imgIRequest::STATUS_LOAD_PARTIAL;
@@ -285,17 +288,14 @@ void imgRequest::Cancel(nsresult aStatus)
RemoveFromCache();
if (mChannel && mLoading)
mChannel->Cancel(aStatus);
if (mRequest && mLoading)
mRequest->Cancel(aStatus);
}
nsresult imgRequest::GetURI(nsIURI **aURI)
{
LOG_FUNC(gImgLog, "imgRequest::GetURI");
if (mChannel)
return mChannel->GetOriginalURI(aURI);
if (mURI) {
*aURI = mURI;
NS_ADDREF(*aURI);
@@ -334,7 +334,7 @@ PRBool imgRequest::HaveProxyWithObserver(imgRequestProxy* aProxyToIgnore) const
PRInt32 imgRequest::Priority() const
{
PRInt32 priority = nsISupportsPriority::PRIORITY_NORMAL;
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(mChannel);
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(mRequest);
if (p)
p->GetPriority(&priority);
return priority;
@@ -352,7 +352,7 @@ void imgRequest::AdjustPriority(imgRequestProxy *proxy, PRInt32 delta)
if (mObservers[0] != proxy)
return;
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(mChannel);
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(mRequest);
if (p)
p->AdjustPriority(delta);
}
@@ -610,21 +610,7 @@ NS_IMETHODIMP imgRequest::OnStartRequest(nsIRequest *aRequest, nsISupports *ctxt
NS_ASSERTION(!mDecoder, "imgRequest::OnStartRequest -- we already have a decoder");
/* if mChannel isn't set here, use aRequest.
Having mChannel set is important for Canceling the load, and since we set
mChannel to null in OnStopRequest. Since with multipart/x-mixed-replace, you
can get multiple OnStartRequests, we need to reinstance mChannel so that when/if
Cancel() gets called, we have a channel to cancel and we don't leave the channel
open forever.
*/
nsCOMPtr<nsIMultiPartChannel> mpchan(do_QueryInterface(aRequest));
if (!mChannel) {
if (mpchan)
mpchan->GetBaseChannel(getter_AddRefs(mChannel));
else
mChannel = do_QueryInterface(aRequest);
}
if (mpchan)
mIsMultiPartChannel = PR_TRUE;
@@ -722,10 +708,7 @@ NS_IMETHODIMP imgRequest::OnStopRequest(nsIRequest *aRequest, nsISupports *ctxt,
/* set our processing flag to false */
mProcessing = PR_FALSE;
if (mChannel) {
mChannel->GetOriginalURI(getter_AddRefs(mURI));
mChannel = nsnull; // we no longer need the channel
}
mRequest = nsnull; // we no longer need the request
// If mImage is still null, we didn't properly load the image.
if (NS_FAILED(status) || !mImage) {

View File

@@ -47,7 +47,7 @@
#include "imgIDecoderObserver.h"
#include "nsICacheEntryDescriptor.h"
#include "nsIChannel.h"
#include "nsIRequest.h"
#include "nsIProperties.h"
#include "nsIStreamListener.h"
#include "nsIURI.h"
@@ -80,7 +80,8 @@ public:
NS_DECL_ISUPPORTS
nsresult Init(nsIChannel *aChannel,
nsresult Init(nsIURI *aURI,
nsIRequest *aRequest,
nsICacheEntryDescriptor *aCacheEntry,
void *aCacheId,
void *aLoadId);
@@ -138,7 +139,7 @@ public:
NS_DECL_NSIREQUESTOBSERVER
private:
nsCOMPtr<nsIChannel> mChannel;
nsCOMPtr<nsIRequest> mRequest;
nsCOMPtr<nsIURI> mURI;
nsCOMPtr<imgIContainer> mImage;
nsCOMPtr<imgIDecoder> mDecoder;