Issue #2084 - Part 1: Remove CSSUnprefixingService.js and associated code

It's effectively dead code since it's been supplanted by built-in webkit-prefixed-CSS support (landed before fork point in Firefox 49).

Based on https://bugzilla.mozilla.org/show_bug.cgi?id=1259348
This commit is contained in:
FranklinDM 2023-01-06 21:07:37 +08:00 committed by roytam1
commit db3ce13f28
15 changed files with 24 additions and 1590 deletions

View file

@ -43,7 +43,6 @@
#include "nsIMediaList.h"
#include "nsStyleUtil.h"
#include "nsIPrincipal.h"
#include "nsICSSUnprefixingService.h"
#include "mozilla/Sprintf.h"
#include "nsContentUtils.h"
#include "nsAutoPtr.h"
@ -66,10 +65,6 @@ typedef nsCSSProps::KTableEntry KTableEntry;
static bool sOpentypeSVGEnabled;
static bool sWebkitPrefixedAliasesEnabled;
static bool sWebkitDevicePixelRatioEnabled;
static bool sUnprefixingServiceEnabled;
#ifdef NIGHTLY_BUILD
static bool sUnprefixingServiceGloballyWhitelisted;
#endif
static bool sMozGradientsEnabled;
static bool sControlCharVisibility;
@ -799,9 +794,7 @@ protected:
enum {
eParseDeclaration_InBraces = 1 << 0,
eParseDeclaration_AllowImportant = 1 << 1,
// The declaration we're parsing was generated by the CSSUnprefixingService:
eParseDeclaration_FromUnprefixingSvc = 1 << 2
eParseDeclaration_AllowImportant = 1 << 1
};
enum nsCSSContextType {
eCSSContext_General,
@ -824,20 +817,6 @@ protected:
nsCSSKeyword LookupKeywordPrefixAware(nsAString& aKeywordStr,
const KTableEntry aKeywordTable[]);
bool ShouldUseUnprefixingService() const;
bool ParsePropertyWithUnprefixingService(const nsAString& aPropertyName,
css::Declaration* aDeclaration,
uint32_t aFlags,
bool aMustCallValueAppended,
bool* aChanged,
nsCSSContextType aContext);
// When we detect a webkit-prefixed gradient expression, this function can be
// used to parse its body into outparam |aValue|, with the help of the
// CSSUnprefixingService.
// Only call if ShouldUseUnprefixingService() returns true.
bool ParseWebkitPrefixedGradientWithService(nsAString& aPrefixedFuncName,
nsCSSValue& aValue);
bool ParseProperty(nsCSSPropertyID aPropID);
bool ParsePropertyByFunction(nsCSSPropertyID aPropID);
CSSParseResult ParseSingleValueProperty(nsCSSValue& aValue,
@ -1518,9 +1497,8 @@ protected:
// This enum helps us track whether we've unprefixed "display: -webkit-box"
// (treating it as "display: flex") in an earlier declaration within a series
// of declarations. (This only impacts behavior when the function
// "ShouldUseUnprefixingService()" returns true, and that should only happen
// for a short whitelist of origins.)
// of declarations. (This only impacts behavior if
// sWebkitPrefixedAliasesEnabled is true.)
enum WebkitBoxUnprefixState : uint8_t {
eNotParsingDecls, // We are *not* currently parsing a sequence of
// CSS declarations. (default state)
@ -7151,7 +7129,9 @@ CSSParserImpl::LookupKeywordPrefixAware(nsAString& aKeywordStr,
// explicitly defers to the former.
if ((keyword == eCSSKeyword__webkit_box ||
keyword == eCSSKeyword__webkit_inline_box)) {
const bool usingUnprefixingService = ShouldUseUnprefixingService();
const bool usingUnprefixingService = false;
// XXXdholbert This bool^ will be removed & this whole function will be
// simplified in the next patch in this series.
if (sWebkitPrefixedAliasesEnabled || usingUnprefixingService) {
// Make a note that we're accepting some "-webkit-{inline-}box" styling,
// so we can give special treatment to subsequent "-moz-{inline}-box".
@ -7180,10 +7160,9 @@ CSSParserImpl::LookupKeywordPrefixAware(nsAString& aKeywordStr,
if (mWebkitBoxUnprefixState == eHaveUnprefixed &&
(keyword == eCSSKeyword__moz_box ||
keyword == eCSSKeyword__moz_inline_box)) {
MOZ_ASSERT(sWebkitPrefixedAliasesEnabled || ShouldUseUnprefixingService(),
"mDidUnprefixWebkitBoxInEarlierDecl should only be set if "
"we're supporting webkit-prefixed aliases, or if we're using "
"the css unprefixing service on this site");
MOZ_ASSERT(sWebkitPrefixedAliasesEnabled,
"The only way mWebkitBoxUnprefixState can be eHaveUnprefixed "
"is if we're supporting webkit-prefixed aliases");
if (sWebkitPrefixedAliasesEnabled) {
return (keyword == eCSSKeyword__moz_box) ?
eCSSKeyword__webkit_box : eCSSKeyword__webkit_inline_box;
@ -7198,153 +7177,6 @@ CSSParserImpl::LookupKeywordPrefixAware(nsAString& aKeywordStr,
return keyword;
}
bool
CSSParserImpl::ShouldUseUnprefixingService() const
{
if (!sUnprefixingServiceEnabled) {
// Unprefixing is globally disabled.
return false;
}
if (sWebkitPrefixedAliasesEnabled) {
// Native webkit-prefix support is enabled, which trumps the unprefixing
// service for handling prefixed CSS. Don't try to use both at once.
return false;
}
#ifdef NIGHTLY_BUILD
if (sUnprefixingServiceGloballyWhitelisted) {
// Unprefixing is globally whitelisted,
// so no need to check mSheetPrincipal.
return true;
}
#endif
// Unprefixing enabled; see if our principal is whitelisted for unprefixing.
return mSheetPrincipal && mSheetPrincipal->IsOnCSSUnprefixingWhitelist();
}
bool
CSSParserImpl::ParsePropertyWithUnprefixingService(
const nsAString& aPropertyName,
css::Declaration* aDeclaration,
uint32_t aFlags,
bool aMustCallValueAppended,
bool* aChanged,
nsCSSContextType aContext)
{
MOZ_ASSERT(ShouldUseUnprefixingService(),
"Caller should've checked ShouldUseUnprefixingService()");
nsCOMPtr<nsICSSUnprefixingService> unprefixingSvc =
do_GetService(NS_CSSUNPREFIXINGSERVICE_CONTRACTID);
NS_ENSURE_TRUE(unprefixingSvc, false);
// Save the state so we can jump back to this spot if our unprefixing fails
// (so we can behave as if we didn't even try to unprefix).
nsAutoCSSParserInputStateRestorer parserStateBeforeTryingToUnprefix(this);
// Caller has already parsed the first half of the declaration --
// aPropertyName and the ":". Now, we record the rest of the CSS declaration
// (the part after ':') into rightHalfOfDecl. (This is the property value,
// plus anything else up to the end of the declaration -- maybe "!important",
// maybe trailing junk characters, maybe a semicolon, maybe a trailing "}".)
bool checkForBraces = (aFlags & eParseDeclaration_InBraces) != 0;
nsAutoString rightHalfOfDecl;
mScanner->StartRecording();
SkipDeclaration(checkForBraces);
mScanner->StopRecording(rightHalfOfDecl);
// Try to unprefix:
bool success;
nsAutoString unprefixedDecl;
nsresult rv =
unprefixingSvc->GenerateUnprefixedDeclaration(aPropertyName,
rightHalfOfDecl,
unprefixedDecl, &success);
if (NS_FAILED(rv) || !success) {
return false;
}
// Attempt to parse the unprefixed declaration:
nsAutoScannerChanger scannerChanger(this, unprefixedDecl);
success = ParseDeclaration(aDeclaration,
aFlags | eParseDeclaration_FromUnprefixingSvc,
aMustCallValueAppended, aChanged, aContext);
if (success) {
// We succeeded, so we'll leave the parser pointing at the end of
// the declaration; don't restore it to the pre-recording position.
parserStateBeforeTryingToUnprefix.DoNotRestore();
}
return success;
}
bool
CSSParserImpl::ParseWebkitPrefixedGradientWithService(
nsAString& aPrefixedFuncName,
nsCSSValue& aValue)
{
MOZ_ASSERT(ShouldUseUnprefixingService(),
"Should only call if we're allowed to use unprefixing service");
// Record the body of the "-webkit-*gradient" function into a string.
// Note: we're already just after the opening "(".
nsAutoString prefixedFuncBody;
mScanner->StartRecording();
bool gotCloseParen = SkipUntil(')');
mScanner->StopRecording(prefixedFuncBody);
if (gotCloseParen) {
// Strip off trailing close-paren, so that the value we pass to the
// unprefixing service is *just* the function-body (no parens).
prefixedFuncBody.Truncate(prefixedFuncBody.Length() - 1);
}
// NOTE: Even if we fail, we'll be leaving the parser's cursor just after
// the close of the "-webkit-*gradient(...)" expression. This is the same
// behavior that the other Parse*Gradient functions have in their failure
// cases -- they call "SkipUntil(')') before returning false. So this is
// probably what we want.
nsCOMPtr<nsICSSUnprefixingService> unprefixingSvc =
do_GetService(NS_CSSUNPREFIXINGSERVICE_CONTRACTID);
NS_ENSURE_TRUE(unprefixingSvc, false);
bool success;
nsAutoString unprefixedFuncName;
nsAutoString unprefixedFuncBody;
nsresult rv =
unprefixingSvc->GenerateUnprefixedGradientValue(aPrefixedFuncName,
prefixedFuncBody,
unprefixedFuncName,
unprefixedFuncBody,
&success);
if (NS_FAILED(rv) || !success) {
return false;
}
// JS service thinks it successfully converted the gradient! Now let's try
// to parse the resulting string.
// First, add a close-paren if we originally recorded one (so that what we're
// about to put into the CSS parser is a faithful representation of what it
// would've seen if it were just parsing the original input stream):
if (gotCloseParen) {
unprefixedFuncBody.Append(char16_t(')'));
}
nsAutoScannerChanger scannerChanger(this, unprefixedFuncBody);
if (unprefixedFuncName.EqualsLiteral("linear-gradient")) {
return ParseLinearGradient(aValue, 0);
}
if (unprefixedFuncName.EqualsLiteral("radial-gradient")) {
return ParseRadialGradient(aValue, 0);
}
NS_ERROR("CSSUnprefixingService returned an unrecognized type of "
"gradient function");
return false;
}
//----------------------------------------------------------------------
bool
@ -7434,19 +7266,7 @@ CSSParserImpl::ParseDeclaration(css::Declaration* aDeclaration,
(aContext == eCSSContext_Page &&
!nsCSSProps::PropHasFlags(propID,
CSS_PROPERTY_APPLIES_TO_PAGE_RULE))) { // unknown property
if (NonMozillaVendorIdentifier(propertyName)) {
if (!mInSupportsCondition &&
aContext == eCSSContext_General &&
!(aFlags & eParseDeclaration_FromUnprefixingSvc) && // no recursion
ShouldUseUnprefixingService()) {
if (ParsePropertyWithUnprefixingService(propertyName,
aDeclaration, aFlags,
aMustCallValueAppended,
aChanged, aContext)) {
return true;
}
}
} else {
if (!NonMozillaVendorIdentifier(propertyName)) {
REPORT_UNEXPECTED_P(PEUnknownProperty, propertyName);
REPORT_UNEXPECTED(PEDeclDropped);
OUTPUT_ERROR();
@ -8074,18 +7894,6 @@ CSSParserImpl::ParseVariant(nsCSSValue& aValue,
}
return CSSParseResult::Ok;
}
if (ShouldUseUnprefixingService() &&
!gradientFlags &&
StringBeginsWith(tmp, NS_LITERAL_STRING("-webkit-"))) {
// Copy 'tmp' into a string on the stack, since as soon as we
// start parsing, its backing store (in "tk") will be overwritten
nsAutoString prefixedFuncName(tmp);
if (!ParseWebkitPrefixedGradientWithService(prefixedFuncName, aValue)) {
return CSSParseResult::Error;
}
return CSSParseResult::Ok;
}
}
if ((aVariantMask & VARIANT_IMAGE_RECT) != 0 &&
eCSSToken_Function == tk->mType &&
@ -10866,7 +10674,7 @@ CSSParserImpl::ParseWebkitGradientRadius(float& aRadius)
// (either a percentage or a number between 0 and 1.0), and a color (any
// valid CSS color). In addition the shorthand functions from and to are
// supported. These functions only require a color argument and are
// equivalent to color-stop(0, ...) and color-stop(1.0, …) respectively.
// equivalent to color-stop(0, ...) and color-stop(1.0, ?? respectively.
bool
CSSParserImpl::ParseWebkitGradientColorStop(nsCSSValueGradient* aGradient)
{
@ -12412,7 +12220,7 @@ CSSParserImpl::IsFunctionTokenValidForImageLayerImage(
funcName.LowerCaseEqualsLiteral("-moz-repeating-radial-gradient") ||
funcName.LowerCaseEqualsLiteral("-moz-image-rect") ||
funcName.LowerCaseEqualsLiteral("-moz-element") ||
((sWebkitPrefixedAliasesEnabled || ShouldUseUnprefixingService()) &&
(sWebkitPrefixedAliasesEnabled &&
(funcName.LowerCaseEqualsLiteral("-webkit-gradient") ||
funcName.LowerCaseEqualsLiteral("-webkit-linear-gradient") ||
funcName.LowerCaseEqualsLiteral("-webkit-radial-gradient") ||
@ -15324,17 +15132,17 @@ CSSParserImpl::ParseFontFeatureSettings(nsCSSValue& aValue)
return true;
}
bool
CSSParserImpl::ParseFontVariationSettings(nsCSSValue& aValue)
{
// TODO: Actually implement this.
// This stub is here because websites insist on considering this
// very hardware-dependent and O.S.-variable low-level font-control
// as a "critical feature" which it isn't as there is 0 guarantee
// that font variation settings are supported or honored by any
// operating system used by the client.
return true;
bool
CSSParserImpl::ParseFontVariationSettings(nsCSSValue& aValue)
{
// TODO: Actually implement this.
// This stub is here because websites insist on considering this
// very hardware-dependent and O.S.-variable low-level font-control
// as a "critical feature" which it isn't as there is 0 guarantee
// that font variation settings are supported or honored by any
// operating system used by the client.
return true;
}
bool
@ -17989,12 +17797,6 @@ nsCSSParser::Startup()
"layout.css.prefixes.webkit");
Preferences::AddBoolVarCache(&sWebkitDevicePixelRatioEnabled,
"layout.css.prefixes.device-pixel-ratio-webkit");
Preferences::AddBoolVarCache(&sUnprefixingServiceEnabled,
"layout.css.unprefixing-service.enabled");
#ifdef NIGHTLY_BUILD
Preferences::AddBoolVarCache(&sUnprefixingServiceGloballyWhitelisted,
"layout.css.unprefixing-service.globally-whitelisted");
#endif
Preferences::AddBoolVarCache(&sMozGradientsEnabled,
"layout.css.prefixes.gradients");
Preferences::AddBoolVarCache(&sControlCharVisibility,