2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-19 02:01:16 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-03-01 10:22:19 +03:00
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* 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/
|
2001-03-01 10:22:19 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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.
|
2001-03-01 10:22:19 +03:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2001-03-01 10:22:19 +03:00
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* Contributor(s):
|
|
|
|
* Bradley Baetz <bbaetz@cs.mcgill.ca>
|
|
|
|
* Christopher A. Aillon <christopher@aillon.com>
|
2007-08-18 02:57:36 +04:00
|
|
|
* Dão Gottwald <dao@design-noir.de>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-19 02:01:16 +04:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-19 02:01:16 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-19 02:01:16 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-03-01 10:22:19 +03:00
|
|
|
|
|
|
|
#include "nsIndexedToHTML.h"
|
|
|
|
#include "nsNetUtil.h"
|
2006-02-14 18:37:10 +03:00
|
|
|
#include "netCore.h"
|
2006-01-02 05:57:15 +03:00
|
|
|
#include "nsStringStream.h"
|
2002-03-06 10:48:55 +03:00
|
|
|
#include "nsIFileURL.h"
|
2001-03-01 10:22:19 +03:00
|
|
|
#include "nsEscape.h"
|
2001-10-03 04:43:30 +04:00
|
|
|
#include "nsIDirIndex.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "nsDateTimeFormatCID.h"
|
2002-09-13 23:32:45 +04:00
|
|
|
#include "nsURLHelper.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2002-11-12 23:06:16 +03:00
|
|
|
#include "nsIPlatformCharset.h"
|
2001-03-01 10:22:19 +03:00
|
|
|
|
2007-07-25 20:22:27 +04:00
|
|
|
NS_IMPL_ISUPPORTS4(nsIndexedToHTML,
|
|
|
|
nsIDirIndexListener,
|
|
|
|
nsIStreamConverter,
|
|
|
|
nsIRequestObserver,
|
|
|
|
nsIStreamListener)
|
2001-03-01 10:22:19 +03:00
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
static void AppendNonAsciiToNCR(const nsAString& in, nsAFlatString& out)
|
2002-08-20 07:32:28 +04:00
|
|
|
{
|
|
|
|
nsAString::const_iterator start, end;
|
|
|
|
|
|
|
|
in.BeginReading(start);
|
|
|
|
in.EndReading(end);
|
|
|
|
|
|
|
|
while (start != end) {
|
|
|
|
if (*start < 128) {
|
|
|
|
out.Append(*start++);
|
|
|
|
} else {
|
2004-06-17 04:13:25 +04:00
|
|
|
out.AppendLiteral("&#x");
|
2002-08-20 07:32:28 +04:00
|
|
|
nsAutoString hex;
|
|
|
|
hex.AppendInt(*start++, 16);
|
|
|
|
out.Append(hex);
|
|
|
|
out.Append((PRUnichar)';');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-05 02:23:21 +03:00
|
|
|
NS_METHOD
|
|
|
|
nsIndexedToHTML::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) {
|
|
|
|
nsresult rv;
|
|
|
|
if (aOuter)
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
|
|
|
|
nsIndexedToHTML* _s = new nsIndexedToHTML();
|
|
|
|
if (_s == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
rv = _s->QueryInterface(aIID, aResult);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-10-03 05:18:58 +04:00
|
|
|
nsresult
|
2001-10-03 04:43:30 +04:00
|
|
|
nsIndexedToHTML::Init(nsIStreamListener* aListener) {
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
mListener = aListener;
|
|
|
|
|
2006-06-04 03:35:59 +04:00
|
|
|
mDateTime = do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
|
2001-10-03 04:43:30 +04:00
|
|
|
|
2001-10-19 07:03:30 +04:00
|
|
|
nsCOMPtr<nsIStringBundleService> sbs =
|
|
|
|
do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2006-02-14 18:37:10 +03:00
|
|
|
rv = sbs->CreateBundle(NECKO_MSGS_URL, getter_AddRefs(mBundle));
|
2001-10-19 07:03:30 +04:00
|
|
|
|
2003-04-19 23:47:28 +04:00
|
|
|
mExpectAbsLoc = PR_FALSE;
|
2001-12-06 03:10:11 +03:00
|
|
|
|
2001-10-03 04:43:30 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIndexedToHTML::Convert(nsIInputStream* aFromStream,
|
2004-06-29 20:45:07 +04:00
|
|
|
const char* aFromType,
|
|
|
|
const char* aToType,
|
2001-10-03 04:43:30 +04:00
|
|
|
nsISupports* aCtxt,
|
|
|
|
nsIInputStream** res) {
|
2001-03-01 10:22:19 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-06-29 20:45:07 +04:00
|
|
|
nsIndexedToHTML::AsyncConvertData(const char *aFromType,
|
|
|
|
const char *aToType,
|
2001-03-01 10:22:19 +03:00
|
|
|
nsIStreamListener *aListener,
|
|
|
|
nsISupports *aCtxt) {
|
2001-10-03 04:43:30 +04:00
|
|
|
return Init(aListener);
|
2001-03-01 10:22:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-10-03 04:43:30 +04:00
|
|
|
nsIndexedToHTML::OnStartRequest(nsIRequest* request, nsISupports *aContext) {
|
|
|
|
nsresult rv;
|
|
|
|
|
2001-03-01 10:22:19 +03:00
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2001-10-03 04:43:30 +04:00
|
|
|
rv = channel->GetURI(getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-09-21 02:43:15 +04:00
|
|
|
channel->SetContentType(NS_LITERAL_CSTRING("text/html"));
|
|
|
|
|
2001-10-03 04:43:30 +04:00
|
|
|
mParser = do_CreateInstance("@mozilla.org/dirIndexParser;1",&rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-03-01 10:22:19 +03:00
|
|
|
|
2001-10-03 04:43:30 +04:00
|
|
|
rv = mParser->SetListener(this);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = mParser->OnStartRequest(request, aContext);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
nsCAutoString baseUri, titleUri;
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = uri->GetAsciiSpec(baseUri);
|
2001-10-03 04:43:30 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-04-17 05:45:15 +04:00
|
|
|
titleUri = baseUri;
|
2001-10-23 04:56:41 +04:00
|
|
|
|
|
|
|
nsCString parentStr;
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
// I'll deal with this when I make the changes to handle welcome messages
|
|
|
|
// The .. stuff should also come from the lower level protocols, but that
|
|
|
|
// would muck up the XUL display
|
|
|
|
// - bbaetz
|
|
|
|
|
|
|
|
PRBool isScheme = PR_FALSE;
|
2006-05-02 10:24:11 +04:00
|
|
|
PRBool isSchemeFile = PR_FALSE;
|
2007-08-18 02:57:36 +04:00
|
|
|
PRBool isSchemeGopher = PR_FALSE;
|
2001-10-23 04:56:41 +04:00
|
|
|
if (NS_SUCCEEDED(uri->SchemeIs("ftp", &isScheme)) && isScheme) {
|
2003-07-16 23:09:00 +04:00
|
|
|
|
2002-04-17 05:45:15 +04:00
|
|
|
// strip out the password here, so it doesn't show in the page title
|
|
|
|
// This is done by the 300: line generation in ftp, but we don't use
|
|
|
|
// that - see above
|
|
|
|
|
|
|
|
nsCAutoString pw;
|
|
|
|
rv = uri->GetPassword(pw);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (!pw.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIURI> newUri;
|
|
|
|
rv = uri->Clone(getter_AddRefs(newUri));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2004-01-30 01:04:45 +03:00
|
|
|
rv = newUri->SetPassword(EmptyCString());
|
2002-04-17 05:45:15 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = newUri->GetAsciiSpec(titleUri);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
2007-11-06 00:02:52 +03:00
|
|
|
nsCAutoString path;
|
|
|
|
rv = uri->GetPath(path);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2004-12-04 13:19:29 +03:00
|
|
|
if (!path.EqualsLiteral("//") && !path.LowerCaseEqualsLiteral("/%2f")) {
|
2003-07-16 23:09:00 +04:00
|
|
|
rv = uri->Resolve(NS_LITERAL_CSTRING(".."),parentStr);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-10-23 04:56:41 +04:00
|
|
|
}
|
2006-05-02 10:24:11 +04:00
|
|
|
} else if (NS_SUCCEEDED(uri->SchemeIs("file", &isSchemeFile)) && isSchemeFile) {
|
2001-10-23 04:56:41 +04:00
|
|
|
nsCOMPtr<nsIFileURL> fileUrl = do_QueryInterface(uri);
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
rv = fileUrl->GetFile(getter_AddRefs(file));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-11-27 00:37:58 +03:00
|
|
|
nsCOMPtr<nsILocalFile> lfile = do_QueryInterface(file, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
lfile->SetFollowLinks(PR_TRUE);
|
2001-10-23 04:56:41 +04:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString url;
|
2002-09-13 23:32:45 +04:00
|
|
|
rv = net_GetURLSpecFromFile(file, url);
|
2001-10-23 04:56:41 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
baseUri.Assign(url);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> parent;
|
|
|
|
rv = file->GetParent(getter_AddRefs(parent));
|
2002-05-01 00:53:09 +04:00
|
|
|
|
|
|
|
if (parent && NS_SUCCEEDED(rv)) {
|
2002-09-13 23:32:45 +04:00
|
|
|
net_GetURLSpecFromFile(parent, url);
|
2001-10-23 04:56:41 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
parentStr.Assign(url);
|
|
|
|
}
|
2002-11-12 23:06:16 +03:00
|
|
|
|
2006-05-02 10:24:11 +04:00
|
|
|
// Directory index will be always encoded in UTF-8 if this is file url
|
|
|
|
rv = mParser->SetEncoding("UTF-8");
|
2002-11-12 23:06:16 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-04-19 23:47:28 +04:00
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
} else if (NS_SUCCEEDED(uri->SchemeIs("gopher", &isSchemeGopher)) && isSchemeGopher) {
|
2003-04-19 23:47:28 +04:00
|
|
|
mExpectAbsLoc = PR_TRUE;
|
2006-03-30 02:10:37 +04:00
|
|
|
} else if (NS_SUCCEEDED(uri->SchemeIs("jar", &isScheme)) && isScheme) {
|
|
|
|
nsCAutoString path;
|
|
|
|
rv = uri->GetPath(path);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// a top-level jar directory URL is of the form jar:foo.zip!/
|
|
|
|
// path will be of the form foo.zip!/, and its last two characters
|
|
|
|
// will be "!/"
|
|
|
|
//XXX this won't work correctly when the name of the directory being
|
|
|
|
//XXX displayed ends with "!", but then again, jar: URIs don't deal
|
|
|
|
//XXX particularly well with such directories anyway
|
|
|
|
if (!StringEndsWith(path, NS_LITERAL_CSTRING("!/"))) {
|
|
|
|
rv = uri->Resolve(NS_LITERAL_CSTRING(".."), parentStr);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
2001-10-23 04:56:41 +04:00
|
|
|
}
|
2004-02-28 03:05:58 +03:00
|
|
|
else {
|
|
|
|
// default behavior for other protocols is to assume the channel's
|
|
|
|
// URL references a directory ending in '/' -- fixup if necessary.
|
|
|
|
nsCAutoString path;
|
|
|
|
rv = uri->GetPath(path);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (baseUri.Last() != '/') {
|
|
|
|
baseUri.Append('/');
|
|
|
|
path.Append('/');
|
|
|
|
uri->SetPath(path);
|
|
|
|
}
|
2004-12-04 13:19:29 +03:00
|
|
|
if (!path.EqualsLiteral("/")) {
|
2004-02-28 03:05:58 +03:00
|
|
|
rv = uri->Resolve(NS_LITERAL_CSTRING(".."), parentStr);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
}
|
2001-10-23 04:56:41 +04:00
|
|
|
|
2001-03-01 10:22:19 +03:00
|
|
|
nsString buffer;
|
2007-08-18 02:57:36 +04:00
|
|
|
buffer.AppendLiteral("<!DOCTYPE html>\n"
|
|
|
|
"<html>\n<head>\n"
|
|
|
|
"<meta http-equiv=\"content-type\" content=\"text/html; charset=");
|
2002-08-20 07:32:28 +04:00
|
|
|
|
|
|
|
// Get the encoding from the parser
|
|
|
|
// XXX - this won't work for any encoding set via a 301: line in the
|
|
|
|
// format - this output stuff would need to move to OnDataAvailable
|
2007-08-18 02:57:36 +04:00
|
|
|
// for that.
|
2002-04-10 14:28:57 +04:00
|
|
|
|
2002-08-20 07:32:28 +04:00
|
|
|
nsXPIDLCString encoding;
|
|
|
|
rv = mParser->GetEncoding(getter_Copies(encoding));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2003-12-23 19:48:40 +03:00
|
|
|
AppendASCIItoUTF16(encoding, buffer);
|
2007-08-18 02:57:36 +04:00
|
|
|
buffer.AppendLiteral("\">\n"
|
|
|
|
"<style type=\"text/css\">\n"
|
|
|
|
":root {\n"
|
|
|
|
" font-family: sans-serif;\n"
|
|
|
|
"}\n"
|
|
|
|
"img {\n"
|
|
|
|
" border: 0;\n"
|
|
|
|
"}\n"
|
|
|
|
"th {\n"
|
|
|
|
" text-align: left;\n"
|
|
|
|
" white-space: nowrap;\n"
|
|
|
|
"}\n"
|
2007-08-24 14:12:46 +04:00
|
|
|
"th > a {\n"
|
|
|
|
" color: inherit;\n"
|
|
|
|
"}\n"
|
2007-09-16 06:14:13 +04:00
|
|
|
"table[order] > thead > tr > th {\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
" cursor: pointer;\n"
|
|
|
|
"}\n"
|
2007-09-16 06:14:13 +04:00
|
|
|
"table[order] > thead > tr > th::after {\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
" display: none;\n"
|
|
|
|
" width: .8em;\n"
|
2008-01-08 02:15:37 +03:00
|
|
|
" -moz-margin-end: -.8em;\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
" text-align: right;\n"
|
|
|
|
"}\n"
|
2007-09-16 06:14:13 +04:00
|
|
|
"table[order=\"asc\"] > thead > tr > th::after {\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
" content: \"\\2193\"; /* DOWNWARDS ARROW (U+2193) */\n"
|
|
|
|
"}\n"
|
2007-09-16 06:14:13 +04:00
|
|
|
"table[order=\"desc\"] > thead > tr > th::after {\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
" content: \"\\2191\"; /* UPWARDS ARROW (U+2191) */\n"
|
|
|
|
"}\n"
|
2007-09-16 06:14:13 +04:00
|
|
|
"table[order][order-by=\"0\"] > thead > tr > th:first-child ,\n"
|
|
|
|
"table[order][order-by=\"1\"] > thead > tr > th:first-child + th ,\n"
|
|
|
|
"table[order][order-by=\"2\"] > thead > tr > th:first-child + th + th {\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
" text-decoration: underline;\n"
|
|
|
|
"}\n"
|
2007-09-16 06:14:13 +04:00
|
|
|
"table[order][order-by=\"0\"] > thead > tr > th:first-child::after ,\n"
|
|
|
|
"table[order][order-by=\"1\"] > thead > tr > th:first-child + th::after ,\n"
|
|
|
|
"table[order][order-by=\"2\"] > thead > tr > th:first-child + th + th::after {\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
" display: inline-block;\n"
|
|
|
|
"}\n"
|
|
|
|
"table.remove-hidden > tbody > tr.hidden-object {\n"
|
|
|
|
" display: none;\n"
|
|
|
|
"}\n"
|
2007-09-16 06:14:13 +04:00
|
|
|
"td > a {\n"
|
|
|
|
" display: block;\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
"}\n"
|
2008-01-08 02:15:37 +03:00
|
|
|
"/* name */\n"
|
|
|
|
"th:first-child {\n"
|
|
|
|
" -moz-padding-end: 2em;\n"
|
|
|
|
"}\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
"/* size */\n"
|
2008-01-08 02:15:37 +03:00
|
|
|
"th:first-child + th {\n"
|
|
|
|
" -moz-padding-end: 1em;\n"
|
|
|
|
"}\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
"td:first-child + td {\n"
|
|
|
|
" text-align: right;\n"
|
2008-01-08 02:15:37 +03:00
|
|
|
" -moz-padding-end: 1em;\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
" white-space: nowrap;\n"
|
|
|
|
"}\n"
|
|
|
|
"/* date */\n"
|
|
|
|
"td:first-child + td + td {\n"
|
2008-01-08 02:15:37 +03:00
|
|
|
" -moz-padding-start: 1em;\n"
|
|
|
|
" -moz-padding-end: .5em;\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
" white-space: nowrap;\n"
|
|
|
|
"}\n"
|
|
|
|
"/* time */\n"
|
|
|
|
"td:last-child {\n"
|
2008-01-08 02:15:37 +03:00
|
|
|
" -moz-padding-start: .5em;\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
" white-space: nowrap;\n"
|
|
|
|
"}\n"
|
|
|
|
"@-moz-document url-prefix(gopher://) {\n"
|
|
|
|
" td {\n"
|
|
|
|
" white-space: pre !important;\n"
|
|
|
|
" font-family: monospace;\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n"
|
|
|
|
".symlink {\n"
|
|
|
|
" font-style: italic;\n"
|
|
|
|
"}\n"
|
|
|
|
".dir ,\n"
|
|
|
|
".symlink ,\n"
|
|
|
|
".file {\n"
|
2008-01-08 02:15:37 +03:00
|
|
|
" -moz-margin-start: 20px;\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
"}\n"
|
|
|
|
".dir::before ,\n"
|
|
|
|
".file > img {\n"
|
2008-01-08 02:15:37 +03:00
|
|
|
" -moz-margin-end: 4px;\n"
|
|
|
|
" -moz-margin-start: -20px;\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
" vertical-align: middle;\n"
|
|
|
|
"}\n"
|
|
|
|
".dir::before {\n"
|
|
|
|
" content: url(resource://gre/res/html/folder.png);\n"
|
|
|
|
"}\n"
|
|
|
|
"</style>\n"
|
|
|
|
"<link rel=\"stylesheet\" media=\"screen, projection\" type=\"text/css\""
|
|
|
|
" href=\"chrome://global/skin/dirListing/dirListing.css\">\n");
|
|
|
|
|
|
|
|
if (!isSchemeGopher) {
|
|
|
|
buffer.AppendLiteral("<script type=\"application/javascript\">\n"
|
|
|
|
"var gTable, gOrderBy, gTBody, gRows, gUI_showHidden;\n"
|
|
|
|
"document.addEventListener(\"DOMContentLoaded\", function() {\n"
|
|
|
|
" gTable = document.getElementsByTagName(\"table\")[0];\n"
|
2007-08-24 14:12:46 +04:00
|
|
|
" gTBody = gTable.tBodies[0];\n"
|
|
|
|
" if (gTBody.rows.length < 2)\n"
|
|
|
|
" return;\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
" gUI_showHidden = document.getElementById(\"UI_showHidden\");\n"
|
|
|
|
" var headCells = gTable.tHead.rows[0].cells,\n"
|
|
|
|
" hiddenObjects = false;\n"
|
|
|
|
" function rowAction(i) {\n"
|
2007-08-24 14:12:46 +04:00
|
|
|
" return function(event) {\n"
|
|
|
|
" event.preventDefault();\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
" orderBy(i);\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
2007-08-24 14:12:46 +04:00
|
|
|
" for (var i = headCells.length - 1; i >= 0; i--) {\n"
|
|
|
|
" var anchor = document.createElement(\"a\");\n"
|
|
|
|
" anchor.href = \"\";\n"
|
|
|
|
" anchor.appendChild(headCells[i].firstChild);\n"
|
|
|
|
" headCells[i].appendChild(anchor);\n"
|
|
|
|
" headCells[i].addEventListener(\"click\", rowAction(i), true);\n"
|
|
|
|
" }\n"
|
2007-10-13 08:00:58 +04:00
|
|
|
" if (gUI_showHidden) {\n"
|
|
|
|
" gRows = Array.slice(gTBody.rows);\n"
|
|
|
|
" hiddenObjects = gRows.some(function (row) row.className == \"hidden-object\");\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
" }\n"
|
2007-09-03 02:19:10 +04:00
|
|
|
" gTable.setAttribute(\"order\", \"\");\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
" if (hiddenObjects) {\n"
|
|
|
|
" gUI_showHidden.style.display = \"block\";\n"
|
|
|
|
" updateHidden();\n"
|
|
|
|
" }\n"
|
|
|
|
"}, \"false\");\n"
|
|
|
|
"function compareRows(rowA, rowB) {\n"
|
|
|
|
" var a = rowA.cells[gOrderBy].getAttribute(\"sortable-data\") || \"\";\n"
|
|
|
|
" var b = rowB.cells[gOrderBy].getAttribute(\"sortable-data\") || \"\";\n"
|
|
|
|
" var intA = +a;\n"
|
|
|
|
" var intB = +b;\n"
|
|
|
|
" if (a == intA && b == intB) {\n"
|
|
|
|
" a = intA;\n"
|
|
|
|
" b = intB;\n"
|
|
|
|
" } else {\n"
|
|
|
|
" a = a.toLowerCase();\n"
|
|
|
|
" b = b.toLowerCase();\n"
|
|
|
|
" }\n"
|
|
|
|
" if (a < b)\n"
|
|
|
|
" return -1;\n"
|
|
|
|
" if (a > b)\n"
|
|
|
|
" return 1;\n"
|
|
|
|
" return 0;\n"
|
|
|
|
"}\n"
|
|
|
|
"function orderBy(column) {\n"
|
2007-10-13 08:00:58 +04:00
|
|
|
" if (!gRows)\n"
|
|
|
|
" gRows = Array.slice(gTBody.rows);\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
" var order;\n"
|
|
|
|
" if (gOrderBy == column) {\n"
|
|
|
|
" order = gTable.getAttribute(\"order\") == \"asc\" ? \"desc\" : \"asc\";\n"
|
|
|
|
" } else {\n"
|
|
|
|
" order = \"asc\";\n"
|
|
|
|
" gOrderBy = column;\n"
|
|
|
|
" gTable.setAttribute(\"order-by\", column);\n"
|
|
|
|
" gRows.sort(compareRows);\n"
|
|
|
|
" }\n"
|
2007-09-03 02:19:10 +04:00
|
|
|
" gTable.removeChild(gTBody);\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
" gTable.setAttribute(\"order\", order);\n"
|
|
|
|
" if (order == \"asc\")\n"
|
|
|
|
" for (var i = 0; i < gRows.length; i++)\n"
|
|
|
|
" gTBody.appendChild(gRows[i]);\n"
|
|
|
|
" else\n"
|
|
|
|
" for (var i = gRows.length - 1; i >= 0; i--)\n"
|
|
|
|
" gTBody.appendChild(gRows[i]);\n"
|
2007-09-03 02:19:10 +04:00
|
|
|
" gTable.appendChild(gTBody);\n"
|
2007-08-18 02:57:36 +04:00
|
|
|
"}\n"
|
|
|
|
"function updateHidden() {\n"
|
|
|
|
" gTable.className = gUI_showHidden.getElementsByTagName(\"input\")[0].checked ?\n"
|
|
|
|
" \"\" :\n"
|
|
|
|
" \"remove-hidden\";\n"
|
|
|
|
"}\n"
|
|
|
|
"</script>\n");
|
|
|
|
}
|
|
|
|
buffer.AppendLiteral("<link rel=\"icon\" type=\"image/png\" href=\"");
|
|
|
|
nsCOMPtr<nsIURI> innerUri = NS_GetInnermostURI(uri);
|
|
|
|
if (!innerUri)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(innerUri));
|
|
|
|
//XXX bug 388553: can't use skinnable icons here due to security restrictions
|
|
|
|
if (fileURL) {
|
|
|
|
//buffer.AppendLiteral("chrome://global/skin/dirListing/local.png");
|
|
|
|
buffer.AppendLiteral("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB"
|
|
|
|
"AAAAAQCAYAAAAf8/9hAAAABGd BTUEAANbY1E9YMgAAAfRJR"
|
|
|
|
"EFUeNrFUk1IVFEU/t7MfU2pMRiGLVxYhGCgEoIbyZVGtFJXt"
|
|
|
|
"hIDQ7BlgtvQpQs1NWgTA5YbscjZZLQNZkRpnEBFRR0sf9FG5"
|
|
|
|
"zne9969z/PuvAHHEN114Xv33nfP+c453znA/15a9C1qhPS3c"
|
|
|
|
"S4cYaPQtgHCmmlhvqkHo2QjLyP4WN44+azgTk3Ow9Rg/URyK"
|
|
|
|
"y7hIOiRwrawTMSLHe/wJkvMHAdF/uB9wOzPIXj8cqQZvrLzA"
|
|
|
|
"RsGnhdP0P6ekHJJmGGgIcB8kKaZa2p9/jffay9Q+QDNdOokG"
|
|
|
|
"CoD109a9EnzKyhmwotzneAjCEUgrBOAp5GIRZD6Sy8sCEEVC"
|
|
|
|
"pGBdHd17wArrMXUkLaaTu1id30RHgHHn1gUvhsVePjU1Sd5Q"
|
|
|
|
"Qp+wLFI1zxsLU3jS1/jBuOU+fHhAZI7e6hq6aVwUTK0LyghA"
|
|
|
|
"Meh0rVqzIZ7EE+gW2WwGQ+htPYVmJ4ggt+5TlKJRJGFapxEC"
|
|
|
|
"ZZnx5yVXzPfh7/iB9N1qtlewK17r0n5cdVsUEng1CXBM47Zx"
|
|
|
|
"Ypw4q9D5FP70bc5ULo4ZjfzgbuPuqDxeaJ/kjHUPZxbUhj4G"
|
|
|
|
"R7G5s5hKDyDVfp1xKisWGS0tSqge9PmwVX/7D2L7X2Euj+g3"
|
|
|
|
"5sDrrmJEW4TAq5Mlw+DGmHDa5WVdWBXdD5LosQ5BeW364651"
|
|
|
|
"CZwAAAAAElFTkSuQmCC");
|
|
|
|
} else {
|
|
|
|
//buffer.AppendLiteral("chrome://global/skin/dirListing/remote.png");
|
|
|
|
buffer.AppendLiteral("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB"
|
|
|
|
"AAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAohJRE"
|
|
|
|
"FUeNqFU0tPE2EUPTMtr5G2DBCNYrVKxAXgKwgLNlYCiWGhG3"
|
|
|
|
"eICxNZuXBl/AEQggsNO4Jxb0gwokYxGmNgIRuMSRcGbMAoVV"
|
|
|
|
"NgBqSveX3e+01LwEicyZ37Te/cc859VMF/rrm5uWvkOm3bhu"
|
|
|
|
"M4YM9mWZaRyWTeKXslJhKJi5FIpL1QKMQqKjQUKAmeB8FBIa"
|
|
|
|
"DrNZiefmkE90i+Qq6DGPVwOIyl5RXJ7nkCnvAISMAlMALXgz"
|
|
|
|
"MzM1fpY42smixEFjEMQ+eEVCq1U7L06+sGAXno7rkkfwum0+"
|
|
|
|
"lMPN7VZZobkl3wLVilkMYvxIlaPYJnU0/R3HJWsnOMFIBLqO"
|
|
|
|
"LkOw/n6ahAoa4o/kN6tt+bmxi5eV4yfpz/ANd1cbD3sq+gxM"
|
|
|
|
"of6rV1UFUVCplaND4zgPB8xpZTbfIs/B5A5frpnQBUBAKBXa"
|
|
|
|
"YWPV/cPGZMh5bwyHwgyyopqODxKKqCQDC4zS49l6Cqfm8I4P"
|
|
|
|
"uhqYHlRWrmVppVjDEAR3VuCJfAjMcP7ENsv4aj9ZWI1lVKMF"
|
|
|
|
"8Br4GN7ubryFsFCchTYQWeWqyTLbnw78UKqAFYngOXS/EsOa"
|
|
|
|
"lSCfmysiCGb5yR47FtB9msz1BeXkZlCLl9qkKJtBuu5yLvWH"
|
|
|
|
"KMUoGu6yvJ5KJGi9PI4zFNkwCycvPW1tbkyNLHpgfyjo2G2h"
|
|
|
|
"PgZW6sb8attxcGclEqfafM0dHRjqamprYqrbo1FKrBi+dPkM"
|
|
|
|
"vlJil0OnlkciRadxKthzvx/ssbpMxfOPejt//v/0K8oSEaqw"
|
|
|
|
"6FSIGLvr5+jI+PxYeGhu5S7F7PfVNsWTnMfp7FwmBWeYVP2A"
|
|
|
|
"Wwurr6bWLicay0/1SGoWna11L89e2fSvvwhlgYzG0r/wN/4X"
|
|
|
|
"tnm2x4eQAAAABJRU5ErkJggg==");
|
|
|
|
}
|
|
|
|
buffer.AppendLiteral("\">\n<title>");
|
2002-04-10 14:28:57 +04:00
|
|
|
|
2001-10-03 04:43:30 +04:00
|
|
|
// Anything but a gopher url needs to end in a /,
|
|
|
|
// otherwise we end up linking to file:///foo/dirfile
|
|
|
|
|
2002-05-17 01:00:48 +04:00
|
|
|
if (!mTextToSubURI) {
|
|
|
|
mTextToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
2002-06-25 11:51:05 +04:00
|
|
|
nsXPIDLString unEscapeSpec;
|
|
|
|
rv = mTextToSubURI->UnEscapeAndConvert(encoding, titleUri.get(),
|
|
|
|
getter_Copies(unEscapeSpec));
|
2006-05-02 10:24:11 +04:00
|
|
|
// unescape may fail because
|
|
|
|
// 1. file URL may be encoded in platform charset for backward compatibility
|
|
|
|
// 2. query part may not be encoded in UTF-8 (see bug 261929)
|
|
|
|
// so try the platform's default if this is file url
|
|
|
|
if (NS_FAILED(rv) && isSchemeFile) {
|
|
|
|
nsCOMPtr<nsIPlatformCharset> platformCharset(do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsCAutoString charset;
|
|
|
|
rv = platformCharset->GetCharset(kPlatformCharsetSel_FileName, charset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mTextToSubURI->UnEscapeAndConvert(charset.get(), titleUri.get(),
|
|
|
|
getter_Copies(unEscapeSpec));
|
|
|
|
}
|
2002-05-17 01:00:48 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2006-05-02 10:24:11 +04:00
|
|
|
|
2002-06-25 11:51:05 +04:00
|
|
|
nsXPIDLString htmlEscSpec;
|
|
|
|
htmlEscSpec.Adopt(nsEscapeHTML2(unEscapeSpec.get(),
|
|
|
|
unEscapeSpec.Length()));
|
2001-10-19 07:03:30 +04:00
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
nsXPIDLString title;
|
2001-10-19 07:03:30 +04:00
|
|
|
const PRUnichar* formatTitle[] = {
|
2002-06-25 11:51:05 +04:00
|
|
|
htmlEscSpec.get()
|
2001-10-19 07:03:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
rv = mBundle->FormatStringFromName(NS_LITERAL_STRING("DirTitle").get(),
|
2002-03-12 08:56:29 +03:00
|
|
|
formatTitle,
|
|
|
|
sizeof(formatTitle)/sizeof(PRUnichar*),
|
2001-10-19 07:03:30 +04:00
|
|
|
getter_Copies(title));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-08-20 07:32:28 +04:00
|
|
|
|
|
|
|
// we want to convert string bundle to NCR
|
|
|
|
// to ensure they're shown in any charsets
|
2007-08-18 02:57:36 +04:00
|
|
|
AppendNonAsciiToNCR(title, buffer);
|
2001-10-19 07:03:30 +04:00
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
buffer.AppendLiteral("</title>\n");
|
2006-11-28 23:32:27 +03:00
|
|
|
|
|
|
|
// If there is a quote character in the baseUri, then
|
|
|
|
// lets not add a base URL. The reason for this is that
|
|
|
|
// if we stick baseUri containing a quote into a quoted
|
|
|
|
// string, the quote character will prematurely close
|
|
|
|
// the base href string. This is a fall-back check;
|
|
|
|
// that's why it is OK to not use a base rather than
|
|
|
|
// trying to play nice and escaping the quotes. See bug
|
|
|
|
// 358128.
|
|
|
|
|
|
|
|
if (baseUri.FindChar('"') == kNotFound)
|
|
|
|
{
|
|
|
|
// Great, the baseUri does not contain a char that
|
|
|
|
// will prematurely close the string. Go ahead an
|
|
|
|
// add a base href.
|
|
|
|
buffer.AppendLiteral("<base href=\"");
|
2007-03-23 02:01:14 +03:00
|
|
|
AppendASCIItoUTF16(baseUri, buffer);
|
2007-08-18 02:57:36 +04:00
|
|
|
buffer.AppendLiteral("\">\n");
|
2006-11-28 23:32:27 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NS_ERROR("broken protocol handler didn't escape double-quote.");
|
|
|
|
}
|
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
buffer.AppendLiteral("</head>\n<body>\n<h1>");
|
2001-10-19 07:03:30 +04:00
|
|
|
|
|
|
|
const PRUnichar* formatHeading[] = {
|
2002-06-25 11:51:05 +04:00
|
|
|
htmlEscSpec.get()
|
2001-10-19 07:03:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
rv = mBundle->FormatStringFromName(NS_LITERAL_STRING("DirTitle").get(),
|
2002-03-12 08:56:29 +03:00
|
|
|
formatHeading,
|
|
|
|
sizeof(formatHeading)/sizeof(PRUnichar*),
|
2001-10-19 07:03:30 +04:00
|
|
|
getter_Copies(title));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
AppendNonAsciiToNCR(title, buffer);
|
|
|
|
buffer.AppendLiteral("</h1>\n");
|
2001-03-13 05:20:55 +03:00
|
|
|
|
2001-10-23 04:56:41 +04:00
|
|
|
if (!parentStr.IsEmpty()) {
|
|
|
|
nsXPIDLString parentText;
|
|
|
|
rv = mBundle->GetStringFromName(NS_LITERAL_STRING("DirGoUp").get(),
|
|
|
|
getter_Copies(parentText));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2007-08-18 02:57:36 +04:00
|
|
|
|
|
|
|
buffer.AppendLiteral("<p id=\"UI_goUp\"><a class=\"up\" href=\"");
|
2007-03-23 02:01:14 +03:00
|
|
|
AppendASCIItoUTF16(parentStr, buffer);
|
2004-12-04 13:19:29 +03:00
|
|
|
buffer.AppendLiteral("\">");
|
2007-08-18 02:57:36 +04:00
|
|
|
AppendNonAsciiToNCR(parentText, buffer);
|
|
|
|
buffer.AppendLiteral("</a></p>\n");
|
2001-10-23 04:56:41 +04:00
|
|
|
}
|
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
if (isSchemeFile) {
|
|
|
|
nsXPIDLString showHiddenText;
|
|
|
|
rv = mBundle->GetStringFromName(NS_LITERAL_STRING("ShowHidden").get(),
|
|
|
|
getter_Copies(showHiddenText));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
buffer.AppendLiteral("<p id=\"UI_showHidden\" style=\"display:none\"><label><input type=\"checkbox\" checked onchange=\"updateHidden()\">");
|
|
|
|
AppendNonAsciiToNCR(showHiddenText, buffer);
|
|
|
|
buffer.AppendLiteral("</label></p>\n");
|
|
|
|
}
|
|
|
|
|
2007-09-03 02:19:10 +04:00
|
|
|
buffer.AppendLiteral("<table>\n");
|
2007-08-18 02:57:36 +04:00
|
|
|
|
2007-09-03 02:19:10 +04:00
|
|
|
if (!isSchemeGopher) {
|
2007-08-18 02:57:36 +04:00
|
|
|
nsXPIDLString columnText;
|
|
|
|
|
|
|
|
buffer.AppendLiteral(" <thead>\n"
|
|
|
|
" <tr>\n"
|
|
|
|
" <th>");
|
|
|
|
|
|
|
|
rv = mBundle->GetStringFromName(NS_LITERAL_STRING("DirColName").get(),
|
|
|
|
getter_Copies(columnText));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
AppendNonAsciiToNCR(columnText, buffer);
|
|
|
|
buffer.AppendLiteral("</th>\n"
|
|
|
|
" <th>");
|
|
|
|
|
|
|
|
rv = mBundle->GetStringFromName(NS_LITERAL_STRING("DirColSize").get(),
|
|
|
|
getter_Copies(columnText));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
AppendNonAsciiToNCR(columnText, buffer);
|
|
|
|
buffer.AppendLiteral("</th>\n"
|
|
|
|
" <th colspan=\"2\">");
|
|
|
|
|
|
|
|
rv = mBundle->GetStringFromName(NS_LITERAL_STRING("DirColMTime").get(),
|
|
|
|
getter_Copies(columnText));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
AppendNonAsciiToNCR(columnText, buffer);
|
|
|
|
buffer.AppendLiteral("</th>\n"
|
|
|
|
" </tr>\n"
|
|
|
|
" </thead>\n");
|
|
|
|
}
|
|
|
|
buffer.AppendLiteral(" <tbody>\n");
|
|
|
|
|
2001-03-01 10:22:19 +03:00
|
|
|
// Push buffer to the listener now, so the initial HTML will not
|
|
|
|
// be parsed in OnDataAvailable().
|
|
|
|
|
2001-10-03 04:43:30 +04:00
|
|
|
rv = mListener->OnStartRequest(request, aContext);
|
2001-03-01 10:22:19 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2006-08-01 21:17:32 +04:00
|
|
|
// The request may have been canceled, and if that happens, we want to
|
|
|
|
// suppress calls to OnDataAvailable.
|
|
|
|
request->GetStatus(&rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-03-01 10:22:19 +03:00
|
|
|
|
2006-08-01 21:17:32 +04:00
|
|
|
rv = FormatInputStream(request, aContext, buffer);
|
2001-03-01 10:22:19 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIndexedToHTML::OnStopRequest(nsIRequest* request, nsISupports *aContext,
|
2001-04-10 10:01:08 +04:00
|
|
|
nsresult aStatus) {
|
2006-08-01 21:17:32 +04:00
|
|
|
if (NS_SUCCEEDED(aStatus)) {
|
|
|
|
nsString buffer;
|
2007-08-18 02:57:36 +04:00
|
|
|
buffer.AssignLiteral("</tbody></table></body></html>\n");
|
2002-04-10 14:28:57 +04:00
|
|
|
|
2006-08-01 21:17:32 +04:00
|
|
|
aStatus = FormatInputStream(request, aContext, buffer);
|
|
|
|
}
|
2001-10-03 04:43:30 +04:00
|
|
|
|
2006-08-01 21:17:32 +04:00
|
|
|
mParser->OnStopRequest(request, aContext, aStatus);
|
2001-10-03 04:43:30 +04:00
|
|
|
mParser = 0;
|
|
|
|
|
2001-04-10 10:01:08 +04:00
|
|
|
return mListener->OnStopRequest(request, aContext, aStatus);
|
2001-03-01 10:22:19 +03:00
|
|
|
}
|
|
|
|
|
2002-05-17 01:00:48 +04:00
|
|
|
nsresult
|
|
|
|
nsIndexedToHTML::FormatInputStream(nsIRequest* aRequest, nsISupports *aContext, const nsAString &aBuffer)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2002-08-20 07:32:28 +04:00
|
|
|
|
|
|
|
// set up unicode encoder
|
|
|
|
if (!mUnicodeEncoder) {
|
|
|
|
nsXPIDLCString encoding;
|
|
|
|
rv = mParser->GetEncoding(getter_Copies(encoding));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2003-06-11 22:16:03 +04:00
|
|
|
nsCOMPtr<nsICharsetConverterManager> charsetConverterManager;
|
2002-08-20 07:32:28 +04:00
|
|
|
charsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
2003-06-11 22:16:03 +04:00
|
|
|
rv = charsetConverterManager->GetUnicodeEncoder(encoding.get(),
|
2002-08-20 07:32:28 +04:00
|
|
|
getter_AddRefs(mUnicodeEncoder));
|
2003-06-11 22:16:03 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-08-20 07:32:28 +04:00
|
|
|
rv = mUnicodeEncoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace,
|
|
|
|
nsnull, (PRUnichar)'?');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// convert the data with unicode encoder
|
|
|
|
char *buffer = nsnull;
|
|
|
|
PRInt32 dstLength;
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
PRInt32 unicharLength = aBuffer.Length();
|
|
|
|
rv = mUnicodeEncoder->GetMaxLength(PromiseFlatString(aBuffer).get(),
|
|
|
|
unicharLength, &dstLength);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
buffer = (char *) nsMemory::Alloc(dstLength);
|
|
|
|
NS_ENSURE_TRUE(buffer, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
rv = mUnicodeEncoder->Convert(PromiseFlatString(aBuffer).get(), &unicharLength,
|
|
|
|
buffer, &dstLength);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
PRInt32 finLen = 0;
|
|
|
|
rv = mUnicodeEncoder->Finish(buffer + dstLength, &finLen);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
dstLength += finLen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if conversion error then fallback to UTF-8
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
rv = NS_OK;
|
|
|
|
if (buffer) {
|
|
|
|
nsMemory::Free(buffer);
|
|
|
|
buffer = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-17 01:00:48 +04:00
|
|
|
nsCOMPtr<nsIInputStream> inputData;
|
2002-08-20 07:32:28 +04:00
|
|
|
if (buffer) {
|
2002-08-24 04:48:58 +04:00
|
|
|
rv = NS_NewCStringInputStream(getter_AddRefs(inputData), Substring(buffer, buffer + dstLength));
|
2002-08-20 07:32:28 +04:00
|
|
|
nsMemory::Free(buffer);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = mListener->OnDataAvailable(aRequest, aContext,
|
|
|
|
inputData, 0, dstLength);
|
|
|
|
}
|
|
|
|
else {
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_ConvertUTF16toUTF8 utf8Buffer(aBuffer);
|
2002-08-20 07:32:28 +04:00
|
|
|
rv = NS_NewCStringInputStream(getter_AddRefs(inputData), utf8Buffer);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = mListener->OnDataAvailable(aRequest, aContext,
|
|
|
|
inputData, 0, utf8Buffer.Length());
|
|
|
|
}
|
2002-05-17 01:00:48 +04:00
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
2001-10-03 04:43:30 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIndexedToHTML::OnDataAvailable(nsIRequest *aRequest,
|
|
|
|
nsISupports *aCtxt,
|
|
|
|
nsIInputStream* aInput,
|
|
|
|
PRUint32 aOffset,
|
|
|
|
PRUint32 aCount) {
|
|
|
|
return mParser->OnDataAvailable(aRequest, aCtxt, aInput, aOffset, aCount);
|
|
|
|
}
|
2001-03-01 10:22:19 +03:00
|
|
|
|
2001-10-03 04:43:30 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIndexedToHTML::OnIndexAvailable(nsIRequest *aRequest,
|
|
|
|
nsISupports *aCtxt,
|
|
|
|
nsIDirIndex *aIndex) {
|
2002-09-04 01:51:24 +04:00
|
|
|
nsresult rv;
|
2001-10-03 04:43:30 +04:00
|
|
|
if (!aIndex)
|
2001-03-01 10:22:19 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2001-10-03 04:43:30 +04:00
|
|
|
nsString pushBuffer;
|
2007-08-18 02:57:36 +04:00
|
|
|
pushBuffer.AppendLiteral("<tr");
|
|
|
|
|
|
|
|
nsXPIDLString description;
|
|
|
|
aIndex->GetDescription(getter_Copies(description));
|
|
|
|
if (description.First() == PRUnichar('.'))
|
|
|
|
pushBuffer.AppendLiteral(" class=\"hidden-object\"");
|
|
|
|
|
|
|
|
pushBuffer.AppendLiteral(">\n <td sortable-data=\"");
|
2007-08-18 02:57:39 +04:00
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
// The sort key is the name of the item, prepended by either 0, 1 or 2
|
|
|
|
// in order to group items.
|
2002-04-10 14:28:57 +04:00
|
|
|
PRUint32 type;
|
|
|
|
aIndex->GetType(&type);
|
2007-08-18 02:57:36 +04:00
|
|
|
switch (type) {
|
|
|
|
case nsIDirIndex::TYPE_SYMLINK:
|
|
|
|
pushBuffer.AppendInt(0);
|
|
|
|
break;
|
|
|
|
case nsIDirIndex::TYPE_DIRECTORY:
|
|
|
|
pushBuffer.AppendInt(1);
|
|
|
|
break;
|
|
|
|
case nsIDirIndex::TYPE_FILE:
|
|
|
|
case nsIDirIndex::TYPE_UNKNOWN:
|
|
|
|
pushBuffer.AppendInt(2);
|
|
|
|
break;
|
2002-04-10 14:28:57 +04:00
|
|
|
}
|
2007-08-18 02:57:36 +04:00
|
|
|
PRUnichar* escaped = nsEscapeHTML2(description.get(), description.Length());
|
|
|
|
pushBuffer.Append(escaped);
|
2001-10-03 04:43:30 +04:00
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
pushBuffer.AppendLiteral("\"><a class=\"");
|
|
|
|
switch (type) {
|
|
|
|
case nsIDirIndex::TYPE_DIRECTORY:
|
|
|
|
pushBuffer.AppendLiteral("dir");
|
|
|
|
break;
|
|
|
|
case nsIDirIndex::TYPE_SYMLINK:
|
|
|
|
pushBuffer.AppendLiteral("symlink");
|
|
|
|
break;
|
|
|
|
case nsIDirIndex::TYPE_FILE:
|
|
|
|
case nsIDirIndex::TYPE_UNKNOWN:
|
|
|
|
pushBuffer.AppendLiteral("file");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pushBuffer.AppendLiteral("\"");
|
|
|
|
|
|
|
|
// Truncate long names to not stretch the table
|
|
|
|
//XXX this should be left to the stylesheet (bug 391471)
|
|
|
|
nsString escapedShort;
|
2007-09-16 06:14:13 +04:00
|
|
|
if (description.Length() > 71) {
|
2007-08-18 02:57:36 +04:00
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = channel->GetURI(getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// No need to do this for Gopher, as the table has only one column in that case
|
|
|
|
PRBool isSchemeGopher = PR_FALSE;
|
|
|
|
if (!(NS_SUCCEEDED(uri->SchemeIs("gopher", &isSchemeGopher)) && isSchemeGopher)) {
|
|
|
|
//XXX this potentially truncates after a combining char (bug 391472)
|
2007-08-26 07:20:24 +04:00
|
|
|
nsXPIDLString descriptionAffix;
|
|
|
|
descriptionAffix.Assign(description);
|
2007-09-16 06:14:13 +04:00
|
|
|
descriptionAffix.Cut(0, descriptionAffix.Length() - 25);
|
2007-08-26 07:20:24 +04:00
|
|
|
if (NS_IS_LOW_SURROGATE(descriptionAffix.First()))
|
|
|
|
descriptionAffix.Cut(0, 1);
|
2007-09-16 06:14:13 +04:00
|
|
|
description.Truncate(PR_MIN(71, description.Length() - 28));
|
2007-08-18 02:57:36 +04:00
|
|
|
if (NS_IS_HIGH_SURROGATE(description.Last()))
|
2007-08-26 07:20:24 +04:00
|
|
|
description.Truncate(description.Length() - 1);
|
2007-08-18 02:57:36 +04:00
|
|
|
|
|
|
|
escapedShort.Adopt(nsEscapeHTML2(description.get(), description.Length()));
|
2008-01-16 04:44:25 +03:00
|
|
|
// add HORIZONTAL ELLIPSIS (U+2026) and ZERO WIDTH SPACE (U+200B) for wrapping
|
|
|
|
escapedShort.AppendLiteral("…​");
|
2007-08-26 07:20:24 +04:00
|
|
|
nsString tmp;
|
|
|
|
tmp.Adopt(nsEscapeHTML2(descriptionAffix.get(), descriptionAffix.Length()));
|
|
|
|
escapedShort.Append(tmp);
|
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
pushBuffer.AppendLiteral(" title=\"");
|
|
|
|
pushBuffer.Append(escaped);
|
|
|
|
pushBuffer.AppendLiteral("\"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (escapedShort.IsEmpty())
|
|
|
|
escapedShort.Assign(escaped);
|
|
|
|
nsMemory::Free(escaped);
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
pushBuffer.AppendLiteral(" href=\"");
|
2001-10-03 04:43:30 +04:00
|
|
|
nsXPIDLCString loc;
|
|
|
|
aIndex->GetLocation(getter_Copies(loc));
|
2003-04-19 23:47:28 +04:00
|
|
|
|
2002-09-04 01:51:24 +04:00
|
|
|
if (!mTextToSubURI) {
|
|
|
|
mTextToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
2006-05-02 10:24:11 +04:00
|
|
|
|
2002-09-04 01:51:24 +04:00
|
|
|
nsXPIDLCString encoding;
|
|
|
|
rv = mParser->GetEncoding(getter_Copies(encoding));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsXPIDLString unEscapeSpec;
|
|
|
|
rv = mTextToSubURI->UnEscapeAndConvert(encoding, loc,
|
|
|
|
getter_Copies(unEscapeSpec));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2006-05-02 10:24:11 +04:00
|
|
|
|
2002-12-05 22:18:57 +03:00
|
|
|
// need to escape links
|
|
|
|
nsCAutoString escapeBuf;
|
|
|
|
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_ConvertUTF16toUTF8 utf8UnEscapeSpec(unEscapeSpec);
|
2001-10-03 04:43:30 +04:00
|
|
|
|
2003-04-19 23:47:28 +04:00
|
|
|
// now minimally re-escape the location...
|
|
|
|
PRUint32 escFlags;
|
|
|
|
// for some protocols, like gopher, we expect the location to be absolute.
|
|
|
|
// if so, and if the location indeed appears to be a valid URI, then go
|
|
|
|
// ahead and treat it like one.
|
|
|
|
if (mExpectAbsLoc &&
|
|
|
|
NS_SUCCEEDED(net_ExtractURLScheme(utf8UnEscapeSpec, nsnull, nsnull, nsnull))) {
|
|
|
|
// escape as absolute
|
|
|
|
escFlags = esc_Forced | esc_OnlyASCII | esc_AlwaysCopy | esc_Minimal;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// escape as relative
|
2006-03-30 02:10:37 +04:00
|
|
|
// esc_Directory is needed for protocols which allow the same name for
|
|
|
|
// both a directory and a file and distinguish between the two by a
|
|
|
|
// trailing '/' -- without it, the trailing '/' will be escaped, and
|
|
|
|
// links from within that directory will be incorrect
|
|
|
|
escFlags = esc_Forced | esc_OnlyASCII | esc_AlwaysCopy | esc_FileBaseName | esc_Colon | esc_Directory;
|
2003-04-19 23:47:28 +04:00
|
|
|
}
|
|
|
|
NS_EscapeURL(utf8UnEscapeSpec.get(), utf8UnEscapeSpec.Length(), escFlags, escapeBuf);
|
2001-04-27 05:51:28 +04:00
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
AppendUTF8toUTF16(escapeBuf, pushBuffer);
|
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
pushBuffer.AppendLiteral("\">");
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
if (type == nsIDirIndex::TYPE_FILE || type == nsIDirIndex::TYPE_UNKNOWN) {
|
|
|
|
pushBuffer.AppendLiteral("<img src=\"moz-icon://");
|
2007-09-03 02:19:10 +04:00
|
|
|
PRInt32 lastDot = escapeBuf.RFindChar('.');
|
|
|
|
if (lastDot != kNotFound) {
|
|
|
|
escapeBuf.Cut(0, lastDot);
|
|
|
|
AppendUTF8toUTF16(escapeBuf, pushBuffer);
|
|
|
|
} else {
|
|
|
|
pushBuffer.AppendLiteral("unknown");
|
|
|
|
}
|
2007-08-18 02:57:36 +04:00
|
|
|
pushBuffer.AppendLiteral("?size=16\" alt=\"");
|
2001-03-01 10:22:19 +03:00
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
nsXPIDLString altText;
|
|
|
|
rv = mBundle->GetStringFromName(NS_LITERAL_STRING("DirFileLabel").get(),
|
|
|
|
getter_Copies(altText));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
AppendNonAsciiToNCR(altText, pushBuffer);
|
|
|
|
pushBuffer.AppendLiteral("\">");
|
|
|
|
}
|
2001-03-01 10:22:19 +03:00
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
pushBuffer.Append(escapedShort);
|
|
|
|
pushBuffer.AppendLiteral("</a></td>\n <td");
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
if (type == nsIDirIndex::TYPE_DIRECTORY || type == nsIDirIndex::TYPE_SYMLINK) {
|
|
|
|
pushBuffer.AppendLiteral(">");
|
|
|
|
} else {
|
|
|
|
PRInt64 size;
|
|
|
|
aIndex->GetSize(&size);
|
|
|
|
|
|
|
|
if (PRUint64(size) != LL_MAXUINT) {
|
|
|
|
pushBuffer.AppendLiteral(" sortable-data=\"");
|
|
|
|
pushBuffer.AppendInt(size);
|
|
|
|
pushBuffer.AppendLiteral("\">");
|
|
|
|
nsAutoString sizeString;
|
|
|
|
FormatSizeString(size, sizeString);
|
|
|
|
pushBuffer.Append(sizeString);
|
|
|
|
} else {
|
|
|
|
pushBuffer.AppendLiteral(">");
|
|
|
|
}
|
2001-03-01 10:22:19 +03:00
|
|
|
}
|
2007-08-18 02:57:36 +04:00
|
|
|
pushBuffer.AppendLiteral("</td>\n <td");
|
2001-03-01 10:22:19 +03:00
|
|
|
|
2001-10-03 04:43:30 +04:00
|
|
|
PRTime t;
|
|
|
|
aIndex->GetLastModified(&t);
|
2001-03-01 10:22:19 +03:00
|
|
|
|
2001-10-03 04:43:30 +04:00
|
|
|
if (t == -1) {
|
2007-08-18 02:57:36 +04:00
|
|
|
pushBuffer.AppendLiteral("></td>\n <td>");
|
2001-10-03 04:43:30 +04:00
|
|
|
} else {
|
2007-08-18 02:57:36 +04:00
|
|
|
pushBuffer.AppendLiteral(" sortable-data=\"");
|
|
|
|
pushBuffer.AppendInt(t);
|
|
|
|
pushBuffer.AppendLiteral("\">");
|
2001-10-03 04:43:30 +04:00
|
|
|
nsAutoString formatted;
|
2001-11-06 04:46:18 +03:00
|
|
|
mDateTime->FormatPRTime(nsnull,
|
2001-10-03 04:43:30 +04:00
|
|
|
kDateFormatShort,
|
2001-11-06 04:46:18 +03:00
|
|
|
kTimeFormatNone,
|
|
|
|
t,
|
|
|
|
formatted);
|
2007-08-18 02:57:36 +04:00
|
|
|
AppendNonAsciiToNCR(formatted, pushBuffer);
|
2004-06-17 04:13:25 +04:00
|
|
|
pushBuffer.AppendLiteral("</td>\n <td>");
|
2001-11-06 04:46:18 +03:00
|
|
|
mDateTime->FormatPRTime(nsnull,
|
|
|
|
kDateFormatNone,
|
2001-10-03 04:43:30 +04:00
|
|
|
kTimeFormatSeconds,
|
|
|
|
t,
|
|
|
|
formatted);
|
2007-08-18 02:57:36 +04:00
|
|
|
// use NCR to show date in any doc charset
|
|
|
|
AppendNonAsciiToNCR(formatted, pushBuffer);
|
2001-03-01 10:22:19 +03:00
|
|
|
}
|
|
|
|
|
2007-08-18 02:57:36 +04:00
|
|
|
pushBuffer.AppendLiteral("</td>\n</tr>");
|
2001-12-06 03:10:11 +03:00
|
|
|
|
2002-05-17 01:00:48 +04:00
|
|
|
return FormatInputStream(aRequest, aCtxt, pushBuffer);
|
2001-10-03 04:43:30 +04:00
|
|
|
}
|
2001-03-01 10:22:19 +03:00
|
|
|
|
2004-06-12 23:49:40 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIndexedToHTML::OnInformationAvailable(nsIRequest *aRequest,
|
|
|
|
nsISupports *aCtxt,
|
|
|
|
const nsAString& aInfo) {
|
|
|
|
nsAutoString pushBuffer;
|
|
|
|
PRUnichar* escaped = nsEscapeHTML2(PromiseFlatString(aInfo).get());
|
|
|
|
if (!escaped)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2004-12-04 13:19:29 +03:00
|
|
|
pushBuffer.AppendLiteral("<tr>\n <td>");
|
2004-06-12 23:49:40 +04:00
|
|
|
pushBuffer.Append(escaped);
|
|
|
|
nsMemory::Free(escaped);
|
2004-12-04 13:19:29 +03:00
|
|
|
pushBuffer.AppendLiteral("</td>\n <td></td>\n <td></td>\n <td></td>\n</tr>\n");
|
2004-06-12 23:49:40 +04:00
|
|
|
|
|
|
|
return FormatInputStream(aRequest, aCtxt, pushBuffer);
|
|
|
|
}
|
|
|
|
|
2004-04-18 17:20:54 +04:00
|
|
|
void nsIndexedToHTML::FormatSizeString(PRInt64 inSize, nsString& outSizeString)
|
2001-11-06 04:46:18 +03:00
|
|
|
{
|
|
|
|
outSizeString.Truncate();
|
2007-08-18 02:57:36 +04:00
|
|
|
if (inSize > PRInt64(0)) {
|
2001-11-06 04:46:18 +03:00
|
|
|
// round up to the nearest Kilobyte
|
2007-08-18 02:57:36 +04:00
|
|
|
PRInt64 upperSize = (inSize + PRInt64(1023)) / PRInt64(1024);
|
2001-11-06 04:46:18 +03:00
|
|
|
outSizeString.AppendInt(upperSize);
|
2004-06-17 04:13:25 +04:00
|
|
|
outSizeString.AppendLiteral(" KB");
|
2001-11-06 04:46:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-01 10:22:19 +03:00
|
|
|
nsIndexedToHTML::nsIndexedToHTML() {
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIndexedToHTML::~nsIndexedToHTML() {
|
|
|
|
}
|