Bug 1447828 part 2 - Remove StyleBackendType uses from nsXULPrototypeCache. r?emilio
MozReview-Commit-ID: 1tYFBTk9BqF
--- a/dom/xbl/nsBindingManager.cpp
+++ b/dom/xbl/nsBindingManager.cpp
@@ -1031,23 +1031,21 @@ nsBindingManager::SizeOfIncludingThis(Ma
SHALLOW_SIZE_INCLUDING(mLoadingDocTable);
#undef SHALLOW_SIZE_INCLUDING
n += mAttachedStack.ShallowSizeOfExcludingThis(aMallocSizeOf);
if (mDocumentTable) {
n += mDocumentTable->ShallowSizeOfIncludingThis(aMallocSizeOf);
#ifdef MOZ_XUL
nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
- StyleBackendType backendType = mDocument->GetStyleBackendType();
#endif
for (auto iter = mDocumentTable->Iter(); !iter.Done(); iter.Next()) {
nsXBLDocumentInfo* docInfo = iter.UserData();
#ifdef MOZ_XUL
- nsXBLDocumentInfo* cachedInfo =
- cache->GetXBLDocumentInfo(iter.Key(), backendType);
+ nsXBLDocumentInfo* cachedInfo = cache->GetXBLDocumentInfo(iter.Key());
if (cachedInfo == docInfo) {
// If this binding has been cached, skip it since it can be
// reused by other documents.
continue;
}
#endif
n += docInfo->SizeOfIncludingThis(aMallocSizeOf);
}
--- a/dom/xbl/nsXBLService.cpp
+++ b/dom/xbl/nsXBLService.cpp
@@ -964,26 +964,19 @@ nsXBLService::LoadBindingDocumentInfo(ns
#ifdef MOZ_XUL
// The second line of defense is the global nsXULPrototypeCache,
// if it's being used.
nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
bool useXULCache = cache && cache->IsEnabled();
if (!info && useXULCache) {
- // Assume Gecko style backend for the XBL document without a bound
- // document. The only case is loading platformHTMLBindings.xml which
- // doesn't have any style sheets or style attributes.
- StyleBackendType styleBackend
- = aBoundDocument ? aBoundDocument->GetStyleBackendType()
- : StyleBackendType::Gecko;
-
// This cache crosses the entire product, so that any XBL bindings that are
// part of chrome will be reused across all XUL documents.
- info = cache->GetXBLDocumentInfo(documentURI, styleBackend);
+ info = cache->GetXBLDocumentInfo(documentURI);
}
bool useStartupCache = useXULCache && IsChromeOrResourceURI(documentURI);
if (!info) {
// Next, look in the startup cache
if (!info && useStartupCache) {
rv = nsXBLDocumentInfo::ReadPrototypeBindings(documentURI, getter_AddRefs(info),
@@ -1037,22 +1030,16 @@ nsXBLService::LoadBindingDocumentInfo(ns
// before, it can continue to use it even if the XUL prototype
// cache gets flushed. That way, if a flush does occur, we
// don't get into a weird state where we're using different
// XBLDocumentInfos for the same XBL document in a single
// document that has loaded some bindings.
bindingManager->PutXBLDocumentInfo(info);
}
- MOZ_ASSERT(!aBoundDocument || !info ||
- aBoundDocument->GetStyleBackendType() ==
- info->GetDocument()->GetStyleBackendType(),
- "Style backend type mismatched between the bound document and "
- "the XBL document loaded.");
-
info.forget(aResult);
return NS_OK;
}
nsresult
nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoundDocument,
nsIURI* aDocumentURI, nsIURI* aBindingURI,
--- a/dom/xul/nsXULPrototypeCache.cpp
+++ b/dom/xul/nsXULPrototypeCache.cpp
@@ -187,32 +187,26 @@ nsXULPrototypeCache::PutPrototype(nsXULP
// Put() releases any old value and addrefs the new one
mPrototypeTable.Put(uri, aDocument);
return NS_OK;
}
mozilla::StyleSheet*
-nsXULPrototypeCache::GetStyleSheet(nsIURI* aURI,
- StyleBackendType aType)
+nsXULPrototypeCache::GetStyleSheet(nsIURI* aURI)
{
- StyleSheetTable& table = StyleSheetTableFor(aType);
- return table.GetWeak(aURI);
+ return mStyleSheetTable.GetWeak(aURI);
}
nsresult
-nsXULPrototypeCache::PutStyleSheet(StyleSheet* aStyleSheet,
- StyleBackendType aType)
+nsXULPrototypeCache::PutStyleSheet(StyleSheet* aStyleSheet)
{
nsIURI* uri = aStyleSheet->GetSheetURI();
-
- StyleSheetTable& table = StyleSheetTableFor(aType);
- table.Put(uri, aStyleSheet);
-
+ mStyleSheetTable.Put(uri, aStyleSheet);
return NS_OK;
}
JSScript*
nsXULPrototypeCache::GetScript(nsIURI* aURI)
{
return mScriptTable.Get(aURI);
}
@@ -235,89 +229,74 @@ nsXULPrototypeCache::PutScript(nsIURI* a
#endif
mScriptTable.Put(aURI, aScriptObject);
return NS_OK;
}
nsXBLDocumentInfo*
-nsXULPrototypeCache::GetXBLDocumentInfo(nsIURI* aURL,
- StyleBackendType aType)
+nsXULPrototypeCache::GetXBLDocumentInfo(nsIURI* aURL)
{
- MOZ_ASSERT(aType != StyleBackendType::None,
- "Please use either gecko or servo when looking up for the cache!");
- return XBLDocTableFor(aType).GetWeak(aURL);
+ return mXBLDocTable.GetWeak(aURL);
}
nsresult
nsXULPrototypeCache::PutXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo)
{
nsIURI* uri = aDocumentInfo->DocumentURI();
- XBLDocTable& table =
- XBLDocTableFor(aDocumentInfo->GetDocument()->GetStyleBackendType());
-
- nsXBLDocumentInfo* info = table.GetWeak(uri);
+ nsXBLDocumentInfo* info = mXBLDocTable.GetWeak(uri);
if (!info) {
- table.Put(uri, aDocumentInfo);
+ mXBLDocTable.Put(uri, aDocumentInfo);
}
return NS_OK;
}
void
nsXULPrototypeCache::FlushSkinFiles()
{
- StyleBackendType tableTypes[] = { StyleBackendType::Gecko,
- StyleBackendType::Servo };
-
- for (auto tableType : tableTypes) {
- // Flush out skin XBL files from the cache.
- XBLDocTable& xblDocTable = XBLDocTableFor(tableType);
- for (auto iter = xblDocTable.Iter(); !iter.Done(); iter.Next()) {
- nsAutoCString str;
- iter.Key()->GetPathQueryRef(str);
- if (strncmp(str.get(), "/skin", 5) == 0) {
- iter.Remove();
- }
+ // Flush out skin XBL files from the cache.
+ for (auto iter = mXBLDocTable.Iter(); !iter.Done(); iter.Next()) {
+ nsAutoCString str;
+ iter.Key()->GetPathQueryRef(str);
+ if (strncmp(str.get(), "/skin", 5) == 0) {
+ iter.Remove();
}
+ }
- // Now flush out our skin stylesheets from the cache.
- StyleSheetTable& table = StyleSheetTableFor(tableType);
- for (auto iter = table.Iter(); !iter.Done(); iter.Next()) {
- nsAutoCString str;
- iter.Data()->GetSheetURI()->GetPathQueryRef(str);
- if (strncmp(str.get(), "/skin", 5) == 0) {
- iter.Remove();
- }
+ // Now flush out our skin stylesheets from the cache.
+ for (auto iter = mStyleSheetTable.Iter(); !iter.Done(); iter.Next()) {
+ nsAutoCString str;
+ iter.Data()->GetSheetURI()->GetPathQueryRef(str);
+ if (strncmp(str.get(), "/skin", 5) == 0) {
+ iter.Remove();
}
+ }
- // Iterate over all the remaining XBL and make sure cached
- // scoped skin stylesheets are flushed and refetched by the
- // prototype bindings.
- for (auto iter = xblDocTable.Iter(); !iter.Done(); iter.Next()) {
- iter.Data()->FlushSkinStylesheets();
- }
+ // Iterate over all the remaining XBL and make sure cached
+ // scoped skin stylesheets are flushed and refetched by the
+ // prototype bindings.
+ for (auto iter = mXBLDocTable.Iter(); !iter.Done(); iter.Next()) {
+ iter.Data()->FlushSkinStylesheets();
}
}
void
nsXULPrototypeCache::FlushScripts()
{
mScriptTable.Clear();
}
void
nsXULPrototypeCache::Flush()
{
mPrototypeTable.Clear();
mScriptTable.Clear();
- mGeckoStyleSheetTable.Clear();
- mServoStyleSheetTable.Clear();
- mGeckoXBLDocTable.Clear();
- mServoXBLDocTable.Clear();
+ mStyleSheetTable.Clear();
+ mXBLDocTable.Clear();
}
bool
nsXULPrototypeCache::IsEnabled()
{
return !gDisableXULCache;
}
@@ -606,24 +585,18 @@ nsXULPrototypeCache::BeginCaching(nsIURI
}
return NS_OK;
}
void
nsXULPrototypeCache::MarkInCCGeneration(uint32_t aGeneration)
{
- StyleBackendType tableTypes[] = { StyleBackendType::Gecko,
- StyleBackendType::Servo };
-
- for (auto tableType : tableTypes) {
- XBLDocTable& xblDocTable = XBLDocTableFor(tableType);
- for (auto iter = xblDocTable.Iter(); !iter.Done(); iter.Next()) {
- iter.Data()->MarkInCCGeneration(aGeneration);
- }
+ for (auto iter = mXBLDocTable.Iter(); !iter.Done(); iter.Next()) {
+ iter.Data()->MarkInCCGeneration(aGeneration);
}
for (auto iter = mPrototypeTable.Iter(); !iter.Done(); iter.Next()) {
iter.Data()->MarkInCCGeneration(aGeneration);
}
}
void
nsXULPrototypeCache::MarkInGC(JSTracer* aTrc)
@@ -674,40 +647,33 @@ nsXULPrototypeCache::CollectMemoryReport
#define REPORT_SIZE(_path, _amount, _desc) \
ReportSize(_path, _amount, NS_LITERAL_CSTRING(_desc), aHandleReport, aData)
other += sInstance->
mPrototypeTable.ShallowSizeOfExcludingThis(mallocSizeOf);
// TODO Report content in mPrototypeTable?
other += sInstance->
- mGeckoStyleSheetTable.ShallowSizeOfExcludingThis(mallocSizeOf);
- // TODO Report content inside mGeckoStyleSheetTable?
- other += sInstance->
- mServoStyleSheetTable.ShallowSizeOfExcludingThis(mallocSizeOf);
- // TODO Report content inside mServoStyleSheetTable?
+ mStyleSheetTable.ShallowSizeOfExcludingThis(mallocSizeOf);
+ // TODO Report content inside mStyleSheetTable?
other += sInstance->
mScriptTable.ShallowSizeOfExcludingThis(mallocSizeOf);
// TODO Report content inside mScriptTable?
- auto reportXBLDocTable =
- [&](const nsACString& prefix, const XBLDocTable& table) {
- other += table.ShallowSizeOfExcludingThis(mallocSizeOf);
- for (auto iter = table.ConstIter(); !iter.Done(); iter.Next()) {
- nsAutoCString path(prefix);
- path += "-xbl-docs/(";
- AppendURIForMemoryReport(iter.Key(), path);
- path += ")";
- size_t size = iter.UserData()->SizeOfIncludingThis(mallocSizeOf);
- REPORT_SIZE(path, size, "Memory used by this XBL document.");
- }
- };
- reportXBLDocTable(NS_LITERAL_CSTRING("gecko"), sInstance->mGeckoXBLDocTable);
- reportXBLDocTable(NS_LITERAL_CSTRING("servo"), sInstance->mServoXBLDocTable);
+ other += sInstance->mXBLDocTable.ShallowSizeOfExcludingThis(mallocSizeOf);
+ for (auto iter = sInstance->mXBLDocTable.ConstIter();
+ !iter.Done(); iter.Next()) {
+ nsAutoCString path;
+ path += "xbl-docs/(";
+ AppendURIForMemoryReport(iter.Key(), path);
+ path += ")";
+ size_t size = iter.UserData()->SizeOfIncludingThis(mallocSizeOf);
+ REPORT_SIZE(path, size, "Memory used by this XBL document.");
+ }
other += sInstance->
mStartupCacheURITable.ShallowSizeOfExcludingThis(mallocSizeOf);
other += sInstance->
mOutputStreamTable.ShallowSizeOfExcludingThis(mallocSizeOf);
other += sInstance->
mInputStreamTable.ShallowSizeOfExcludingThis(mallocSizeOf);
--- a/dom/xul/nsXULPrototypeCache.h
+++ b/dom/xul/nsXULPrototypeCache.h
@@ -61,34 +61,31 @@ public:
// from the cache.
nsXULPrototypeDocument* GetPrototype(nsIURI* aURI);
nsresult PutPrototype(nsXULPrototypeDocument* aDocument);
JSScript* GetScript(nsIURI* aURI);
nsresult PutScript(nsIURI* aURI, JS::Handle<JSScript*> aScriptObject);
- nsXBLDocumentInfo* GetXBLDocumentInfo(nsIURI* aURL,
- mozilla::StyleBackendType aType);
+ nsXBLDocumentInfo* GetXBLDocumentInfo(nsIURI* aURL);
nsresult PutXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo);
/**
* Get a style sheet by URI. If the style sheet is not in the cache,
* returns nullptr.
*/
- mozilla::StyleSheet* GetStyleSheet(nsIURI* aURI,
- mozilla::StyleBackendType aType);
+ mozilla::StyleSheet* GetStyleSheet(nsIURI* aURI);
/**
* Store a style sheet in the cache. The key, style sheet's URI is obtained
* from the style sheet itself.
*/
- nsresult PutStyleSheet(mozilla::StyleSheet* aStyleSheet,
- mozilla::StyleBackendType aType);
+ nsresult PutStyleSheet(mozilla::StyleSheet* aStyleSheet);
/**
* Write the XUL prototype document to a cache file. The proto must be
* fully loaded.
*/
nsresult WritePrototype(nsXULPrototypeDocument* aPrototypeDocument);
/**
@@ -125,32 +122,20 @@ protected:
static nsXULPrototypeCache* sInstance;
void FlushSkinFiles();
using StyleSheetTable = nsRefPtrHashtable<nsURIHashKey, mozilla::StyleSheet>;
using XBLDocTable = nsRefPtrHashtable<nsURIHashKey, nsXBLDocumentInfo>;
- StyleSheetTable& StyleSheetTableFor(mozilla::StyleBackendType aType) {
- return aType == mozilla::StyleBackendType::Gecko ? mGeckoStyleSheetTable
- : mServoStyleSheetTable;
- }
-
- XBLDocTable& XBLDocTableFor(mozilla::StyleBackendType aType) {
- return aType == mozilla::StyleBackendType::Gecko ? mGeckoXBLDocTable
- : mServoXBLDocTable;
- }
-
nsRefPtrHashtable<nsURIHashKey,nsXULPrototypeDocument> mPrototypeTable; // owns the prototypes
- StyleSheetTable mGeckoStyleSheetTable;
- StyleSheetTable mServoStyleSheetTable;
+ StyleSheetTable mStyleSheetTable;
nsJSThingHashtable<nsURIHashKey, JSScript*> mScriptTable;
- XBLDocTable mGeckoXBLDocTable;
- XBLDocTable mServoXBLDocTable;
+ XBLDocTable mXBLDocTable;
// URIs already written to the startup cache, to prevent double-caching.
nsTHashtable<nsURIHashKey> mStartupCacheURITable;
nsInterfaceHashtable<nsURIHashKey, nsIStorageStream> mOutputStreamTable;
nsInterfaceHashtable<nsURIHashKey, nsIObjectInputStream> mInputStreamTable;
// Bootstrap caching service
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -917,17 +917,17 @@ Loader::CreateSheet(nsIURI* aURI,
aSheetState = eSheetComplete;
RefPtr<StyleSheet> sheet;
// First, the XUL cache
#ifdef MOZ_XUL
if (IsChromeURI(aURI)) {
nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
if (cache && cache->IsEnabled()) {
- sheet = cache->GetStyleSheet(aURI, GetStyleBackendType());
+ sheet = cache->GetStyleSheet(aURI);
LOG((" From XUL cache: %p", sheet.get()));
}
}
#endif
bool fromCompleteSheets = false;
if (!sheet) {
// Then our per-document complete sheets.
@@ -1802,21 +1802,21 @@ Loader::DoSheetComplete(SheetLoadData* a
break;
}
data = data->mNext;
}
#ifdef MOZ_XUL
if (IsChromeURI(aLoadData->mURI)) {
nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
if (cache && cache->IsEnabled()) {
- if (!cache->GetStyleSheet(aLoadData->mURI, GetStyleBackendType())) {
+ if (!cache->GetStyleSheet(aLoadData->mURI)) {
LOG((" Putting sheet in XUL prototype cache"));
NS_ASSERTION(sheet->IsComplete(),
"Should only be caching complete sheets");
- cache->PutStyleSheet(sheet, GetStyleBackendType());
+ cache->PutStyleSheet(sheet);
}
}
}
else {
#endif
URIPrincipalReferrerPolicyAndCORSModeHashKey key(aLoadData->mURI,
aLoadData->mLoaderPrincipal,
aLoadData->mSheet->GetCORSMode(),