From 5e4a6d80b43fbda26344a9a7d077732e2e23efd5 Mon Sep 17 00:00:00 2001 From: "morse%netscape.com" Date: Sun, 29 Oct 2000 01:57:24 +0000 Subject: [PATCH] bug 55731, files on disk need explicit html suffix, r=valeski, a=gagan, sr=mscott git-svn-id: svn://10.0.0.236/trunk@81975 18797224-902f-48f8-a5cc-f745e15eee43 --- .../converters/nsUnknownDecoder.cpp | 64 ++++++++++++++----- .../streamconv/converters/nsUnknownDecoder.h | 3 +- 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.cpp b/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.cpp index b73abed8aab..081c4cd7010 100644 --- a/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.cpp +++ b/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.cpp @@ -30,10 +30,13 @@ #include "nsIOutputStream.h" #include "nsMimeTypes.h" #include "netCore.h" +#include "nsXPIDLString.h" +#include "nsIPref.h" #define MAX_BUFFER_SIZE 1024 static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID); +static NS_DEFINE_IID(kPrefServiceCID, NS_PREF_CID); nsUnknownDecoder::nsUnknownDecoder() @@ -42,6 +45,14 @@ nsUnknownDecoder::nsUnknownDecoder() mBuffer = nsnull; mBufferLen = 0; + mRequireHTMLsuffix = PR_FALSE; + + nsresult rv; + nsCOMPtr pPrefService = do_GetService(kPrefServiceCID, &rv); + if (NS_SUCCEEDED(rv)) { + rv = pPrefService->GetBoolPref("security.requireHTMLsuffix", &mRequireHTMLsuffix); + } + } @@ -150,7 +161,7 @@ nsUnknownDecoder::OnDataAvailable(nsIChannel *aChannel, // aSourceOffset += mBufferLen; - DetermineContentType(); + DetermineContentType(aChannel); NS_ASSERTION(!mContentType.IsEmpty(), "Content type should be known by now."); @@ -208,7 +219,7 @@ nsUnknownDecoder::OnStopRequest(nsIChannel *aChannel, nsISupports *aCtxt, // Analyze the buffer now... // if (mContentType.IsEmpty()) { - DetermineContentType(); + DetermineContentType(aChannel); NS_ASSERTION(!mContentType.IsEmpty(), "Content type should be known by now."); @@ -226,7 +237,7 @@ nsUnknownDecoder::OnStopRequest(nsIChannel *aChannel, nsISupports *aCtxt, } -void nsUnknownDecoder::DetermineContentType() +void nsUnknownDecoder::DetermineContentType(nsIChannel *aChannel) { PRUint32 i; @@ -258,24 +269,47 @@ void nsUnknownDecoder::DetermineContentType() // If the buffer contains "common" HTML tags then lets call it HTML :-) // else { - PRInt32 offset; - offset = str.Find(" pURL; + nsresult rv = aChannel->GetURI(getter_AddRefs(pURL)); + if (NS_SUCCEEDED(rv)) { + nsXPIDLCString protocol; + rv = pURL->GetScheme(getter_Copies(protocol)); + if (NS_SUCCEEDED(rv)) { + if (!PL_strcasecmp(protocol, "file")) { + isLocalFile = PR_TRUE; } } } } - if (offset >= 0) { - mContentType = TEXT_HTML; + if (!mRequireHTMLsuffix || !isLocalFile) { + PRInt32 offset; + + offset = str.Find("= 0) { + mContentType = TEXT_HTML; + } } } diff --git a/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.h b/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.h index f3b8151387e..4cc2be95291 100644 --- a/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.h +++ b/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.h @@ -59,7 +59,7 @@ public: protected: virtual ~nsUnknownDecoder(); - void DetermineContentType(); + void DetermineContentType(nsIChannel *aChannel); nsresult FireListenerNotifications(nsIChannel *aChannel, nsISupports *aCtxt); protected: @@ -67,6 +67,7 @@ protected: char *mBuffer; PRUint32 mBufferLen; + PRBool mRequireHTMLsuffix; nsCString mContentType; };