diff --git a/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.cpp b/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.cpp index 4e4e5b12b69..6f4e4c14eae 100644 --- a/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.cpp +++ b/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.cpp @@ -49,9 +49,9 @@ nsFTPChannel::nsFTPChannel() mSourceOffset(0), mAmount(0), mContentLength(-1), - mLock(nsnull), mBufferSegmentSize(0), mBufferMaxSize(0), + mLock(nsnull), mStatus(NS_OK) { NS_INIT_REFCNT(); @@ -254,7 +254,8 @@ nsFTPChannel::OpenInputStream(nsIInputStream **result) if (!thread) return NS_ERROR_OUT_OF_MEMORY; mConnThread = thread; - rv = thread->Init(mHandler, this, mBufferSegmentSize, mBufferMaxSize); + rv = thread->Init(mHandler, this, mPrompter, + mBufferSegmentSize, mBufferMaxSize); mHandler = 0; if (NS_FAILED(rv)) return rv; @@ -327,7 +328,8 @@ nsFTPChannel::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt) if (!thread) return NS_ERROR_OUT_OF_MEMORY; mConnThread = thread; - rv = thread->Init(mHandler, this, mBufferSegmentSize, mBufferMaxSize); + rv = thread->Init(mHandler, this, mPrompter, + mBufferSegmentSize, mBufferMaxSize); mHandler = nsnull; if (NS_FAILED(rv)) return rv; @@ -365,7 +367,8 @@ nsFTPChannel::AsyncWrite(nsIInputStream *fromStream, if (!thread) return NS_ERROR_OUT_OF_MEMORY; mConnThread = thread; - rv = thread->Init(mHandler, this, mBufferSegmentSize, mBufferMaxSize); + rv = thread->Init(mHandler, this, mPrompter, + mBufferSegmentSize, mBufferMaxSize); mHandler = 0; if (NS_FAILED(rv)) return rv; @@ -576,11 +579,11 @@ nsFTPChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallb mCallbacks = aNotificationCallbacks; if (mCallbacks) { - nsresult rv = mCallbacks->GetInterface(NS_GET_IID(nsIProgressEventSink), - getter_AddRefs(mEventSink)); - if (NS_FAILED(rv)) { - PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFTPChannel::Init() (couldn't find event sink)\n")); - } + (void)mCallbacks->GetInterface(NS_GET_IID(nsIProgressEventSink), + getter_AddRefs(mEventSink)); + + (void)mCallbacks->GetInterface(NS_GET_IID(nsIPrompt), + getter_AddRefs(mPrompter)); } return NS_OK; } diff --git a/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.h b/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.h index 42d264f3b18..93cc2700581 100644 --- a/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.h +++ b/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.h @@ -38,6 +38,7 @@ #include "nsXPIDLString.h" #include "nsIStreamListener.h" #include "nsAutoLock.h" +#include "nsIPrompt.h" class nsFTPChannel : public nsIChannel, public nsIInterfaceRequestor, @@ -73,6 +74,7 @@ protected: nsCOMPtr mOriginalURI; nsCOMPtr mURL; nsCOMPtr mEventSink; + nsCOMPtr mPrompter; nsCOMPtr mCallbacks; PRBool mConnected; diff --git a/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp b/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp index d38deea9a15..416ff84a95b 100644 --- a/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp +++ b/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp @@ -36,17 +36,9 @@ #include "nsEscape.h" #include "nsNetUtil.h" -#include "nsAppShellCIDs.h" // TODO remove later -#include "nsIAppShellService.h" // TODO remove later -#include "nsIXULWindow.h" // TODO remove later -#include "nsINetPrompt.h" - static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID); static NS_DEFINE_CID(kMIMEServiceCID, NS_MIMESERVICE_CID); - -static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); static NS_DEFINE_CID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID); - static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); @@ -81,7 +73,7 @@ nsFtpConnectionThread::nsFtpConnectionThread() { mPasv = 0; mLastModified = LL_ZERO; mAsyncReadEvent = 0; - mWriteCount = -1; + mWriteCount = 0; mBufferSegmentSize = 0; mBufferMaxSize = 0; } @@ -788,20 +780,16 @@ nsFtpConnectionThread::S_user() { usernameStr.Append("anonymous"); } else { if (!mUsername.Length()) { + if (!mPrompter) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr appShellService(do_GetService(kAppShellServiceCID)); - NS_ENSURE_TRUE(appShellService, NS_ERROR_FAILURE); - - nsCOMPtr xulWindow; - appShellService->GetHiddenWindow(getter_AddRefs( xulWindow ) ); - nsCOMPtr prompter( do_QueryInterface( xulWindow ) ); - - NS_WITH_SERVICE(nsIProxyObjectManager, pIProxyObjectManager, kProxyObjectManagerCID, &rv); + NS_WITH_SERVICE(nsIProxyObjectManager, pIProxyObjectManager, + kProxyObjectManagerCID, &rv); if (NS_FAILED(rv)) return rv; - nsCOMPtr proxyprompter; + + nsCOMPtr proxyprompter; rv = pIProxyObjectManager->GetProxyObject(NS_UI_THREAD_EVENTQ, - NS_GET_IID(nsINetPrompt), prompter, + NS_GET_IID(nsIPrompt), mPrompter, PROXY_SYNC, getter_AddRefs(proxyprompter)); PRUnichar *user = nsnull, *passwd = nsnull; PRBool retval; @@ -814,7 +802,9 @@ nsFtpConnectionThread::S_user() { message += host; } - rv = proxyprompter->PromptUsernameAndPassword(host, PR_TRUE, NULL, message.GetUnicode(), &user, &passwd, &retval); + rv = proxyprompter->PromptUsernameAndPassword(message.GetUnicode(), + &user, &passwd, &retval); + // if the user canceled or didn't supply a username we want to fail if (!retval || (user && !*user) ) return NS_ERROR_FAILURE; @@ -867,34 +857,21 @@ nsFtpConnectionThread::S_pass() { passwordStr.Append("mozilla@"); } else { if (!mPassword.Length() || mRetryPass) { - // ignore any password we have, it's not working - nsCOMPtr appShellService(do_GetService(kAppShellServiceCID)); - NS_ENSURE_TRUE(appShellService, NS_ERROR_FAILURE); + if (!mPrompter) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr xulWindow; - appShellService->GetHiddenWindow(getter_AddRefs( xulWindow ) ); - nsCOMPtr prompter( do_QueryInterface( xulWindow ) ); - - NS_WITH_SERVICE(nsIProxyObjectManager, pIProxyObjectManager, kProxyObjectManagerCID, &rv); + NS_WITH_SERVICE(nsIProxyObjectManager, pIProxyObjectManager, + kProxyObjectManagerCID, &rv); if (NS_FAILED(rv)) return rv; - - nsCOMPtr proxyprompter; + + nsCOMPtr proxyprompter; rv = pIProxyObjectManager->GetProxyObject(NS_UI_THREAD_EVENTQ, - NS_GET_IID(nsINetPrompt), prompter, + NS_GET_IID(nsIPrompt), mPrompter, PROXY_SYNC, getter_AddRefs(proxyprompter)); PRUnichar *passwd = nsnull; PRBool retval; static nsAutoString message; - nsXPIDLCString host2; - rv = mURL->GetHost(getter_Copies(host2)); - if (NS_FAILED(rv)) { - return rv; - } - nsAutoString userAtHost; - userAtHost = mUsername; - userAtHost += "@"; - userAtHost += host2; - char * userAtHostC = userAtHost.ToNewCString(); + nsAutoString title("Password"); + if (message.Length() < 1) { nsXPIDLCString host; rv = mURL->GetHost(getter_Copies(host)); @@ -904,8 +881,9 @@ nsFtpConnectionThread::S_pass() { message += " on "; message += host; } - rv = proxyprompter->PromptPassword(userAtHostC, PR_TRUE, NULL, message.GetUnicode(), &passwd, &retval); - nsCRT::free(userAtHostC); + rv = proxyprompter->PromptPassword(message.GetUnicode(), + title.GetUnicode(), + &passwd, &retval); // we want to fail if the user canceled or didn't enter a password. if (!retval || (passwd && !*passwd) ) @@ -1581,12 +1559,15 @@ nsFtpConnectionThread::Resume(void) nsresult nsFtpConnectionThread::Init(nsIProtocolHandler* aHandler, nsIChannel* aChannel, + nsIPrompt* aPrompter, PRUint32 bufferSegmentSize, PRUint32 bufferMaxSize) { nsresult rv = NS_OK; if (mConnected) return NS_ERROR_ALREADY_CONNECTED; + mPrompter = aPrompter; + mBufferSegmentSize = bufferSegmentSize; mBufferMaxSize = bufferMaxSize; diff --git a/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.h b/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.h index 8bb50474223..ed3dbd64fbc 100644 --- a/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.h +++ b/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.h @@ -41,6 +41,7 @@ #include "nsIBufferOutputStream.h" #include "nsAutoLock.h" #include "nsIEventQueueService.h" +#include "nsIPrompt.h" // ftp server types #define FTP_GENERIC_TYPE 0 @@ -95,6 +96,7 @@ public: nsresult Init(nsIProtocolHandler *aHandler, nsIChannel *aChannel, + nsIPrompt *aPrompter, PRUint32 bufferSegmentSize, PRUint32 bufferMaxSize); @@ -211,6 +213,7 @@ private: PRBool mFireCallbacks; // Fire the listener callbacks. nsCOMPtr mEventQueue; + nsCOMPtr mPrompter; }; #define NS_FTP_BUFFER_READ_SIZE (8*1024)