Bug 1366180 - Fix title and parent links in resource:// listings. r?valentin draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 24 May 2017 11:27:22 +0900
changeset 583456 24637b8bde848950acea5630d3bead1cb9b3ee84
parent 583455 051f43027fbdbcf803b6c31f757fe86033de2a62
child 630059 e55157aa43373c55fffd6d73b45107b97b7f75d7
push id60396
push userbmo:mh+mozilla@glandium.org
push dateWed, 24 May 2017 02:36:35 +0000
reviewersvalentin
bugs1366180
milestone55.0a1
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.
netwerk/streamconv/converters/nsIndexedToHTML.cpp
--- 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
     {