Bug 1339627 Part 1: Add a Servo-specific StyleSheet table to nsXULPrototypeCache. draft
authorBrad Werth <bwerth@mozilla.com>
Mon, 06 Mar 2017 14:59:37 -0800
changeset 494446 ffa7a4300926baae0322d0198ae75d99e3960df6
parent 494263 b7e42143bbbc9dc3e5c05bd1e93b6485ce1d0ad4
child 494447 8d3063e4d7a70df5a337e0158fbb1c117ffd3e8f
push id48028
push userbwerth@mozilla.com
push dateTue, 07 Mar 2017 03:31:23 +0000
bugs1339627
milestone55.0a1
Bug 1339627 Part 1: Add a Servo-specific StyleSheet table to nsXULPrototypeCache. MozReview-Commit-ID: 98dUNnccdn1
dom/xul/nsXULPrototypeCache.cpp
dom/xul/nsXULPrototypeCache.h
layout/style/Loader.cpp
--- a/dom/xul/nsXULPrototypeCache.cpp
+++ b/dom/xul/nsXULPrototypeCache.cpp
@@ -184,27 +184,36 @@ nsXULPrototypeCache::PutPrototype(nsXULP
     aDocument->GetURI()->CloneIgnoringRef(getter_AddRefs(uri));
 
     // 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)
+{
+    StyleSheetTable& table = TableForBackendType(aType);
+    return table.GetWeak(aURI);
+}
+
 nsresult
-nsXULPrototypeCache::PutStyleSheet(StyleSheet* aStyleSheet)
+nsXULPrototypeCache::PutStyleSheet(StyleSheet* aStyleSheet,
+                                   StyleBackendType aType)
 {
     nsIURI* uri = aStyleSheet->GetSheetURI();
 
-    mStyleSheetTable.Put(uri, aStyleSheet);
+    StyleSheetTable& table = TableForBackendType(aType);
+    table.Put(uri, aStyleSheet);
 
     return NS_OK;
 }
 
-
 JSScript*
 nsXULPrototypeCache::GetScript(nsIURI* aURI)
 {
     return mScriptTable.Get(aURI);
 }
 
 nsresult
 nsXULPrototypeCache::PutScript(nsIURI* aURI,
@@ -249,21 +258,26 @@ nsXULPrototypeCache::FlushSkinFiles()
     nsAutoCString str;
     iter.Key()->GetPath(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()->GetPath(str);
-    if (strncmp(str.get(), "/skin", 5) == 0) {
-      iter.Remove();
+  mozilla::StyleBackendType tableTypes[] = { StyleBackendType::Gecko,
+                                             StyleBackendType::Servo };
+  for (auto tableType : tableTypes) {
+    StyleSheetTable& table = TableForBackendType(tableType);
+    for (auto iter = table.Iter(); !iter.Done(); iter.Next()) {
+      nsAutoCString str;
+      iter.Data()->GetSheetURI()->GetPath(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 = mXBLDocTable.Iter(); !iter.Done(); iter.Next()) {
     iter.Data()->FlushSkinStylesheets();
@@ -276,17 +290,18 @@ nsXULPrototypeCache::FlushScripts()
     mScriptTable.Clear();
 }
 
 void
 nsXULPrototypeCache::Flush()
 {
     mPrototypeTable.Clear();
     mScriptTable.Clear();
-    mStyleSheetTable.Clear();
+    mGeckoStyleSheetTable.Clear();
+    mServoStyleSheetTable.Clear();
     mXBLDocTable.Clear();
 }
 
 
 bool
 nsXULPrototypeCache::IsEnabled()
 {
     return !gDisableXULCache;
--- a/dom/xul/nsXULPrototypeCache.h
+++ b/dom/xul/nsXULPrototypeCache.h
@@ -69,25 +69,25 @@ public:
         return mXBLDocTable.GetWeak(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) {
-        return mStyleSheetTable.GetWeak(aURI);
-    }
+    mozilla::StyleSheet* GetStyleSheet(nsIURI* aURI,
+                                       mozilla::StyleBackendType aType);
 
     /**
      * 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);
+    nsresult PutStyleSheet(mozilla::StyleSheet* aStyleSheet,
+                           mozilla::StyleBackendType aType);
 
     /**
      * Write the XUL prototype document to a cache file. The proto must be
      * fully loaded.
      */
     nsresult WritePrototype(nsXULPrototypeDocument* aPrototypeDocument);
 
     /**
@@ -117,18 +117,25 @@ protected:
 
     nsXULPrototypeCache();
     virtual ~nsXULPrototypeCache();
 
     static nsXULPrototypeCache* sInstance;
 
     void FlushSkinFiles();
 
+    typedef nsRefPtrHashtable<nsURIHashKey, mozilla::StyleSheet> StyleSheetTable;
+    StyleSheetTable& TableForBackendType(mozilla::StyleBackendType aType) {
+      return aType == mozilla::StyleBackendType::Gecko ? mGeckoStyleSheetTable
+                                                       : mServoStyleSheetTable;
+    }
+
     nsRefPtrHashtable<nsURIHashKey,nsXULPrototypeDocument>   mPrototypeTable; // owns the prototypes
-    nsRefPtrHashtable<nsURIHashKey,mozilla::StyleSheet>      mStyleSheetTable;
+    StyleSheetTable                                          mGeckoStyleSheetTable;
+    StyleSheetTable                                          mServoStyleSheetTable;
     nsJSThingHashtable<nsURIHashKey, JSScript*>              mScriptTable;
     nsRefPtrHashtable<nsURIHashKey,nsXBLDocumentInfo>        mXBLDocTable;
 
     // URIs already written to the startup cache, to prevent double-caching.
     nsTHashtable<nsURIHashKey>                               mStartupCacheURITable;
 
     nsInterfaceHashtable<nsURIHashKey, nsIStorageStream>     mOutputStreamTable;
     nsInterfaceHashtable<nsURIHashKey, nsIObjectInputStream> mInputStreamTable;
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -1117,17 +1117,17 @@ Loader::CreateSheet(nsIURI* aURI,
 #ifdef MOZ_XUL
     // The XUL cache is a singleton that only holds Gecko-style sheets, so
     // only use the cache if the loader is also Gecko.
     if (IsChromeURI(aURI) &&
         GetStyleBackendType() == StyleBackendType::Gecko) {
       nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
       if (cache) {
         if (cache->IsEnabled()) {
-          sheet = cache->GetStyleSheet(aURI);
+          sheet = cache->GetStyleSheet(aURI, GetStyleBackendType());
           LOG(("  From XUL cache: %p", sheet.get()));
         }
       }
     }
 #endif
 
     bool fromCompleteSheets = false;
     if (!sheet) {
@@ -1956,21 +1956,21 @@ Loader::DoSheetComplete(SheetLoadData* a
       }
       data = data->mNext;
     }
 #ifdef MOZ_XUL
     if (IsChromeURI(aLoadData->mURI) &&
         GetStyleBackendType() == StyleBackendType::Gecko) {
       nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
       if (cache && cache->IsEnabled()) {
-        if (!cache->GetStyleSheet(aLoadData->mURI)) {
+        if (!cache->GetStyleSheet(aLoadData->mURI, GetStyleBackendType())) {
           LOG(("  Putting sheet in XUL prototype cache"));
           NS_ASSERTION(sheet->IsComplete(),
                        "Should only be caching complete sheets");
-          cache->PutStyleSheet(sheet);
+          cache->PutStyleSheet(sheet, GetStyleBackendType());
         }
       }
     }
     else {
 #endif
       URIPrincipalReferrerPolicyAndCORSModeHashKey key(aLoadData->mURI,
                                          aLoadData->mLoaderPrincipal,
                                          aLoadData->mSheet->GetCORSMode(),