Bug 1034999 - fix XUL cache and overlay system to ignore refs/hashes, r=smaug,mossop
--- 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)