bug #21459 (r=warren). Made the consumer OnStopRequest fire before the channel is removed from the loadgroup...

This commit is contained in:
rpotts%netscape.com 1999-12-15 23:12:48 +00:00
parent 5818d49be7
commit 1aafb0dcce
5 changed files with 89 additions and 45 deletions

View File

@ -835,20 +835,22 @@ private:
NS_IMETHOD
OnDataAvailable(nsIChannel *aChannel, nsISupports *aContext,
nsIInputStream *aStream, PRUint32 aSourceOffset, PRUint32 aCount) {
return mListener->OnDataAvailable(aChannel, aContext, aStream, aSourceOffset, aCount);
nsIInputStream *aStream, PRUint32 aSourceOffset,
PRUint32 aCount)
{
return mListener->OnDataAvailable(mChannel, aContext,
aStream, aSourceOffset, aCount);
}
NS_IMETHOD
OnStartRequest(nsIChannel *aChannel, nsISupports *aContext) {
return mListener->OnStartRequest(aChannel, aContext);
return mListener->OnStartRequest(mChannel, aContext);
}
NS_IMETHOD
OnStopRequest(nsIChannel *aChannel, nsISupports *aContext,
nsresult aStatus, const PRUnichar *aErrorMsg) {
mChannel->ResponseCompleted(0, aStatus, aErrorMsg);
return mListener->OnStopRequest(aChannel, aContext, aStatus, aErrorMsg);
return mChannel->ResponseCompleted(nsnull, mListener, aStatus, aErrorMsg);
}
protected:
@ -918,7 +920,7 @@ nsHTTPChannel::ReadFromCache(PRUint32 aStartPosition, PRInt32 aReadCount)
mResponseContext, listener);
NS_RELEASE(listener);
if (NS_FAILED(rv)) {
ResponseCompleted(0, rv, 0);
ResponseCompleted(0, nsnull, rv, 0);
}
return rv;
}
@ -1097,7 +1099,7 @@ nsHTTPChannel::Open(void)
}
if (NS_FAILED(rv)) {
// Unable to create a transport... End the request...
(void) ResponseCompleted(nsnull, rv, nsnull);
(void) ResponseCompleted(nsnull, mResponseDataListener, rv, nsnull);
return rv;
}
@ -1105,7 +1107,7 @@ nsHTTPChannel::Open(void)
rv = transport->SetNotificationCallbacks(this);
if (NS_FAILED(rv)) {
// Unable to create a transport... End the request...
(void) ResponseCompleted(nsnull, rv, nsnull);
(void) ResponseCompleted(nsnull, mResponseDataListener, rv, nsnull);
return rv;
}
@ -1242,11 +1244,47 @@ nsresult nsHTTPChannel::Redirect(const char *aNewLocation,
nsresult nsHTTPChannel::ResponseCompleted(nsIChannel* aTransport,
nsIStreamListener *aListener,
nsresult aStatus,
const PRUnichar* aMsg)
{
nsresult rv = NS_OK;
//
// First:
//
// Call the consumer OnStopRequest(...) to end the request...
if (aListener) {
rv = aListener->OnStopRequest(this, mResponseContext, aStatus, aMsg);
if (NS_FAILED(rv)) {
PR_LOG(gHTTPLog, PR_LOG_ERROR,
("nsHTTPChannel::OnStopRequest(...) [this=%x]."
"\tOnStopRequest to consumer failed! Status:%x\n",
this, rv));
}
}
// Release the transport...
if (aTransport) {
(void)mHandler->ReleaseTransport(aTransport);
}
//
// After the consumer has been notified, remove the channel from its
// load group... This will trigger an OnStopRequest from the load group.
//
if (mLoadGroup) {
(void)mLoadGroup->RemoveChannel(this, nsnull, aStatus, nsnull);
}
//
// Finally, notify the OpenObserver that the request has completed.
//
if (mOpenObserver) {
(void) mOpenObserver->OnStopRequest(this, mOpenContext, aStatus, aMsg);
}
// Null out pointers that are no longer needed...
// rjc says: don't null out mResponseContext;
@ -1256,21 +1294,6 @@ nsresult nsHTTPChannel::ResponseCompleted(nsIChannel* aTransport,
mResponseDataListener = 0;
NS_IF_RELEASE(mCachedResponse);
// Release the transport...
if (aTransport) {
(void)mHandler->ReleaseTransport(aTransport);
}
// Remove the channel from its load group...
if (mLoadGroup) {
(void)mLoadGroup->RemoveChannel(this, nsnull, aStatus, nsnull);
}
if (mOpenObserver) {
rv = mOpenObserver->OnStopRequest(this, mOpenContext, aStatus, aMsg);
if (NS_FAILED(rv)) return rv;
}
return rv;
}
@ -1283,6 +1306,15 @@ nsresult nsHTTPChannel::SetResponse(nsHTTPResponse* i_pResp)
return NS_OK;
}
nsresult nsHTTPChannel::GetDataConsumer(nsIStreamListener* *aListener)
{
*aListener = mResponseDataListener;
NS_IF_ADDREF(*aListener);
return NS_OK;
}
nsresult nsHTTPChannel::GetResponseContext(nsISupports** aContext)
{
if (aContext) {

View File

@ -86,9 +86,12 @@ public:
nsresult Open();
nsresult Redirect(const char *aURL,
nsIChannel **aResult);
nsresult ResponseCompleted(nsIChannel* aTransport,
nsIStreamListener* aListener,
nsresult aStatus,
const PRUnichar* aMsg);
nsresult SetResponse(nsHTTPResponse* i_pResp);
nsresult GetResponseContext(nsISupports** aContext);
nsresult CacheReceivedResponse(nsIStreamListener *aListener,
@ -101,6 +104,8 @@ public:
nsresult FinishedResponseHeaders();
nsresult GetDataConsumer(nsIStreamListener* *aListener);
protected:
nsresult CheckCache();
nsresult ReadFromCache(PRUint32 aStartPosition, PRInt32 aReadCount);

View File

@ -498,7 +498,11 @@ nsHTTPRequest::OnStopRequest(nsIChannel* channel, nsISupports* i_Context,
this, iStatus));
// Notify the HTTPChannel that the request has finished
mConnection->ResponseCompleted(mTransport, iStatus, i_Msg);
nsCOMPtr<nsIStreamListener> consumer;
mConnection->GetDataConsumer(getter_AddRefs(consumer));
mConnection->ResponseCompleted(mTransport, consumer, iStatus, i_Msg);
mTransport = null_nsCOMPtr();
rv = iStatus;

View File

@ -59,7 +59,6 @@ static const int kMAX_HEADER_SIZE = 60000;
nsHTTPResponseListener::nsHTTPResponseListener(nsHTTPChannel* aConnection):
mFirstLineParsed(PR_FALSE),
mHeadersDone(PR_FALSE),
mAborted(PR_FALSE),
mResponse(nsnull),
mBytesReceived(0)
{
@ -178,7 +177,7 @@ nsHTTPResponseListener::OnDataAvailable(nsIChannel* channel,
// Abort the connection if the consumer has been released. This will
// happen if a redirect has been processed...
//
if (mAborted) {
if (!mResponseDataListener) {
// XXX: What should the return code be?
rv = NS_BINDING_ABORTED;
}
@ -247,23 +246,13 @@ nsHTTPResponseListener::OnStopRequest(nsIChannel* channel,
// Notify the HTTPChannel that the response has completed...
NS_ASSERTION(mChannel, "HTTPChannel is null.");
if (mChannel) {
mChannel->ResponseCompleted(channel, i_Status, i_pMsg);
mChannel->ResponseCompleted(channel, mResponseDataListener,
i_Status, i_pMsg);
// The HTTPChannel is no longer needed...
mChannel->mRawResponseListener = 0;
}
// Call the consumer OnStopRequest(...) to end the request...
if (mResponseDataListener && !mAborted) {
rv = mResponseDataListener->OnStopRequest(mChannel, mChannel->mResponseContext, i_Status, i_pMsg);
if (NS_FAILED(rv)) {
PR_LOG(gHTTPLog, PR_LOG_ERROR,
("nsHTTPChannel::OnStopRequest(...) [this=%x]."
"\tOnStopRequest to consumer failed! Status:%x\n",
this, rv));
}
}
// The HTTPChannel is no longer needed...
mChannel->mRawResponseListener = 0;
NS_IF_RELEASE(mChannel);
NS_IF_RELEASE(mResponse);
@ -273,6 +262,21 @@ nsHTTPResponseListener::OnStopRequest(nsIChannel* channel,
////////////////////////////////////////////////////////////////////////////////
// nsHTTPResponseListener methods:
nsresult nsHTTPResponseListener::Abort()
{
PR_LOG(gHTTPLog, PR_LOG_ALWAYS,
("nsHTTPResponseListener::Abort [this=%x].", this));
//
// Clearing the data consumer will cause the response to abort. This
// also prevents any more notifications from being passed out to the consumer.
//
mResponseDataListener = 0;
return NS_OK;
}
nsresult nsHTTPResponseListener::FireSingleOnData(nsIStreamListener *aListener, nsISupports *aContext)
{
nsresult rv;
@ -281,7 +285,7 @@ nsresult nsHTTPResponseListener::FireSingleOnData(nsIStreamListener *aListener,
rv = FinishedResponseHeaders();
if (NS_FAILED(rv)) return rv;
if (mBytesReceived) {
if (mBytesReceived && mResponseDataListener) {
rv = mResponseDataListener->OnDataAvailable(mChannel, mChannel->mResponseContext,
mDataStream, 0, mBytesReceived);
}
@ -499,7 +503,7 @@ nsresult nsHTTPResponseListener::FinishedResponseHeaders(void)
//
// Fire the OnStartRequest notification - now that user data is available
//
if (NS_SUCCEEDED(rv) && mResponseDataListener && !mAborted) {
if (NS_SUCCEEDED(rv) && mResponseDataListener) {
rv = mResponseDataListener->OnStartRequest(mChannel, mChannel->mResponseContext);
if (NS_FAILED(rv)) {
PR_LOG(gHTTPLog, PR_LOG_ERROR,

View File

@ -63,7 +63,7 @@ public:
NS_DECL_NSISTREAMLISTENER
nsresult FireSingleOnData(nsIStreamListener *aListener, nsISupports *aContext);
void Abort() { mAborted = PR_TRUE; }
nsresult Abort();
void SetResponseDataListener(nsIStreamListener *aListener) {
mResponseDataListener = aListener;
}
@ -86,7 +86,6 @@ protected:
nsHTTPResponse* mResponse;
PRBool mFirstLineParsed;
PRBool mHeadersDone;
PRBool mAborted;
nsCOMPtr<nsIInputStream> mDataStream;
PRUint32 mBytesReceived;