From 9e6e105dfdeefbf3d2fc1034f44b23b5b0aee73c Mon Sep 17 00:00:00 2001 From: "dougt%meer.net" Date: Thu, 9 Nov 2006 22:47:43 +0000 Subject: [PATCH] exposing the network status of a image request to wpl consumers. bug 355555. r=stuart. git-svn-id: svn://10.0.0.236/trunk@215060 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/modules/libpr0n/src/imgRequest.cpp | 18 +++++++++++++++++- mozilla/modules/libpr0n/src/imgRequest.h | 7 +++++-- .../modules/libpr0n/src/imgRequestProxy.cpp | 9 +++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/mozilla/modules/libpr0n/src/imgRequest.cpp b/mozilla/modules/libpr0n/src/imgRequest.cpp index 8f531892674..2b532f7acd9 100644 --- a/mozilla/modules/libpr0n/src/imgRequest.cpp +++ b/mozilla/modules/libpr0n/src/imgRequest.cpp @@ -79,7 +79,7 @@ NS_IMPL_ISUPPORTS6(imgRequest, imgILoad, imgRequest::imgRequest() : mObservers(0), mLoading(PR_FALSE), mProcessing(PR_FALSE), mHadLastPart(PR_FALSE), - mImageStatus(imgIRequest::STATUS_NONE), mState(0), + mNetworkStatus(0), mImageStatus(imgIRequest::STATUS_NONE), mState(0), mCacheId(0), mValidator(nsnull), mIsMultiPartChannel(PR_FALSE) { /* member initializers and constructor code */ @@ -738,6 +738,10 @@ NS_IMETHODIMP imgRequest::OnStopRequest(nsIRequest *aRequest, nsISupports *ctxt, } // XXXldb What if this is a non-last part of a multipart request? + // xxx before we release our reference to mChannel, lets + // save the last status that we saw so that the + // imgRequestProxy will have access to it. + mRequest->GetStatus(&mNetworkStatus); mRequest = nsnull; // we no longer need the request // If mImage is still null, we didn't properly load the image. @@ -928,3 +932,15 @@ imgRequest::SniffMimeType(const char *buf, PRUint32 len) { imgLoader::GetMimeTypeFromContent(buf, len, mContentType); } + +nsresult +imgRequest::GetNetworkStatus() +{ + nsresult status; + if (mRequest) + mRequest->GetStatus(&status); + else + status = mNetworkStatus; + + return status; +} diff --git a/mozilla/modules/libpr0n/src/imgRequest.h b/mozilla/modules/libpr0n/src/imgRequest.h index 9b36f135d45..0246a162627 100644 --- a/mozilla/modules/libpr0n/src/imgRequest.h +++ b/mozilla/modules/libpr0n/src/imgRequest.h @@ -102,6 +102,10 @@ public: // being made... PRBool IsReusable(void *aCacheId) { return !mLoading || (aCacheId == mCacheId); } + // get the current or last network status from our + // internal nsIChannel. + nsresult GetNetworkStatus(); + private: friend class imgRequestProxy; friend class imgLoader; @@ -155,10 +159,9 @@ private: PRPackedBool mLoading; PRPackedBool mProcessing; PRPackedBool mHadLastPart; - + PRUint32 mNetworkStatus; PRUint32 mImageStatus; PRUint32 mState; - nsCString mContentType; nsCOMPtr mCacheEntry; /* we hold on to this to this so long as we have observers */ diff --git a/mozilla/modules/libpr0n/src/imgRequestProxy.cpp b/mozilla/modules/libpr0n/src/imgRequestProxy.cpp index 59cbc52ce40..8548cb1aea9 100644 --- a/mozilla/modules/libpr0n/src/imgRequestProxy.cpp +++ b/mozilla/modules/libpr0n/src/imgRequestProxy.cpp @@ -187,13 +187,18 @@ NS_IMETHODIMP imgRequestProxy::GetName(nsACString &aName) /* boolean isPending (); */ NS_IMETHODIMP imgRequestProxy::IsPending(PRBool *_retval) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_NOT_IMPLEMENTED; } /* readonly attribute nsresult status; */ NS_IMETHODIMP imgRequestProxy::GetStatus(nsresult *aStatus) { - return NS_ERROR_NOT_IMPLEMENTED; + if (!mOwner) + return NS_ERROR_FAILURE; + + *aStatus = mOwner->GetNetworkStatus(); + + return NS_OK; } /* void cancel (in nsresult status); */