From e3328da83532b0634eb5e3e722b0ae3b6fed5dfc Mon Sep 17 00:00:00 2001 From: Wes Kocher Date: Tue, 25 Mar 2014 18:20:40 -0700 Subject: [PATCH] Backed out changeset 18f95fb1d866 (bug 948901) for breaking OSX m-oth --- .../streamconv/converters/nsIndexedToHTML.cpp | 286 ++++++++++++++---- .../streamconv/converters/nsIndexedToHTML.h | 7 +- .../osx/global/dirListing/dirListing.css | 2 +- .../windows/global/dirListing/dirListing.css | 2 +- 4 files changed, 226 insertions(+), 71 deletions(-) diff --git a/netwerk/streamconv/converters/nsIndexedToHTML.cpp b/netwerk/streamconv/converters/nsIndexedToHTML.cpp index 8f52114665e..b069c9ea5b1 100644 --- a/netwerk/streamconv/converters/nsIndexedToHTML.cpp +++ b/netwerk/streamconv/converters/nsIndexedToHTML.cpp @@ -31,7 +31,7 @@ NS_IMPL_ISUPPORTS4(nsIndexedToHTML, nsIRequestObserver, nsIStreamListener) -static void AppendNonAsciiToNCR(const nsAString& in, nsCString& out) +static void AppendNonAsciiToNCR(const nsAString& in, nsAFlatString& out) { nsAString::const_iterator start, end; @@ -43,8 +43,10 @@ static void AppendNonAsciiToNCR(const nsAString& in, nsCString& out) out.Append(*start++); } else { out.AppendLiteral("&#x"); - out.AppendInt(*start++, 16); - out.Append(';'); + nsAutoString hex; + hex.AppendInt(*start++, 16); + out.Append(hex); + out.Append((char16_t)';'); } } } @@ -65,6 +67,22 @@ nsIndexedToHTML::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) { nsresult nsIndexedToHTML::Init(nsIStreamListener* aListener) { + + nsXPIDLString ellipsis; + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefs) { + nsCOMPtr prefVal; + prefs->GetComplexValue("intl.ellipsis", + NS_GET_IID(nsIPrefLocalizedString), + getter_AddRefs(prefVal)); + if (prefVal) + prefVal->ToString(getter_Copies(ellipsis)); + } + if (ellipsis.IsEmpty()) + mEscapedEllipsis.AppendLiteral("…"); + else + mEscapedEllipsis.Adopt(nsEscapeHTML2(ellipsis.get(), ellipsis.Length())); + nsresult rv = NS_OK; mListener = aListener; @@ -102,7 +120,7 @@ nsIndexedToHTML::AsyncConvertData(const char *aFromType, NS_IMETHODIMP nsIndexedToHTML::OnStartRequest(nsIRequest* request, nsISupports *aContext) { - nsCString buffer; + nsString buffer; nsresult rv = DoOnStartRequest(request, aContext, buffer); if (NS_FAILED(rv)) { request->Cancel(rv); @@ -118,13 +136,13 @@ nsIndexedToHTML::OnStartRequest(nsIRequest* request, nsISupports *aContext) { // Push our buffer to the listener. - rv = SendToListener(request, aContext, buffer); + rv = FormatInputStream(request, aContext, buffer); return rv; } nsresult nsIndexedToHTML::DoOnStartRequest(nsIRequest* request, nsISupports *aContext, - nsCString& aBuffer) { + nsString& aBuffer) { nsresult rv; nsCOMPtr channel = do_QueryInterface(request); @@ -150,9 +168,6 @@ nsIndexedToHTML::DoOnStartRequest(nsIRequest* request, nsISupports *aContext, nsCString parentStr; - nsCString buffer; - buffer.AppendLiteral("\n\n\n"); - // XXX - should be using the 300: line from the parser. // We can't guarantee that that comes before any entry, so we'd have to // buffer, and do other painful stuff. @@ -212,7 +227,8 @@ nsIndexedToHTML::DoOnStartRequest(nsIRequest* request, nsISupports *aContext, } // Directory index will be always encoded in UTF-8 if this is file url - buffer.AppendLiteral("\n"); + rv = mParser->SetEncoding("UTF-8"); + NS_ENSURE_SUCCESS(rv, rv); } else if (NS_SUCCEEDED(uri->SchemeIs("jar", &isScheme)) && isScheme) { nsAutoCString path; @@ -247,11 +263,23 @@ nsIndexedToHTML::DoOnStartRequest(nsIRequest* request, nsISupports *aContext, } } + nsString buffer; + buffer.AppendLiteral("\n" + "\n\n" + "\n" + AppendASCIItoUTF16(encoding, buffer); + buffer.AppendLiteral("\">\n" + "