From db3ce13f2897cc76bb083f93ebb60d07e567a7d7 Mon Sep 17 00:00:00 2001 From: FranklinDM Date: Fri, 6 Jan 2023 21:07:37 +0800 Subject: [PATCH] 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 --- caps/BasePrincipal.h | 2 - caps/nsIPrincipal.idl | 11 +- caps/nsPrincipal.cpp | 204 --------- caps/nsPrincipal.h | 3 - layout/style/CSSUnprefixingService.js | 341 --------------- layout/style/CSSUnprefixingService.manifest | 2 - layout/style/moz.build | 11 - layout/style/nsCSSParser.cpp | 244 +---------- layout/style/nsICSSUnprefixingService.idl | 76 ---- layout/style/test/mochitest.ini | 4 - .../style/test/test_unprefixing_service.html | 93 ----- .../test/test_unprefixing_service_prefs.html | 132 ------ .../test/unprefixing_service_iframe.html | 394 ------------------ .../style/test/unprefixing_service_utils.js | 87 ---- modules/libpref/init/all.js | 10 - 15 files changed, 24 insertions(+), 1590 deletions(-) delete mode 100644 layout/style/CSSUnprefixingService.js delete mode 100644 layout/style/CSSUnprefixingService.manifest delete mode 100644 layout/style/nsICSSUnprefixingService.idl delete mode 100644 layout/style/test/test_unprefixing_service.html delete mode 100644 layout/style/test/test_unprefixing_service_prefs.html delete mode 100644 layout/style/test/unprefixing_service_iframe.html delete mode 100644 layout/style/test/unprefixing_service_utils.js diff --git a/caps/BasePrincipal.h b/caps/BasePrincipal.h index f6a179fa8f..b1f151521f 100644 --- a/caps/BasePrincipal.h +++ b/caps/BasePrincipal.h @@ -287,8 +287,6 @@ public: virtual bool AddonHasPermission(const nsAString& aPerm); - virtual bool IsOnCSSUnprefixingWhitelist() override { return false; } - virtual bool IsCodebasePrincipal() const { return false; }; static BasePrincipal* Cast(nsIPrincipal* aPrin) { return static_cast(aPrin); } diff --git a/caps/nsIPrincipal.idl b/caps/nsIPrincipal.idl index d278decdb4..1d58dcb7fa 100644 --- a/caps/nsIPrincipal.idl +++ b/caps/nsIPrincipal.idl @@ -21,7 +21,7 @@ interface nsIDOMDocument; [ptr] native JSPrincipals(JSPrincipals); [ptr] native PrincipalArray(nsTArray >); -[scriptable, builtinclass, uuid(3da7b133-f1a0-4de9-a2bc-5c49014c1077)] +[scriptable, builtinclass, uuid(f75f502d-79fd-48be-a079-e5a7b8f80c8b)] interface nsIPrincipal : nsISerializable { /** @@ -333,15 +333,6 @@ interface nsIPrincipal : nsISerializable * Returns true iff this is the system principal. */ [infallible] readonly attribute boolean isSystemPrincipal; - - /** - * Returns true if this principal's origin is recognized as being on the - * whitelist of sites that can use the CSS Unprefixing Service. - * - * (This interface provides a trivial implementation, just returning false; - * subclasses can implement something more complex as-needed.) - */ - [noscript,notxpcom,nostdcall] bool IsOnCSSUnprefixingWhitelist(); }; /** diff --git a/caps/nsPrincipal.cpp b/caps/nsPrincipal.cpp index 05d00c80a3..c9e66fef7a 100644 --- a/caps/nsPrincipal.cpp +++ b/caps/nsPrincipal.cpp @@ -35,7 +35,6 @@ using namespace mozilla; -static bool gIsWhitelistingTestDomains = false; static bool gCodeBasePrincipalSupport = false; static bool URIIsImmutable(nsIURI* aURI) @@ -61,10 +60,6 @@ NS_IMPL_CI_INTERFACE_GETTER(nsPrincipal, /* static */ void nsPrincipal::InitializeStatics() { - Preferences::AddBoolVarCache( - &gIsWhitelistingTestDomains, - "layout.css.unprefixing-service.include-test-domains"); - Preferences::AddBoolVarCache(&gCodeBasePrincipalSupport, "signed.applets.codebase_principal_support", false); @@ -483,196 +478,6 @@ nsPrincipal::Write(nsIObjectOutputStream* aStream) return NS_OK; } -// Helper-function to indicate whether the CSS Unprefixing Service -// whitelist should include dummy domains that are only intended for -// use in testing. (Controlled by a pref.) -static inline bool -IsWhitelistingTestDomains() -{ - return gIsWhitelistingTestDomains; -} - -// Checks if the given URI's host is on our "full domain" whitelist -// (i.e. if it's an exact match against a domain that needs unprefixing) -static bool -IsOnFullDomainWhitelist(nsIURI* aURI) -{ - nsAutoCString hostStr; - nsresult rv = aURI->GetHost(hostStr); - NS_ENSURE_SUCCESS(rv, false); - - // NOTE: This static whitelist is expected to be short. If that changes, - // we should consider a different representation; e.g. hash-set, prefix tree. - static const nsLiteralCString sFullDomainsOnWhitelist[] = { - // 0th entry only active when testing: - NS_LITERAL_CSTRING("test1.example.org"), - NS_LITERAL_CSTRING("map.baidu.com"), - NS_LITERAL_CSTRING("3g.163.com"), - NS_LITERAL_CSTRING("3glogo.gtimg.com"), // for 3g.163.com - NS_LITERAL_CSTRING("info.3g.qq.com"), // for 3g.qq.com - NS_LITERAL_CSTRING("3gimg.qq.com"), // for 3g.qq.com - NS_LITERAL_CSTRING("img.m.baidu.com"), // for [shucheng|ks].baidu.com - NS_LITERAL_CSTRING("m.mogujie.com"), - NS_LITERAL_CSTRING("touch.qunar.com"), - NS_LITERAL_CSTRING("mjs.sinaimg.cn"), // for sina.cn - NS_LITERAL_CSTRING("static.qiyi.com"), // for m.iqiyi.com - NS_LITERAL_CSTRING("cdn.kuaidi100.com"), // for m.kuaidi100.com - NS_LITERAL_CSTRING("m.pc6.com"), - NS_LITERAL_CSTRING("m.haosou.com"), - NS_LITERAL_CSTRING("m.mi.com"), - NS_LITERAL_CSTRING("wappass.baidu.com"), - NS_LITERAL_CSTRING("m.video.baidu.com"), - NS_LITERAL_CSTRING("m.video.baidu.com"), - NS_LITERAL_CSTRING("imgcache.gtimg.cn"), // for m.v.qq.com - NS_LITERAL_CSTRING("s.tabelog.jp"), - NS_LITERAL_CSTRING("s.yimg.jp"), // for s.tabelog.jp - NS_LITERAL_CSTRING("i.yimg.jp"), // for *.yahoo.co.jp - NS_LITERAL_CSTRING("ai.yimg.jp"), // for *.yahoo.co.jp - NS_LITERAL_CSTRING("m.finance.yahoo.co.jp"), - NS_LITERAL_CSTRING("daily.c.yimg.jp"), // for sp.daily.co.jp - NS_LITERAL_CSTRING("stat100.ameba.jp"), // for ameblo.jp - NS_LITERAL_CSTRING("user.ameba.jp"), // for ameblo.jp - NS_LITERAL_CSTRING("www.goo.ne.jp"), - NS_LITERAL_CSTRING("x.gnst.jp"), // for mobile.gnavi.co.jp - NS_LITERAL_CSTRING("c.x.gnst.jp"), // for mobile.gnavi.co.jp - NS_LITERAL_CSTRING("www.smbc-card.com"), - NS_LITERAL_CSTRING("static.card.jp.rakuten-static.com"), // for rakuten-card.co.jp - NS_LITERAL_CSTRING("img.travel.rakuten.co.jp"), // for travel.rakuten.co.jp - NS_LITERAL_CSTRING("img.mixi.net"), // for mixi.jp - NS_LITERAL_CSTRING("girlschannel.net"), - NS_LITERAL_CSTRING("www.fancl.co.jp"), - NS_LITERAL_CSTRING("s.cosme.net"), - NS_LITERAL_CSTRING("www.sapporobeer.jp"), - NS_LITERAL_CSTRING("www.mapion.co.jp"), - NS_LITERAL_CSTRING("touch.navitime.co.jp"), - NS_LITERAL_CSTRING("sp.mbga.jp"), - NS_LITERAL_CSTRING("ava-a.sp.mbga.jp"), // for sp.mbga.jp - NS_LITERAL_CSTRING("www.ntv.co.jp"), - NS_LITERAL_CSTRING("mobile.suntory.co.jp"), // for suntory.jp - NS_LITERAL_CSTRING("www.aeonsquare.net"), - NS_LITERAL_CSTRING("mw.nikkei.com"), - NS_LITERAL_CSTRING("www.nhk.or.jp"), - NS_LITERAL_CSTRING("www.tokyo-sports.co.jp"), - NS_LITERAL_CSTRING("www.bellemaison.jp"), - NS_LITERAL_CSTRING("www.kuronekoyamato.co.jp"), - NS_LITERAL_CSTRING("formassist.jp"), // for orico.jp - NS_LITERAL_CSTRING("sp.m.reuters.co.jp"), - NS_LITERAL_CSTRING("www.atre.co.jp"), - NS_LITERAL_CSTRING("www.jtb.co.jp"), - NS_LITERAL_CSTRING("www.sharp.co.jp"), - NS_LITERAL_CSTRING("www.biccamera.com"), - NS_LITERAL_CSTRING("weathernews.jp"), - NS_LITERAL_CSTRING("cache.ymail.jp"), // for www.yamada-denkiweb.com - }; - static const size_t sNumFullDomainsOnWhitelist = - MOZ_ARRAY_LENGTH(sFullDomainsOnWhitelist); - - // Skip 0th (dummy) entry in whitelist, unless a pref is enabled. - const size_t firstWhitelistIdx = IsWhitelistingTestDomains() ? 0 : 1; - - for (size_t i = firstWhitelistIdx; i < sNumFullDomainsOnWhitelist; ++i) { - if (hostStr == sFullDomainsOnWhitelist[i]) { - return true; - } - } - return false; -} - -// Checks if the given URI's host is on our "base domain" whitelist -// (i.e. if it's a subdomain of some host that we've whitelisted as needing -// unprefixing for all its subdomains) -static bool -IsOnBaseDomainWhitelist(nsIURI* aURI) -{ - static const nsLiteralCString sBaseDomainsOnWhitelist[] = { - // 0th entry only active when testing: - NS_LITERAL_CSTRING("test2.example.org"), - NS_LITERAL_CSTRING("tbcdn.cn"), // for m.taobao.com - NS_LITERAL_CSTRING("alicdn.com"), // for m.taobao.com - NS_LITERAL_CSTRING("dpfile.com"), // for m.dianping.com - NS_LITERAL_CSTRING("hao123img.com"), // for hao123.com - NS_LITERAL_CSTRING("tabelog.k-img.com"), // for s.tabelog.com - NS_LITERAL_CSTRING("tsite.jp"), // for *.tsite.jp - }; - static const size_t sNumBaseDomainsOnWhitelist = - MOZ_ARRAY_LENGTH(sBaseDomainsOnWhitelist); - - nsCOMPtr tldService = - do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID); - - if (tldService) { - // Skip 0th test-entry in whitelist, unless the testing pref is enabled. - const size_t firstWhitelistIdx = IsWhitelistingTestDomains() ? 0 : 1; - - // Right now, the test base-domain "test2.example.org" is the only entry in - // its whitelist with a nonzero "depth". So we'll only bother going beyond - // 0 depth (to 1) if that entry is enabled. (No point in slowing down the - // normal codepath, for the benefit of a disabled test domain.) If we add a - // "real" base-domain with a depth of >= 1 to our whitelist, we can get rid - // of this conditional & just make this a static variable. - const uint32_t maxSubdomainDepth = IsWhitelistingTestDomains() ? 1 : 0; - - for (uint32_t subdomainDepth = 0; - subdomainDepth <= maxSubdomainDepth; ++subdomainDepth) { - - // Get the base domain (to depth |subdomainDepth|) from passed-in URI: - nsAutoCString baseDomainStr; - nsresult rv = tldService->GetBaseDomain(aURI, subdomainDepth, - baseDomainStr); - if (NS_FAILED(rv)) { - // aURI doesn't have |subdomainDepth| levels of subdomains. If we got - // here without a match yet, then aURI is not on our whitelist. - return false; - } - - // Compare the base domain against each entry in our whitelist: - for (size_t i = firstWhitelistIdx; i < sNumBaseDomainsOnWhitelist; ++i) { - if (baseDomainStr == sBaseDomainsOnWhitelist[i]) { - return true; - } - } - } - } - - return false; -} - -// The actual (non-cached) implementation of IsOnCSSUnprefixingWhitelist(): -static bool -IsOnCSSUnprefixingWhitelistImpl(nsIURI* aURI) -{ - // Check scheme, so we can drop any non-HTTP/HTTPS URIs right away - nsAutoCString schemeStr; - nsresult rv = aURI->GetScheme(schemeStr); - NS_ENSURE_SUCCESS(rv, false); - - // Only proceed if scheme is "http" or "https" - if (!(StringBeginsWith(schemeStr, NS_LITERAL_CSTRING("http")) && - (schemeStr.Length() == 4 || - (schemeStr.Length() == 5 && schemeStr[4] == 's')))) { - return false; - } - - return (IsOnFullDomainWhitelist(aURI) || - IsOnBaseDomainWhitelist(aURI)); -} - - -bool -nsPrincipal::IsOnCSSUnprefixingWhitelist() -{ - if (mIsOnCSSUnprefixingWhitelist.isNothing()) { - // Value not cached -- perform our lazy whitelist-check. - // (NOTE: If our URI is mutable, we just assume it's not on the whitelist, - // since our caching strategy won't work. This isn't expected to be common.) - mIsOnCSSUnprefixingWhitelist.emplace( - mCodebaseImmutable && - IsOnCSSUnprefixingWhitelistImpl(mCodebase)); - } - - return *mIsOnCSSUnprefixingWhitelist; -} - /************************************************************************************************************************/ NS_IMPL_CLASSINFO(nsExpandedPrincipal, nullptr, nsIClassInfo::MAIN_THREAD_ONLY, @@ -837,15 +642,6 @@ nsExpandedPrincipal::AddonHasPermission(const nsAString& aPerm) return false; } -bool -nsExpandedPrincipal::IsOnCSSUnprefixingWhitelist() -{ - // CSS Unprefixing Whitelist is a per-origin thing; doesn't really make sense - // for an expanded principal. (And probably shouldn't be needed.) - return false; -} - - nsresult nsExpandedPrincipal::GetScriptLocation(nsACString& aStr) { diff --git a/caps/nsPrincipal.h b/caps/nsPrincipal.h index d20d81ee3b..c122952c70 100644 --- a/caps/nsPrincipal.h +++ b/caps/nsPrincipal.h @@ -25,7 +25,6 @@ public: NS_IMETHOD GetDomain(nsIURI** aDomain) override; NS_IMETHOD SetDomain(nsIURI* aDomain) override; NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override; - virtual bool IsOnCSSUnprefixingWhitelist() override; bool IsCodebasePrincipal() const override { return true; } nsresult GetOriginInternal(nsACString& aOrigin) override; @@ -55,7 +54,6 @@ public: bool mCodebaseImmutable; bool mDomainImmutable; bool mInitialized; - mozilla::Maybe mIsOnCSSUnprefixingWhitelist; // Lazily-computed protected: virtual ~nsPrincipal(); @@ -81,7 +79,6 @@ public: NS_IMETHOD SetDomain(nsIURI* aDomain) override; NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override; virtual bool AddonHasPermission(const nsAString& aPerm) override; - virtual bool IsOnCSSUnprefixingWhitelist() override; virtual nsresult GetScriptLocation(nsACString &aStr) override; nsresult GetOriginInternal(nsACString& aOrigin) override; diff --git a/layout/style/CSSUnprefixingService.js b/layout/style/CSSUnprefixingService.js deleted file mode 100644 index f6c63a0237..0000000000 --- a/layout/style/CSSUnprefixingService.js +++ /dev/null @@ -1,341 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- / -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/* Implementation of a service that converts certain vendor-prefixed CSS - properties to their unprefixed equivalents, for sites on a whitelist. */ - -"use strict"; - -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cu = Components.utils; - -Cu.import("resource://gre/modules/XPCOMUtils.jsm"); - -function CSSUnprefixingService() { -} - -CSSUnprefixingService.prototype = { - // Boilerplate: - classID: Components.ID("{f0729490-e15c-4a2f-a3fb-99e1cc946b42}"), - _xpcom_factory: XPCOMUtils.generateSingletonFactory(CSSUnprefixingService), - QueryInterface: XPCOMUtils.generateQI([Ci.nsICSSUnprefixingService]), - - // See documentation in nsICSSUnprefixingService.idl - generateUnprefixedDeclaration: function(aPropName, aRightHalfOfDecl, - aUnprefixedDecl /*out*/) { - - // Convert our input strings to lower-case, for easier string-matching. - // (NOTE: If we ever need to add support for unprefixing properties that - // have case-sensitive parts, then we should do these toLowerCase() - // conversions in a more targeted way, to avoid breaking those properties.) - aPropName = aPropName.toLowerCase(); - aRightHalfOfDecl = aRightHalfOfDecl.toLowerCase(); - - // We have several groups of supported properties: - // FIRST GROUP: Properties that can just be handled as aliases: - // ============================================================ - const propertiesThatAreJustAliases = { - "-webkit-background-size": "background-size", - "-webkit-box-flex": "flex-grow", - "-webkit-box-ordinal-group": "order", - "-webkit-box-sizing": "box-sizing", - "-webkit-transform": "transform", - "-webkit-transform-origin": "transform-origin", - }; - - let unprefixedPropName = propertiesThatAreJustAliases[aPropName]; - if (unprefixedPropName !== undefined) { - aUnprefixedDecl.value = unprefixedPropName + ":" + aRightHalfOfDecl; - return true; - } - - // SECOND GROUP: Properties that take a single keyword, where the - // unprefixed version takes a different (but analogous) set of keywords: - // ===================================================================== - const propertiesThatNeedKeywordMapping = { - "-webkit-box-align" : { - unprefixedPropName : "align-items", - valueMap : { - "start" : "flex-start", - "center" : "center", - "end" : "flex-end", - "baseline" : "baseline", - "stretch" : "stretch" - } - }, - "-webkit-box-orient" : { - unprefixedPropName : "flex-direction", - valueMap : { - "horizontal" : "row", - "inline-axis" : "row", - "vertical" : "column", - "block-axis" : "column" - } - }, - "-webkit-box-pack" : { - unprefixedPropName : "justify-content", - valueMap : { - "start" : "flex-start", - "center" : "center", - "end" : "flex-end", - "justify" : "space-between" - } - }, - }; - - let propInfo = propertiesThatNeedKeywordMapping[aPropName]; - if (typeof(propInfo) != "undefined") { - // Regexp for parsing the right half of a declaration, for keyword-valued - // properties. Divides the right half of the declaration into: - // 1) any leading whitespace - // 2) the property value (one or more alphabetical character or hyphen) - // 3) anything after that (e.g. "!important", ";") - // Then we can look up the appropriate unprefixed-property value for the - // value (part 2), and splice that together with the other parts and with - // the unprefixed property-name to make the final declaration. - const keywordValuedPropertyRegexp = /^(\s*)([a-z\-]+)(.*)/; - let parts = keywordValuedPropertyRegexp.exec(aRightHalfOfDecl); - if (!parts) { - // Failed to parse a keyword out of aRightHalfOfDecl. (It probably has - // no alphabetical characters.) - return false; - } - - let mappedKeyword = propInfo.valueMap[parts[2]]; - if (mappedKeyword === undefined) { - // We found a keyword in aRightHalfOfDecl, but we don't have a mapping - // to an equivalent keyword for the unprefixed version of the property. - return false; - } - - aUnprefixedDecl.value = propInfo.unprefixedPropName + ":" + - parts[1] + // any leading whitespace - mappedKeyword + - parts[3]; // any trailing text (e.g. !important, semicolon, etc) - - return true; - } - - // THIRD GROUP: Properties that may need arbitrary string-replacement: - // =================================================================== - const propertiesThatNeedStringReplacement = { - // "-webkit-transition" takes a multi-part value. If "-webkit-transform" - // appears as part of that value, replace it w/ "transform". - // And regardless, we unprefix the "-webkit-transition" property-name. - // (We could handle other prefixed properties in addition to 'transform' - // here, but in practice "-webkit-transform" is the main one that's - // likely to be transitioned & that we're concerned about supporting.) - "-webkit-transition": { - unprefixedPropName : "transition", - stringMap : { - "-webkit-transform" : "transform", - } - }, - }; - - propInfo = propertiesThatNeedStringReplacement[aPropName]; - if (typeof(propInfo) != "undefined") { - let newRightHalf = aRightHalfOfDecl; - for (let strToReplace in propInfo.stringMap) { - let replacement = propInfo.stringMap[strToReplace]; - newRightHalf = newRightHalf.split(strToReplace).join(replacement); - } - aUnprefixedDecl.value = propInfo.unprefixedPropName + ":" + newRightHalf; - - return true; - } - - // No known mapping for property aPropName. - return false; - }, - - // See documentation in nsICSSUnprefixingService.idl - generateUnprefixedGradientValue: function(aPrefixedFuncName, - aPrefixedFuncBody, - aUnprefixedFuncName, /*[out]*/ - aUnprefixedFuncBody /*[out]*/) { - var unprefixedFuncName, newValue; - if (aPrefixedFuncName == "-webkit-gradient") { - // Create expression for oldGradientParser: - var parts = this.oldGradientParser(aPrefixedFuncBody); - var type = parts[0].name; - newValue = this.standardizeOldGradientArgs(type, parts.slice(1)); - unprefixedFuncName = type + "-gradient"; - }else{ // we're dealing with more modern syntax - should be somewhat easier, at least for linear gradients. - // Fix three things: remove -webkit-, add 'to ' before reversed top/bottom keywords (linear) or 'at ' before position keywords (radial), recalculate deg-values - // -webkit-linear-gradient( [ [ | [top | bottom] || [left | right] ],]? [, ]+); - if (aPrefixedFuncName != "-webkit-linear-gradient" && - aPrefixedFuncName != "-webkit-radial-gradient") { - // Unrecognized prefixed gradient type - return false; - } - unprefixedFuncName = aPrefixedFuncName.replace(/-webkit-/, ''); - - // Keywords top, bottom, left, right: can be stand-alone or combined pairwise but in any order ('top left' or 'left top') - // These give the starting edge or corner in the -webkit syntax. The standardised equivalent is 'to ' plus opposite values for linear gradients, 'at ' plus same values for radial gradients - if(unprefixedFuncName.indexOf('linear') > -1){ - newValue = aPrefixedFuncBody.replace(/(top|bottom|left|right)+\s*(top|bottom|left|right)*/, function(str){ - var words = str.split(/\s+/); - for(var i=0; iIsOnCSSUnprefixingWhitelist(); -} - -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 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 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, diff --git a/layout/style/nsICSSUnprefixingService.idl b/layout/style/nsICSSUnprefixingService.idl deleted file mode 100644 index 11c3bf43f1..0000000000 --- a/layout/style/nsICSSUnprefixingService.idl +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/* interface for a service that converts certain vendor-prefixed CSS properties - to their unprefixed equivalents */ - -#include "nsISupports.idl" - -[scriptable, uuid(a5d6e2f4-d3ec-11e4-b002-782bcbaebb28)] -interface nsICSSUnprefixingService : nsISupports -{ - /** - * This function helps to convert unsupported vendor-prefixed CSS into - * supported unprefixed CSS. Given a vendor-prefixed property name and a - * value (or e.g. value + trailing junk like " !important;}"), this function - * will attempt to produce an equivalent CSS declaration that uses a - * supported unprefixed CSS property. - * - * @param aPropName - * The vendor-prefixed property name. - * - * @param aRightHalfOfDecl - * Everything after the ":" in the CSS declaration. This includes - * the property's value, along with possibly some leading whitespace - * and trailing text like "!important", and possibly a ';' and/or - * '}' (along with any other bogus text the author happens to - * include before those, which will probably make the decl invalid). - * - * @param aUnprefixedDecl[out] - * The resulting unprefixed declaration, if we return true. - * - * @return true if we were able to unprefix -- i.e. if we were able to - * convert the property to a known unprefixed equivalent, and we also - * performed any known-to-be-necessary fixup on the value, and we put - * the result in aUnprefixedDecl. - * Otherwise, this function returns false. - */ - boolean generateUnprefixedDeclaration(in AString aPropName, - in AString aRightHalfOfDecl, - out AString aUnprefixedDecl); - - /** - * @param aPrefixedFuncName - * The webkit-prefixed gradient function: either - * "-webkit-gradient", "-webkit-linear-gradient", or - * "-webkit-radial-gradient". - * - * @param aPrefixedFuncBody - * The body of the gradient function, inside (& not including) the - * parenthesis. - * - * @param aUnprefixedFuncName[out] - * The resulting unprefixed gradient function name: - * either "linear-gradient" or "radial-gradient". - * - * @param aUnprefixedFuncBody[out] - * The resulting unprefixed gradient function body, suitable for - * including in a "linear-gradient(...)" or "radial-gradient(...)" - * expression. - * - * @returns true if we were able to successfully parse aWebkitGradientStr - * and populate the outparams accordingly; false otherwise. - * - */ - boolean generateUnprefixedGradientValue(in AString aPrefixedFuncName, - in AString aPrefixedFuncBody, - out AString aUnprefixedFuncName, - out AString aUnprefixedFuncBody); -}; - -%{C++ -#define NS_CSSUNPREFIXINGSERVICE_CONTRACTID \ - "@mozilla.org/css-unprefixing-service;1" -%} diff --git a/layout/style/test/mochitest.ini b/layout/style/test/mochitest.ini index 8b36e3e1e8..2f0ab87a28 100644 --- a/layout/style/test/mochitest.ini +++ b/layout/style/test/mochitest.ini @@ -273,10 +273,6 @@ support-files = ../../reftests/fonts/markA.woff ../../reftests/fonts/markB.woff [test_units_frequency.html] [test_units_length.html] [test_units_time.html] -[test_unprefixing_service.html] -support-files = unprefixing_service_iframe.html unprefixing_service_utils.js -[test_unprefixing_service_prefs.html] -support-files = unprefixing_service_iframe.html unprefixing_service_utils.js [test_value_cloning.html] [test_value_computation.html] [test_value_storage.html] diff --git a/layout/style/test/test_unprefixing_service.html b/layout/style/test/test_unprefixing_service.html deleted file mode 100644 index c489e2ac01..0000000000 --- a/layout/style/test/test_unprefixing_service.html +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - Test for Bug 1107378 - - - - - -Mozilla Bug 1107378 -
- -
-
-
-
- - diff --git a/layout/style/test/test_unprefixing_service_prefs.html b/layout/style/test/test_unprefixing_service_prefs.html deleted file mode 100644 index 329dce2a63..0000000000 --- a/layout/style/test/test_unprefixing_service_prefs.html +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - Test for Bug 1132743 - - - - - -Mozilla Bug 1132743 -
- -
-
-
-
- - diff --git a/layout/style/test/unprefixing_service_iframe.html b/layout/style/test/unprefixing_service_iframe.html deleted file mode 100644 index 8edeb20dce..0000000000 --- a/layout/style/test/unprefixing_service_iframe.html +++ /dev/null @@ -1,394 +0,0 @@ - - - - - Helper file for testing CSS Unprefixing Service - - - - -
-
-
- - - - diff --git a/layout/style/test/unprefixing_service_utils.js b/layout/style/test/unprefixing_service_utils.js deleted file mode 100644 index cd17d20d08..0000000000 --- a/layout/style/test/unprefixing_service_utils.js +++ /dev/null @@ -1,87 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// Shared data & functionality used in tests for CSS Unprefixing Service. - -// Whitelisted hosts: -// (per implementation of nsPrincipal::IsOnCSSUnprefixingWhitelist()) -var gWhitelistedHosts = [ - // test1.example.org is on the whitelist. - "test1.example.org", - // test2.example.org is on the "allow all subdomains" whitelist. - "test2.example.org", - "sub1.test2.example.org", - "sub2.test2.example.org" -]; - -// *NOT* whitelisted hosts: -var gNotWhitelistedHosts = [ - // Though test1.example.org is on the whitelist, its subdomains are not. - "sub1.test1.example.org", - // mochi.test is not on the whitelist. - "mochi.test:8888" -]; - -// Names of prefs: -const PREF_UNPREFIXING_SERVICE = - "layout.css.unprefixing-service.enabled"; -const PREF_INCLUDE_TEST_DOMAINS = - "layout.css.unprefixing-service.include-test-domains"; - -// Helper-function to make unique URLs in testHost(): -var gCounter = 0; -function getIncreasingCounter() { - return gCounter++; -} - -// This function tests a particular host in our iframe. -// @param aHost The host to be tested -// @param aExpectEnabled Should we expect unprefixing to be enabled for host? -function testHost(aHost, aExpectEnabled) { - // Build the URL: - let url = window.location.protocol; // "http:" or "https:" - url += "//"; - url += aHost; - - // Append the path-name, up to the actual filename (the final "/"): - const re = /(.*\/).*/; - url += window.location.pathname.replace(re, "$1"); - url += IFRAME_TESTFILE; - // In case this is the same URL as last time, we add "?N" for some unique N, - // to make each URL different, so that the iframe actually (re)loads: - url += "?" + getIncreasingCounter(); - // We give the URL a #suffix to indicate to the test whether it should expect - // that unprefixing is enabled or disabled: - url += (aExpectEnabled ? "#expectEnabled" : "#expectDisabled"); - - let iframe = document.getElementById("testIframe"); - iframe.contentWindow.location = url; - // The iframe will report its results back via postMessage. - // Our caller had better have set up a postMessage listener. -} - -// Register a postMessage() handler, to allow our cross-origin iframe to -// communicate back to the main page's mochitest functionality. -// The handler expects postMessage to be called with an object like: -// { type: ["is"|"ok"|"testComplete"], ... } -// The "is" and "ok" types will trigger the corresponding function to be -// called in the main page, with named arguments provided in the payload. -// The "testComplete" type will trigger the passed-in aTestCompleteCallback -// function to be invoked (e.g. to advance to the next testcase, or to finish -// the overall test, as-appropriate). -function registerPostMessageListener(aTestCompleteCallback) { - let receiveMessage = function(event) { - if (event.data.type === "is") { - is(event.data.actual, event.data.expected, event.data.desc); - } else if (event.data.type === "ok") { - ok(event.data.condition, event.data.desc); - } else if (event.data.type === "testComplete") { - aTestCompleteCallback(); - } else { - ok(false, "unrecognized data in postMessage call"); - } - }; - - window.addEventListener("message", receiveMessage, false); -} diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index a57f1000e7..6e4cff6092 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -2551,16 +2551,6 @@ pref("layout.css.prefixes.webkit", true); // pref is set to false.) pref("layout.css.prefixes.device-pixel-ratio-webkit", false); -// Is the CSS Unprefixing Service enabled? (This service emulates support -// for certain vendor-prefixed properties & values, for sites on a "fixlist".) -pref("layout.css.unprefixing-service.enabled", true); -#ifdef NIGHTLY_BUILD -// Is the CSS Unprefixing Service whitelisted for all domains? -// (This pref is only honored in Nightly builds and can be removed when -// Bug 1177263 is fixed.) -pref("layout.css.unprefixing-service.globally-whitelisted", false); -#endif - // Is support for the :scope selector enabled? pref("layout.css.scope-pseudo.enabled", true);