Bug 792347 - Fix PathifyURI to properly return a resource/app path for resource://app/ urls when the application is in a subdirectory of the GRE. r=mwu
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 20 Sep 2012 09:52:12 +0200
changeset 107617 61d680a20cea0c0a41b9041a6741c53f77cfd1c6
parent 107616 60db83025921c2bbe85b9603255072ca85ddbc22
child 107618 174e8b89a5ab1619c94f60224ed5751dfa135410
push id23498
push userryanvm@gmail.com
push dateFri, 21 Sep 2012 01:27:06 +0000
treeherdermozilla-central@488beb32bca5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu
bugs792347
milestone18.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 792347 - Fix PathifyURI to properly return a resource/app path for resource://app/ urls when the application is in a subdirectory of the GRE. r=mwu
startupcache/StartupCacheUtils.cpp
--- a/startupcache/StartupCacheUtils.cpp
+++ b/startupcache/StartupCacheUtils.cpp
@@ -99,31 +99,50 @@ NewBufferFromStorageStream(nsIStorageStr
   *buffer = temp.forget();
   return NS_OK;
 }
 
 static const char baseName[2][5] = { "gre/", "app/" };
 
 static inline bool
 canonicalizeBase(nsAutoCString &spec,
-                 nsACString &out,
-                 mozilla::Omnijar::Type aType)
+                 nsACString &out)
 {
-    nsAutoCString base;
-    nsresult rv = mozilla::Omnijar::GetURIString(aType, base);
+    nsAutoCString greBase, appBase;
+    nsresult rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::GRE, greBase);
+    if (NS_FAILED(rv) || !greBase.Length())
+        return false;
 
-    if (NS_FAILED(rv) || !base.Length())
+    rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::APP, appBase);
+    if (NS_FAILED(rv))
         return false;
 
-    if (base.Compare(spec.get(), false, base.Length()))
+    bool underGre = !greBase.Compare(spec.get(), false, greBase.Length());
+    bool underApp = appBase.Length() &&
+                    !appBase.Compare(spec.get(), false, appBase.Length());
+
+    if (!underGre && !underApp)
         return false;
 
+    /**
+     * At this point, if both underGre and underApp are true, it can be one
+     * of the two following cases:
+     * - the GRE directory points to a subdirectory of the APP directory,
+     *   meaning spec points under GRE.
+     * - the APP directory points to a subdirectory of the GRE directory,
+     *   meaning spec points under APP.
+     * Checking the GRE and APP path length is enough to know in which case
+     * we are.
+     */
+    if (underGre && underApp && greBase.Length() < appBase.Length())
+        underGre = false;
+
     out.Append("/resource/");
-    out.Append(baseName[aType]);
-    out.Append(Substring(spec, base.Length()));
+    out.Append(baseName[underGre ? mozilla::Omnijar::GRE : mozilla::Omnijar::APP]);
+    out.Append(Substring(spec, underGre ? greBase.Length() : appBase.Length()));
     return true;
 }
 
 /**
  * PathifyURI transforms uris into useful zip paths
  * to make it easier to manipulate startup cache entries
  * using standard zip tools.
  * Transformations applied:
@@ -183,18 +202,17 @@ PathifyURI(nsIURI *in, nsACString &out)
             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 (!canonicalizeBase(spec, out)) {
         if (NS_SUCCEEDED(uri->SchemeIs("file", &equals)) && equals) {
             nsCOMPtr<nsIFileURL> baseFileURL;
             baseFileURL = do_QueryInterface(uri, &rv);
             NS_ENSURE_SUCCESS(rv, rv);
 
             nsAutoCString path;
             rv = baseFileURL->GetPath(path);
             NS_ENSURE_SUCCESS(rv, rv);