Fix #115625 - Fix file:// protocol handler to enable html dir listing...
r=dougt, sr=rpotts git-svn-id: svn://10.0.0.236/branches/MOZILLA_0_9_4_BRANCH@110653 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -258,3 +258,5 @@ res/arrowd.gif
|
||||
res/loading-image.gif
|
||||
res/broken-image.gif
|
||||
res/builtin/*
|
||||
res/html/gopher-unknown.gif
|
||||
res/html/gopher-menu.gif
|
||||
@@ -285,3 +285,5 @@ res\builtin\selectBindings.xml
|
||||
res\builtin\textfields.css
|
||||
res\builtin\xbl-forms.css
|
||||
res\fonts\fontEncoding.properties
|
||||
res\html\gopher-unknown.gif
|
||||
res\html\gopher-menu.gif
|
||||
@@ -189,14 +189,16 @@ nsDirectoryIndexStream::Read(char* aBuf, PRUint32 aCount, PRUint32* aReadCount)
|
||||
}
|
||||
|
||||
PRInt64 fileSize;
|
||||
PRInt64 fileInfoModifyTime;
|
||||
PRInt64 tmpTime, fileInfoModifyTime;
|
||||
rv = current->GetFileSize( &fileSize );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PROffset32 fileInfoSize;
|
||||
LL_L2I( fileInfoSize,fileSize );
|
||||
|
||||
rv = current->GetLastModificationDate( &fileInfoModifyTime );
|
||||
rv = current->GetLastModificationDate( &tmpTime );
|
||||
// Why does nsIFile give this back in milliseconds?
|
||||
LL_MUL(fileInfoModifyTime, tmpTime, PR_USEC_PER_MSEC);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mBuf += "201: ";
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = necko
|
||||
LIBRARY_NAME = nkfile_s
|
||||
REQUIRES = xpcom string exthandler mimetype
|
||||
REQUIRES = xpcom string exthandler mimetype pref
|
||||
|
||||
CPPSRCS = \
|
||||
nsFileChannel.cpp \
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "nsFileChannel.h"
|
||||
#include "nsIFileChannel.h"
|
||||
#include "nsIStreamConverterService.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIServiceManager.h"
|
||||
@@ -37,6 +38,7 @@
|
||||
|
||||
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
|
||||
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
|
||||
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -59,13 +61,15 @@ nsFileChannel::nsFileChannel()
|
||||
nsresult
|
||||
nsFileChannel::Init(PRInt32 ioFlags,
|
||||
PRInt32 perm,
|
||||
nsIURI* uri)
|
||||
nsIURI* uri,
|
||||
PRBool generateHTMLDirs)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
mIOFlags = ioFlags;
|
||||
mPerm = perm;
|
||||
mURI = uri;
|
||||
mGenerateHTMLDirs = generateHTMLDirs;
|
||||
|
||||
// if we support the nsIURL interface then use it to get just
|
||||
// the file path with no other garbage!
|
||||
@@ -315,7 +319,10 @@ nsFileChannel::GetContentType(char * *aContentType)
|
||||
PRBool directory;
|
||||
mFile->IsDirectory(&directory);
|
||||
if (directory) {
|
||||
mContentType = APPLICATION_HTTP_INDEX_FORMAT;
|
||||
if (mGenerateHTMLDirs)
|
||||
mContentType = "text/html";
|
||||
else
|
||||
mContentType = APPLICATION_HTTP_INDEX_FORMAT;
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIMIMEService> MIMEService(do_GetService(NS_MIMESERVICE_CONTRACTID, &rv));
|
||||
@@ -428,6 +435,26 @@ nsFileChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsFileChannel::SetStreamConverter()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIStreamListener> converterListener = mRealListener;
|
||||
|
||||
nsCOMPtr<nsIStreamConverterService> scs = do_GetService(kStreamConverterServiceCID, &rv);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = scs->AsyncConvertData(NS_LITERAL_STRING(APPLICATION_HTTP_INDEX_FORMAT).get(),
|
||||
NS_LITERAL_STRING("text/html").get(),
|
||||
converterListener,
|
||||
mURI,
|
||||
getter_AddRefs(mRealListener));
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIStreamListener methods:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -444,6 +471,17 @@ nsFileChannel::OnStartRequest(nsIRequest* request, nsISupports* context)
|
||||
NS_ASSERTION(mRealListener, "No listener...");
|
||||
nsresult rv = NS_OK;
|
||||
if (mRealListener) {
|
||||
if (mGenerateHTMLDirs)
|
||||
{
|
||||
PRBool directory;
|
||||
mFile->IsDirectory(&directory); // this stat should be cached and will not hit disk.
|
||||
if (directory) {
|
||||
rv = SetStreamConverter();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
rv = mRealListener->OnStartRequest(this, context);
|
||||
}
|
||||
return rv;
|
||||
|
||||
@@ -64,8 +64,9 @@ public:
|
||||
static NS_METHOD
|
||||
Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
|
||||
|
||||
nsresult Init(PRInt32 ioFlags, PRInt32 perm, nsIURI* uri);
|
||||
nsresult Init(PRInt32 ioFlags, PRInt32 perm, nsIURI* uri, PRBool generateHTMLDirs = PR_FALSE);
|
||||
nsresult EnsureTransport();
|
||||
nsresult SetStreamConverter();
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIFile> mFile;
|
||||
@@ -87,6 +88,7 @@ protected:
|
||||
nsresult mStatus;
|
||||
nsCOMPtr<nsIProgressEventSink> mProgress;
|
||||
nsCOMPtr<nsIRequest> mCurrentRequest;
|
||||
PRBool mGenerateHTMLDirs;
|
||||
#ifdef DEBUG
|
||||
PRThread* mInitiator;
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "nsIURL.h"
|
||||
#include "nsIURLParser.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
@@ -38,17 +39,24 @@
|
||||
#include "nsNetCID.h"
|
||||
|
||||
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
|
||||
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsFileProtocolHandler::nsFileProtocolHandler()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mGenerateHTMLContent = PR_FALSE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsFileProtocolHandler::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> pPref(do_GetService(kPrefCID, &rv));
|
||||
if (NS_SUCCEEDED(rv) || pPref) {
|
||||
pPref->GetBoolPref("network.dir.generate_html", &mGenerateHTMLContent);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -134,7 +142,8 @@ nsFileProtocolHandler::NewChannel(nsIURI* url, nsIChannel* *result)
|
||||
|
||||
rv = channel->Init(-1, // ioFlags unspecified
|
||||
-1, // permissions unspecified
|
||||
url);
|
||||
url,
|
||||
mGenerateHTMLContent);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(channel);
|
||||
return rv;
|
||||
|
||||
@@ -55,6 +55,9 @@ public:
|
||||
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
nsresult Init();
|
||||
|
||||
protected:
|
||||
PRBool mGenerateHTMLContent;
|
||||
};
|
||||
|
||||
#endif /* nsFileProtocolHandler_h___ */
|
||||
|
||||
@@ -131,6 +131,9 @@ nsIndexedToHTML::Handle201(char* buffer, nsString &pushBuffer)
|
||||
if (buffer == nsnull)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// Is the current entry we're dealing with a "FILE"?
|
||||
char *pIsFile = PL_strstr((const char *)buffer, "FILE");
|
||||
|
||||
char* bufferOffset = nsnull;
|
||||
|
||||
if (*buffer == '\"') {
|
||||
@@ -161,11 +164,18 @@ nsIndexedToHTML::Handle201(char* buffer, nsString &pushBuffer)
|
||||
pushBuffer.AppendWithConversion(filename);
|
||||
pushBuffer.AppendWithConversion("\"> ");
|
||||
|
||||
if(pIsFile)
|
||||
pushBuffer.Append(NS_LITERAL_STRING("<img align=absbottom border=0 src=\"internal-gopher-unknown\">"));
|
||||
else //Use the folder icon for DIRECTORY and SYMLINKS
|
||||
pushBuffer.Append(NS_LITERAL_STRING("<img align=absbottom border=0 src=\"internal-gopher-menu\">"));
|
||||
|
||||
nsUnescape(NS_CONST_CAST(char*, filename.get()));
|
||||
pushBuffer.AppendWithConversion(filename);
|
||||
pushBuffer.AppendWithConversion("</a>");
|
||||
pushBuffer.Append(NS_LITERAL_STRING(" "));
|
||||
pushBuffer.AppendWithConversion("</td>\n");
|
||||
|
||||
int iCurColNum = 1; // =1 since we just got done with the "filename" column above
|
||||
while (*bufferOffset)
|
||||
{
|
||||
char* bufferStart = bufferOffset;
|
||||
@@ -180,14 +190,37 @@ nsIndexedToHTML::Handle201(char* buffer, nsString &pushBuffer)
|
||||
if (bufferOffset == nsnull)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*bufferOffset = '\0';
|
||||
*bufferOffset = '\0';
|
||||
iCurColNum++;
|
||||
++bufferOffset;
|
||||
nsUnescape(bufferStart);
|
||||
nsCString cstring(bufferStart);
|
||||
cstring.ToLowerCase();
|
||||
|
||||
pushBuffer.AppendWithConversion(" <td>");
|
||||
pushBuffer.AppendWithConversion(cstring);
|
||||
switch(iCurColNum) {
|
||||
case 2: // We're looking at the "Content-Length" column
|
||||
// Add the "Content-Length" column only for files
|
||||
// Skip for directories etc. so we do not show a zero length
|
||||
if (pIsFile)
|
||||
pushBuffer.AppendWithConversion(cstring);
|
||||
else
|
||||
pushBuffer.Append(NS_LITERAL_STRING(" "));
|
||||
pushBuffer.Append(NS_LITERAL_STRING(" "));
|
||||
break;
|
||||
case 3: // We're looking at the "Last-Modified" column
|
||||
pushBuffer.AppendWithConversion(cstring);
|
||||
pushBuffer.Append(NS_LITERAL_STRING(" "));
|
||||
break;
|
||||
case 4: // We're looking at the "File-Type" column
|
||||
cstring.ToLowerCase();//Convert "FILE" etc. -> lowercase
|
||||
// Uppercase just the first char. So, we have "File" and so on
|
||||
cstring.SetCharAt(nsCRT::ToUpper(GetCharAt(cstring, 0)), 0);
|
||||
pushBuffer.AppendWithConversion(cstring);
|
||||
break;
|
||||
default:
|
||||
pushBuffer.AppendWithConversion(cstring);
|
||||
break;
|
||||
}
|
||||
pushBuffer.AppendWithConversion("</td>\n");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user