Bug 1447828 part 6 - Have only a single nsLayoutStylesheetCache instance. r?emilio draft
authorXidorn Quan <me@upsuper.org>
Wed, 28 Mar 2018 20:58:59 +1100
changeset 773746 cd66e264953865b0604054fb9d0b741d0ae19ebf
parent 773745 8ffba0152d4bd16f87d2ddefefacb7081a46443b
child 773747 09e1b57c52fbfe3145b47d80ac098c487970d8b4
push id104288
push userxquan@mozilla.com
push dateWed, 28 Mar 2018 11:04:19 +0000
reviewersemilio
bugs1447828
milestone61.0a1
Bug 1447828 part 6 - Have only a single nsLayoutStylesheetCache instance. r?emilio MozReview-Commit-ID: BjCgc8MZjIq
dom/html/nsHTMLDocument.cpp
dom/ipc/ContentParent.cpp
dom/mathml/nsMathMLElement.cpp
dom/svg/SVGDocument.cpp
dom/svg/SVGSVGElement.cpp
dom/xul/nsXULElement.cpp
layout/base/PresShell.cpp
layout/base/nsDocumentViewer.cpp
layout/base/nsPresContext.cpp
layout/printing/nsPrintJob.cpp
layout/style/nsLayoutStylesheetCache.cpp
layout/style/nsLayoutStylesheetCache.h
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -2263,17 +2263,17 @@ nsHTMLDocument::TearingDownEditor()
 
     nsCOMPtr<nsIPresShell> presShell = GetShell();
     if (!presShell)
       return;
 
     nsTArray<RefPtr<StyleSheet>> agentSheets;
     presShell->GetAgentStyleSheets(agentSheets);
 
-    auto cache = nsLayoutStylesheetCache::For(GetStyleBackendType());
+    auto cache = nsLayoutStylesheetCache::Singleton();
 
     agentSheets.RemoveElement(cache->ContentEditableSheet());
     if (oldState == eDesignMode)
       agentSheets.RemoveElement(cache->DesignModeSheet());
 
     presShell->SetAgentStyleSheets(agentSheets);
 
     presShell->RestyleForCSSRuleChanges();
@@ -2409,17 +2409,17 @@ nsHTMLDocument::EditingStateChanged()
 
     // Before making this window editable, we need to modify UA style sheet
     // because new style may change whether focused element will be focusable
     // or not.
     nsTArray<RefPtr<StyleSheet>> agentSheets;
     rv = presShell->GetAgentStyleSheets(agentSheets);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    auto cache = nsLayoutStylesheetCache::For(GetStyleBackendType());
