From 94216118f13aaabe7601cff195e8c25e22288a4c Mon Sep 17 00:00:00 2001 From: "mscott%netscape.com" Date: Thu, 16 Dec 1999 06:06:00 +0000 Subject: [PATCH] Bug #21884 --> backing out Rick's changes to http to fix this regression crasher tonight. a=chofmann --- netwerk/protocol/http/src/nsHTTPChannel.cpp | 78 ++++++------------- netwerk/protocol/http/src/nsHTTPChannel.h | 5 -- netwerk/protocol/http/src/nsHTTPRequest.cpp | 6 +- .../http/src/nsHTTPResponseListener.cpp | 42 +++++----- .../http/src/nsHTTPResponseListener.h | 3 +- 5 files changed, 45 insertions(+), 89 deletions(-) diff --git a/netwerk/protocol/http/src/nsHTTPChannel.cpp b/netwerk/protocol/http/src/nsHTTPChannel.cpp index 741bc9538373..9dcc3cc92078 100644 --- a/netwerk/protocol/http/src/nsHTTPChannel.cpp +++ b/netwerk/protocol/http/src/nsHTTPChannel.cpp @@ -835,22 +835,20 @@ private: NS_IMETHOD OnDataAvailable(nsIChannel *aChannel, nsISupports *aContext, - nsIInputStream *aStream, PRUint32 aSourceOffset, - PRUint32 aCount) - { - return mListener->OnDataAvailable(mChannel, aContext, - aStream, aSourceOffset, aCount); + nsIInputStream *aStream, PRUint32 aSourceOffset, PRUint32 aCount) { + return mListener->OnDataAvailable(aChannel, aContext, aStream, aSourceOffset, aCount); } NS_IMETHOD OnStartRequest(nsIChannel *aChannel, nsISupports *aContext) { - return mListener->OnStartRequest(mChannel, aContext); + return mListener->OnStartRequest(aChannel, aContext); } NS_IMETHOD OnStopRequest(nsIChannel *aChannel, nsISupports *aContext, nsresult aStatus, const PRUnichar *aErrorMsg) { - return mChannel->ResponseCompleted(nsnull, mListener, aStatus, aErrorMsg); + mChannel->ResponseCompleted(0, aStatus, aErrorMsg); + return mListener->OnStopRequest(aChannel, aContext, aStatus, aErrorMsg); } protected: @@ -920,7 +918,7 @@ nsHTTPChannel::ReadFromCache(PRUint32 aStartPosition, PRInt32 aReadCount) mResponseContext, listener); NS_RELEASE(listener); if (NS_FAILED(rv)) { - ResponseCompleted(0, nsnull, rv, 0); + ResponseCompleted(0, rv, 0); } return rv; } @@ -1099,7 +1097,7 @@ nsHTTPChannel::Open(void) } if (NS_FAILED(rv)) { // Unable to create a transport... End the request... - (void) ResponseCompleted(nsnull, mResponseDataListener, rv, nsnull); + (void) ResponseCompleted(nsnull, rv, nsnull); return rv; } @@ -1107,7 +1105,7 @@ nsHTTPChannel::Open(void) rv = transport->SetNotificationCallbacks(this); if (NS_FAILED(rv)) { // Unable to create a transport... End the request... - (void) ResponseCompleted(nsnull, mResponseDataListener, rv, nsnull); + (void) ResponseCompleted(nsnull, rv, nsnull); return rv; } @@ -1244,47 +1242,11 @@ 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; @@ -1294,6 +1256,21 @@ 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; } @@ -1306,15 +1283,6 @@ 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) { diff --git a/netwerk/protocol/http/src/nsHTTPChannel.h b/netwerk/protocol/http/src/nsHTTPChannel.h index f10a16377459..4b345b183264 100644 --- a/netwerk/protocol/http/src/nsHTTPChannel.h +++ b/netwerk/protocol/http/src/nsHTTPChannel.h @@ -86,12 +86,9 @@ 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, @@ -104,8 +101,6 @@ public: nsresult FinishedResponseHeaders(); - nsresult GetDataConsumer(nsIStreamListener* *aListener); - protected: nsresult CheckCache(); nsresult ReadFromCache(PRUint32 aStartPosition, PRInt32 aReadCount); diff --git a/netwerk/protocol/http/src/nsHTTPRequest.cpp b/netwerk/protocol/http/src/nsHTTPRequest.cpp index 35617546798a..0139e577c093 100644 --- a/netwerk/protocol/http/src/nsHTTPRequest.cpp +++ b/netwerk/protocol/http/src/nsHTTPRequest.cpp @@ -498,11 +498,7 @@ nsHTTPRequest::OnStopRequest(nsIChannel* channel, nsISupports* i_Context, this, iStatus)); // Notify the HTTPChannel that the request has finished - nsCOMPtr consumer; - - mConnection->GetDataConsumer(getter_AddRefs(consumer)); - - mConnection->ResponseCompleted(mTransport, consumer, iStatus, i_Msg); + mConnection->ResponseCompleted(mTransport, iStatus, i_Msg); mTransport = null_nsCOMPtr(); rv = iStatus; diff --git a/netwerk/protocol/http/src/nsHTTPResponseListener.cpp b/netwerk/protocol/http/src/nsHTTPResponseListener.cpp index 302431d74ee8..f2b48ed874e3 100644 --- a/netwerk/protocol/http/src/nsHTTPResponseListener.cpp +++ b/netwerk/protocol/http/src/nsHTTPResponseListener.cpp @@ -59,6 +59,7 @@ static const int kMAX_HEADER_SIZE = 60000; nsHTTPResponseListener::nsHTTPResponseListener(nsHTTPChannel* aConnection): mFirstLineParsed(PR_FALSE), mHeadersDone(PR_FALSE), + mAborted(PR_FALSE), mResponse(nsnull), mBytesReceived(0) { @@ -177,7 +178,7 @@ nsHTTPResponseListener::OnDataAvailable(nsIChannel* channel, // Abort the connection if the consumer has been released. This will // happen if a redirect has been processed... // - if (!mResponseDataListener) { + if (mAborted) { // XXX: What should the return code be? rv = NS_BINDING_ABORTED; } @@ -246,13 +247,23 @@ nsHTTPResponseListener::OnStopRequest(nsIChannel* channel, // Notify the HTTPChannel that the response has completed... NS_ASSERTION(mChannel, "HTTPChannel is null."); if (mChannel) { - mChannel->ResponseCompleted(channel, mResponseDataListener, - i_Status, i_pMsg); - - // The HTTPChannel is no longer needed... - mChannel->mRawResponseListener = 0; + mChannel->ResponseCompleted(channel, i_Status, i_pMsg); } + // 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); @@ -262,21 +273,6 @@ 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; @@ -285,7 +281,7 @@ nsresult nsHTTPResponseListener::FireSingleOnData(nsIStreamListener *aListener, rv = FinishedResponseHeaders(); if (NS_FAILED(rv)) return rv; - if (mBytesReceived && mResponseDataListener) { + if (mBytesReceived) { rv = mResponseDataListener->OnDataAvailable(mChannel, mChannel->mResponseContext, mDataStream, 0, mBytesReceived); } @@ -503,7 +499,7 @@ nsresult nsHTTPResponseListener::FinishedResponseHeaders(void) // // Fire the OnStartRequest notification - now that user data is available // - if (NS_SUCCEEDED(rv) && mResponseDataListener) { + if (NS_SUCCEEDED(rv) && mResponseDataListener && !mAborted) { rv = mResponseDataListener->OnStartRequest(mChannel, mChannel->mResponseContext); if (NS_FAILED(rv)) { PR_LOG(gHTTPLog, PR_LOG_ERROR, diff --git a/netwerk/protocol/http/src/nsHTTPResponseListener.h b/netwerk/protocol/http/src/nsHTTPResponseListener.h index 18e11eb0d752..0657e4b86e7e 100644 --- a/netwerk/protocol/http/src/nsHTTPResponseListener.h +++ b/netwerk/protocol/http/src/nsHTTPResponseListener.h @@ -63,7 +63,7 @@ public: NS_DECL_NSISTREAMLISTENER nsresult FireSingleOnData(nsIStreamListener *aListener, nsISupports *aContext); - nsresult Abort(); + void Abort() { mAborted = PR_TRUE; } void SetResponseDataListener(nsIStreamListener *aListener) { mResponseDataListener = aListener; } @@ -86,6 +86,7 @@ protected: nsHTTPResponse* mResponse; PRBool mFirstLineParsed; PRBool mHeadersDone; + PRBool mAborted; nsCOMPtr mDataStream; PRUint32 mBytesReceived;