Issue #2112 - Part 7: Remove Servo CSS Loader support

This commit is contained in:
FranklinDM 2024-03-25 16:57:34 +08:00 • committed by roytam1
commit 14764253a5
17 changed files with 37 additions and 87 deletions

View file

@ -4065,7 +4065,7 @@ nsDocument::LoadAdditionalStyleSheet(additionalSheetType aType,
return NS_ERROR_INVALID_ARG;
// Loading the sheet sync.
RefPtr<css::Loader> loader = new css::Loader(GetStyleBackendType());
RefPtr<css::Loader> loader = new css::Loader();
css::SheetParsingMode parsingMode;
switch (aType) {

View file

@ -2380,7 +2380,7 @@ nsHTMLDocument::TearingDownEditor(nsIEditor *aEditor)
nsTArray<RefPtr<StyleSheet>> 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();

View file

@ -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();

View file

@ -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 {

View file

@ -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());

View file

@ -138,7 +138,7 @@ SVGDocument::EnsureNonSVGUserAgentStyleSheetsLoaded()
}
}
auto cache = nsLayoutStylesheetCache::For(GetStyleBackendType());
auto cache = nsLayoutStylesheetCache::Get();
StyleSheet* sheet = cache->NumberControlSheet();
if (sheet) {

View file

@ -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());
}

View file

@ -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

View file

@ -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<mozilla::css::Loader> cssLoader =
new mozilla::css::Loader(backendType);
RefPtr<mozilla::css::Loader> cssLoader = new mozilla::css::Loader();
char *str = ToNewCString(sheets);
char *newStr = str;

View file

@ -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) {

View file

@ -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<StyleSheet> newPrefSheet =
mPresContext->IsChromeOriginImage() ?
cache->ChromePreferenceSheet(mPresContext) :

View file

@ -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<css::Loader> loader = new css::Loader(StyleBackendType::Gecko);
RefPtr<css::Loader> loader = new css::Loader();
RefPtr<StyleSheet> 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<css::Loader> loader = new css::Loader(StyleBackendType::Gecko);
RefPtr<css::Loader> loader = new css::Loader();
RefPtr<StyleSheet> sheet;
nsresult rv = loader->LoadSheetSync(aSheetURI, parsingMode, true, &sheet);

View file

@ -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);

View file

@ -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<StyleSheet> 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

View file

@ -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<URIPrincipalReferrerPolicyAndCORSModeHashKey,
RefPtr<StyleSheet>,
@ -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<StyleBackendType> mStyleBackendType;
bool mEnabled; // is enabled to load new styles
nsCOMPtr<nsIConsoleReportCollector> mReporter;

View file

@ -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<nsIObserverService> 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<StyleSheet>* aGeckoSheet,
RefPtr<StyleSheet>* 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<StyleSheet>* 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>
nsLayoutStylesheetCache::gStyleCache_Servo;
mozilla::StaticRefPtr<mozilla::css::Loader>
nsLayoutStylesheetCache::gCSSLoader_Gecko;
mozilla::StaticRefPtr<mozilla::css::Loader>
nsLayoutStylesheetCache::gCSSLoader_Servo;
nsLayoutStylesheetCache::gCSSLoader;
mozilla::StaticRefPtr<nsIURI>
nsLayoutStylesheetCache::gUserContentSheetURL;

View file

@ -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<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<mozilla::css::Loader> gCSSLoader;
static mozilla::StaticRefPtr<nsIURI> gUserContentSheetURL;
mozilla::StyleBackendType mBackendType;
RefPtr<mozilla::StyleSheet> mChromePreferenceSheet;
RefPtr<mozilla::StyleSheet> mContentEditableSheet;
RefPtr<mozilla::StyleSheet> mContentPreferenceSheet;