Bug 1034999 - fix XUL cache and overlay system to ignore refs/hashes, r=smaug,mossop
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 16 Sep 2014 14:57:45 +0200
changeset 206049 28c446b22a15ce0f85c680c3106406f7aff712b7
parent 206048 c417a2154756a42efbce35a1d3591d03ea595a7b
child 206050 8a6e14c73d94dd2c4dadbf94f12c03f41f49b8e6
push id49338
push userkwierso@gmail.com
push dateThu, 18 Sep 2014 23:10:09 +0000
treeherdermozilla-inbound@245051c6a7ed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, mossop
bugs1034999
milestone35.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 1034999 - fix XUL cache and overlay system to ignore refs/hashes, r=smaug,mossop
chrome/nsChromeRegistryChrome.cpp
content/xul/document/src/nsXULPrototypeCache.cpp
--- a/chrome/nsChromeRegistryChrome.cpp
+++ b/chrome/nsChromeRegistryChrome.cpp
@@ -676,28 +676,36 @@ nsChromeRegistryChrome::OverlayListHash:
   return &entry->mArray;
 }
 
 #ifdef MOZ_XUL
 NS_IMETHODIMP
 nsChromeRegistryChrome::GetStyleOverlays(nsIURI *aChromeURL,
                                          nsISimpleEnumerator **aResult)
 {
-  const nsCOMArray<nsIURI>* parray = mStyleHash.GetArray(aChromeURL);
+  nsCOMPtr<nsIURI> chromeURLWithoutHash;
+  if (aChromeURL) {
+    aChromeURL->CloneIgnoringRef(getter_AddRefs(chromeURLWithoutHash));
+  }
+  const nsCOMArray<nsIURI>* parray = mStyleHash.GetArray(chromeURLWithoutHash);
   if (!parray)
     return NS_NewEmptyEnumerator(aResult);
 
   return NS_NewArrayEnumerator(aResult, *parray);
 }
 
 NS_IMETHODIMP
 nsChromeRegistryChrome::GetXULOverlays(nsIURI *aChromeURL,
                                        nsISimpleEnumerator **aResult)
 {
-  const nsCOMArray<nsIURI>* parray = mOverlayHash.GetArray(aChromeURL);
+  nsCOMPtr<nsIURI> chromeURLWithoutHash;
+  if (aChromeURL) {
+    aChromeURL->CloneIgnoringRef(getter_AddRefs(chromeURLWithoutHash));
+  }
+  const nsCOMArray<nsIURI>* parray = mOverlayHash.GetArray(chromeURLWithoutHash);
   if (!parray)
     return NS_NewEmptyEnumerator(aResult);
 
   return NS_NewArrayEnumerator(aResult, *parray);
 }
 #endif // MOZ_XUL
 
 nsIURI*
@@ -890,17 +898,20 @@ nsChromeRegistryChrome::ManifestOverlay(
   }
 
   if (!CanLoadResource(overlayuri)) {
     LogMessageWithContext(cx.GetManifestURI(), lineno, nsIScriptError::warningFlag,
                           "Cannot register non-local URI '%s' as an overlay.", overlay);
     return;
   }
 
-  mOverlayHash.Add(baseuri, overlayuri);
+  nsCOMPtr<nsIURI> baseuriWithoutHash;
+  baseuri->CloneIgnoringRef(getter_AddRefs(baseuriWithoutHash));
+
+  mOverlayHash.Add(baseuriWithoutHash, overlayuri);
 }
 
 void
 nsChromeRegistryChrome::ManifestStyle(ManifestProcessingContext& cx, int lineno,
                                       char *const * argv, bool platform,
                                       bool contentaccessible)
 {
   char* base = argv[0];
@@ -915,17 +926,20 @@ nsChromeRegistryChrome::ManifestStyle(Ma
   }
 
   if (!CanLoadResource(overlayuri)) {
     LogMessageWithContext(cx.GetManifestURI(), lineno, nsIScriptError::warningFlag,
                           "Cannot register non-local URI '%s' as a style overlay.", overlay);
     return;
   }
 
-  mStyleHash.Add(baseuri, overlayuri);
+  nsCOMPtr<nsIURI> baseuriWithoutHash;
+  baseuri->CloneIgnoringRef(getter_AddRefs(baseuriWithoutHash));
+
+  mStyleHash.Add(baseuriWithoutHash, overlayuri);
 }
 
 void
 nsChromeRegistryChrome::ManifestOverride(ManifestProcessingContext& cx, int lineno,
                                          char *const * argv, bool platform,
                                          bool contentaccessible)
 {
   char* chrome = argv[0];
--- a/content/xul/document/src/nsXULPrototypeCache.cpp
+++ b/content/xul/document/src/nsXULPrototypeCache.cpp
@@ -126,17 +126,23 @@ nsXULPrototypeCache::Observe(nsISupports
         NS_WARNING("Unexpected observer topic.");
     }
     return NS_OK;
 }
 
 nsXULPrototypeDocument*
 nsXULPrototypeCache::GetPrototype(nsIURI* aURI)
 {
-    nsXULPrototypeDocument* protoDoc = mPrototypeTable.GetWeak(aURI);
+    if (!aURI)
+        return nullptr;
+
+    nsCOMPtr<nsIURI> uriWithoutRef;
+    aURI->CloneIgnoringRef(getter_AddRefs(uriWithoutRef));
+
+    nsXULPrototypeDocument* protoDoc = mPrototypeTable.GetWeak(uriWithoutRef);
     if (protoDoc)
         return protoDoc;
 
     nsresult rv = BeginCaching(aURI);
     if (NS_FAILED(rv))
         return nullptr;
 
     // No prototype in XUL memory cache. Spin up the cache Service.
@@ -159,17 +165,23 @@ nsXULPrototypeCache::GetPrototype(nsIURI
     
     mInputStreamTable.Remove(aURI);
     return newProto;
 }
 
 nsresult
 nsXULPrototypeCache::PutPrototype(nsXULPrototypeDocument* aDocument)
 {
-    nsCOMPtr<nsIURI> uri = aDocument->GetURI();
+    if (!aDocument->GetURI()) {
+        return NS_ERROR_FAILURE;
+    }
+
+    nsCOMPtr<nsIURI> uri;
+    aDocument->GetURI()->CloneIgnoringRef(getter_AddRefs(uri));
+
     // Put() releases any old value and addrefs the new one
     mPrototypeTable.Put(uri, aDocument);
 
     return NS_OK;
 }
 
 nsresult
 nsXULPrototypeCache::PutStyleSheet(CSSStyleSheet* aStyleSheet)