Fixes 64795 - Allows viewing FTP without the treewidget. r=valeski@netscape.com, sr=waterson@netscape.com

This commit is contained in:
dougt%netscape.com 2001-03-06 02:14:42 +00:00
parent af28bdfda7
commit 80614d95ae
7 changed files with 48 additions and 22 deletions

View File

@ -173,7 +173,7 @@ UnregisterBasicAuth(nsIComponentManager *aCompMgr, nsIFile *aPath,
#include "mozTXTToHTMLConv.h"
#include "nsUnknownDecoder.h"
#include "nsTXTToHTMLConv.h"
#include "nsIndexedToHTML.h"
nsresult NS_NewFTPDirListingConv(nsFTPDirListingConv** result);
nsresult NS_NewMultiMixedConv (nsMultiMixedConv** result);
nsresult MOZ_NewTXTToHTMLConv (mozTXTToHTMLConv** result);
@ -515,6 +515,12 @@ static nsModuleComponentInfo gNetModuleInfo[] = {
NS_ISTREAMCONVERTER_KEY "?from=text/ftp-dir-nt&to=application/http-index-format",
CreateNewFTPDirListingConv
},
{ "Indexed to HTML Converter",
NS_NSINDEXEDTOHTMLCONVERTER_CID,
NS_ISTREAMCONVERTER_KEY "?from=application/http-index-format&to=text/html",
nsIndexedToHTML::Create
},
{ "MultiMixedConverter",
NS_MULTIMIXEDCONVERTER_CID,

View File

@ -393,6 +393,7 @@ nsFTPChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallb
(void)mCallbacks->GetInterface(NS_GET_IID(nsIProgressEventSink),
getter_AddRefs(mEventSink));
(void)mCallbacks->GetInterface(NS_GET_IID(nsIPrompt),
getter_AddRefs(mPrompter));
}

View File

@ -52,7 +52,6 @@
#define NS_FTP_BUFFER_WRITE_SIZE (8*1024)
#define FTP_CACHE_CONTROL_CONNECTION 1
//#define FTP_NO_HTTP_INDEX_FORMAT
//#define FTP_SIMULATE_DROPPED_CONTROL_CONNECTION

View File

@ -42,11 +42,13 @@
#include "nsIProxy.h"
#include "nsIMemory.h"
#include "nsIStringStream.h"
#include "nsIPref.h"
#ifdef MOZ_NEW_CACHE
#include "nsIInputStreamTee.h"
#endif
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
static NS_DEFINE_CID(kWalletServiceCID, NS_WALLETSERVICE_CID);
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
@ -235,6 +237,12 @@ nsFtpState::nsFtpState() {
mIPv6ServerAddress = nsnull;
mControlConnection = nsnull;
mGenerateHTMLContent = PR_FALSE;
nsresult rv;
NS_WITH_SERVICE(nsIPref, pPref, kPrefCID, &rv);
if (NS_SUCCEEDED(rv) || pPref)
pPref->GetBoolPref("network.dir.generate_html", &mGenerateHTMLContent);
}
nsFtpState::~nsFtpState()
@ -1284,11 +1292,13 @@ nsFtpState::R_cwd() {
// update
mURL->SetPath(mCwd);
#ifdef FTP_NO_HTTP_INDEX_FORMAT
nsresult rv = mChannel->SetContentType("text/html");
#else
nsresult rv = mChannel->SetContentType("application/http-index-format");
#endif
nsresult rv;
if (mGenerateHTMLContent)
rv = mChannel->SetContentType("text/html");
else
rv = mChannel->SetContentType("application/http-index-format");
if (NS_FAILED(rv)) return FTP_ERROR;
// success
@ -1401,9 +1411,30 @@ nsFtpState::S_list() {
NS_WITH_SERVICE(nsIStreamConverterService, streamConvService, kStreamConverterServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
nsAutoString fromStr; fromStr.AssignWithConversion("text/ftp-dir-");
nsAutoString httpIndexFormatStr = NS_LITERAL_STRING("application/http-index-format");
nsAutoString fromStr = NS_LITERAL_STRING("text/ftp-dir-");
SetDirMIMEType(fromStr);
if (mGenerateHTMLContent) {
nsAutoString textHTMLStr = NS_LITERAL_STRING("text/html");
nsCOMPtr<nsIStreamListener> converterListener2;
rv = streamConvService->AsyncConvertData(httpIndexFormatStr.GetUnicode(), textHTMLStr.GetUnicode(),
mListener, mURL, getter_AddRefs(converterListener2));
if (NS_FAILED(rv)){
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("(%x) streamConvService->AsyncConvertData failed (rv=%d)\n", this, rv));
return rv;
}
rv = streamConvService->AsyncConvertData(fromStr.GetUnicode(), httpIndexFormatStr.GetUnicode(),
converterListener2, mURL, getter_AddRefs(converterListener));
} else {
rv = streamConvService->AsyncConvertData(fromStr.GetUnicode(), httpIndexFormatStr.GetUnicode(),
mListener, mURL, getter_AddRefs(converterListener));
}
#ifdef MOZ_NEW_CACHE
if ( mCacheEntry ) {
if (!mReadingFromCache) {
@ -1417,26 +1448,13 @@ nsFtpState::S_list() {
}
#endif
nsAutoString toStr; toStr.AssignWithConversion("application/http-index-format");
rv = streamConvService->AsyncConvertData(fromStr.GetUnicode(), toStr.GetUnicode(),
mListener, mURL, getter_AddRefs(converterListener));
if (NS_FAILED(rv)){
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("(%x) streamConvService->AsyncConvertData failed (rv=%d)\n", this, rv));
return rv;
}
mFireCallbacks = PR_FALSE; // listener callbacks will be handled by the transport.
DataRequestForwarder *forwarder = new DataRequestForwarder;
if (!forwarder) return NS_ERROR_FAILURE;
NS_ADDREF(forwarder);
#ifdef FTP_NO_HTTP_INDEX_FORMAT
fowarder->Init(mChannel, mListener);
#else
forwarder->Init(mChannel, converterListener);
#endif
#ifdef MOZ_NEW_CACHE
if (mCacheEntry && mReadingFromCache)

View File

@ -208,7 +208,7 @@ private:
nsCOMPtr<nsIInputStream> mWriteStream; // This stream is written to the server.
PRUint32 mWriteCount; // The amount of data to write to the server.
PRPackedBool mFireCallbacks; // Fire the listener callbacks.
PRBool mGenerateHTMLContent;
PRPackedBool mIPv6Checked;
nsCOMPtr<nsIPrompt> mPrompter;
char *mIPv6ServerAddress; // Server IPv6 address; null if server not IPv6

View File

@ -42,6 +42,7 @@ CPPSRCS = \
nsHTTPChunkConv.cpp \
nsHTTPCompressConv.cpp \
nsTXTToHTMLConv.cpp \
nsIndexedToHTML.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a

View File

@ -39,6 +39,7 @@ CPP_OBJS = \
.\$(OBJDIR)\nsHTTPCompressConv.obj \
.\$(OBJDIR)\nsUnknownDecoder.obj \
.\$(OBJDIR)\nsTXTToHTMLConv.obj \
.\$(OBJDIR)\nsIndexedToHTML.obj \
$(NULL)
include <$(DEPTH)\config\rules.mak>