r=rpotts, 17052. FTP now implements nsIProgressEventSink and sits inbetween the transport's notifications and the consumers.

This commit is contained in:
valeski%netscape.com 1999-11-30 15:07:32 +00:00
Родитель 8257b5e853
Коммит 643953578f
4 изменённых файлов: 50 добавлений и 29 удалений

Просмотреть файл

@ -68,7 +68,7 @@ nsFTPChannel::~nsFTPChannel() {
PR_LOG(gFTPLog, PR_LOG_ALWAYS, ("~nsFTPChannel() called"));
}
NS_IMPL_ISUPPORTS3(nsFTPChannel, nsPIFTPChannel, nsIChannel, nsIRequest);
NS_IMPL_ISUPPORTS5(nsFTPChannel, nsPIFTPChannel, nsIChannel, nsIRequest, nsIInterfaceRequestor, nsIProgressEventSink);
nsresult
nsFTPChannel::Init(const char* verb,
@ -218,7 +218,7 @@ nsFTPChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
NS_ADDREF(mConnThread); // keep our own ref to the thread obj (we'll
// release it later in this same call.
rv = mConnThread->Init(mHandler, this, nsnull, mCallbacks);
rv = mConnThread->Init(mHandler, this, nsnull);
mHandler = 0;
if (NS_FAILED(rv)) {
NS_RELEASE(mConnThread);
@ -270,7 +270,7 @@ nsFTPChannel::AsyncOpen(nsIStreamObserver *observer, nsISupports* ctxt)
mThreadRequest = do_QueryInterface((nsISupports*)(nsIRequest*)mConnThread);
rv = mConnThread->Init(mHandler, this, ctxt, mCallbacks);
rv = mConnThread->Init(mHandler, this, ctxt);
mHandler = 0;
if (NS_FAILED(rv)) {
NS_RELEASE(mConnThread);
@ -335,7 +335,7 @@ nsFTPChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
mThreadRequest = do_QueryInterface((nsISupports*)(nsIRequest*)mConnThread);
rv = mConnThread->Init(mHandler, this, ctxt, mCallbacks);
rv = mConnThread->Init(mHandler, this, ctxt);
mHandler = 0;
if (NS_FAILED(rv)) {
NS_RELEASE(mConnThread);
@ -542,3 +542,31 @@ nsFTPChannel::Stopped(nsresult aStatus, const PRUnichar *aMsg) {
return rv;
}
// nsIInterfaceRequestor method
NS_IMETHODIMP
nsFTPChannel::GetInterface(const nsIID &anIID, void **aResult ) {
// capture the progress event sink stuff. pass the rest through.
if (anIID.Equals(NS_GET_IID(nsIProgressEventSink))) {
*aResult = NS_STATIC_CAST(nsIProgressEventSink*, this);
NS_ADDREF(this);
return NS_OK;
} else {
return mCallbacks ? mCallbacks->GetInterface(anIID, aResult) : NS_ERROR_NO_INTERFACE;
}
}
// nsIProgressEventSink methods
NS_IMETHODIMP
nsFTPChannel::OnStatus(nsIChannel *aChannel,
nsISupports *aContext,
const PRUnichar *aMsg) {
return mEventSink ? mEventSink->OnStatus(this, aContext, aMsg) : NS_OK;
}
NS_IMETHODIMP
nsFTPChannel::OnProgress(nsIChannel* aChannel, nsISupports* aContext,
PRUint32 aProgress, PRUint32 aProgressMax) {
return mEventSink ? mEventSink->OnProgress(this, aContext, aProgress, aProgressMax) : NS_OK;
}

Просмотреть файл

@ -41,13 +41,18 @@
#include "nsAutoLock.h"
#include "nsFtpConnectionThread.h"
#include "netCore.h"
#include "nsIProgressEventSink.h"
class nsFTPChannel : public nsPIFTPChannel {
class nsFTPChannel : public nsPIFTPChannel,
public nsIInterfaceRequestor,
public nsIProgressEventSink {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL
NS_DECL_NSPIFTPCHANNEL
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSIPROGRESSEVENTSINK
// nsFTPChannel methods:
nsFTPChannel();

Просмотреть файл

@ -34,6 +34,7 @@
#include "nsProxiedService.h"
#include "nsAutoLock.h"
#include "nsCRT.h"
#include "nsIInterfaceRequestor.h"
#include "nsAppShellCIDs.h" // TODO remove later
#include "nsIAppShellService.h" // TODO remove later
@ -1395,6 +1396,7 @@ nsFtpConnectionThread::R_list() {
if (!listBuf) return FTP_ERROR;
rv = mDInStream->Read(listBuf, NS_FTP_BUFFER_READ_SIZE, &read);
if (NS_FAILED(rv)) {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x R_list() data pipe read failed w/ rv = %d\n", mURL.get(), rv));
nsAllocator::Free(listBuf);
@ -1564,6 +1566,12 @@ nsFtpConnectionThread::R_pasv() {
rv = mSTS->CreateTransport(host.GetBuffer(), port, nsnull, getter_AddRefs(mDPipe)); // the data channel
if (NS_FAILED(rv)) return FTP_ERROR;
// hook ourself up as a proxy for progress notifications
nsCOMPtr<nsIInterfaceRequestor> progressProxy(do_QueryInterface(mChannel));
rv = mDPipe->SetNotificationCallbacks(progressProxy);
if (NS_FAILED(rv)) return FTP_ERROR;
if (mAction == GET) {
// Setup the data channel for file reception
} else {
@ -1745,9 +1753,6 @@ nsFtpConnectionThread::Run() {
rv = mSTS->CreateTransport(host, mPort, host, getter_AddRefs(mCPipe)); // the command channel
if (NS_FAILED(rv)) return rv;
rv = mCPipe->SetNotificationCallbacks(mCallbacks);
if (NS_FAILED(rv)) return rv;
// get the output stream so we can write to the server
rv = mCPipe->OpenOutputStream(0, getter_AddRefs(mCOutStream));
if (NS_FAILED(rv)) return rv;
@ -1920,15 +1925,12 @@ nsFtpConnectionThread::Resume(void)
nsresult
nsFtpConnectionThread::Init(nsIProtocolHandler* aHandler,
nsIChannel* aChannel,
nsISupports* aContext,
nsIInterfaceRequestor* notificationCallbacks) {
nsISupports* aContext) {
nsresult rv;
// parameter validation
NS_ASSERTION(aChannel, "FTP: thread needs a channel");
mCallbacks = notificationCallbacks;
// setup internal member variables
mChannel = aChannel; // a straight com ptr to the channel
mContext = aContext; // this is the original caller's context
@ -2013,17 +2015,6 @@ nsFtpConnectionThread::StopProcessing() {
// kill the event loop
mKeepRunning = PR_FALSE;
NS_WITH_SERVICE(nsIProxyObjectManager, pIProxyObjectManager, kProxyObjectManagerCID, &rv);
if(NS_FAILED(rv)) return rv;
nsCOMPtr<nsPIFTPChannel> ftpChannel;
rv = pIProxyObjectManager->GetProxyObject(nsnull,
NS_GET_IID(nsPIFTPChannel),
mChannel,
PROXY_SYNC | PROXY_ALWAYS,
getter_AddRefs(ftpChannel));
if (NS_FAILED(rv)) return rv;
// setup any internal error message to propegate
if (NS_FAILED(mInternalError)) {
// generate a FTP specific error msg.
@ -2032,7 +2023,7 @@ nsFtpConnectionThread::StopProcessing() {
}
rv = ftpChannel->Stopped(mInternalError, errorMsg);
rv = mFTPChannel->Stopped(mInternalError, errorMsg);
if (NS_FAILED(rv)) return rv;
// if we have a listener, end the transaction.

Просмотреть файл

@ -27,7 +27,6 @@
#include "nsIRunnable.h"
#include "nsIRequest.h"
#include "nsISocketTransportService.h"
#include "nsIInterfaceRequestor.h"
#include "nsIServiceManager.h"
#include "nsIStreamListener.h"
#include "nsIURI.h"
@ -132,8 +131,7 @@ public:
nsresult Init(nsIProtocolHandler *aHandler,
nsIChannel *aChannel,
nsISupports *aContext,
nsIInterfaceRequestor* notificationCallbacks);
nsISupports *aContext);
nsresult Process();
@ -261,8 +259,7 @@ private:
nsString2 mContentType; // the content type of the data we're dealing w/.
nsXPIDLCString mURLSpec;
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
nsCOMPtr<nsPIFTPChannel> mFTPChannel;
nsCOMPtr<nsPIFTPChannel> mFTPChannel;
nsCOMPtr<nsIBufferInputStream> mBufInStream;
nsCOMPtr<nsIBufferOutputStream> mBufOutStream;