From c889bc5ce1b8cbbbc057dc629eb1d1a45c171ada Mon Sep 17 00:00:00 2001 From: Cameron Kaiser Date: Wed, 19 Apr 2023 21:55:52 -0700 Subject: [PATCH] #659: initial support for per-host CSS grid whitelist --- layout/base/nsLayoutUtils.cpp | 3 +++ layout/style/nsCSSParser.cpp | 31 +++++++++++++++++++++++++++++++ modules/libpref/init/all.js | 7 +++---- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index f5a89763b..9a3278ed6 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -174,6 +174,9 @@ static ContentMap& GetContentMap() { // When the pref "layout.css.grid.enabled" changes, this function is invoked // to let us update kDisplayKTable, to selectively disable or restore the // entries for "grid" and "inline-grid" in that table. +// +// NB: as of TenFourFox issue 659, a whitelist entry per host is also required +// to enable (but turning it off turns it off globally). static void GridEnabledPrefChangeCallback(const char* aPrefName, void* aClosure) { diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index 2e77eae0d..a4f598fa4 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -1439,6 +1439,10 @@ protected: // Value to make sure our resolved variable results stay within sane limits. const uint32_t MAX_CSS_VAR_LENGTH = 10240; + // TenFourFox issue 659 + // If this host is whitelisted, turn on CSS grid and inline grid. + bool mHostCSSGridOK : 1; + public: // Used from nsCSSParser constructors and destructors CSSParserImpl* mNextFree; @@ -1587,6 +1591,25 @@ CSSParserImpl::InitScanner(nsCSSScanner& aScanner, mSheetURI = aSheetURI; mSheetPrincipal = aSheetPrincipal; mHavePushBack = false; + + mHostCSSGridOK = false; + if (MOZ_LIKELY(mBaseURI)) { + nsCString host; + + nsresult rv = mBaseURI->GetHost(host); + if (NS_SUCCEEDED(rv)) { + nsCString pref; + + pref.AssignLiteral("layout.css.grid.host."); + pref.SetCapacity(pref.Length() + host.Length()); + pref += host; + mHostCSSGridOK = Preferences::GetBool(pref.get(), false); +#if DEBUG + if (mHostCSSGridOK) + fprintf(stderr, "CSS grid enabled for %s\n", pref.get()); +#endif + } + } } void @@ -7586,6 +7609,14 @@ CSSParserImpl::ParseVariant(nsCSSValue& aValue, } if ((aVariantMask & VARIANT_KEYWORD) != 0) { int32_t value; + + // TenFourFox issue 659 + if (MOZ_UNLIKELY(!mHostCSSGridOK && + aKeywordTable == nsCSSProps::kDisplayKTable && + (keyword == eCSSKeyword_grid || + keyword == eCSSKeyword_inline_grid))) { + // pretend the keyword wasn't found + } else if (nsCSSProps::FindKeyword(keyword, aKeywordTable, value)) { aValue.SetIntValue(value, eCSSUnit_Enumerated); return CSSParseResult::Ok; diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index a32f996d8..6953a792b 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -2395,11 +2395,10 @@ pref("layout.css.variables.enabled", true); pref("layout.css.overflow-clip-box.enabled", false); // Is support for CSS grid enabled? -#ifdef RELEASE_BUILD -pref("layout.css.grid.enabled", false); -#else +// TenFourFox issue 659 makes this into a per-host whitelist. pref("layout.css.grid.enabled", true); -#endif +// Whitelist by default: +pref("layout.css.grid.host.developer.mozilla.org", true); // Is support for CSS "grid-template-{columns,rows}: subgrid X" enabled? pref("layout.css.grid-template-subgrid-value.enabled", false);