Bug 110760 - directory listings shouldn't reuly on libappcomps.
Also fixes bug 102826 & related issues. r=dougt, sr=darin git-svn-id: svn://10.0.0.236/trunk@114994 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -78,6 +78,7 @@
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsIHistoryEntry.h"
|
||||
#include "nsISHistoryListener.h"
|
||||
#include "nsIDirectoryListing.h"
|
||||
|
||||
// Editor-related
|
||||
#include "nsIEditingSession.h"
|
||||
@@ -4618,6 +4619,11 @@ nsresult nsDocShell::DoURILoad(nsIURI * aURI,
|
||||
httpChannel->SetReferrer(aReferrerURI,
|
||||
nsIHttpChannel::REFERRER_LINK_CLICK);
|
||||
}
|
||||
// We want to use the pref for directory listings
|
||||
nsCOMPtr<nsIDirectoryListing> dirList = do_QueryInterface(channel);
|
||||
if (dirList) {
|
||||
(void)dirList->SetListFormat(nsIDirectoryListing::FORMAT_PREF);
|
||||
}
|
||||
//
|
||||
// Set the owner of the channel - only for javascript and data channels.
|
||||
//
|
||||
|
||||
@@ -440,7 +440,9 @@ pref("network.http.proxy.ssl.connect",true);
|
||||
// Idle timeout for ftp control connections - 5 minute default
|
||||
pref("network.ftp.idleConnectionTimeout", 300);
|
||||
|
||||
pref("network.dir.generate_html", true);
|
||||
// directory listing format - constants are defined in nsIDirectoryListing.idl
|
||||
// Do not set this to 0...
|
||||
pref("network.dir.format", 2);
|
||||
|
||||
// sspitzer: change this back to "news" when we get to beta.
|
||||
// for now, set this to news.mozilla.org because you can only
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
nsIAuthenticator.idl
|
||||
nsIAuthPrompt.idl
|
||||
nsIChannel.idl
|
||||
nsIFileChannel.idl
|
||||
nsIDirectoryListing.idl
|
||||
nsIDownloader.idl
|
||||
nsIFileChannel.idl
|
||||
nsIFileTransportService.idl
|
||||
nsIMIMEInputStream.idl
|
||||
nsIPasswordManager.idl
|
||||
|
||||
@@ -32,8 +32,9 @@ XPIDLSRCS = \
|
||||
nsIAuthenticator.idl \
|
||||
nsIAuthPrompt.idl \
|
||||
nsIChannel.idl \
|
||||
nsIFileChannel.idl \
|
||||
nsIDirectoryListing.idl \
|
||||
nsIDownloader.idl \
|
||||
nsIFileChannel.idl \
|
||||
nsIFileStreams.idl \
|
||||
nsIFileTransportService.idl \
|
||||
nsIIOService.idl \
|
||||
|
||||
@@ -32,9 +32,10 @@ EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
XPIDLSRCS = \
|
||||
.\nsIAuthenticator.idl \
|
||||
.\nsIAuthenticator.idl \
|
||||
.\nsIAuthPrompt.idl \
|
||||
.\nsIChannel.idl \
|
||||
.\nsIDirectoryListing.idl \
|
||||
.\nsIFileChannel.idl \
|
||||
.\nsIFileStreams.idl \
|
||||
.\nsIFileTransportService.idl \
|
||||
|
||||
68
mozilla/netwerk/base/public/nsIDirectoryListing.idl
Normal file
68
mozilla/netwerk/base/public/nsIDirectoryListing.idl
Normal file
@@ -0,0 +1,68 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bradley Baetz
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001, 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Bradley Baetz <bbaetz@student.usyd.edu.au>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/** This interface allows setting the output format for a directory listing
|
||||
* Implementations of this interface should default to html, since that is the
|
||||
* lowest common denominator which all places can deal with.
|
||||
*/
|
||||
[scriptable, uuid(a465d8ed-3661-483d-a6f1-a82a6bd617b3)]
|
||||
interface nsIDirectoryListing : nsISupports {
|
||||
/** Use the pref */
|
||||
const unsigned long FORMAT_PREF = 0;
|
||||
|
||||
/** Raw format - exactly what comes off the network. It is very
|
||||
* unlikely that you want this
|
||||
*/
|
||||
const unsigned long FORMAT_RAW = 1;
|
||||
|
||||
/** HTML */
|
||||
const unsigned long FORMAT_HTML = 2;
|
||||
|
||||
/** application/http-index-format
|
||||
* This will end up at the code in xpfe/components/directory so if
|
||||
* you explicitly set this, be sure that this dependancy is OK
|
||||
*/
|
||||
const unsigned long FORMAT_HTTP_INDEX = 3;
|
||||
|
||||
/** The actual format
|
||||
* If the given format is not supported, NS_ERROR_FAILURE is returned.
|
||||
* The getter for this returns the actual value, having translated
|
||||
* FORMAT_PREF into the current pref format
|
||||
*/
|
||||
attribute unsigned long listFormat;
|
||||
};
|
||||
@@ -231,14 +231,14 @@ nsDirectoryIndexStream::Init(nsIFile* aDir)
|
||||
rv = pc->GetCharset(kPlatformCharsetSel_FileName, tmp);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mFSCharset.Adopt(ToNewCString(tmp));
|
||||
#else
|
||||
mFSCharset.Assign(NS_LITERAL_CSTRING("ISO-8859-1"));
|
||||
#endif
|
||||
}
|
||||
|
||||
mBuf.Append("301: ");
|
||||
mBuf.Append(mFSCharset);
|
||||
mBuf.Append('\n');
|
||||
|
||||
if (!mFSCharset.IsEmpty()) {
|
||||
mBuf.Append("301: ");
|
||||
mBuf.Append(mFSCharset);
|
||||
mBuf.Append('\n');
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -1435,6 +1435,13 @@
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS></FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIDirectoryListing.idl</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS></FILEFLAGS>
|
||||
</FILE>
|
||||
</FILELIST>
|
||||
<LINKORDER>
|
||||
<FILEREF>
|
||||
@@ -1862,6 +1869,11 @@
|
||||
<PATH>nsIResumableEntityID.idl</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIDirectoryListing.idl</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
</LINKORDER>
|
||||
</TARGET>
|
||||
<TARGET>
|
||||
@@ -3239,6 +3251,13 @@
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS></FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIDirectoryListing.idl</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS></FILEFLAGS>
|
||||
</FILE>
|
||||
</FILELIST>
|
||||
<LINKORDER>
|
||||
<FILEREF>
|
||||
@@ -3661,6 +3680,11 @@
|
||||
<PATH>nsIResumableEntityID.idl</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIDirectoryListing.idl</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
</LINKORDER>
|
||||
</TARGET>
|
||||
</TARGETLIST>
|
||||
@@ -4207,6 +4231,12 @@
|
||||
<PATH>nsIMultiPartChannel.idl</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<TARGETNAME>headers</TARGETNAME>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIDirectoryListing.idl</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
</GROUPLIST>
|
||||
|
||||
</PROJECT>
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "nsMimeTypes.h"
|
||||
#include "nsIProxyObjectManager.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsIPref.h"
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
extern PRLogModuleInfo* gFTPLog;
|
||||
@@ -77,6 +78,7 @@ PRTimeToSeconds(PRTime t_usec)
|
||||
nsFTPChannel::nsFTPChannel()
|
||||
: mIsPending(0),
|
||||
mLoadFlags(LOAD_NORMAL),
|
||||
mListFormat(FORMAT_HTML),
|
||||
mSourceOffset(0),
|
||||
mAmount(0),
|
||||
mContentLength(-1),
|
||||
@@ -113,6 +115,7 @@ NS_INTERFACE_MAP_BEGIN(nsFTPChannel)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
|
||||
NS_INTERFACE_MAP_ENTRY(nsICacheListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDirectoryListing)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIChannel)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
@@ -736,3 +739,40 @@ nsFTPChannel::SetUploadFile(nsIFile *file, const char *contentType, PRInt32 cont
|
||||
// set the stream on ourselves
|
||||
return SetUploadStream(stream, nsnull, -1);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFTPChannel::SetListFormat(PRUint32 format) {
|
||||
if (format != FORMAT_PREF &&
|
||||
format != FORMAT_RAW &&
|
||||
format != FORMAT_HTML &&
|
||||
format != FORMAT_HTTP_INDEX) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Convert the pref value
|
||||
if (format == FORMAT_PREF) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
PRInt32 sFormat;
|
||||
rv = prefs->GetIntPref("network.dir.format", &sFormat);
|
||||
if (NS_FAILED(rv))
|
||||
format = FORMAT_HTML; // default
|
||||
else
|
||||
format = sFormat;
|
||||
|
||||
if (format == FORMAT_PREF) {
|
||||
NS_WARNING("Who set the directory format pref to 'read from prefs'??");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
mListFormat = format;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFTPChannel::GetListFormat(PRUint32 *format) {
|
||||
*format = mListFormat;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
#include "nsIProxyInfo.h"
|
||||
#include "nsIResumableChannel.h"
|
||||
#include "nsIResumableEntityID.h"
|
||||
#include "nsIDirectoryListing.h"
|
||||
|
||||
#include "nsICacheService.h"
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
@@ -82,7 +83,8 @@ class nsFTPChannel : public nsIFTPChannel,
|
||||
public nsIProgressEventSink,
|
||||
public nsIStreamListener,
|
||||
public nsICacheListener,
|
||||
public nsIResumableChannel
|
||||
public nsIResumableChannel,
|
||||
public nsIDirectoryListing
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
@@ -96,6 +98,7 @@ public:
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSICACHELISTENER
|
||||
NS_DECL_NSIRESUMABLECHANNEL
|
||||
NS_DECL_NSIDIRECTORYLISTING
|
||||
|
||||
// nsFTPChannel methods:
|
||||
nsFTPChannel();
|
||||
@@ -129,6 +132,7 @@ protected:
|
||||
|
||||
PRBool mIsPending;
|
||||
PRUint32 mLoadFlags;
|
||||
PRUint32 mListFormat;
|
||||
|
||||
PRUint32 mSourceOffset;
|
||||
PRInt32 mAmount;
|
||||
|
||||
@@ -416,13 +416,6 @@ nsFtpState::nsFtpState() {
|
||||
mDRequestForwarder = nsnull;
|
||||
mFileSize = PRUint32(-1);
|
||||
mModTime = -1;
|
||||
|
||||
mGenerateRawContent = PR_FALSE;
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> pPref(do_GetService(kPrefCID, &rv));
|
||||
if (NS_SUCCEEDED(rv) || pPref) {
|
||||
pPref->GetBoolPref("network.ftp.raw_output", &mGenerateRawContent);
|
||||
}
|
||||
}
|
||||
|
||||
nsFtpState::~nsFtpState()
|
||||
@@ -1402,15 +1395,31 @@ nsFtpState::R_mdtm() {
|
||||
nsresult
|
||||
nsFtpState::SetContentType()
|
||||
{
|
||||
if (mGenerateRawContent) {
|
||||
nsAutoString fromStr(NS_LITERAL_STRING("text/ftp-dir-"));
|
||||
SetDirMIMEType(fromStr);
|
||||
nsCOMPtr<nsIDirectoryListing> list = do_QueryInterface(mChannel);
|
||||
NS_ASSERTION(list, "ftp channel isn't listable!");
|
||||
(void)list->GetListFormat(&mListFormat);
|
||||
nsCAutoString contentType;
|
||||
switch (mListFormat) {
|
||||
case nsIDirectoryListing::FORMAT_RAW:
|
||||
{
|
||||
nsAutoString fromStr(NS_LITERAL_STRING("text/ftp-dir-"));
|
||||
SetDirMIMEType(fromStr);
|
||||
|
||||
nsCAutoString contentType;contentType.AssignWithConversion(fromStr);
|
||||
return mChannel->SetContentType(contentType.get());
|
||||
contentType.Assign("text/ftp-dir-");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
NS_WARNING("Unknown directory type");
|
||||
// fall through
|
||||
case nsIDirectoryListing::FORMAT_HTML:
|
||||
contentType.Assign(TEXT_HTML);
|
||||
break;
|
||||
case nsIDirectoryListing::FORMAT_HTTP_INDEX:
|
||||
contentType.Assign(APPLICATION_HTTP_INDEX_FORMAT);
|
||||
break;
|
||||
}
|
||||
|
||||
return mChannel->SetContentType("application/http-index-format");
|
||||
return mChannel->SetContentType(contentType.get());
|
||||
}
|
||||
|
||||
nsresult
|
||||
@@ -2315,16 +2324,38 @@ nsFtpState::BuildStreamConverter(nsIStreamListener** convertStreamListener)
|
||||
|
||||
nsAutoString fromStr(NS_LITERAL_STRING("text/ftp-dir-"));
|
||||
SetDirMIMEType(fromStr);
|
||||
if (mGenerateRawContent) {
|
||||
switch (mListFormat) {
|
||||
case nsIDirectoryListing::FORMAT_RAW:
|
||||
converterListener = listener;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
default:
|
||||
// fall through
|
||||
case nsIDirectoryListing::FORMAT_HTML:
|
||||
// XXX - work arround bug 126417. We have to do the chaining
|
||||
// manually so that we don't crash
|
||||
{
|
||||
nsCOMPtr<nsIStreamListener> tmpListener;
|
||||
rv = scs->AsyncConvertData(NS_LITERAL_STRING(APPLICATION_HTTP_INDEX_FORMAT).get(),
|
||||
NS_LITERAL_STRING(TEXT_HTML).get(),
|
||||
listener,
|
||||
mURL,
|
||||
getter_AddRefs(tmpListener));
|
||||
if (NS_FAILED(rv)) break;
|
||||
rv = scs->AsyncConvertData(fromStr.get(),
|
||||
NS_LITERAL_STRING(APPLICATION_HTTP_INDEX_FORMAT).get(),
|
||||
tmpListener,
|
||||
mURL,
|
||||
getter_AddRefs(converterListener));
|
||||
|
||||
}
|
||||
break;
|
||||
case nsIDirectoryListing::FORMAT_HTTP_INDEX:
|
||||
rv = scs->AsyncConvertData(fromStr.get(),
|
||||
NS_LITERAL_STRING(APPLICATION_HTTP_INDEX_FORMAT).get(),
|
||||
listener,
|
||||
mURL,
|
||||
getter_AddRefs(converterListener));
|
||||
break;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
|
||||
@@ -221,10 +221,10 @@ private:
|
||||
nsCOMPtr<nsIInputStream> mWriteStream; // This stream is written to the server.
|
||||
PRPackedBool mFireCallbacks; // Fire the listener callback.
|
||||
PRPackedBool mIPv6Checked;
|
||||
PRBool mGenerateRawContent;
|
||||
nsCOMPtr<nsIPrompt> mPrompter;
|
||||
nsCOMPtr<nsIFTPEventSink> mFTPEventSink;
|
||||
nsCOMPtr<nsIAuthPrompt> mAuthPrompter;
|
||||
PRUint32 mListFormat;
|
||||
|
||||
static PRUint32 mSessionStartTime;
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ REQUIRES = xpcom \
|
||||
necko \
|
||||
string \
|
||||
mimetype \
|
||||
pref \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
|
||||
@@ -24,6 +24,7 @@ REQUIRES = xpcom \
|
||||
string \
|
||||
mimetype \
|
||||
necko \
|
||||
pref \
|
||||
$(NULL)
|
||||
|
||||
LIBRARY_NAME=nkgopher_s
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "nsIProgressEventSink.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "prlog.h"
|
||||
#include "nsIPref.h"
|
||||
|
||||
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
||||
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
|
||||
@@ -54,6 +55,7 @@ extern PRLogModuleInfo* gGopherLog;
|
||||
nsGopherChannel::nsGopherChannel()
|
||||
: mContentLength(-1),
|
||||
mActAsObserver(PR_TRUE),
|
||||
mListFormat(FORMAT_HTML),
|
||||
mType(-1),
|
||||
mStatus(NS_OK)
|
||||
{
|
||||
@@ -69,11 +71,12 @@ nsGopherChannel::~nsGopherChannel()
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS4(nsGopherChannel,
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS5(nsGopherChannel,
|
||||
nsIChannel,
|
||||
nsIRequest,
|
||||
nsIStreamListener,
|
||||
nsIRequestObserver);
|
||||
nsIRequestObserver,
|
||||
nsIDirectoryListing);
|
||||
|
||||
nsresult
|
||||
nsGopherChannel::Init(nsIURI* uri, nsIProxyInfo* proxyInfo)
|
||||
@@ -326,7 +329,20 @@ nsGopherChannel::GetContentType(char* *aContentType)
|
||||
*aContentType = nsCRT::strdup(TEXT_HTML);
|
||||
break;
|
||||
case '1':
|
||||
*aContentType = nsCRT::strdup(APPLICATION_HTTP_INDEX_FORMAT);
|
||||
switch (mListFormat) {
|
||||
case nsIDirectoryListing::FORMAT_RAW:
|
||||
*aContentType = strdup("text/gopher-dir");
|
||||
break;
|
||||
default:
|
||||
NS_WARNING("Unknown directory type");
|
||||
// fall through
|
||||
case nsIDirectoryListing::FORMAT_HTML:
|
||||
*aContentType = strdup(TEXT_HTML);
|
||||
break;
|
||||
case nsIDirectoryListing::FORMAT_HTTP_INDEX:
|
||||
*aContentType = strdup(APPLICATION_HTTP_INDEX_FORMAT);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '2': // CSO search - unhandled, should not be selectable
|
||||
*aContentType = nsCRT::strdup(TEXT_HTML);
|
||||
@@ -511,11 +527,39 @@ nsGopherChannel::OnStopRequest(nsIRequest* aRequest, nsISupports* aContext,
|
||||
// What we now do depends on what type of file we have
|
||||
if (mType=='1' || mType=='7') {
|
||||
// Send the directory format back for a directory
|
||||
rv = StreamConvService->AsyncConvertData(NS_LITERAL_STRING("text/gopher-dir").get(),
|
||||
NS_LITERAL_STRING("application/http-index-format").get(),
|
||||
this,
|
||||
mUrl,
|
||||
getter_AddRefs(converterListener));
|
||||
switch (mListFormat) {
|
||||
case nsIDirectoryListing::FORMAT_RAW:
|
||||
converterListener = this;
|
||||
break;
|
||||
default:
|
||||
// fall through
|
||||
case nsIDirectoryListing::FORMAT_HTML:
|
||||
// XXX - work arround bug 126417. We have to do the chaining
|
||||
// manually so that we don't crash
|
||||
{
|
||||
nsCOMPtr<nsIStreamListener> tmpListener;
|
||||
rv = StreamConvService->AsyncConvertData(
|
||||
NS_LITERAL_STRING(APPLICATION_HTTP_INDEX_FORMAT).get(),
|
||||
NS_LITERAL_STRING(TEXT_HTML).get(),
|
||||
this,
|
||||
mUrl,
|
||||
getter_AddRefs(tmpListener));
|
||||
if (NS_FAILED(rv)) break;
|
||||
rv = StreamConvService->AsyncConvertData(NS_LITERAL_STRING("text/gopher-dir").get(),
|
||||
NS_LITERAL_STRING(APPLICATION_HTTP_INDEX_FORMAT).get(),
|
||||
tmpListener,
|
||||
mUrl,
|
||||
getter_AddRefs(converterListener));
|
||||
}
|
||||
break;
|
||||
case nsIDirectoryListing::FORMAT_HTTP_INDEX:
|
||||
rv = StreamConvService->AsyncConvertData(NS_LITERAL_STRING("text/gopher-dir").get(),
|
||||
NS_LITERAL_STRING(APPLICATION_HTTP_INDEX_FORMAT).get(),
|
||||
this,
|
||||
mUrl,
|
||||
getter_AddRefs(converterListener));
|
||||
break;
|
||||
}
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
} else if (mType=='0') {
|
||||
// Convert general file
|
||||
@@ -648,3 +692,40 @@ nsGopherChannel::SendRequest(nsITransport* aTransport)
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGopherChannel::SetListFormat(PRUint32 format) {
|
||||
if (format != FORMAT_PREF &&
|
||||
format != FORMAT_RAW &&
|
||||
format != FORMAT_HTML &&
|
||||
format != FORMAT_HTTP_INDEX) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Convert the pref value
|
||||
if (format == FORMAT_PREF) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
PRInt32 sFormat;
|
||||
rv = prefs->GetIntPref("network.dir.format", &sFormat);
|
||||
if (NS_FAILED(rv))
|
||||
format = FORMAT_HTML; // default
|
||||
else
|
||||
format = sFormat;
|
||||
|
||||
if (format == FORMAT_PREF) {
|
||||
NS_WARNING("Who set the directory format pref to 'read from prefs'??");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
mListFormat = format;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGopherChannel::GetListFormat(PRUint32 *format) {
|
||||
*format = mListFormat;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,15 +39,18 @@
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsITransport.h"
|
||||
#include "nsIProxyInfo.h"
|
||||
#include "nsIDirectoryListing.h"
|
||||
|
||||
class nsGopherChannel : public nsIChannel,
|
||||
public nsIStreamListener {
|
||||
public nsIStreamListener,
|
||||
public nsIDirectoryListing {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIREQUEST
|
||||
NS_DECL_NSICHANNEL
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSIDIRECTORYLISTING
|
||||
|
||||
// nsGopherChannel methods:
|
||||
nsGopherChannel();
|
||||
@@ -73,6 +76,7 @@ protected:
|
||||
PRUint32 mBufferSegmentSize;
|
||||
PRUint32 mBufferMaxSize;
|
||||
PRBool mActAsObserver;
|
||||
PRUint32 mListFormat;
|
||||
|
||||
nsXPIDLCString mHost;
|
||||
PRInt32 mPort;
|
||||
|
||||
@@ -89,6 +89,7 @@
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIStreamConverterService.h"
|
||||
#include "nsIDirectoryListing.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
//
|
||||
@@ -1017,6 +1018,12 @@ nsHTTPIndex::FireTimer(nsITimer* aTimer, void* aClosure)
|
||||
}
|
||||
if (NS_SUCCEEDED(rv) && (channel)) {
|
||||
channel->SetNotificationCallbacks(httpIndex);
|
||||
nsCOMPtr<nsIDirectoryListing> dirList = do_QueryInterface(channel);
|
||||
NS_ASSERTION(dirList, "Directory listing doesn't impl nsIDirectoryListing");
|
||||
if (dirList) {
|
||||
rv = dirList->SetListFormat(nsIDirectoryListing::FORMAT_HTTP_INDEX);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Could not set directory list format");
|
||||
}
|
||||
rv = channel->AsyncOpen(httpIndex, aSource);
|
||||
}
|
||||
}
|
||||
@@ -1363,8 +1370,12 @@ nsDirectoryViewerFactory::CreateInstance(const char *aCommand,
|
||||
nsCOMPtr<nsIPref> prefSrv = do_GetService(NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRBool useHtml;
|
||||
rv = prefSrv->GetBoolPref("network.dir.generate_html", &useHtml);
|
||||
PRBool useXUL = PR_FALSE;
|
||||
PRInt32 dirPref;
|
||||
rv = prefSrv->GetIntPref("network.dir.format", &dirPref);
|
||||
if (NS_SUCCEEDED(rv) && dirPref == nsIDirectoryListing::FORMAT_HTTP_INDEX) {
|
||||
useXUL = PR_TRUE;
|
||||
}
|
||||
|
||||
// We need to disable html mode for file:///, at least for the moment
|
||||
// The charset coding isn't quite right for non ASCII systems
|
||||
@@ -1374,12 +1385,12 @@ nsDirectoryViewerFactory::CreateInstance(const char *aCommand,
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRBool isFile;
|
||||
if (NS_SUCCEEDED(uri->SchemeIs("file", &isFile)) && isFile)
|
||||
useHtml = PR_FALSE;
|
||||
useXUL = PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool viewSource = (PL_strstr(aContentType,"view-source") != 0);
|
||||
|
||||
if ((NS_FAILED(rv) || !useHtml) && !viewSource) {
|
||||
if ((NS_FAILED(rv) || useXUL) && !viewSource) {
|
||||
|
||||
// This is where we shunt the HTTP/Index stream into our datasource,
|
||||
// and open the directory viewer XUL file as the content stream to
|
||||
@@ -1407,7 +1418,7 @@ nsDirectoryViewerFactory::CreateInstance(const char *aCommand,
|
||||
aContainer, aExtraInfo, getter_AddRefs(listener),
|
||||
aDocViewerResult);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
rv = channel->AsyncOpen(listener, nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<script type="application/x-javascript">
|
||||
<![CDATA[
|
||||
var _elementIDs = ["browserEnableKeepAlive", "browserEnablePipelining",
|
||||
"dirGenerateHtml", "httpVersionString", "acceptEncodingString",
|
||||
"dirFormat", "httpVersionString", "acceptEncodingString",
|
||||
"nglayoutDebugDisableXULCache", "browserEnableCache", "browserEnableDiskCache", ];
|
||||
]]>
|
||||
</script>
|
||||
@@ -46,8 +46,18 @@
|
||||
prefstring="network.http.keep-alive"/>
|
||||
<checkbox id="browserEnablePipelining" label="&debugEnablePipelining.label;"
|
||||
prefstring="network.http.pipelining"/>
|
||||
<checkbox id="dirGenerateHtml" label="&debugEnableHTML.label;"
|
||||
prefstring="network.dir.generate_html"/>
|
||||
<description>&dirFormat;</description>
|
||||
<vbox align="start" class="indent">
|
||||
<radiogroup id="dirFormat"
|
||||
prefstring="network.dir.format">
|
||||
<radio value="1" label="&raw.label;"/>
|
||||
<radio value="2" label="&html.label;"/>
|
||||
<!-- OK, this is application/http-index-format, not XUL. But the
|
||||
result is that the XUL viwer is used. Anyway, this is only a
|
||||
debug panel, so lets not get worked up about it -->
|
||||
<radio value="3" label="&xul.label;"/>
|
||||
</radiogroup>
|
||||
</vbox>
|
||||
</vbox>
|
||||
<label value="&httpVersion.label;" control="httpVersionString"/>
|
||||
<textbox id="httpVersionString" maxlength="3"
|
||||
|
||||
@@ -9,7 +9,10 @@
|
||||
<!ENTITY debugNetworking.label "Networking">
|
||||
<!ENTITY debugEnableKeepAlive.label "Enable Keep Alive">
|
||||
<!ENTITY debugEnablePipelining.label "Enable HTTP Pipelining">
|
||||
<!ENTITY debugEnableHTML.label "Enable html directory listing">
|
||||
<!ENTITY dirFormat "Directory Listing Format">
|
||||
<!ENTITY raw.label "Raw">
|
||||
<!ENTITY html.label "HTML">
|
||||
<!ENTITY xul.label "XUL (tree-based)">
|
||||
<!ENTITY acceptEncoding.label "Accept-Encoding">
|
||||
<!ENTITY httpVersion.label "HTTP Version">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user