Bug 1366180 - Fix title and parent links in resource:// listings. r?valentin
For a long time, opening a resource:// url that leads to a file list has
used a title of the form "Index of jar:file://..." where the
jar:file://... url is the actual location the resource:// url has been
resolved to in the omni.ja.
That same url is used to derive a link to the parent directory. Because
of security context restrictions, the resource://... page can't open a
link to jar:file://... .
So we use the original resource:// url to derive the parent directory
link, and while here, also fix the title.
--- a/netwerk/streamconv/converters/nsIndexedToHTML.cpp
+++ b/netwerk/streamconv/converters/nsIndexedToHTML.cpp
@@ -122,19 +122,30 @@ nsIndexedToHTML::OnStartRequest(nsIReque
nsresult
nsIndexedToHTML::DoOnStartRequest(nsIRequest* request, nsISupports *aContext,
nsCString& aBuffer) {
nsresult rv;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
nsCOMPtr<nsIURI> uri;
- rv = channel->GetURI(getter_AddRefs(uri));
+ rv = channel->GetOriginalURI(getter_AddRefs(uri));
+ if (NS_FAILED(rv)) return rv;
+
+ bool isResource = false;
+ rv = uri->SchemeIs("resource", &isResource);
if (NS_FAILED(rv)) return rv;
+ // We use the original URI for the title and parent link when it's a
+ // resource:// url, instead of the jar:file:// url it resolves to.
+ if (!isResource) {
+ rv = channel->GetURI(getter_AddRefs(uri));
+ if (NS_FAILED(rv)) return rv;
+ }
+
channel->SetContentType(NS_LITERAL_CSTRING("text/html"));
mParser = do_CreateInstance("@mozilla.org/dirIndexParser;1",&rv);
if (NS_FAILED(rv)) return rv;
rv = mParser->SetListener(this);
if (NS_FAILED(rv)) return rv;
@@ -539,22 +550,17 @@ nsIndexedToHTML::DoOnStartRequest(nsIReq
// 358128.
if (!baseUri.Contains('"'))
{
// Great, the baseUri does not contain a char that
// will prematurely close the string. Go ahead an
// add a base href, but only do so if we're not
// dealing with a resource URI.
- nsCOMPtr<nsIURI> originalUri;
- rv = channel->GetOriginalURI(getter_AddRefs(originalUri));
- bool wasResource = false;
- if (NS_FAILED(rv) ||
- NS_FAILED(originalUri->SchemeIs("resource", &wasResource)) ||
- !wasResource) {
+ if (!isResource) {
buffer.AppendLiteral("<base href=\"");
nsAdoptingCString htmlEscapedUri(nsEscapeHTML(baseUri.get()));
buffer.Append(htmlEscapedUri);
buffer.AppendLiteral("\" />\n");
}
}
else
{