diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index a74a81d7cf..e24cfae688 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -4065,7 +4065,7 @@ nsDocument::LoadAdditionalStyleSheet(additionalSheetType aType, return NS_ERROR_INVALID_ARG; // Loading the sheet sync. - RefPtr loader = new css::Loader(GetStyleBackendType()); + RefPtr loader = new css::Loader(); css::SheetParsingMode parsingMode; switch (aType) { diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp index 3fb7ddf160..bfce03ec63 100644 --- a/dom/html/nsHTMLDocument.cpp +++ b/dom/html/nsHTMLDocument.cpp @@ -2380,7 +2380,7 @@ nsHTMLDocument::TearingDownEditor(nsIEditor *aEditor) nsTArray> agentSheets; presShell->GetAgentStyleSheets(agentSheets); - auto cache = nsLayoutStylesheetCache::For(GetStyleBackendType()); + auto cache = nsLayoutStylesheetCache::Get(); agentSheets.RemoveElement(cache->ContentEditableSheet()); if (oldState == eDesignMode) @@ -2524,7 +2524,7 @@ nsHTMLDocument::EditingStateChanged() rv = presShell->GetAgentStyleSheets(agentSheets); NS_ENSURE_SUCCESS(rv, rv); - auto cache = nsLayoutStylesheetCache::For(GetStyleBackendType()); + auto cache = nsLayoutStylesheetCache::Get(); StyleSheet* contentEditableSheet = cache->ContentEditableSheet(); diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index 0fe805c4d5..8e7df1e288 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -2092,10 +2092,7 @@ static void PreloadSlowThings() { // This fetches and creates all the built-in stylesheets. - // - // XXXheycam In the future we might want to preload the Servo-flavoured - // UA sheets too, but for now that will be a waste of time. - nsLayoutStylesheetCache::For(StyleBackendType::Gecko)->UserContentSheet(); + nsLayoutStylesheetCache::Get()->UserContentSheet(); TabChild::PreloadSlowThings(); diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 51a663969b..3fc86f5b6b 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -2669,7 +2669,7 @@ ContentParent::RecvGetXPCOMProcessAttributes(bool* aIsOffline, // Content processes have no permission to access profile directory, so we // send the file URL instead. - StyleSheet* ucs = nsLayoutStylesheetCache::For(StyleBackendType::Gecko)->UserContentSheet(); + StyleSheet* ucs = nsLayoutStylesheetCache::Get()->UserContentSheet(); if (ucs) { SerializeURI(ucs->GetSheetURI(), *aUserContentCSSURL); } else { diff --git a/dom/mathml/nsMathMLElement.cpp b/dom/mathml/nsMathMLElement.cpp index d28182ae37..a980abd924 100644 --- a/dom/mathml/nsMathMLElement.cpp +++ b/dom/mathml/nsMathMLElement.cpp @@ -111,7 +111,7 @@ nsMathMLElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, // 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::Get(); doc->SetMathMLEnabled(); doc->EnsureOnDemandBuiltInUASheet(cache->MathMLSheet()); diff --git a/dom/svg/SVGDocument.cpp b/dom/svg/SVGDocument.cpp index 12a5619f42..6c4f6f513c 100644 --- a/dom/svg/SVGDocument.cpp +++ b/dom/svg/SVGDocument.cpp @@ -138,7 +138,7 @@ SVGDocument::EnsureNonSVGUserAgentStyleSheetsLoaded() } } - auto cache = nsLayoutStylesheetCache::For(GetStyleBackendType()); + auto cache = nsLayoutStylesheetCache::Get(); StyleSheet* sheet = cache->NumberControlSheet(); if (sheet) { diff --git a/dom/svg/SVGSVGElement.cpp b/dom/svg/SVGSVGElement.cpp index 70800cff00..fa60979316 100644 --- a/dom/svg/SVGSVGElement.cpp +++ b/dom/svg/SVGSVGElement.cpp @@ -751,7 +751,7 @@ SVGSVGElement::BindToTree(nsIDocument* aDocument, // 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::Get(); doc->EnsureOnDemandBuiltInUASheet(cache->SVGSheet()); } diff --git a/dom/xul/nsXULElement.cpp b/dom/xul/nsXULElement.cpp index 2ae03e0b17..332e7bb8b4 100644 --- a/dom/xul/nsXULElement.cpp +++ b/dom/xul/nsXULElement.cpp @@ -825,7 +825,7 @@ nsXULElement::BindToTree(nsIDocument* aDocument, // can be moved from the document that creates them to another document. if (!XULElementsRulesInMinimalXULSheet(NodeInfo()->NameAtom())) { - auto cache = nsLayoutStylesheetCache::For(doc->GetStyleBackendType()); + auto cache = nsLayoutStylesheetCache::Get(); doc->EnsureOnDemandBuiltInUASheet(cache->XULSheet()); // To keep memory usage down it is important that we try and avoid // pulling xul.css into non-XUL documents. That should be very rare, and diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index fa776cf466..1068669a8a 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -2276,8 +2276,6 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument) // this should eventually get expanded to allow for creating // different sets for different media - StyleBackendType backendType = aDocument->GetStyleBackendType(); - StyleSetHandle styleSet = new nsStyleSet(); styleSet->BeginUpdate(); @@ -2298,7 +2296,7 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument) return styleSet; } - auto cache = nsLayoutStylesheetCache::For(backendType); + auto cache = nsLayoutStylesheetCache::Get(); // Handle the user sheets. StyleSheet* sheet = nullptr; @@ -2332,8 +2330,7 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument) nsAutoString sheets; elt->GetAttribute(NS_LITERAL_STRING("usechromesheets"), sheets); if (!sheets.IsEmpty() && baseURI) { - RefPtr cssLoader = - new mozilla::css::Loader(backendType); + RefPtr cssLoader = new mozilla::css::Loader(); char *str = ToNewCString(sheets); char *newStr = str; diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 729567e338..6ea95463db 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -1143,7 +1143,7 @@ nsPresContext::CompatibilityModeChanged() } StyleSetHandle styleSet = mShell->StyleSet(); - auto cache = nsLayoutStylesheetCache::For(styleSet->BackendType()); + auto cache = nsLayoutStylesheetCache::Get(); StyleSheet* sheet = cache->QuirkSheet(); if (needsQuirkSheet) { diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index f656e6eed2..cca4bb1228 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -1388,7 +1388,7 @@ PresShell::UpdatePreferenceStyles() // 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::Get(); RefPtr newPrefSheet = mPresContext->IsChromeOriginImage() ? cache->ChromePreferenceSheet(mPresContext) : diff --git a/layout/base/nsStyleSheetService.cpp b/layout/base/nsStyleSheetService.cpp index c7c3d9cb08..6ff54462ee 100644 --- a/layout/base/nsStyleSheetService.cpp +++ b/layout/base/nsStyleSheetService.cpp @@ -226,9 +226,7 @@ nsStyleSheetService::LoadAndRegisterSheetInternal(nsIURI *aSheetURI, return NS_ERROR_INVALID_ARG; } - // XXXheycam We'll need to load and register both a Gecko- and Servo-backed - // style sheet. - RefPtr loader = new css::Loader(StyleBackendType::Gecko); + RefPtr loader = new css::Loader(); RefPtr sheet; nsresult rv = loader->LoadSheetSync(aSheetURI, parsingMode, true, &sheet); @@ -279,10 +277,7 @@ nsStyleSheetService::PreloadSheet(nsIURI *aSheetURI, uint32_t aSheetType, return NS_ERROR_INVALID_ARG; } - // XXXheycam PreloadSheet can't support ServoStyleSheets until they implement - // nsIDOMStyleSheet. - - RefPtr loader = new css::Loader(StyleBackendType::Gecko); + RefPtr loader = new css::Loader(); RefPtr sheet; nsresult rv = loader->LoadSheetSync(aSheetURI, parsingMode, true, &sheet); diff --git a/layout/style/CSSStyleSheet.cpp b/layout/style/CSSStyleSheet.cpp index 4f4c9491ee..7c9e433dd9 100644 --- a/layout/style/CSSStyleSheet.cpp +++ b/layout/style/CSSStyleSheet.cpp @@ -1963,7 +1963,7 @@ CSSStyleSheet::ReparseSheet(const nsAString& aInput) loader = mDocument->CSSLoader(); NS_ASSERTION(loader, "Document with no CSS loader!"); } else { - loader = new css::Loader(StyleBackendType::Gecko); + loader = new css::Loader(); } mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true); diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index 83de9c8de6..f7777a1fa8 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -516,11 +516,10 @@ LoaderReusableStyleSheets::FindReusableStyleSheet(nsIURI* aURL, * Loader Implementation * *************************/ -Loader::Loader(StyleBackendType aType) +Loader::Loader(void) : mDocument(nullptr) , mDatasToNotifyOn(0) , mCompatMode(eCompatibility_FullStandards) - , mStyleBackendType(Some(aType)) , mEnabled(true) , mReporter(new ConsoleReportCollector()) #ifdef DEBUG @@ -1098,8 +1097,7 @@ Loader::CreateSheet(nsIURI* aURI, // can mess with our hashtables. *aIsAlternate = IsAlternate(aTitle, aHasAlternateRel); - // XXXheycam Cached sheets currently must be CSSStyleSheets. - if (aURI && GetStyleBackendType() == StyleBackendType::Gecko) { + if (aURI) { aSheetState = eSheetComplete; RefPtr sheet; @@ -2642,17 +2640,5 @@ Loader::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const return n; } -StyleBackendType -Loader::GetStyleBackendType() const -{ - MOZ_ASSERT(mStyleBackendType || mDocument, - "you must construct a Loader with a document or set a " - "StyleBackendType on it before calling GetStyleBackendType"); - if (mStyleBackendType) { - return *mStyleBackendType; - } - return mDocument->GetStyleBackendType(); -} - } // namespace css } // namespace mozilla diff --git a/layout/style/Loader.h b/layout/style/Loader.h index 4a3088b6b4..c9af2f39e8 100644 --- a/layout/style/Loader.h +++ b/layout/style/Loader.h @@ -23,7 +23,6 @@ #include "mozilla/StyleSheetInlines.h" #include "mozilla/Maybe.h" #include "mozilla/MemoryReporting.h" -#include "mozilla/StyleBackendType.h" #include "mozilla/StyleSheet.h" #include "mozilla/net/ReferrerPolicy.h" @@ -191,7 +190,7 @@ class Loader final { typedef mozilla::net::ReferrerPolicy ReferrerPolicy; public: - explicit Loader(StyleBackendType aType); + explicit Loader(); explicit Loader(nsIDocument*); private: @@ -548,8 +547,6 @@ private: void DoSheetComplete(SheetLoadData* aLoadData, nsresult aStatus, LoadDataArray& aDatasToNotify); - StyleBackendType GetStyleBackendType() const; - struct Sheets { nsBaseHashtable, @@ -586,10 +583,6 @@ private: nsCompatibility mCompatMode; nsString mPreferredSheet; // title of preferred sheet - // Set explicitly when the Loader(StyleBackendType) constructor is used, or - // taken from the document when the Loader(nsIDocument*) constructor is used. - mozilla::Maybe mStyleBackendType; - bool mEnabled; // is enabled to load new styles nsCOMPtr mReporter; diff --git a/layout/style/nsLayoutStylesheetCache.cpp b/layout/style/nsLayoutStylesheetCache.cpp index 95464694da..d3c0f2790d 100644 --- a/layout/style/nsLayoutStylesheetCache.cpp +++ b/layout/style/nsLayoutStylesheetCache.cpp @@ -237,8 +237,7 @@ nsLayoutStylesheetCache::DesignModeSheet() void nsLayoutStylesheetCache::Shutdown() { - gCSSLoader_Gecko = nullptr; - gCSSLoader_Servo = nullptr; + gCSSLoader = nullptr; gStyleCache_Gecko = nullptr; gStyleCache_Servo = nullptr; MOZ_ASSERT(!gUserContentSheetURL, "Got the URL but never used?"); @@ -295,14 +294,12 @@ nsLayoutStylesheetCache::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf // 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 obsSvc = mozilla::services::GetObserverService(); @@ -353,16 +350,15 @@ nsLayoutStylesheetCache::InitMemoryReporter() } /* static */ nsLayoutStylesheetCache* -nsLayoutStylesheetCache::For(StyleBackendType aType) +nsLayoutStylesheetCache::Get() { MOZ_ASSERT(NS_IsMainThread()); bool mustInit = !gStyleCache_Gecko && !gStyleCache_Servo; - auto& cache = aType == StyleBackendType::Gecko ? gStyleCache_Gecko : - gStyleCache_Servo; + auto& cache = gStyleCache_Gecko; if (!cache) { - cache = new nsLayoutStylesheetCache(aType); + cache = new nsLayoutStylesheetCache(); cache->InitMemoryReporter(); } @@ -475,19 +471,15 @@ nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI, return; } - auto& loader = mBackendType == StyleBackendType::Gecko ? - gCSSLoader_Gecko : - gCSSLoader_Servo; - - if (!loader) { - loader = new mozilla::css::Loader(mBackendType); - if (!loader) { + if (!gCSSLoader) { + gCSSLoader = new mozilla::css::Loader(); + if (!gCSSLoader) { ErrorLoadingSheet(aURI, "no Loader", eCrash); return; } } - 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 %x", rv).get(), @@ -499,8 +491,7 @@ nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI, nsLayoutStylesheetCache::InvalidateSheet(RefPtr* aGeckoSheet, RefPtr* aServoSheet) { - MOZ_ASSERT(gCSSLoader_Gecko || gCSSLoader_Servo, - "pref changed before we loaded a sheet?"); + MOZ_ASSERT(gCSSLoader, "pref changed before we loaded a sheet?"); const bool gotGeckoSheet = aGeckoSheet && *aGeckoSheet; const bool gotServoSheet = aServoSheet && *aServoSheet; @@ -519,11 +510,8 @@ nsLayoutStylesheetCache::InvalidateSheet(RefPtr* aGeckoSheet, return; } - if (gCSSLoader_Gecko) { - gCSSLoader_Gecko->ObsoleteSheet(uri); - } - if (gCSSLoader_Servo) { - gCSSLoader_Servo->ObsoleteSheet(uri); + if (gCSSLoader) { + gCSSLoader->ObsoleteSheet(uri); } if (gotGeckoSheet) { *aGeckoSheet = nullptr; @@ -540,7 +528,7 @@ nsLayoutStylesheetCache::DependentPrefChanged(const char* aPref, void* aData) "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 + // 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. @@ -679,10 +667,7 @@ mozilla::StaticRefPtr nsLayoutStylesheetCache::gStyleCache_Servo; mozilla::StaticRefPtr -nsLayoutStylesheetCache::gCSSLoader_Gecko; - -mozilla::StaticRefPtr -nsLayoutStylesheetCache::gCSSLoader_Servo; +nsLayoutStylesheetCache::gCSSLoader; mozilla::StaticRefPtr nsLayoutStylesheetCache::gUserContentSheetURL; diff --git a/layout/style/nsLayoutStylesheetCache.h b/layout/style/nsLayoutStylesheetCache.h index 70ab5e88d9..87a2d2997d 100644 --- a/layout/style/nsLayoutStylesheetCache.h +++ b/layout/style/nsLayoutStylesheetCache.h @@ -11,7 +11,6 @@ #include "mozilla/Attributes.h" #include "mozilla/MemoryReporting.h" #include "mozilla/StaticPtr.h" -#include "mozilla/StyleBackendType.h" #include "mozilla/css/Loader.h" class nsIFile; @@ -49,7 +48,7 @@ class nsLayoutStylesheetCache final * and a particular UA style sheet might be cached in both, one or neither * nsLayoutStylesheetCache.) */ - static nsLayoutStylesheetCache* For(mozilla::StyleBackendType aType); + static nsLayoutStylesheetCache* Get(); mozilla::StyleSheet* ScrollbarsSheet(); mozilla::StyleSheet* FormsSheet(); @@ -82,7 +81,7 @@ class nsLayoutStylesheetCache final size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; private: - explicit nsLayoutStylesheetCache(mozilla::StyleBackendType aImpl); + explicit nsLayoutStylesheetCache(); ~nsLayoutStylesheetCache(); void InitFromProfile(); @@ -106,10 +105,8 @@ private: static mozilla::StaticRefPtr gStyleCache_Gecko; static mozilla::StaticRefPtr gStyleCache_Servo; - static mozilla::StaticRefPtr gCSSLoader_Gecko; - static mozilla::StaticRefPtr gCSSLoader_Servo; + static mozilla::StaticRefPtr gCSSLoader; static mozilla::StaticRefPtr gUserContentSheetURL; - mozilla::StyleBackendType mBackendType; RefPtr mChromePreferenceSheet; RefPtr mContentEditableSheet; RefPtr mContentPreferenceSheet;