+    auto cache = nsLayoutStylesheetCache::Singleton();
 
     StyleSheet* contentEditableSheet = cache->ContentEditableSheet();
 
     if (!agentSheets.Contains(contentEditableSheet)) {
       agentSheets.AppendElement(contentEditableSheet);
     }
 
     // Should we update the editable state of all the nodes in the document? We
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -2294,17 +2294,17 @@ ContentParent::InitInternal(ProcessPrior
   nsTArray<SystemFontListEntry> fontList;
   gfxPlatform::GetPlatform()->ReadSystemFontList(&fontList);
   nsTArray<LookAndFeelInt> lnfCache = LookAndFeel::GetIntCache();
 
   // Content processes have no permission to access profile directory, so we
   // send the file URL instead.
   StyleBackendType backendType =
     StyleBackendType::Servo;
-  StyleSheet* ucs = nsLayoutStylesheetCache::For(backendType)->UserContentSheet();
+  StyleSheet* ucs = nsLayoutStylesheetCache::Singleton()->UserContentSheet();
   if (ucs) {
     SerializeURI(ucs->GetSheetURI(), xpcomInit.userContentSheetURL());
   } else {
     SerializeURI(nullptr, xpcomInit.userContentSheetURL());
   }
 
   // 1. Build ContentDeviceData first, as it may affect some gfxVars.
   gfxPlatform::GetPlatform()->BuildContentDeviceData(&xpcomInit.contentDeviceData());
--- a/dom/mathml/nsMathMLElement.cpp
+++ b/dom/mathml/nsMathMLElement.cpp
@@ -107,17 +107,17 @@ nsMathMLElement::BindToTree(nsIDocument*
   }
 
   nsIDocument* doc = GetComposedDoc();
   if (doc) {
     if (!doc->GetMathMLEnabled()) {
       // Enable MathML and setup the style sheet during binding, not element
       // construction, because we could move a MathML element from the document
       // that created it to another document.
-      auto cache = nsLayoutStylesheetCache::For(doc->GetStyleBackendType());
+      auto cache = nsLayoutStylesheetCache::Singleton();
       doc->SetMathMLEnabled();
       doc->EnsureOnDemandBuiltInUASheet(cache->MathMLSheet());
 
       // Rebuild style data for the presshell, because style system
       // optimizations may have taken place assuming MathML was disabled.
       // (See nsRuleNode::CheckSpecifiedProperties.)
       RefPtr<nsPresContext> presContext = doc->GetPresContext();
       if (presContext) {
--- a/dom/svg/SVGDocument.cpp
+++ b/dom/svg/SVGDocument.cpp
@@ -150,17 +150,17 @@ SVGDocument::EnsureNonSVGUserAgentStyleS
               }
             }
           }
         }
       }
     }
   }
 
-  auto cache = nsLayoutStylesheetCache::For(GetStyleBackendType());
+  auto cache = nsLayoutStylesheetCache::Singleton();
 
   StyleSheet* sheet = cache->NumberControlSheet();
   if (sheet) {
     // number-control.css can be behind a pref
     EnsureOnDemandBuiltInUASheet(sheet);
   }
   EnsureOnDemandBuiltInUASheet(cache->FormsSheet());
   EnsureOnDemandBuiltInUASheet(cache->CounterStylesSheet());
