From 179bab7a56370e363e9ce508c6ed81a804e2fc1a Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Mon, 30 Sep 2002 21:50:18 +0000 Subject: [PATCH] Fixes two FTP bugs 148881 cancelling ftp download before save file dialog is present and 169214 Viewing an HTML page with a missing CSS file via FTP crash. r=rpotts@netscape.com, sr=darin@netscape.com --- netwerk/protocol/ftp/src/nsFTPChannel.cpp | 17 +++--- .../ftp/src/nsFtpConnectionThread.cpp | 55 +++++++++---------- .../protocol/ftp/src/nsFtpConnectionThread.h | 4 +- 3 files changed, 37 insertions(+), 39 deletions(-) diff --git a/netwerk/protocol/ftp/src/nsFTPChannel.cpp b/netwerk/protocol/ftp/src/nsFTPChannel.cpp index 038a0009b42..670e38da3ad 100644 --- a/netwerk/protocol/ftp/src/nsFTPChannel.cpp +++ b/netwerk/protocol/ftp/src/nsFTPChannel.cpp @@ -630,17 +630,18 @@ nsFTPChannel::OnStopRequest(nsIRequest *request, nsISupports* aContext, nsresult rv = NS_OK; - mStatus = aStatus; - + if (NS_SUCCEEDED(mStatus)) + mStatus = aStatus; + if (mListener) { - (void) mListener->OnStopRequest(this, mUserContext, aStatus); + (void) mListener->OnStopRequest(this, mUserContext, mStatus); } if (mLoadGroup) { - (void) mLoadGroup->RemoveRequest(this, nsnull, aStatus); + (void) mLoadGroup->RemoveRequest(this, nsnull, mStatus); } if (mCacheEntry) { - if (NS_SUCCEEDED(aStatus)) { + if (NS_SUCCEEDED(mStatus)) { (void) mCacheEntry->SetExpirationTime( NowInSeconds() + 900 ); // valid for 15 minutes. (void) mCacheEntry->MarkValid(); } @@ -666,12 +667,14 @@ nsFTPChannel::OnStartRequest(nsIRequest *request, nsISupports *aContext) ("nsFTPChannel::OnStartRequest() called [this=%x, request=%x]\n", this, request)); - nsresult rv = NS_OK; - request->GetStatus(&mStatus); + if (NS_SUCCEEDED(mStatus)) + request->GetStatus(&mStatus); + nsCOMPtr resumable = do_QueryInterface(request); if (resumable) resumable->GetEntityID(getter_AddRefs(mEntityID)); + nsresult rv = NS_OK; if (mListener) { rv = mListener->OnStartRequest(this, mUserContext); if (NS_FAILED(rv)) return rv; diff --git a/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp b/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp index bb9665f3318..f0595bf1788 100644 --- a/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp +++ b/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp @@ -115,7 +115,6 @@ public: PRUint32 GetBytesTransfered() {return mBytesTransfered;} ; void Uploading(PRBool value); void SetRetrying(PRBool retry); - PRBool HaveFiredNotification() { return mFired; }; protected: @@ -130,7 +129,7 @@ protected: PRPackedBool mDelayedOnStartFired; PRPackedBool mUploading; PRPackedBool mRetrying; - PRPackedBool mFired; + nsresult DelayedOnStartRequest(nsIRequest *request, nsISupports *ctxt); }; @@ -153,8 +152,7 @@ NS_IMPL_THREADSAFE_ISUPPORTS8(DataRequestForwarder, DataRequestForwarder::DataRequestForwarder() { PR_LOG(gFTPLog, PR_LOG_DEBUG, ("(%x) DataRequestForwarder CREATED\n", this)); - - mFired = PR_FALSE; + mBytesTransfered = 0; mRetrying = mUploading = mDelayedOnStartFired = PR_FALSE; NS_INIT_ISUPPORTS(); @@ -278,7 +276,6 @@ nsresult DataRequestForwarder::DelayedOnStartRequest(nsIRequest *request, nsISupports *ctxt) { PR_LOG(gFTPLog, PR_LOG_DEBUG, ("(%x) DataRequestForwarder DelayedOnStartRequest \n", this)); - mFired = PR_TRUE; return mListener->OnStartRequest(this, ctxt); } @@ -1963,19 +1960,8 @@ nsFtpState::Cancel(nsresult status) if (NS_SUCCEEDED(mControlStatus)) mControlStatus = status; - // kill the data connection immediately. But first, save it's - // notification-firing state - PRBool fired = PR_FALSE; - if (mDRequestForwarder) { - fired = mDRequestForwarder->HaveFiredNotification(); - NS_RELEASE(mDRequestForwarder); - } - if (mDPipeRequest) { - mDPipeRequest->Cancel(status); - mDPipeRequest = 0; - } - - (void) StopProcessing(fired); + if (mKeepRunning) + (void) StopProcessing(); return NS_OK; } @@ -2374,7 +2360,7 @@ nsFtpState::KillControlConnection() { } nsresult -nsFtpState::StopProcessing(PRBool aPreventNotification) { +nsFtpState::StopProcessing() { PR_LOG(gFTPLog, PR_LOG_ALWAYS, ("(%x) nsFtpState stopping", this)); #ifdef DEBUG_dougt @@ -2395,17 +2381,28 @@ nsFtpState::StopProcessing(PRBool aPreventNotification) { if ( NS_SUCCEEDED(broadcastErrorCode)) broadcastErrorCode = mInternalError; - if (mChannel && !aPreventNotification && - ( (!mDRequestForwarder) || - ( mDRequestForwarder && !mDRequestForwarder->HaveFiredNotification() ))) { - nsCOMPtr channelListener = do_QueryInterface(mChannel); - NS_ASSERTION(channelListener, "ftp channel should be a stream listener"); - nsCOMPtr asyncListener; - NS_NewAsyncStreamListener(getter_AddRefs(asyncListener), channelListener, NS_UI_THREAD_EVENTQ); - if(asyncListener) { - (void) asyncListener->OnStartRequest(this, nsnull); - (void) asyncListener->OnStopRequest(this, nsnull, broadcastErrorCode); + if (mDPipeRequest && NS_FAILED(broadcastErrorCode)) + mDPipeRequest->Cancel(broadcastErrorCode); + + if (mDRequestForwarder) { + NS_RELEASE(mDRequestForwarder); + } + else + { + // The forwarding object was never created which means that we never sent our notifications. + + nsCOMPtr asyncObserver = do_QueryInterface(mChannel); + nsCOMPtr arg = do_QueryInterface(mChannel); + + NS_NewRequestObserverProxy(getter_AddRefs(asyncObserver), + arg, + NS_CURRENT_EVENTQ); + if(asyncObserver) { + (void) asyncObserver->OnStartRequest(this, nsnull); + (void) asyncObserver->OnStopRequest(this, nsnull, broadcastErrorCode); } + + } // Clean up the event loop diff --git a/netwerk/protocol/ftp/src/nsFtpConnectionThread.h b/netwerk/protocol/ftp/src/nsFtpConnectionThread.h index a75e0d7faa7..4814e88ec8c 100644 --- a/netwerk/protocol/ftp/src/nsFtpConnectionThread.h +++ b/netwerk/protocol/ftp/src/nsFtpConnectionThread.h @@ -161,9 +161,7 @@ private: nsresult Process(); void KillControlConnection(); - // Set aPreventNotification to true if StopProcessing should not - // notify the listener. - nsresult StopProcessing(PRBool aPreventNotification = PR_FALSE); + nsresult StopProcessing(); nsresult EstablishControlConnection(); nsresult SendFTPCommand(nsCString& command); void ConvertFilespecToVMS(nsCString& fileSpec);