Bug 592943 - (4/5) Improve PathifyURI to handle chrome URIs, r=glandium
authorMichael Wu <mwu@mozilla.com>
Thu, 16 Jun 2011 12:54:48 +0800
changeset 71687 8468c5916b757c7f2938feb68d87a9785eec8c2e
parent 71686 743bc4458fc11da351ec5acdd43e4e6d8a4375da
child 71688 59d282cf2d86ef320474ce3dd23600768fd9cd45
push id159
push usereakhgari@mozilla.com
push dateTue, 16 Aug 2011 17:53:11 +0000
treeherdermozilla-beta@8786e3e49240 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs592943
milestone7.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 592943 - (4/5) Improve PathifyURI to handle chrome URIs, r=glandium
startupcache/StartupCacheUtils.cpp
--- a/startupcache/StartupCacheUtils.cpp
+++ b/startupcache/StartupCacheUtils.cpp
@@ -1,15 +1,16 @@
 
 #include "nsCOMPtr.h"
 #include "nsIInputStream.h"
 #include "nsIStringStream.h"
 #include "nsNetUtil.h"
 #include "nsIJARURI.h"
 #include "nsIResProtocolHandler.h"
+#include "nsIChromeRegistry.h"
 #include "nsAutoPtr.h"
 #include "StartupCacheUtils.h"
 #include "mozilla/scache/StartupCache.h"
 #include "mozilla/Omnijar.h"
 
 namespace mozilla {
 namespace scache {
 
@@ -116,29 +117,29 @@ canonicalizeBase(nsCAutoString &spec,
  * using standard zip tools.
  * Transformations applied:
  *  * resource:// URIs are resolved to their corresponding file/jar URI to
  *    canonicalize resources URIs other than gre and app.
  *  * Paths under GRE or APP directory have their base path replaced with
  *    resource/gre or resource/app to avoid depending on install location.
  *  * jar:file:///path/to/file.jar!/sub/path urls are replaced with
  *    /path/to/file.jar/sub/path
- *  * .bin suffix is added to the end of the path to indicate that jsloader/ entries
- *     are binary representations of JS source.
- *  The result is appended to the string passed in, and it is recommended
- *  to add some sort of prefix before calling to group types of entries
- * For example, in the js loader:
+ *
+ *  The result is appended to the string passed in. Adding a prefix before
+ *  calling is recommended to avoid colliding with other cache users.
+ *
+ * For example, in the js loader (string is prefixed with jsloader by caller):
  *  resource://gre/modules/XPCOMUtils.jsm or
  *  file://$GRE_DIR/modules/XPCOMUtils.jsm or
- *  jar:file://$GRE_DIR/omni.jar!/modules/XPCOMUtils.jsm become
- *     jsloader/resource/gre/modules/XPCOMUtils.jsm.bin
+ *  jar:file://$GRE_DIR/omni.jar!/modules/XPCOMUtils.jsm becomes
+ *     jsloader/resource/gre/modules/XPCOMUtils.jsm
  *  file://$PROFILE_DIR/extensions/{uuid}/components/component.js becomes
- *     jsloader/$PROFILE_DIR/extensions/%7Buuid%7D/components/component.js.bin
+ *     jsloader/$PROFILE_DIR/extensions/%7Buuid%7D/components/component.js
  *  jar:file://$PROFILE_DIR/extensions/some.xpi!/components/component.js becomes
- *     jsloader/$PROFILE_DIR/extensions/some.xpi/components/component.js.bin
+ *     jsloader/$PROFILE_DIR/extensions/some.xpi/components/component.js
  */
 NS_EXPORT nsresult
 NS_PathifyURI(nsIURI *in, nsACString &out)
 {
     PRBool equals;
     nsresult rv;
     nsCOMPtr<nsIURI> uri = in;
     nsCAutoString spec;
@@ -157,17 +158,27 @@ NS_PathifyURI(nsIURI *in, nsACString &ou
         NS_ENSURE_SUCCESS(rv, rv);
 
         rv = irph->ResolveURI(in, spec);
         NS_ENSURE_SUCCESS(rv, rv);
 
         rv = ioService->NewURI(spec, nsnull, nsnull, getter_AddRefs(uri));
         NS_ENSURE_SUCCESS(rv, rv);
     } else {
-        rv = in->GetSpec(spec);
+        if (NS_SUCCEEDED(in->SchemeIs("chrome", &equals)) && equals) {
+            nsCOMPtr<nsIChromeRegistry> chromeReg =
+                mozilla::services::GetChromeRegistryService();
+            if (!chromeReg)
+                return NS_ERROR_UNEXPECTED;
+
+            rv = chromeReg->ConvertChromeURL(in, getter_AddRefs(uri));
+            NS_ENSURE_SUCCESS(rv, rv);
+        }
+
+        rv = uri->GetSpec(spec);
         NS_ENSURE_SUCCESS(rv, rv);
     }
 
     if (!canonicalizeBase(spec, out, mozilla::Omnijar::GRE) &&
         !canonicalizeBase(spec, out, mozilla::Omnijar::APP)) {
         if (NS_SUCCEEDED(uri->SchemeIs("file", &equals)) && equals) {
             nsCOMPtr<nsIFileURL> baseFileURL;
             baseFileURL = do_QueryInterface(uri, &rv);
@@ -181,37 +192,30 @@ NS_PathifyURI(nsIURI *in, nsACString &ou
         } else if (NS_SUCCEEDED(uri->SchemeIs("jar", &equals)) && equals) {
             nsCOMPtr<nsIJARURI> jarURI = do_QueryInterface(uri, &rv);
             NS_ENSURE_SUCCESS(rv, rv);
 
             nsCOMPtr<nsIURI> jarFileURI;
             rv = jarURI->GetJARFile(getter_AddRefs(jarFileURI));
             NS_ENSURE_SUCCESS(rv, rv);
 
-            nsCOMPtr<nsIFileURL> jarFileURL;
-            jarFileURL = do_QueryInterface(jarFileURI, &rv);
+            rv = NS_PathifyURI(jarFileURI, out);
             NS_ENSURE_SUCCESS(rv, rv);
 
             nsCAutoString path;
-            rv = jarFileURL->GetPath(path);
-            NS_ENSURE_SUCCESS(rv, rv);
-            out.Append(path);
-
             rv = jarURI->GetJAREntry(path);
             NS_ENSURE_SUCCESS(rv, rv);
             out.Append("/");
             out.Append(path);
         } else { // Very unlikely
             nsCAutoString spec;
             rv = uri->GetSpec(spec);
             NS_ENSURE_SUCCESS(rv, rv);
 
             out.Append("/");
             out.Append(spec);
         }
     }
-
-    out.Append(".bin");
     return NS_OK;
 }
 
 }
 }