--- a/dom/svg/SVGSVGElement.cpp
+++ b/dom/svg/SVGSVGElement.cpp
@@ -519,17 +519,17 @@ SVGSVGElement::BindToTree(nsIDocument* a
                                               aCompileEventHandlers);
   NS_ENSURE_SUCCESS(rv,rv);
 
   nsIDocument* doc = GetComposedDoc();
   if (doc) {
     // Setup the style sheet during binding, not element construction,
     // because we could move the root SVG element from the document
     // that created it to another document.
-    auto cache = nsLayoutStylesheetCache::For(doc->GetStyleBackendType());
+    auto cache = nsLayoutStylesheetCache::Singleton();
     doc->EnsureOnDemandBuiltInUASheet(cache->SVGSheet());
   }
 
   if (mTimedDocumentRoot && smilController) {
     rv = mTimedDocumentRoot->SetParent(smilController);
     if (mStartAnimationOnBindToTree) {
       mTimedDocumentRoot->Begin();
       mStartAnimationOnBindToTree = false;
--- a/dom/xul/nsXULElement.cpp
+++ b/dom/xul/nsXULElement.cpp
@@ -13,17 +13,16 @@
 #include "nsIDOMDocument.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMEventListener.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMXULCommandDispatcher.h"
 #include "nsIDOMXULElement.h"
 #include "nsIDOMXULSelectCntrlItemEl.h"
 #include "nsIDocument.h"
-#include "nsLayoutStylesheetCache.h"
 #include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/EventListenerManager.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/DeclarationBlockInlines.h"
 #include "nsFocusManager.h"
 #include "nsHTMLStyleSheet.h"
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -1499,17 +1499,17 @@ PresShell::UpdatePreferenceStyles()
   // We need to pass in mPresContext so that if the nsLayoutStylesheetCache
   // needs to recreate the pref style sheet, it has somewhere to get the
   // pref styling information from.  All pres contexts for
   // IsChromeOriginImage() == false will have the same pref styling information,
   // and similarly for IsChromeOriginImage() == true, so it doesn't really
   // matter which pres context we pass in when it does need to be recreated.
   // (See nsPresContext::GetDocumentColorPreferences for how whether we
   // are a chrome origin image affects some pref styling information.)
-  auto cache = nsLayoutStylesheetCache::For(mStyleSet->BackendType());
+  auto cache = nsLayoutStylesheetCache::Singleton();
   RefPtr<StyleSheet> newPrefSheet =
     mPresContext->IsChromeOriginImage() ?
       cache->ChromePreferenceSheet(mPresContext) :
       cache->ContentPreferenceSheet(mPresContext);
 
   if (mPrefStyleSheet == newPrefSheet) {
     return;
   }
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -2339,17 +2339,17 @@ nsDocumentViewer::CreateStyleSet(nsIDocu
     // xul.css) to be loaded on-demand.
     // XXXjwatt Nothing else is loaded on-demand, but I don't think that
     // should matter for SVG-as-an-image. If it does, I want to know why!
 
     // Caller will handle calling EndUpdate, per contract.
     return styleSet;
   }
 
-  auto cache = nsLayoutStylesheetCache::For(backendType);
+  auto cache = nsLayoutStylesheetCache::Singleton();
 
   // Handle the user sheets.
   StyleSheet* sheet = nullptr;
   if (nsContentUtils::IsInChromeDocshell(aDocument)) {
     sheet = cache->UserChromeSheet();
   } else {
     sheet = cache->UserContentSheet();
   }
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -1216,17 +1216,17 @@ nsPresContext::CompatibilityModeChanged(
     return;
   }
 
   bool needsQuirkSheet = CompatibilityMode() == eCompatibility_NavQuirks;
   if (mQuirkSheetAdded == needsQuirkSheet) {
     return;
   }
 
-  auto cache = nsLayoutStylesheetCache::For(styleSet->BackendType());
+  auto cache = nsLayoutStylesheetCache::Singleton();
   StyleSheet* sheet = cache->QuirkSheet();
 
   if (needsQuirkSheet) {
     // quirk.css needs to come after html.css; we just keep it at the end.
     DebugOnly<nsresult> rv =
       styleSet->AppendStyleSheet(SheetType::Agent, sheet);
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "failed to insert quirk.css");
   } else {
--- a/layout/printing/nsPrintJob.cpp
+++ b/layout/printing/nsPrintJob.cpp
@@ -2345,17 +2345,17 @@ nsPrintJob::ReflowPrintObject(const Uniq
   rv = aPO->mViewManager->Init(printData->mPrintDC);
   NS_ENSURE_SUCCESS(rv,rv);
 
   StyleSetHandle styleSet = mDocViewerPrint->CreateStyleSet(aPO->mDocument);
 
   if (aPO->mDocument->IsSVGDocument()) {
     // The SVG document only loads minimal-xul.css, so it doesn't apply other
     // styles. We should add ua.css for applying style which related to print.
-    auto cache = nsLayoutStylesheetCache::For(aPO->mDocument->GetStyleBackendType());
+    auto cache = nsLayoutStylesheetCache::Singleton();
     styleSet->PrependStyleSheet(SheetType::Agent, cache->UASheet());
   }
 
   aPO->mPresShell = aPO->mDocument->CreateShell(aPO->mPresContext,
                                                 aPO->mViewManager, styleSet);
   if (!aPO->mPresShell) {
     styleSet->Delete();
     return NS_ERROR_FAILURE;
--- a/layout/style/nsLayoutStylesheetCache.cpp
+++ b/layout/style/nsLayoutStylesheetCache.cpp
@@ -258,34 +258,28 @@ nsLayoutStylesheetCache::DesignModeSheet
   }
 
   return mDesignModeSheet;
 }
 
 void
 nsLayoutStylesheetCache::Shutdown()
 {
-  gCSSLoader_Gecko = nullptr;
-  gCSSLoader_Servo = nullptr;
-  NS_WARNING_ASSERTION(!gStyleCache_Gecko || !gUserContentSheetURL_Gecko,
-                       "Got the URL but never used by Gecko?");
-  NS_WARNING_ASSERTION(!gStyleCache_Servo || !gUserContentSheetURL_Servo,
-                       "Got the URL but never used by Servo?");
-  gStyleCache_Gecko = nullptr;
-  gStyleCache_Servo = nullptr;
-  gUserContentSheetURL_Gecko = nullptr;
-  gUserContentSheetURL_Servo = nullptr;
+  gCSSLoader = nullptr;
+  NS_WARNING_ASSERTION(!gStyleCache || !gUserContentSheetURL,
+                       "Got the URL but never used?");
+  gStyleCache = nullptr;
+  gUserContentSheetURL = nullptr;
 }
 
 void
 nsLayoutStylesheetCache::SetUserContentCSSURL(nsIURI* aURI)
 {
   MOZ_ASSERT(XRE_IsContentProcess(), "Only used in content processes.");
-  gUserContentSheetURL_Gecko = aURI;
-  gUserContentSheetURL_Servo = aURI;
+  gUserContentSheetURL = aURI;
 }
 
 MOZ_DEFINE_MALLOC_SIZE_OF(LayoutStylesheetCacheMallocSizeOf)
 
 NS_IMETHODIMP
 nsLayoutStylesheetCache::CollectReports(nsIHandleReportCallback* aHandleReport,
                                         nsISupports* aData, bool aAnonymize)
 {
@@ -323,24 +317,22 @@ nsLayoutStylesheetCache::SizeOfIncluding
   MEASURE(mUASheet);
   MEASURE(mUserChromeSheet);
   MEASURE(mUserContentSheet);
   MEASURE(mXULSheet);
   MEASURE(mXULComponentsSheet);
 
   // Measurement of the following members may be added later if DMD finds it is
   // worthwhile:
-  // - gCSSLoader_Gecko
-  // - gCSSLoader_Servo
+  // - gCSSLoader
 
   return n;
 }
 
-nsLayoutStylesheetCache::nsLayoutStylesheetCache(StyleBackendType aType)
-  : mBackendType(aType)
+nsLayoutStylesheetCache::nsLayoutStylesheetCache()
 {
   nsCOMPtr<nsIObserverService> obsSvc =
     mozilla::services::GetObserverService();
   NS_ASSERTION(obsSvc, "No global observer service?");
 
   if (obsSvc) {
     obsSvc->AddObserver(this, "profile-before-change", false);
     obsSvc->AddObserver(this, "profile-do-change", false);
@@ -363,23 +355,21 @@ nsLayoutStylesheetCache::nsLayoutStylesh
   LoadSheetURL("resource://gre/res/svg.css",
                &mSVGSheet, eAgentSheetFeatures, eCrash);
   if (XRE_IsParentProcess()) {
     // We know we need xul.css for the UI, so load that now too:
     XULSheet();
     XULComponentsSheet();
   }
 
-  auto& userContentSheetURL = aType == StyleBackendType::Gecko ?
-                              gUserContentSheetURL_Gecko :
-                              gUserContentSheetURL_Servo;
-  if (userContentSheetURL) {
+  if (gUserContentSheetURL) {
     MOZ_ASSERT(XRE_IsContentProcess(), "Only used in content processes.");
-    LoadSheet(userContentSheetURL, &mUserContentSheet, eUserSheetFeatures, eLogToConsole);
-    userContentSheetURL = nullptr;
+    LoadSheet(gUserContentSheetURL, &mUserContentSheet,
+              eUserSheetFeatures, eLogToConsole);
+    gUserContentSheetURL = nullptr;
   }
 
   // The remaining sheets are created on-demand do to their use being rarer
   // (which helps save memory for Firefox OS apps) or because they need to
   // be re-loadable in DependentPrefChanged.
 }
 
 nsLayoutStylesheetCache::~nsLayoutStylesheetCache()
@@ -389,45 +379,36 @@ nsLayoutStylesheetCache::~nsLayoutStyles
 
 void
 nsLayoutStylesheetCache::InitMemoryReporter()
 {
   mozilla::RegisterWeakMemoryReporter(this);
 }
 
 /* static */ nsLayoutStylesheetCache*
-nsLayoutStylesheetCache::For(StyleBackendType aType)
+nsLayoutStylesheetCache::Singleton()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  bool mustInit = !gStyleCache_Gecko && !gStyleCache_Servo;
-  auto& cache = aType == StyleBackendType::Gecko ? gStyleCache_Gecko :
-                                                   gStyleCache_Servo;
-
-  if (!cache) {
-    cache = new nsLayoutStylesheetCache(aType);
-    cache->InitMemoryReporter();
-  }
-
-  if (mustInit) {
-    // Initialization that only needs to be done once for both
-    // nsLayoutStylesheetCaches.
+  if (!gStyleCache) {
+    gStyleCache = new nsLayoutStylesheetCache;
+    gStyleCache->InitMemoryReporter();
 
     Preferences::AddBoolVarCache(&sNumberControlEnabled, NUMBER_CONTROL_PREF,
                                  true);
 
     // For each pref that controls a CSS feature that a UA style sheet depends
     // on (such as a pref that enables a property that a UA style sheet uses),
     // register DependentPrefChanged as a callback to ensure that the relevant
     // style sheets will be re-parsed.
     // Preferences::RegisterCallback(&DependentPrefChanged,
     //                               "layout.css.example-pref.enabled");
   }
 
-  return cache;
+  return gStyleCache;
 }
 
 void
 nsLayoutStylesheetCache::InitFromProfile()
 {
   nsCOMPtr<nsIXULRuntime> appInfo = do_GetService("@mozilla.org/xre/app-info;1");
   if (appInfo) {
     bool inSafeMode = false;
@@ -793,122 +774,80 @@ nsLayoutStylesheetCache::LoadSheet(nsIUR
                                    SheetParsingMode aParsingMode,
                                    FailureAction aFailureAction)
 {
   if (!aURI) {
     ErrorLoadingSheet(aURI, "null URI", eCrash);
     return;
   }
 
-  auto& loader = mBackendType == StyleBackendType::Gecko ?
-    gCSSLoader_Gecko :
-    gCSSLoader_Servo;
-
-  if (!loader) {
-    loader = new Loader;
-    if (!loader) {
+  if (!gCSSLoader) {
+    gCSSLoader = new Loader;
+    if (!gCSSLoader) {
       ErrorLoadingSheet(aURI, "no Loader", eCrash);
       return;
     }
   }
 
   nsZipArchive::sFileCorruptedReason = nullptr;
 
-  nsresult rv = loader->LoadSheetSync(aURI, aParsingMode, true, aSheet);
+  nsresult rv = gCSSLoader->LoadSheetSync(aURI, aParsingMode, true, aSheet);
   if (NS_FAILED(rv)) {
     ErrorLoadingSheet(aURI,
       nsPrintfCString("LoadSheetSync failed with error %" PRIx32, static_cast<uint32_t>(rv)).get(),
       aFailureAction);
   }
 }
 
 /* static */ void
-nsLayoutStylesheetCache::InvalidateSheet(RefPtr<StyleSheet>* aGeckoSheet,
-                                         RefPtr<StyleSheet>* aServoSheet)
+nsLayoutStylesheetCache::InvalidateSheet(RefPtr<StyleSheet>* aSheet)
 {
-  MOZ_ASSERT(gCSSLoader_Gecko || gCSSLoader_Servo,
-             "pref changed before we loaded a sheet?");
-
-  const bool gotGeckoSheet = aGeckoSheet && *aGeckoSheet;
-  const bool gotServoSheet = aServoSheet && *aServoSheet;
-
-  // Make sure sheets have the expected types
-  MOZ_ASSERT(!gotGeckoSheet || (*aGeckoSheet)->IsGecko());
-  MOZ_ASSERT(!gotServoSheet || (*aServoSheet)->IsServo());
-  // Make sure the URIs match
-  MOZ_ASSERT(!gotServoSheet || !gotGeckoSheet ||
-             (*aGeckoSheet)->GetSheetURI() == (*aServoSheet)->GetSheetURI(),
-             "Sheets passed should have the same URI");
-
-  nsIURI* uri;
-  if (gotGeckoSheet) {
-    uri = (*aGeckoSheet)->GetSheetURI();
-  } else if (gotServoSheet) {
-    uri = (*aServoSheet)->GetSheetURI();
-  } else {
-    return;
-  }
-
-  if (gCSSLoader_Gecko) {
-    gCSSLoader_Gecko->ObsoleteSheet(uri);
-  }
-  if (gCSSLoader_Servo) {
-    gCSSLoader_Servo->ObsoleteSheet(uri);
-  }
-  if (gotGeckoSheet) {
-    *aGeckoSheet = nullptr;
-  }
-  if (gotServoSheet) {
-    *aServoSheet = nullptr;
+  MOZ_ASSERT(gCSSLoader, "pref changed before we loaded a sheet?");
+  if (aSheet && *aSheet) {
+    nsIURI* uri = (*aSheet)->GetSheetURI();
+    if (gCSSLoader) {
+      gCSSLoader->ObsoleteSheet(uri);
+    }
+    *aSheet = nullptr;
   }
 }
 
 /* static */ void
 nsLayoutStylesheetCache::DependentPrefChanged(const char* aPref, void* aData)
 {
-  MOZ_ASSERT(gStyleCache_Gecko || gStyleCache_Servo,
-             "pref changed after shutdown?");
+  MOZ_ASSERT(gStyleCache, "pref changed after shutdown?");
 
   // Cause any UA style sheets whose parsing depends on the value of prefs
-  // to be re-parsed by dropping the sheet from gCSSLoader_{Gecko,Servo}'s cache
-  // then setting our cached sheet pointer to null.  This will only work for
+  // to be re-parsed by dropping the sheet from gCSSLoader's cache then
+  // setting our cached sheet pointer to null.  This will only work for
   // sheets that are loaded lazily.
 
 #define INVALIDATE(sheet_) \
-  InvalidateSheet(gStyleCache_Gecko ? &gStyleCache_Gecko->sheet_ : nullptr, \
-                  gStyleCache_Servo ? &gStyleCache_Servo->sheet_ : nullptr);
+  InvalidateSheet(gStyleCache ? &gStyleCache->sheet_ : nullptr);
 
   // INVALIDATE(mUASheet);  // for layout.css.example-pref.enabled
 
 #undef INVALIDATE
 }
 
 /* static */ void
 nsLayoutStylesheetCache::InvalidatePreferenceSheets()
 {
-  if (gStyleCache_Gecko) {
-    gStyleCache_Gecko->mContentPreferenceSheet = nullptr;
-    gStyleCache_Gecko->mChromePreferenceSheet = nullptr;
-  }
-  if (gStyleCache_Servo) {
-    gStyleCache_Servo->mContentPreferenceSheet = nullptr;
-    gStyleCache_Servo->mChromePreferenceSheet = nullptr;
+  if (gStyleCache) {
+    gStyleCache->mContentPreferenceSheet = nullptr;
+    gStyleCache->mChromePreferenceSheet = nullptr;
   }
 }
 
 void
 nsLayoutStylesheetCache::BuildPreferenceSheet(RefPtr<StyleSheet>* aSheet,
                                               nsPresContext* aPresContext)
 {
-  if (mBackendType == StyleBackendType::Gecko) {
-    MOZ_CRASH("old style system disabled");
-  } else {
-    *aSheet = new ServoStyleSheet(eAgentSheetFeatures, CORS_NONE,
-                                  mozilla::net::RP_Unset, dom::SRIMetadata());
-  }
+  *aSheet = new ServoStyleSheet(eAgentSheetFeatures, CORS_NONE,
+                                mozilla::net::RP_Unset, dom::SRIMetadata());
 
   StyleSheet* sheet = *aSheet;
 
   nsCOMPtr<nsIURI> uri;
   NS_NewURI(getter_AddRefs(uri), "about:PreferenceStyleSheet", nullptr);
   MOZ_ASSERT(uri, "URI creation shouldn't fail");
 
   sheet->SetURIs(uri, uri, uri);
@@ -993,37 +932,25 @@ nsLayoutStylesheetCache::BuildPreference
         NS_GET_R_G_B(focusText),
         NS_GET_R_G_B(focusBG));
   }
 
   NS_ASSERTION(sheetText.Length() <= kPreallocSize,
                "kPreallocSize should be big enough to build preference style "
                "sheet without reallocation");
 
-  if (sheet->IsGecko()) {
-    MOZ_CRASH("old style system disabled");
-  } else {
-    ServoStyleSheet* servoSheet = sheet->AsServo();
-    // NB: The pref sheet never has @import rules.
-    servoSheet->ParseSheetSync(
-      nullptr, sheetText, uri, uri, nullptr, /* aLoadData = */ nullptr, 0, eCompatibility_FullStandards);
-  }
+  ServoStyleSheet* servoSheet = sheet->AsServo();
+  // NB: The pref sheet never has @import rules.
+  servoSheet->ParseSheetSync(nullptr, sheetText, uri, uri, nullptr,
+                             /* aLoadData = */ nullptr, 0,
+                             eCompatibility_FullStandards);
 
 #undef NS_GET_R_G_B
 }
 
 mozilla::StaticRefPtr<nsLayoutStylesheetCache>
-nsLayoutStylesheetCache::gStyleCache_Gecko;
-
-mozilla::StaticRefPtr<nsLayoutStylesheetCache>
-nsLayoutStylesheetCache::gStyleCache_Servo;
+nsLayoutStylesheetCache::gStyleCache;
 
 mozilla::StaticRefPtr<mozilla::css::Loader>
-nsLayoutStylesheetCache::gCSSLoader_Gecko;
-
-mozilla::StaticRefPtr<mozilla::css::Loader>
-nsLayoutStylesheetCache::gCSSLoader_Servo;
+nsLayoutStylesheetCache::gCSSLoader;
 
 mozilla::StaticRefPtr<nsIURI>
-nsLayoutStylesheetCache::gUserContentSheetURL_Gecko;
-
-mozilla::StaticRefPtr<nsIURI>
-nsLayoutStylesheetCache::gUserContentSheetURL_Servo;
+nsLayoutStylesheetCache::gUserContentSheetURL;
--- a/layout/style/nsLayoutStylesheetCache.h
+++ b/layout/style/nsLayoutStylesheetCache.h
@@ -7,17 +7,16 @@
 #ifndef nsLayoutStylesheetCache_h__
 #define nsLayoutStylesheetCache_h__
 
 #include "nsIMemoryReporter.h"
 #include "nsIObserver.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/StaticPtr.h"
-#include "mozilla/StyleBackendType.h"
 #include "mozilla/css/Loader.h"
 
 class nsIFile;
 class nsIURI;
 
 namespace mozilla {
 class CSSStyleSheet;
 } // namespace mozilla
@@ -37,25 +36,17 @@ enum FailureAction {
 class nsLayoutStylesheetCache final
  : public nsIObserver
  , public nsIMemoryReporter
 {
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
   NS_DECL_NSIMEMORYREPORTER
 
-  /**
-   * Returns the nsLayoutStylesheetCache for the given style backend type.
-   * Callers should pass in a value for aType that matches the style system
-   * backend type for the style set in use.  (A process may call For
-   * and obtain nsLayoutStylesheetCache objects for both backend types,
-   * and a particular UA style sheet might be cached in both, one or neither
-   * nsLayoutStylesheetCache.)
-   */
-  static nsLayoutStylesheetCache* For(mozilla::StyleBackendType aType);
+  static nsLayoutStylesheetCache* Singleton();
 
   mozilla::StyleSheet* ScrollbarsSheet();
   mozilla::StyleSheet* FormsSheet();
   // This function is expected to return nullptr when the dom.forms.number
   // pref is disabled.
   mozilla::StyleSheet* NumberControlSheet();
   mozilla::StyleSheet* UserContentSheet();
   mozilla::StyleSheet* UserChromeSheet();
@@ -79,45 +70,40 @@ class nsLayoutStylesheetCache final
 
   static void Shutdown();
 
   static void SetUserContentCSSURL(nsIURI* aURI);
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
 private:
-  explicit nsLayoutStylesheetCache(mozilla::StyleBackendType aImpl);
+  nsLayoutStylesheetCache();
   ~nsLayoutStylesheetCache();
 
   void InitFromProfile();
   void InitMemoryReporter();
   void LoadSheetURL(const char* aURL,
                     RefPtr<mozilla::StyleSheet>* aSheet,
                     mozilla::css::SheetParsingMode aParsingMode,
                     mozilla::css::FailureAction aFailureAction);
   void LoadSheetFile(nsIFile* aFile,
                      RefPtr<mozilla::StyleSheet>* aSheet,
                      mozilla::css::SheetParsingMode aParsingMode,
                      mozilla::css::FailureAction aFailureAction);
   void LoadSheet(nsIURI* aURI, RefPtr<mozilla::StyleSheet>* aSheet,
                  mozilla::css::SheetParsingMode aParsingMode,
                  mozilla::css::FailureAction aFailureAction);
-  static void InvalidateSheet(RefPtr<mozilla::StyleSheet>* aGeckoSheet,
-                              RefPtr<mozilla::StyleSheet>* aServoSheet);
+  static void InvalidateSheet(RefPtr<mozilla::StyleSheet>* aSheet);
   static void DependentPrefChanged(const char* aPref, void* aData);
   void BuildPreferenceSheet(RefPtr<mozilla::StyleSheet>* aSheet,
                             nsPresContext* aPresContext);
 
-  static mozilla::StaticRefPtr<nsLayoutStylesheetCache> gStyleCache_Gecko;
-  static mozilla::StaticRefPtr<nsLayoutStylesheetCache> gStyleCache_Servo;
-  static mozilla::StaticRefPtr<mozilla::css::Loader> gCSSLoader_Gecko;
-  static mozilla::StaticRefPtr<mozilla::css::Loader> gCSSLoader_Servo;
-  static mozilla::StaticRefPtr<nsIURI> gUserContentSheetURL_Gecko;
-  static mozilla::StaticRefPtr<nsIURI> gUserContentSheetURL_Servo;
-  mozilla::StyleBackendType mBackendType;
+  static mozilla::StaticRefPtr<nsLayoutStylesheetCache> gStyleCache;
+  static mozilla::StaticRefPtr<mozilla::css::Loader> gCSSLoader;
+  static mozilla::StaticRefPtr<nsIURI> gUserContentSheetURL;
   RefPtr<mozilla::StyleSheet> mChromePreferenceSheet;
   RefPtr<mozilla::StyleSheet> mContentEditableSheet;
   RefPtr<mozilla::StyleSheet> mContentPreferenceSheet;
   RefPtr<mozilla::StyleSheet> mCounterStylesSheet;
   RefPtr<mozilla::StyleSheet> mDesignModeSheet;
   RefPtr<mozilla::StyleSheet> mFormsSheet;
   RefPtr<mozilla::StyleSheet> mHTMLSheet;
   RefPtr<mozilla::StyleSheet> mMathMLSheet;