Make FontFace parsing worker-safe
authorclord@igalia.com <clord@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Apr 2021 11:14:07 +0000 (11:14 +0000)
committerclord@igalia.com <clord@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Apr 2021 11:14:07 +0000 (11:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=224426

Reviewed by Darin Adler.

Make CSS FontFace property parsing safe to do in a Worker. Instead of
constructing a rule per property and using the full CSSPropertyParser
path, instead factor out the specific, necessary property parsers into a
new CSSPropertyParserWorkerSafe and make sure they're safe to use in a
Worker (mainly by allowing for specifying the CSSValuePool so that
main-thread singletons don't get used).

No new tests, no change in behavior.

* Sources.txt: Add CSSPropertyParserWorkerSafe.cpp/.h
* WebCore.xcodeproj/project.pbxproj:

* css/FontFace.cpp: Call setters with the ScriptExecutionContext so
  that we have access to ::cssValuePool() and use new worker-safe
  parser functions.
(WebCore::FontFace::create):
(WebCore::FontFace::setFamily):
(WebCore::FontFace::setStyle):
(WebCore::FontFace::setWeight):
(WebCore::FontFace::setStretch):
(WebCore::FontFace::setUnicodeRange):
(WebCore::FontFace::setFeatureSettings):
(WebCore::FontFace::setDisplay):
* css/FontFace.h:
* css/FontFace.idl:

* css/parser/CSSParser.cpp: Move WorkerSafe parsing functions to
  CSSPropertyParserWorkerSafe and remove now-unnecessary
  parseFontFaceDescriptor.
* css/parser/CSSParser.h:

* css/parser/CSSPropertyParser.cpp: Move FontFace property parsers to
  CSSPropertyParserWorkerSafe.
(WebCore::CSSPropertyParser::parseSingleValue):
(WebCore::CSSPropertyParser::parseFontFaceDescriptor):
(WebCore::CSSPropertyParser::consumeFont):
* css/parser/CSSPropertyParser.h:

* css/parser/CSSPropertyParserHelpers.cpp: Add WorkerSafe variants for
  some of the basic consume helpers.
(WebCore::CSSPropertyParserHelpers::CalcParser::CalcParser):
(WebCore::CSSPropertyParserHelpers::CalcParser::consumeValue):
(WebCore::CSSPropertyParserHelpers::CalcParser::consumeInteger):
(WebCore::CSSPropertyParserHelpers::CalcParser::consumeNumber):
(WebCore::CSSPropertyParserHelpers::consumeFontWeightNumber):
(WebCore::CSSPropertyParserHelpers::consumeFontWeightNumberWorkerSafe):
(WebCore::CSSPropertyParserHelpers::consumePercent):
(WebCore::CSSPropertyParserHelpers::consumePercentWorkerSafe):
(WebCore::CSSPropertyParserHelpers::consumeAngle):
(WebCore::CSSPropertyParserHelpers::consumeAngleWorkerSafe):
(WebCore::CSSPropertyParserHelpers::consumeIdent):
(WebCore::CSSPropertyParserHelpers::consumeIdentWorkerSafe):
(WebCore::CSSPropertyParserHelpers::consumeFontRaw):
* css/parser/CSSPropertyParserHelpers.h:
(WebCore::CSSPropertyParserHelpers::consumeIdent):
(WebCore::CSSPropertyParserHelpers::consumeIdentWorkerSafe):

* css/parser/CSSPropertyParserWorkerSafe.cpp: Added.
(WebCore::CSSPropertyParserWorkerSafe::parseFont):
(WebCore::CSSPropertyParserWorkerSafe::parseColor):
(WebCore::CSSPropertyParserWorkerSafe::parseFontFaceSrc):
(WebCore::CSSPropertyParserWorkerSafe::parseFontFaceStyle):
(WebCore::CSSPropertyParserWorkerSafe::parseFontFaceWeight):
(WebCore::CSSPropertyParserWorkerSafe::parseFontFaceStretch):
(WebCore::CSSPropertyParserWorkerSafe::parseFontFaceUnicodeRange):
(WebCore::CSSPropertyParserWorkerSafe::parseFontFaceFeatureSettings):
(WebCore::CSSPropertyParserWorkerSafe::parseFontFaceDisplay):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontFaceSrcURI):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontFaceSrcLocal):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontFaceSrc):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontStyle):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontStyleKeywordValue):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontStyleRange):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontWeightAbsoluteKeywordValue):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontWeightAbsoluteRange):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontWeightAbsolute):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontStretchKeywordValue):
(WebCore::CSSPropertyParserHelpersWorkerSafe::fontStretchIsWithinRange):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontStretch):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontStretchRange):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontFaceUnicodeRange):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontFeatureTag):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontFeatureSettings):
(WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontFaceFontDisplay):
* css/parser/CSSPropertyParserWorkerSafe.h: Added.

* dom/ScriptExecutionContext.cpp: Add ::cssValuePool().
(WebCore::ScriptExecutionContext::cssValuePool):
* dom/ScriptExecutionContext.h:

* html/canvas/CanvasRenderingContext2D.cpp: Update due to refactoring.
(WebCore::CanvasRenderingContext2D::setFontWithoutUpdatingStyle):
* html/canvas/CanvasStyle.cpp:
(WebCore::parseColor):
* html/canvas/OffscreenCanvasRenderingContext2D.cpp:
(WebCore::OffscreenCanvasRenderingContext2D::setFont):
* workers/WorkerGlobalScope.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@276017 268f45cc-cd09-0410-ab3c-d52691b4dbfc

20 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/FontFace.cpp
Source/WebCore/css/FontFace.h
Source/WebCore/css/FontFace.idl
Source/WebCore/css/parser/CSSParser.cpp
Source/WebCore/css/parser/CSSParser.h
Source/WebCore/css/parser/CSSPropertyParser.cpp
Source/WebCore/css/parser/CSSPropertyParser.h
Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
Source/WebCore/css/parser/CSSPropertyParserHelpers.h
Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp [new file with mode: 0644]
Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.h [new file with mode: 0644]
Source/WebCore/dom/ScriptExecutionContext.cpp
Source/WebCore/dom/ScriptExecutionContext.h
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
Source/WebCore/html/canvas/CanvasStyle.cpp
Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.cpp
Source/WebCore/workers/WorkerGlobalScope.h

index 0f445e5..a99743f 100644 (file)
@@ -1,3 +1,108 @@
+2021-04-15  Chris Lord  <clord@igalia.com>
+
+        Make FontFace parsing worker-safe
+        https://bugs.webkit.org/show_bug.cgi?id=224426
+
+        Reviewed by Darin Adler.
+
+        Make CSS FontFace property parsing safe to do in a Worker. Instead of
+        constructing a rule per property and using the full CSSPropertyParser
+        path, instead factor out the specific, necessary property parsers into a
+        new CSSPropertyParserWorkerSafe and make sure they're safe to use in a
+        Worker (mainly by allowing for specifying the CSSValuePool so that
+        main-thread singletons don't get used).
+
+        No new tests, no change in behavior.
+
+        * Sources.txt: Add CSSPropertyParserWorkerSafe.cpp/.h
+        * WebCore.xcodeproj/project.pbxproj:
+
+        * css/FontFace.cpp: Call setters with the ScriptExecutionContext so
+          that we have access to ::cssValuePool() and use new worker-safe
+          parser functions.
+        (WebCore::FontFace::create):
+        (WebCore::FontFace::setFamily):
+        (WebCore::FontFace::setStyle):
+        (WebCore::FontFace::setWeight):
+        (WebCore::FontFace::setStretch):
+        (WebCore::FontFace::setUnicodeRange):
+        (WebCore::FontFace::setFeatureSettings):
+        (WebCore::FontFace::setDisplay):
+        * css/FontFace.h:
+        * css/FontFace.idl:
+
+        * css/parser/CSSParser.cpp: Move WorkerSafe parsing functions to
+          CSSPropertyParserWorkerSafe and remove now-unnecessary
+          parseFontFaceDescriptor.
+        * css/parser/CSSParser.h:
+
+        * css/parser/CSSPropertyParser.cpp: Move FontFace property parsers to
+          CSSPropertyParserWorkerSafe.
+        (WebCore::CSSPropertyParser::parseSingleValue):
+        (WebCore::CSSPropertyParser::parseFontFaceDescriptor):
+        (WebCore::CSSPropertyParser::consumeFont):
+        * css/parser/CSSPropertyParser.h:
+
+        * css/parser/CSSPropertyParserHelpers.cpp: Add WorkerSafe variants for
+          some of the basic consume helpers.
+        (WebCore::CSSPropertyParserHelpers::CalcParser::CalcParser):
+        (WebCore::CSSPropertyParserHelpers::CalcParser::consumeValue):
+        (WebCore::CSSPropertyParserHelpers::CalcParser::consumeInteger):
+        (WebCore::CSSPropertyParserHelpers::CalcParser::consumeNumber):
+        (WebCore::CSSPropertyParserHelpers::consumeFontWeightNumber):
+        (WebCore::CSSPropertyParserHelpers::consumeFontWeightNumberWorkerSafe):
+        (WebCore::CSSPropertyParserHelpers::consumePercent):
+        (WebCore::CSSPropertyParserHelpers::consumePercentWorkerSafe):
+        (WebCore::CSSPropertyParserHelpers::consumeAngle):
+        (WebCore::CSSPropertyParserHelpers::consumeAngleWorkerSafe):
+        (WebCore::CSSPropertyParserHelpers::consumeIdent):
+        (WebCore::CSSPropertyParserHelpers::consumeIdentWorkerSafe):
+        (WebCore::CSSPropertyParserHelpers::consumeFontRaw):
+        * css/parser/CSSPropertyParserHelpers.h:
+        (WebCore::CSSPropertyParserHelpers::consumeIdent):
+        (WebCore::CSSPropertyParserHelpers::consumeIdentWorkerSafe):
+
+        * css/parser/CSSPropertyParserWorkerSafe.cpp: Added.
+        (WebCore::CSSPropertyParserWorkerSafe::parseFont):
+        (WebCore::CSSPropertyParserWorkerSafe::parseColor):
+        (WebCore::CSSPropertyParserWorkerSafe::parseFontFaceSrc):
+        (WebCore::CSSPropertyParserWorkerSafe::parseFontFaceStyle):
+        (WebCore::CSSPropertyParserWorkerSafe::parseFontFaceWeight):
+        (WebCore::CSSPropertyParserWorkerSafe::parseFontFaceStretch):
+        (WebCore::CSSPropertyParserWorkerSafe::parseFontFaceUnicodeRange):
+        (WebCore::CSSPropertyParserWorkerSafe::parseFontFaceFeatureSettings):
+        (WebCore::CSSPropertyParserWorkerSafe::parseFontFaceDisplay):
+        (WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontFaceSrcURI):
+        (WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontFaceSrcLocal):
+        (WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontFaceSrc):
+        (WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontStyle):
+        (WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontStyleKeywordValue):
+        (WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontStyleRange):
+        (WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontWeightAbsoluteKeywordValue):
+        (WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontWeightAbsoluteRange):
+        (WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontWeightAbsolute):
+        (WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontStretchKeywordValue):
+        (WebCore::CSSPropertyParserHelpersWorkerSafe::fontStretchIsWithinRange):
+        (WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontStretch):
+        (WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontStretchRange):
+        (WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontFaceUnicodeRange):
+        (WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontFeatureTag):
+        (WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontFeatureSettings):
+        (WebCore::CSSPropertyParserHelpersWorkerSafe::consumeFontFaceFontDisplay):
+        * css/parser/CSSPropertyParserWorkerSafe.h: Added.
+
+        * dom/ScriptExecutionContext.cpp: Add ::cssValuePool().
+        (WebCore::ScriptExecutionContext::cssValuePool):
+        * dom/ScriptExecutionContext.h:
+
+        * html/canvas/CanvasRenderingContext2D.cpp: Update due to refactoring.
+        (WebCore::CanvasRenderingContext2D::setFontWithoutUpdatingStyle):
+        * html/canvas/CanvasStyle.cpp:
+        (WebCore::parseColor):
+        * html/canvas/OffscreenCanvasRenderingContext2D.cpp:
+        (WebCore::OffscreenCanvasRenderingContext2D::setFont):
+        * workers/WorkerGlobalScope.h:
+
 2021-04-15  Manuel Rego Casasnovas  <rego@igalia.com>
 
         Move FocusRemovalEventsMode into FocusOptions
index 6b494e2..ecacdeb 100644 (file)
@@ -837,6 +837,7 @@ css/parser/CSSParserToken.cpp
 css/parser/CSSParserTokenRange.cpp
 css/parser/CSSPropertyParser.cpp
 css/parser/CSSPropertyParserHelpers.cpp
+css/parser/CSSPropertyParserWorkerSafe.cpp
 css/parser/CSSSelectorParser.cpp
 css/parser/CSSSupportsParser.cpp
 css/parser/CSSTokenizer.cpp
index 7d2c52e..a380535 100644 (file)
                946D37401D6CE3C20077084F /* CSSParserToken.h in Headers */ = {isa = PBXBuildFile; fileRef = 946D373D1D6CE31A0077084F /* CSSParserToken.h */; settings = {ATTRIBUTES = (Private, ); }; };
                946D37441D6CF7B20077084F /* CSSParserIdioms.h in Headers */ = {isa = PBXBuildFile; fileRef = 946D37431D6CF7880077084F /* CSSParserIdioms.h */; };
                946D37461D6D01D40077084F /* CSSPropertyParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 946D37421D6CF6320077084F /* CSSPropertyParser.h */; };
+               946D37461D6D01D50077084F /* CSSPropertyParserWorkerSafe.h in Headers */ = {isa = PBXBuildFile; fileRef = 946D37421D6D06320077084F /* CSSPropertyParserWorkerSafe.h */; };
                946D374A1D6D06280077084F /* CSSMarkup.h in Headers */ = {isa = PBXBuildFile; fileRef = 946D37481D6D060C0077084F /* CSSMarkup.h */; };
                946D374E1D6D08AA0077084F /* CSSParserTokenRange.h in Headers */ = {isa = PBXBuildFile; fileRef = 946D374C1D6D07F50077084F /* CSSParserTokenRange.h */; settings = {ATTRIBUTES = (Private, ); }; };
                947949251E0308AF00018D85 /* DeprecatedCSSOMValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 947949231E02F90B00018D85 /* DeprecatedCSSOMValue.h */; settings = {ATTRIBUTES = (Private, ); }; };
                946D373E1D6CE31A0077084F /* CSSParserToken.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CSSParserToken.cpp; path = parser/CSSParserToken.cpp; sourceTree = "<group>"; };
                946D37411D6CF6320077084F /* CSSPropertyParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CSSPropertyParser.cpp; path = parser/CSSPropertyParser.cpp; sourceTree = "<group>"; };
                946D37421D6CF6320077084F /* CSSPropertyParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CSSPropertyParser.h; path = parser/CSSPropertyParser.h; sourceTree = "<group>"; };
+               946D37411D6D06320077084F /* CSSPropertyParserWorkerSafe.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CSSPropertyParserWorkerSafe.cpp; path = parser/CSSPropertyParserWorkerSafe.cpp; sourceTree = "<group>"; };
+               946D37421D6D06320077084F /* CSSPropertyParserWorkerSafe.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CSSPropertyParserWorkerSafe.h; path = parser/CSSPropertyParserWorkerSafe.h; sourceTree = "<group>"; };
                946D37431D6CF7880077084F /* CSSParserIdioms.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CSSParserIdioms.h; path = parser/CSSParserIdioms.h; sourceTree = "<group>"; };
                946D37471D6D060C0077084F /* CSSMarkup.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSMarkup.cpp; sourceTree = "<group>"; };
                946D37481D6D060C0077084F /* CSSMarkup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSMarkup.h; sourceTree = "<group>"; };
                                946D37421D6CF6320077084F /* CSSPropertyParser.h */,
                                949C77021D6E393500C0DE4F /* CSSPropertyParserHelpers.cpp */,
                                949C77031D6E393500C0DE4F /* CSSPropertyParserHelpers.h */,
+                               946D37411D6D06320077084F /* CSSPropertyParserWorkerSafe.cpp */,
+                               946D37421D6D06320077084F /* CSSPropertyParserWorkerSafe.h */,
                                94DE5C8B1D80801500164F2A /* CSSSelectorParser.cpp */,
                                94DE5C8C1D80801500164F2A /* CSSSelectorParser.h */,
                                94DE5C8F1D8300CB00164F2A /* CSSSupportsParser.cpp */,
                                656580F409D12B20000E61D7 /* CSSPropertyNames.h in Headers */,
                                946D37461D6D01D40077084F /* CSSPropertyParser.h in Headers */,
                                949C77051D6E39EA00C0DE4F /* CSSPropertyParserHelpers.h in Headers */,
+                               946D37461D6D01D50077084F /* CSSPropertyParserWorkerSafe.h in Headers */,
                                82E3D8DF122EA0D1003AE5BC /* CSSPropertySourceData.h in Headers */,
                                BC5A12E00DC0414800C9AFAD /* CSSReflectValue.h in Headers */,
                                4BDA40012151B6F500FD6604 /* CSSRegisteredCustomProperty.h in Headers */,
index 35ffc03..19d9b44 100644 (file)
@@ -33,6 +33,7 @@
 #include "CSSFontStyleValue.h"
 #include "CSSParser.h"
 #include "CSSPrimitiveValueMappings.h"
+#include "CSSPropertyParserWorkerSafe.h"
 #include "CSSUnicodeRangeValue.h"
 #include "CSSValueList.h"
 #include "CSSValuePool.h"
@@ -76,10 +77,10 @@ Ref<FontFace> FontFace::create(Document& document, const String& family, Source&
 
     auto sourceConversionResult = WTF::switchOn(source,
         [&] (String& string) -> ExceptionOr<void> {
-            auto value = FontFace::parseString(string, CSSPropertySrc);
-            if (!is<CSSValueList>(value))
+            auto value = CSSPropertyParserWorkerSafe::parseFontFaceSrc(string, CSSParserContext(document));
+            if (!value)
                 return Exception { SyntaxError };
-            CSSFontFace::appendSources(result->backing(), downcast<CSSValueList>(*value), &document, false);
+            CSSFontFace::appendSources(result->backing(), *value, &document, false);
             return { };
         },
         [&] (RefPtr<ArrayBufferView>& arrayBufferView) -> ExceptionOr<void> {
@@ -100,32 +101,32 @@ Ref<FontFace> FontFace::create(Document& document, const String& family, Source&
     }
 
     // These ternaries match the default strings inside the FontFaceDescriptors dictionary inside FontFace.idl.
-    auto setStyleResult = result->setStyle(descriptors.style.isEmpty() ? "normal"_s : descriptors.style);
+    auto setStyleResult = result->setStyle(document, descriptors.style.isEmpty() ? "normal"_s : descriptors.style);
     if (setStyleResult.hasException()) {
         result->setErrorState();
         return result;
     }
-    auto setWeightResult = result->setWeight(descriptors.weight.isEmpty() ? "normal"_s : descriptors.weight);
+    auto setWeightResult = result->setWeight(document, descriptors.weight.isEmpty() ? "normal"_s : descriptors.weight);
     if (setWeightResult.hasException()) {
         result->setErrorState();
         return result;
     }
-    auto setStretchResult = result->setStretch(descriptors.stretch.isEmpty() ? "normal"_s : descriptors.stretch);
+    auto setStretchResult = result->setStretch(document, descriptors.stretch.isEmpty() ? "normal"_s : descriptors.stretch);
     if (setStretchResult.hasException()) {
         result->setErrorState();
         return result;
     }
-    auto setUnicodeRangeResult = result->setUnicodeRange(descriptors.unicodeRange.isEmpty() ? "U+0-10FFFF"_s : descriptors.unicodeRange);
+    auto setUnicodeRangeResult = result->setUnicodeRange(document, descriptors.unicodeRange.isEmpty() ? "U+0-10FFFF"_s : descriptors.unicodeRange);
     if (setUnicodeRangeResult.hasException()) {
         result->setErrorState();
         return result;
     }
-    auto setFeatureSettingsResult = result->setFeatureSettings(descriptors.featureSettings.isEmpty() ? "normal"_s : descriptors.featureSettings);
+    auto setFeatureSettingsResult = result->setFeatureSettings(document, descriptors.featureSettings.isEmpty() ? "normal"_s : descriptors.featureSettings);
     if (setFeatureSettingsResult.hasException()) {
         result->setErrorState();
         return result;
     }
-    auto setDisplayResult = result->setDisplay(descriptors.display.isEmpty() ? "auto"_s : descriptors.display);
+    auto setDisplayResult = result->setDisplay(document, descriptors.display.isEmpty() ? "auto"_s : descriptors.display);
     if (setDisplayResult.hasException()) {
         result->setErrorState();
         return result;
@@ -168,98 +169,94 @@ FontFace::~FontFace()
     m_backing->removeClient(*this);
 }
 
-RefPtr<CSSValue> FontFace::parseString(const String& string, CSSPropertyID propertyID)
-{
-    // FIXME: Should use the Document to get the right parsing mode.
-    return CSSParser::parseFontFaceDescriptor(propertyID, string, HTMLStandardMode);
-}
-
-ExceptionOr<void> FontFace::setFamily(Document& document, const String& family)
+ExceptionOr<void> FontFace::setFamily(ScriptExecutionContext& context, const String& family)
 {
     if (family.isEmpty())
         return Exception { SyntaxError };
 
     String familyNameToUse = family;
-    if (familyNameToUse.contains('\'') && document.quirks().shouldStripQuotationMarkInFontFaceSetFamily())
+    // FIXME: Quirks currently aren't present on Workers, but should likely be inherited
+    //        from the parent Document where applicable.
+    if (familyNameToUse.contains('\'') && is<Document>(context) && downcast<Document>(context).quirks().shouldStripQuotationMarkInFontFaceSetFamily())
         familyNameToUse = family.removeCharacters([](auto character) { return character == '\''; });
 
     // FIXME: https://bugs.webkit.org/show_bug.cgi?id=196381 Don't use a list here.
     // See consumeFontFamilyDescriptor() in CSSPropertyParser.cpp for why we're using it.
     auto list = CSSValueList::createCommaSeparated();
-    list->append(CSSValuePool::singleton().createFontFamilyValue(familyNameToUse));
+    list->append(context.cssValuePool().createFontFamilyValue(familyNameToUse));
     bool success = m_backing->setFamilies(list);
     if (!success)
         return Exception { SyntaxError };
     return { };
 }
 
-ExceptionOr<void> FontFace::setStyle(const String& style)
+ExceptionOr<void> FontFace::setStyle(ScriptExecutionContext& context, const String& style)
 {
     if (style.isEmpty())
         return Exception { SyntaxError };
 
-    if (auto value = parseString(style, CSSPropertyFontStyle)) {
+    if (auto value = CSSPropertyParserWorkerSafe::parseFontFaceStyle(style, context)) {
         m_backing->setStyle(*value);
         return { };
     }
     return Exception { SyntaxError };
 }
 
-ExceptionOr<void> FontFace::setWeight(const String& weight)
+ExceptionOr<void> FontFace::setWeight(ScriptExecutionContext& context, const String& weight)
 {
     if (weight.isEmpty())
         return Exception { SyntaxError };
 
-    if (auto value = parseString(weight, CSSPropertyFontWeight)) {
+    if (auto value = CSSPropertyParserWorkerSafe::parseFontFaceWeight(weight, context)) {
         m_backing->setWeight(*value);
         return { };
     }
     return Exception { SyntaxError };
 }
 
-ExceptionOr<void> FontFace::setStretch(const String& stretch)
+ExceptionOr<void> FontFace::setStretch(ScriptExecutionContext& context, const String& stretch)
 {
     if (stretch.isEmpty())
         return Exception { SyntaxError };
 
-    if (auto value = parseString(stretch, CSSPropertyFontStretch)) {
+    if (auto value = CSSPropertyParserWorkerSafe::parseFontFaceStretch(stretch, context)) {
         m_backing->setStretch(*value);
         return { };
     }
     return Exception { SyntaxError };
 }
 
-ExceptionOr<void> FontFace::setUnicodeRange(const String& unicodeRange)
+ExceptionOr<void> FontFace::setUnicodeRange(ScriptExecutionContext& context, const String& unicodeRange)
 {
     if (unicodeRange.isEmpty())
         return Exception { SyntaxError };
 
     bool success = false;
-    if (auto value = parseString(unicodeRange, CSSPropertyUnicodeRange))
+    if (auto value = CSSPropertyParserWorkerSafe::parseFontFaceUnicodeRange(unicodeRange, context))
         success = m_backing->setUnicodeRange(*value);
     if (!success)
         return Exception { SyntaxError };
     return { };
 }
 
-ExceptionOr<void> FontFace::setFeatureSettings(const String& featureSettings)
+ExceptionOr<void> FontFace::setFeatureSettings(ScriptExecutionContext& context, const String& featureSettings)
 {
     if (featureSettings.isEmpty())
         return Exception { SyntaxError };
 
-    auto value = parseString(featureSettings, CSSPropertyFontFeatureSettings);
+    auto value = CSSPropertyParserWorkerSafe::parseFontFaceFeatureSettings(featureSettings, context);
     if (!value)
         return Exception { SyntaxError };
     m_backing->setFeatureSettings(*value);
     return { };
 }
 
-ExceptionOr<void> FontFace::setDisplay(const String& display)
+ExceptionOr<void> FontFace::setDisplay(ScriptExecutionContext& context, const String& display)
 {
     if (display.isEmpty())
         return Exception { SyntaxError };
 
-    if (auto value = parseString(display, CSSPropertyFontDisplay)) {
+    if (auto value = CSSPropertyParserWorkerSafe::parseFontFaceDisplay(display, context)) {
         m_backing->setLoadingBehavior(*value);
         return { };
     }
index fc17ea6..f1b55a8 100644 (file)
@@ -58,13 +58,13 @@ public:
     static Ref<FontFace> create(ScriptExecutionContext*, CSSFontFace&);
     virtual ~FontFace();
 
-    ExceptionOr<void> setFamily(Document&, const String&);
-    ExceptionOr<void> setStyle(const String&);
-    ExceptionOr<void> setWeight(const String&);
-    ExceptionOr<void> setStretch(const String&);
-    ExceptionOr<void> setUnicodeRange(const String&);
-    ExceptionOr<void> setFeatureSettings(const String&);
-    ExceptionOr<void> setDisplay(const String&);
+    ExceptionOr<void> setFamily(ScriptExecutionContext&, const String&);
+    ExceptionOr<void> setStyle(ScriptExecutionContext&, const String&);
+    ExceptionOr<void> setWeight(ScriptExecutionContext&, const String&);
+    ExceptionOr<void> setStretch(ScriptExecutionContext&, const String&);
+    ExceptionOr<void> setUnicodeRange(ScriptExecutionContext&, const String&);
+    ExceptionOr<void> setFeatureSettings(ScriptExecutionContext&, const String&);
+    ExceptionOr<void> setDisplay(ScriptExecutionContext&, const String&);
 
     String family() const;
     String style() const;
@@ -85,8 +85,6 @@ public:
 
     CSSFontFace& backing() { return m_backing; }
 
-    static RefPtr<CSSValue> parseString(const String&, CSSPropertyID);
-
     void fontStateChanged(CSSFontFace&, CSSFontFace::Status oldState, CSSFontFace::Status newState) final;
 
     void ref() final { RefCounted::ref(); }
index a902cb0..33467af 100644 (file)
@@ -47,13 +47,13 @@ dictionary FontFaceDescriptors {
 ] interface FontFace {
     [CallWith=Document] constructor(DOMString family, (DOMString or BinaryData) source, optional FontFaceDescriptors descriptors);
 
-    [SetterCallWith=Document] attribute DOMString family;
-    attribute DOMString style;
-    attribute DOMString weight;
-    attribute DOMString stretch;
-    attribute DOMString unicodeRange;
-    attribute DOMString featureSettings;
-    attribute DOMString display;
+    [SetterCallWith=ScriptExecutionContext] attribute DOMString family;
+    [SetterCallWith=ScriptExecutionContext] attribute DOMString style;
+    [SetterCallWith=ScriptExecutionContext] attribute DOMString weight;
+    [SetterCallWith=ScriptExecutionContext] attribute DOMString stretch;
+    [SetterCallWith=ScriptExecutionContext] attribute DOMString unicodeRange;
+    [SetterCallWith=ScriptExecutionContext] attribute DOMString featureSettings;
+    [SetterCallWith=ScriptExecutionContext] attribute DOMString display;
 
     readonly attribute FontFaceLoadStatus status;
 
index 7648f50..9dfc3c7 100644 (file)
@@ -108,18 +108,6 @@ Color CSSParser::parseColor(const String& string, bool strict)
     return primitiveValue.color();
 }
 
-Color CSSParser::parseColorWorkerSafe(const String& string)
-{
-    if (auto color = CSSParserFastPaths::parseSimpleColor(string))
-        return *color;
-
-    CSSTokenizer tokenizer(string);
-    CSSParserTokenRange range(tokenizer.tokenRange());
-    range.consumeWhitespace();
-
-    return CSSPropertyParserHelpers::consumeColorWorkerSafe(range, CSSParserContext(HTMLStandardMode));
-}
-
 Color CSSParser::parseSystemColor(StringView string)
 {
     auto keyword = cssValueKeywordID(string);
@@ -138,15 +126,6 @@ Optional<SRGBA<uint8_t>> CSSParser::parseHexColor(StringView string)
     return CSSParserFastPaths::parseHexColor(string);
 }
 
-Optional<CSSPropertyParserHelpers::FontRaw> CSSParser::parseFontWorkerSafe(const String& string, CSSParserMode cssParserMode)
-{
-    CSSTokenizer tokenizer(string);
-    CSSParserTokenRange range(tokenizer.tokenRange());
-    range.consumeWhitespace();
-
-    return CSSPropertyParserHelpers::consumeFontWorkerSafe(range, cssParserMode);
-}
-
 RefPtr<CSSValue> CSSParser::parseSingleValue(CSSPropertyID propertyID, const String& string, const CSSParserContext& context)
 {
     if (string.isEmpty())
@@ -261,13 +240,4 @@ Vector<double> CSSParser::parseKeyframeKeyList(const String& selector)
     return CSSParserImpl::parseKeyframeKeyList(selector);
 }
 
-RefPtr<CSSValue> CSSParser::parseFontFaceDescriptor(CSSPropertyID propertyID, const String& propertyValue, const CSSParserContext& context)
-{
-    String string = makeString("@font-face { ", getPropertyNameString(propertyID), " : ", propertyValue, "; }");
-    RefPtr<StyleRuleBase> rule = parseRule(context, nullptr, string);
-    if (!rule || !rule->isFontFaceRule())
-        return nullptr;
-    return downcast<StyleRuleFontFace>(*rule.get()).properties().getPropertyCSSValue(propertyID);
-}
-
 }
index f221d18..60f14d7 100644 (file)
@@ -34,6 +34,7 @@ namespace WebCore {
 
 class CSSParserObserver;
 class CSSSelectorList;
+class CSSValueList;
 class CSSValuePool;
 class Color;
 class Element;
@@ -79,8 +80,6 @@ public:
     static ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, bool important, const CSSParserContext&);
     static ParseResult parseCustomPropertyValue(MutableStyleProperties&, const AtomString& propertyName, const String&, bool important, const CSSParserContext&);
     
-    static RefPtr<CSSValue> parseFontFaceDescriptor(CSSPropertyID, const String&, const CSSParserContext&);
-
     static RefPtr<CSSValue> parseSingleValue(CSSPropertyID, const String&, const CSSParserContext& = strictCSSParserContext());
 
     WEBCORE_EXPORT bool parseDeclaration(MutableStyleProperties&, const String&);
@@ -91,13 +90,10 @@ public:
     RefPtr<CSSValue> parseValueWithVariableReferences(CSSPropertyID, const CSSValue&, Style::BuilderState&);
 
     WEBCORE_EXPORT static Color parseColor(const String&, bool strict = false);
-    static Color parseColorWorkerSafe(const String&);
     static Color parseSystemColor(StringView);
     static Optional<SRGBA<uint8_t>> parseNamedColor(StringView);
     static Optional<SRGBA<uint8_t>> parseHexColor(StringView);
 
-    static Optional<CSSPropertyParserHelpers::FontRaw> parseFontWorkerSafe(const String&, CSSParserMode = HTMLStandardMode);
-
 private:
     ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, bool important);
 
index a7e0a4a..5900518 100644 (file)
@@ -190,6 +190,7 @@ CSSPropertyID cssPropertyID(StringView string)
 }
     
 using namespace CSSPropertyParserHelpers;
+using namespace CSSPropertyParserHelpersWorkerSafe;
 
 CSSPropertyParser::CSSPropertyParser(const CSSParserTokenRange& range, const CSSParserContext& context, Vector<CSSProperty, 256>* parsedProperties, bool consumeWhitespace)
     : m_range(range)
@@ -426,54 +427,6 @@ static RefPtr<CSSValue> consumeWillChange(CSSParserTokenRange& range)
     return values;
 }
 
-static RefPtr<CSSFontFeatureValue> consumeFontFeatureTag(CSSParserTokenRange& range)
-{
-    // Feature tag name consists of 4-letter characters.
-    static const unsigned tagNameLength = 4;
-
-    const CSSParserToken& token = range.consumeIncludingWhitespace();
-    // Feature tag name comes first
-    if (token.type() != StringToken)
-        return nullptr;
-    if (token.value().length() != tagNameLength)
-        return nullptr;
-    
-    FontTag tag;
-    for (unsigned i = 0; i < tag.size(); ++i) {
-        // Limits the range of characters to 0x20-0x7E, following the tag name rules defiend in the OpenType specification.
-        UChar character = token.value()[i];
-        if (character < 0x20 || character > 0x7E)
-            return nullptr;
-        tag[i] = toASCIILower(character);
-    }
-
-    int tagValue = 1;
-    if (!range.atEnd() && range.peek().type() != CommaToken) {
-        // Feature tag values could follow: <integer> | on | off
-        if (auto integer = consumeIntegerRaw(range, 0))
-            tagValue = *integer;
-        else if (range.peek().id() == CSSValueOn || range.peek().id() == CSSValueOff)
-            tagValue = range.consumeIncludingWhitespace().id() == CSSValueOn;
-        else
-            return nullptr;
-    }
-    return CSSFontFeatureValue::create(WTFMove(tag), tagValue);
-}
-
-static RefPtr<CSSValue> consumeFontFeatureSettings(CSSParserTokenRange& range)
-{
-    if (range.peek().id() == CSSValueNormal)
-        return consumeIdent(range);
-    RefPtr<CSSValueList> settings = CSSValueList::createCommaSeparated();
-    do {
-        RefPtr<CSSFontFeatureValue> fontFeatureValue = consumeFontFeatureTag(range);
-        if (!fontFeatureValue)
-            return nullptr;
-        settings->append(fontFeatureValue.releaseNonNull());
-    } while (consumeCommaIncludingWhitespace(range));
-    return settings;
-}
-
 #if ENABLE(VARIATION_FONTS)
 static RefPtr<CSSValue> consumeFontVariationTag(CSSParserTokenRange& range)
 {
@@ -850,140 +803,6 @@ static RefPtr<CSSPrimitiveValue> consumeFontWeight(CSSParserTokenRange& range)
     return nullptr;
 }
 
-static RefPtr<CSSPrimitiveValue> consumeFontWeightAbsoluteKeywordValue(CSSParserTokenRange& range)
-{
-    return consumeIdent<CSSValueNormal, CSSValueBold>(range);
-}
-
-#if ENABLE(VARIATION_FONTS)
-static RefPtr<CSSValue> consumeFontWeightAbsoluteRange(CSSParserTokenRange& range)
-{
-    if (auto result = consumeFontWeightAbsoluteKeywordValue(range))
-        return result;
-    auto firstNumber = consumeFontWeightNumber(range);
-    if (!firstNumber)
-        return nullptr;
-    if (range.atEnd())
-        return firstNumber;
-    auto secondNumber = consumeFontWeightNumber(range);
-    if (!secondNumber || firstNumber->floatValue() > secondNumber->floatValue())
-        return nullptr;
-    auto result = CSSValueList::createSpaceSeparated();
-    result->append(firstNumber.releaseNonNull());
-    result->append(secondNumber.releaseNonNull());
-    return RefPtr<CSSValue>(WTFMove(result));
-}
-#else
-static RefPtr<CSSPrimitiveValue> consumeFontWeightAbsolute(CSSParserTokenRange& range)
-{
-    if (auto result = consumeFontWeightAbsoluteKeywordValue(range))
-        return result;
-    return consumeFontWeightNumber(range);
-}
-#endif
-
-static RefPtr<CSSPrimitiveValue> consumeFontStretchKeywordValue(CSSParserTokenRange& range)
-{
-    if (auto valueID = consumeFontStretchKeywordValueRaw(range))
-        return CSSValuePool::singleton().createIdentifierValue(*valueID);
-    return nullptr;
-}
-
-#if ENABLE(VARIATION_FONTS)
-static bool fontStretchIsWithinRange(float stretch)
-{
-    return stretch >= 0;
-}
-#endif
-
-static RefPtr<CSSPrimitiveValue> consumeFontStretch(CSSParserTokenRange& range)
-{
-    if (auto result = consumeFontStretchKeywordValue(range))
-        return result;
-#if ENABLE(VARIATION_FONTS)
-    if (auto percent = consumePercent(range, ValueRangeNonNegative))
-        return fontStretchIsWithinRange(percent->value<float>()) ? percent : nullptr;
-#endif
-    return nullptr;
-}
-
-#if ENABLE(VARIATION_FONTS)
-static RefPtr<CSSValue> consumeFontStretchRange(CSSParserTokenRange& range)
-{
-    if (auto result = consumeFontStretchKeywordValue(range))
-        return result;
-    auto firstPercent = consumePercent(range, ValueRangeNonNegative);
-    if (!firstPercent || !fontStretchIsWithinRange(firstPercent->value<float>()))
-        return nullptr;
-    if (range.atEnd())
-        return firstPercent;
-    auto secondPercent = consumePercent(range, ValueRangeNonNegative);
-    if (!secondPercent || !fontStretchIsWithinRange(secondPercent->value<float>()) || firstPercent->floatValue() > secondPercent->floatValue())
-        return nullptr;
-    auto result = CSSValueList::createSpaceSeparated();
-    result->append(firstPercent.releaseNonNull());
-    result->append(secondPercent.releaseNonNull());
-    return RefPtr<CSSValue>(WTFMove(result));
-}
-#endif
-
-static RefPtr<CSSPrimitiveValue> consumeFontStyleKeywordValue(CSSParserTokenRange& range)
-{
-    return consumeIdent<CSSValueNormal, CSSValueItalic, CSSValueOblique>(range);
-}
-
-static RefPtr<CSSFontStyleValue> consumeFontStyle(CSSParserTokenRange& range, CSSParserMode cssParserMode)
-{
-    if (auto result = consumeFontStyleRaw(range, cssParserMode)) {
-#if ENABLE(VARIATION_FONTS)
-        if (result->style == CSSValueOblique && result->angle) {
-            return CSSFontStyleValue::create(CSSValuePool::singleton().createIdentifierValue(CSSValueOblique),
-                CSSValuePool::singleton().createValue(result->angle->value, result->angle->type));
-        }
-#endif
-        return CSSFontStyleValue::create(CSSValuePool::singleton().createIdentifierValue(result->style));
-    }
-    return nullptr;
-}
-
-#if ENABLE(VARIATION_FONTS)
-static RefPtr<CSSFontStyleRangeValue> consumeFontStyleRange(CSSParserTokenRange& range, CSSParserMode cssParserMode)
-{
-    auto keyword = consumeFontStyleKeywordValue(range);
-    if (!keyword)
-        return nullptr;
-
-    if (keyword->valueID() != CSSValueOblique || range.atEnd())
-        return CSSFontStyleRangeValue::create(keyword.releaseNonNull());
-
-    // FIXME: This should probably not allow the unitless zero.
-    if (auto firstAngle = consumeAngle(range, cssParserMode, UnitlessQuirk::Forbid, UnitlessZeroQuirk::Allow)) {
-        auto firstAngleInDegrees = firstAngle->doubleValue(CSSUnitType::CSS_DEG);
-        if (!isFontStyleAngleInRange(firstAngleInDegrees))
-            return nullptr;
-        if (range.atEnd()) {
-            auto result = CSSValueList::createSpaceSeparated();
-            result->append(firstAngle.releaseNonNull());
-            return CSSFontStyleRangeValue::create(keyword.releaseNonNull(), WTFMove(result));
-        }
-
-        // FIXME: This should probably not allow the unitless zero.
-        auto secondAngle = consumeAngle(range, cssParserMode, UnitlessQuirk::Forbid, UnitlessZeroQuirk::Allow);
-        if (!secondAngle)
-            return nullptr;
-        auto secondAngleInDegrees = secondAngle->doubleValue(CSSUnitType::CSS_DEG);
-        if (!isFontStyleAngleInRange(secondAngleInDegrees) || firstAngleInDegrees > secondAngleInDegrees)
-            return nullptr;
-        auto result = CSSValueList::createSpaceSeparated();
-        result->append(firstAngle.releaseNonNull());
-        result->append(secondAngle.releaseNonNull());
-        return CSSFontStyleRangeValue::create(keyword.releaseNonNull(), WTFMove(result));
-    }
-
-    return nullptr;
-}
-#endif
-
 static RefPtr<CSSValue> consumeFamilyName(CSSParserTokenRange& range)
 {
     auto familyName = consumeFamilyNameRaw(range);
@@ -4078,15 +3897,15 @@ RefPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID property, CSS
     case CSSPropertyFontVariantEastAsian:
         return consumeFontVariantEastAsian(m_range);
     case CSSPropertyFontFeatureSettings:
-        return consumeFontFeatureSettings(m_range);
+        return consumeFontFeatureSettings(m_range, CSSValuePool::singleton());
     case CSSPropertyFontFamily:
         return consumeFontFamily(m_range);
     case CSSPropertyFontWeight:
         return consumeFontWeight(m_range);
     case CSSPropertyFontStretch:
-        return consumeFontStretch(m_range);
+        return consumeFontStretch(m_range, CSSValuePool::singleton());
     case CSSPropertyFontStyle:
-        return consumeFontStyle(m_range, m_context.mode);
+        return consumeFontStyle(m_range, m_context.mode, CSSValuePool::singleton());
     case CSSPropertyFontSynthesis:
         return consumeFontSynthesis(m_range);
 #if ENABLE(VARIATION_FONTS)
@@ -4615,90 +4434,6 @@ RefPtr<CSSCustomPropertyValue> CSSPropertyParser::parseTypedCustomPropertyValue(
     return nullptr;
 }
 
-static RefPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParserTokenRange& range)
-{
-    RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
-
-    do {
-        const CSSParserToken& token = range.consumeIncludingWhitespace();
-        if (token.type() != UnicodeRangeToken)
-            return nullptr;
-
-        UChar32 start = token.unicodeRangeStart();
-        UChar32 end = token.unicodeRangeEnd();
-        if (start > end)
-            return nullptr;
-        values->append(CSSUnicodeRangeValue::create(start, end));
-    } while (consumeCommaIncludingWhitespace(range));
-
-    return values;
-}
-
-static RefPtr<CSSPrimitiveValue> consumeFontFaceFontDisplay(CSSParserTokenRange& range)
-{
-    return consumeIdent<CSSValueAuto, CSSValueBlock, CSSValueSwap, CSSValueFallback, CSSValueOptional>(range);
-}
-
-static RefPtr<CSSValue> consumeFontFaceSrcURI(CSSParserTokenRange& range, const CSSParserContext& context)
-{
-    String url = consumeUrlAsStringView(range).toString();
-    if (url.isNull())
-        return nullptr;
-
-    RefPtr<CSSFontFaceSrcValue> uriValue = CSSFontFaceSrcValue::create(context.completeURL(url).string(), context.isContentOpaque ? LoadedFromOpaqueSource::Yes : LoadedFromOpaqueSource::No);
-
-    if (range.peek().functionId() != CSSValueFormat)
-        return uriValue;
-
-    // FIXME: https://drafts.csswg.org/css-fonts says that format() contains a comma-separated list of strings,
-    // but CSSFontFaceSrcValue stores only one format. Allowing one format for now.
-    // FIXME: We're allowing the format to be an identifier as well as a string, because the old
-    // parser did. It's not clear if we need to continue to support this behavior, but we have lots of
-    // layout tests that rely on it.
-    CSSParserTokenRange args = consumeFunction(range);
-    const CSSParserToken& arg = args.consumeIncludingWhitespace();
-    if ((arg.type() != StringToken && arg.type() != IdentToken) || !args.atEnd())
-        return nullptr;
-    uriValue->setFormat(arg.value().toString());
-    return uriValue;
-}
-
-static RefPtr<CSSValue> consumeFontFaceSrcLocal(CSSParserTokenRange& range)
-{
-    CSSParserTokenRange args = consumeFunction(range);
-    if (args.peek().type() == StringToken) {
-        const CSSParserToken& arg = args.consumeIncludingWhitespace();
-        if (!args.atEnd())
-            return nullptr;
-        return CSSFontFaceSrcValue::createLocal(arg.value().toString());
-    }
-    if (args.peek().type() == IdentToken) {
-        String familyName = concatenateFamilyName(args);
-        if (!args.atEnd())
-            return nullptr;
-        return CSSFontFaceSrcValue::createLocal(familyName);
-    }
-    return nullptr;
-}
-
-static RefPtr<CSSValueList> consumeFontFaceSrc(CSSParserTokenRange& range, const CSSParserContext& context)
-{
-    RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
-
-    do {
-        const CSSParserToken& token = range.peek();
-        RefPtr<CSSValue> parsedValue;
-        if (token.functionId() == CSSValueLocal)
-            parsedValue = consumeFontFaceSrcLocal(range);
-        else
-            parsedValue = consumeFontFaceSrcURI(range, context);
-        if (!parsedValue)
-            return nullptr;
-        values->append(parsedValue.releaseNonNull());
-    } while (consumeCommaIncludingWhitespace(range));
-    return values;
-}
-
 bool CSSPropertyParser::parseFontFaceDescriptor(CSSPropertyID propId)
 {
     RefPtr<CSSValue> parsedValue;
@@ -4713,27 +4448,27 @@ bool CSSPropertyParser::parseFontFaceDescriptor(CSSPropertyID propId)
         parsedValue = consumeFontFaceUnicodeRange(m_range);
         break;
     case CSSPropertyFontDisplay:
-        parsedValue = consumeFontFaceFontDisplay(m_range);
+        parsedValue = consumeFontFaceFontDisplay(m_range, CSSValuePool::singleton());
         break;
     case CSSPropertyFontWeight:
 #if ENABLE(VARIATION_FONTS)
-        parsedValue = consumeFontWeightAbsoluteRange(m_range);
+        parsedValue = consumeFontWeightAbsoluteRange(m_range, CSSValuePool::singleton());
 #else
-        parsedValue = consumeFontWeightAbsolute(m_range);
+        parsedValue = consumeFontWeightAbsolute(m_range, CSSValuePool::singleton());
 #endif
         break;
     case CSSPropertyFontStretch:
 #if ENABLE(VARIATION_FONTS)
-        parsedValue = consumeFontStretchRange(m_range);
+        parsedValue = consumeFontStretchRange(m_range, CSSValuePool::singleton());
 #else
-        parsedValue = consumeFontStretch(m_range);
+        parsedValue = consumeFontStretch(m_range, CSSValuePool::singleton());
 #endif
         break;
     case CSSPropertyFontStyle:
 #if ENABLE(VARIATION_FONTS)
-        parsedValue = consumeFontStyleRange(m_range, m_context.mode);
+        parsedValue = consumeFontStyleRange(m_range, m_context.mode, CSSValuePool::singleton());
 #else
-        parsedValue = consumeFontStyle(m_range, m_context.mode);
+        parsedValue = consumeFontStyle(m_range, m_context.mode, CSSValuePool::singleton());
 #endif
         break;
     case CSSPropertyFontVariantCaps:
@@ -4757,7 +4492,7 @@ bool CSSPropertyParser::parseFontFaceDescriptor(CSSPropertyID propId)
     case CSSPropertyFontVariant:
         return consumeFontVariantShorthand(false);
     case CSSPropertyFontFeatureSettings:
-        parsedValue = consumeFontFeatureSettings(m_range);
+        parsedValue = consumeFontFeatureSettings(m_range, CSSValuePool::singleton());
         break;
     default:
         break;
@@ -4814,7 +4549,7 @@ bool CSSPropertyParser::consumeFont(bool important)
     while (!m_range.atEnd()) {
         CSSValueID id = m_range.peek().id();
         if (!fontStyle) {
-            fontStyle = consumeFontStyle(m_range, m_context.mode);
+            fontStyle = consumeFontStyle(m_range, m_context.mode, CSSValuePool::singleton());
             if (fontStyle)
                 continue;
         }
@@ -4831,7 +4566,7 @@ bool CSSPropertyParser::consumeFont(bool important)
                 continue;
         }
         if (!fontStretch) {
-            fontStretch = consumeFontStretchKeywordValue(m_range);
+            fontStretch = consumeFontStretchKeywordValue(m_range, CSSValuePool::singleton());
             if (fontStretch)
                 continue;
         }
index 0a0ba4b..71a1ad8 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "CSSParserTokenRange.h"
 #include "CSSPropertyParserHelpers.h"
+#include "CSSPropertyParserWorkerSafe.h"
 #include "StyleRule.h"
 #include <wtf/text/StringView.h>
 
@@ -31,6 +32,7 @@ namespace WebCore {
 
 class CSSProperty;
 class CSSValue;
+class CSSValueList;
 class StylePropertyShorthand;
 class StyleSheetContents;
 
index 13413de..0f7c670 100644 (file)
@@ -97,9 +97,10 @@ static Optional<double> consumeNumberOrPercentDividedBy100Raw(CSSParserTokenRang
 // FIXME: consider pulling in the parsing logic from CSSCalculationValue.cpp.
 class CalcParser {
 public:
-    explicit CalcParser(CSSParserTokenRange& range, CalculationCategory destinationCategory, ValueRange valueRange = ValueRangeAll)
+    explicit CalcParser(CSSParserTokenRange& range, CalculationCategory destinationCategory, ValueRange valueRange = ValueRangeAll, CSSValuePool& cssValuePool = CSSValuePool::singleton())
         : m_sourceRange(range)
         , m_range(range)
+        , m_valuePool(cssValuePool)
     {
         const CSSParserToken& token = range.peek();
         auto functionId = token.functionId();
@@ -114,7 +115,7 @@ public:
         if (!m_calcValue)
             return nullptr;
         m_sourceRange = m_range;
-        return CSSValuePool::singleton().createValue(WTFMove(m_calcValue));
+        return m_valuePool.createValue(WTFMove(m_calcValue));
     }
 
     RefPtr<CSSPrimitiveValue> consumeInteger(double minimumValue)
@@ -122,7 +123,7 @@ public:
         if (!m_calcValue)
             return nullptr;
         m_sourceRange = m_range;
-        return CSSValuePool::singleton().createValue(std::round(std::max(m_calcValue->doubleValue(), minimumValue)), CSSUnitType::CSS_NUMBER);
+        return m_valuePool.createValue(std::round(std::max(m_calcValue->doubleValue(), minimumValue)), CSSUnitType::CSS_NUMBER);
     }
 
     template<typename IntType> Optional<IntType> consumeIntegerTypeRaw(double minimumValue)
@@ -138,7 +139,7 @@ public:
         if (!m_calcValue)
             return nullptr;
         m_sourceRange = m_range;
-        return CSSValuePool::singleton().createValue(m_calcValue->doubleValue(), CSSUnitType::CSS_NUMBER);
+        return m_valuePool.createValue(m_calcValue->doubleValue(), CSSUnitType::CSS_NUMBER);
     }
 
     Optional<double> consumeNumberRaw()
@@ -199,6 +200,7 @@ private:
     CSSParserTokenRange& m_sourceRange;
     CSSParserTokenRange m_range;
     RefPtr<CSSCalcValue> m_calcValue;
+    CSSValuePool& m_valuePool;
 };
 
 template<typename IntType> Optional<IntType> consumeIntegerTypeRaw(CSSParserTokenRange& range, double minimumValue)
@@ -317,8 +319,13 @@ Optional<double> consumeFontWeightNumberRaw(CSSParserTokenRange& range)
 
 RefPtr<CSSPrimitiveValue> consumeFontWeightNumber(CSSParserTokenRange& range)
 {
+    return consumeFontWeightNumberWorkerSafe(range, CSSValuePool::singleton());
+}
+
+RefPtr<CSSPrimitiveValue> consumeFontWeightNumberWorkerSafe(CSSParserTokenRange& range, CSSValuePool& cssValuePool)
+{
     if (auto result = consumeFontWeightNumberRaw(range))
-        return CSSValuePool::singleton().createValue(*result, CSSUnitType::CSS_NUMBER);
+        return cssValuePool.createValue(*result, CSSUnitType::CSS_NUMBER);
     return nullptr;
 }
 
@@ -418,9 +425,14 @@ Optional<double> consumePercentRaw(CSSParserTokenRange& range, ValueRange valueR
 
 RefPtr<CSSPrimitiveValue> consumePercent(CSSParserTokenRange& range, ValueRange valueRange)
 {
+    return consumePercentWorkerSafe(range, valueRange, CSSValuePool::singleton());
+}
+
+RefPtr<CSSPrimitiveValue> consumePercentWorkerSafe(CSSParserTokenRange& range, ValueRange valueRange, CSSValuePool& cssValuePool)
+{
     const CSSParserToken& token = range.peek();
     if (token.type() == FunctionToken) {
-        CalcParser calcParser(range, CalculationCategory::Percent, valueRange);
+        CalcParser calcParser(range, CalculationCategory::Percent, valueRange, cssValuePool);
         if (const CSSCalcValue* calculation = calcParser.value()) {
             if (calculation->category() == CalculationCategory::Percent)
                 return calcParser.consumeValue();
@@ -429,7 +441,7 @@ RefPtr<CSSPrimitiveValue> consumePercent(CSSParserTokenRange& range, ValueRange
     }
 
     if (auto percent = consumePercentRaw(range, valueRange))
-        return CSSValuePool::singleton().createValue(*percent, CSSUnitType::CSS_PERCENTAGE);
+        return cssValuePool.createValue(*percent, CSSUnitType::CSS_PERCENTAGE);
 
     return nullptr;
 }
@@ -523,9 +535,14 @@ Optional<AngleRaw> consumeAngleRaw(CSSParserTokenRange& range, CSSParserMode css
 
 RefPtr<CSSPrimitiveValue> consumeAngle(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless, UnitlessZeroQuirk unitlessZero)
 {
+    return consumeAngleWorkerSafe(range, cssParserMode, CSSValuePool::singleton(), unitless, unitlessZero);
+}
+
+RefPtr<CSSPrimitiveValue> consumeAngleWorkerSafe(CSSParserTokenRange& range, CSSParserMode cssParserMode, CSSValuePool& cssValuePool, UnitlessQuirk unitless, UnitlessZeroQuirk unitlessZero)
+{
     const CSSParserToken& token = range.peek();
     if (token.type() == FunctionToken) {
-        CalcParser calcParser(range, CalculationCategory::Angle, ValueRangeAll);
+        CalcParser calcParser(range, CalculationCategory::Angle, ValueRangeAll, cssValuePool);
         if (const CSSCalcValue* calculation = calcParser.value()) {
             if (calculation->category() == CalculationCategory::Angle)
                 return calcParser.consumeValue();
@@ -534,7 +551,7 @@ RefPtr<CSSPrimitiveValue> consumeAngle(CSSParserTokenRange& range, CSSParserMode
     }
 
     if (auto angle = consumeAngleRaw(range, cssParserMode, unitless, unitlessZero))
-        return CSSValuePool::singleton().createValue(angle->value, angle->type);
+        return cssValuePool.createValue(angle->value, angle->type);
 
     return nullptr;
 }
@@ -626,8 +643,13 @@ Optional<CSSValueID> consumeIdentRaw(CSSParserTokenRange& range)
 
 RefPtr<CSSPrimitiveValue> consumeIdent(CSSParserTokenRange& range)
 {
+    return consumeIdentWorkerSafe(range, CSSValuePool::singleton());
+}
+
+RefPtr<CSSPrimitiveValue> consumeIdentWorkerSafe(CSSParserTokenRange& range, CSSValuePool& cssValuePool)
+{
     if (auto result = consumeIdentRaw(range))
-        return CSSValuePool::singleton().createIdentifierValue(*result);
+        return cssValuePool.createIdentifierValue(*result);
     return nullptr;
 }
 
@@ -3040,7 +3062,7 @@ Optional<LineHeightRaw> consumeLineHeightRaw(CSSParserTokenRange& range, CSSPars
     return WTF::nullopt;
 }
 
-Optional<FontRaw> consumeFontWorkerSafe(CSSParserTokenRange& range, CSSParserMode cssParserMode)
+Optional<FontRaw> consumeFontRaw(CSSParserTokenRange& range, CSSParserMode cssParserMode)
 {
     // Let's check if there is an inherit or initial somewhere in the shorthand.
     CSSParserTokenRange rangeCopy = range;
index 82f442f..473282a 100644 (file)
@@ -82,24 +82,29 @@ Optional<double> consumeNumberRaw(CSSParserTokenRange&, ValueRange = ValueRangeA
 RefPtr<CSSPrimitiveValue> consumeNumber(CSSParserTokenRange&, ValueRange);
 Optional<double> consumeFontWeightNumberRaw(CSSParserTokenRange&);
 RefPtr<CSSPrimitiveValue> consumeFontWeightNumber(CSSParserTokenRange&);
+RefPtr<CSSPrimitiveValue> consumeFontWeightNumberWorkerSafe(CSSParserTokenRange&, CSSValuePool&);
 Optional<LengthRaw> consumeLengthRaw(CSSParserTokenRange&, CSSParserMode, ValueRange, UnitlessQuirk = UnitlessQuirk::Forbid);
 RefPtr<CSSPrimitiveValue> consumeLength(CSSParserTokenRange&, CSSParserMode, ValueRange, UnitlessQuirk = UnitlessQuirk::Forbid);
 Optional<double> consumePercentRaw(CSSParserTokenRange&, ValueRange = ValueRangeAll);
 RefPtr<CSSPrimitiveValue> consumePercent(CSSParserTokenRange&, ValueRange);
+RefPtr<CSSPrimitiveValue> consumePercentWorkerSafe(CSSParserTokenRange&, ValueRange, CSSValuePool&);
 Optional<LengthOrPercentRaw> consumeLengthOrPercentRaw(CSSParserTokenRange&, CSSParserMode, ValueRange, UnitlessQuirk = UnitlessQuirk::Forbid);
 RefPtr<CSSPrimitiveValue> consumeLengthOrPercent(CSSParserTokenRange&, CSSParserMode, ValueRange, UnitlessQuirk = UnitlessQuirk::Forbid);
 Optional<AngleRaw> consumeAngleRaw(CSSParserTokenRange&, CSSParserMode, UnitlessQuirk = UnitlessQuirk::Forbid, UnitlessZeroQuirk = UnitlessZeroQuirk::Forbid);
 RefPtr<CSSPrimitiveValue> consumeAngle(CSSParserTokenRange&, CSSParserMode, UnitlessQuirk = UnitlessQuirk::Forbid, UnitlessZeroQuirk = UnitlessZeroQuirk::Forbid);
+RefPtr<CSSPrimitiveValue> consumeAngleWorkerSafe(CSSParserTokenRange&, CSSParserMode, CSSValuePool&, UnitlessQuirk = UnitlessQuirk::Forbid, UnitlessZeroQuirk = UnitlessZeroQuirk::Forbid);
 RefPtr<CSSPrimitiveValue> consumeTime(CSSParserTokenRange&, CSSParserMode, ValueRange, UnitlessQuirk = UnitlessQuirk::Forbid);
 RefPtr<CSSPrimitiveValue> consumeResolution(CSSParserTokenRange&, AllowXResolutionUnit = AllowXResolutionUnit::Forbid);
 
 Optional<CSSValueID> consumeIdentRaw(CSSParserTokenRange&);
 RefPtr<CSSPrimitiveValue> consumeIdent(CSSParserTokenRange&);
+RefPtr<CSSPrimitiveValue> consumeIdentWorkerSafe(CSSParserTokenRange&, CSSValuePool&);
 Optional<CSSValueID> consumeIdentRangeRaw(CSSParserTokenRange&, CSSValueID lower, CSSValueID upper);
 RefPtr<CSSPrimitiveValue> consumeIdentRange(CSSParserTokenRange&, CSSValueID lower, CSSValueID upper);
 template<CSSValueID, CSSValueID...> inline bool identMatches(CSSValueID id);
 template<CSSValueID... allowedIdents> Optional<CSSValueID> consumeIdentRaw(CSSParserTokenRange&);
 template<CSSValueID... allowedIdents> RefPtr<CSSPrimitiveValue> consumeIdent(CSSParserTokenRange&);
+template<CSSValueID... allowedIdents> RefPtr<CSSPrimitiveValue> consumeIdentWorkerSafe(CSSParserTokenRange&, CSSValuePool&);
 
 RefPtr<CSSPrimitiveValue> consumeCustomIdent(CSSParserTokenRange&);
 RefPtr<CSSPrimitiveValue> consumeString(CSSParserTokenRange&);
@@ -172,7 +177,7 @@ Optional<CSSValueID> consumeGenericFamilyRaw(CSSParserTokenRange&);
 Optional<Vector<FontFamilyRaw>> consumeFontFamilyRaw(CSSParserTokenRange&);
 Optional<FontSizeRaw> consumeFontSizeRaw(CSSParserTokenRange&, CSSParserMode, UnitlessQuirk = UnitlessQuirk::Forbid);
 Optional<LineHeightRaw> consumeLineHeightRaw(CSSParserTokenRange&, CSSParserMode);
-Optional<FontRaw> consumeFontWorkerSafe(CSSParserTokenRange&, CSSParserMode);
+Optional<FontRaw> consumeFontRaw(CSSParserTokenRange&, CSSParserMode);
 const AtomString& genericFontFamily(CSSValueID);
 WebKitFontFamilyNames::FamilyNamesIndex genericFontFamilyIndex(CSSValueID);
 
@@ -195,9 +200,14 @@ template<CSSValueID... names> Optional<CSSValueID> consumeIdentRaw(CSSParserToke
 
 template<CSSValueID... names> RefPtr<CSSPrimitiveValue> consumeIdent(CSSParserTokenRange& range)
 {
+    return consumeIdentWorkerSafe<names...>(range, CSSValuePool::singleton());
+}
+
+template<CSSValueID... names> RefPtr<CSSPrimitiveValue> consumeIdentWorkerSafe(CSSParserTokenRange& range, CSSValuePool& cssValuePool)
+{
     if (range.peek().type() != IdentToken || !identMatches<names...>(range.peek().id()))
         return nullptr;
-    return CSSValuePool::singleton().createIdentifierValue(range.consumeIncludingWhitespace().id());
+    return cssValuePool.createIdentifierValue(range.consumeIncludingWhitespace().id());
 }
 
 inline bool isFontStyleAngleInRange(double angleInDegrees)
diff --git a/Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp b/Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp
new file mode 100644 (file)
index 0000000..23451ea
--- /dev/null
@@ -0,0 +1,461 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright (C) 2016 Apple Inc. All rights reserved.
+// Copyright (C) 2021 Metrological Group B.V.
+// Copyright (C) 2021 Igalia S.L.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//    * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//    * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+//    * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "config.h"
+#include "CSSPropertyParserWorkerSafe.h"
+
+#include "CSSFontStyleValue.h"
+#include "CSSParserFastPaths.h"
+#include "CSSParserImpl.h"
+#include "CSSParserTokenRange.h"
+#include "CSSPropertyParser.h"
+#include "CSSPropertyParserHelpers.h"
+#include "CSSTokenizer.h"
+#include "ScriptExecutionContext.h"
+
+#if ENABLE(VARIATION_FONTS)
+#include "CSSFontStyleRangeValue.h"
+#endif
+
+namespace WebCore {
+
+Optional<FontRaw> CSSPropertyParserWorkerSafe::parseFont(const String& string, CSSParserMode mode)
+{
+    CSSTokenizer tokenizer(string);
+    CSSParserTokenRange range(tokenizer.tokenRange());
+    range.consumeWhitespace();
+
+    return CSSPropertyParserHelpers::consumeFontRaw(range, mode);
+}
+
+Color CSSPropertyParserWorkerSafe::parseColor(const String& string)
+{
+    if (auto color = CSSParserFastPaths::parseSimpleColor(string))
+        return *color;
+
+    CSSTokenizer tokenizer(string);
+    CSSParserTokenRange range(tokenizer.tokenRange());
+    range.consumeWhitespace();
+
+    return CSSPropertyParserHelpers::consumeColorWorkerSafe(range, CSSParserContext(HTMLStandardMode));
+}
+
+static CSSParserContext parserContext(ScriptExecutionContext& context)
+{
+    if (!is<Document>(context))
+        return HTMLStandardMode;
+    return downcast<Document>(context).inQuirksMode() ? HTMLQuirksMode : HTMLStandardMode;
+}
+
+RefPtr<CSSValueList> CSSPropertyParserWorkerSafe::parseFontFaceSrc(const String& string, const CSSParserContext& context)
+{
+    CSSParserImpl parser(context, string);
+    CSSParserTokenRange range = parser.tokenizer()->tokenRange();
+    range.consumeWhitespace();
+    if (range.atEnd())
+        return nullptr;
+    auto parsedValue = CSSPropertyParserHelpersWorkerSafe::consumeFontFaceSrc(range, parser.context());
+    if (!parsedValue || !range.atEnd())
+        return nullptr;
+
+    return parsedValue;
+}
+
+RefPtr<CSSValue> CSSPropertyParserWorkerSafe::parseFontFaceStyle(const String& string, ScriptExecutionContext& context)
+{
+    CSSParserImpl parser(parserContext(context), string);
+    CSSParserTokenRange range = parser.tokenizer()->tokenRange();
+    range.consumeWhitespace();
+    if (range.atEnd())
+        return nullptr;
+    auto parsedValue =
+#if ENABLE(VARIATION_FONTS)
+        CSSPropertyParserHelpersWorkerSafe::consumeFontStyleRange(range, parser.context().mode, context.cssValuePool());
+#else
+        CSSPropertyParserHelpersWorkerSafe::consumeFontStyle(range, parser.context().mode, context.cssValuePool());
+#endif
+    if (!parsedValue || !range.atEnd())
+        return nullptr;
+
+    return parsedValue;
+}
+
+RefPtr<CSSValue> CSSPropertyParserWorkerSafe::parseFontFaceWeight(const String& string, ScriptExecutionContext& context)
+{
+    CSSParserImpl parser(parserContext(context), string);
+    CSSParserTokenRange range = parser.tokenizer()->tokenRange();
+    range.consumeWhitespace();
+    if (range.atEnd())
+        return nullptr;
+    auto parsedValue =
+#if ENABLE(VARIATION_FONTS)
+        CSSPropertyParserHelpersWorkerSafe::consumeFontWeightAbsoluteRange(range, context.cssValuePool());
+#else
+        CSSPropertyParserHelpersWorkerSafe::consumeFontWeightAbsolute(range, context.cssValuePool());
+#endif
+    if (!parsedValue || !range.atEnd())
+        return nullptr;
+
+    return parsedValue;
+}
+
+RefPtr<CSSValue> CSSPropertyParserWorkerSafe::parseFontFaceStretch(const String& string, ScriptExecutionContext& context)
+{
+    CSSParserImpl parser(parserContext(context), string);
+    CSSParserTokenRange range = parser.tokenizer()->tokenRange();
+    range.consumeWhitespace();
+    if (range.atEnd())
+        return nullptr;
+    auto parsedValue =
+#if ENABLE(VARIATION_FONTS)
+        CSSPropertyParserHelpersWorkerSafe::consumeFontStretchRange(range, context.cssValuePool());
+#else
+        CSSPropertyParserHelpersWorkerSafe::consumeFontStretch(range, context.cssValuePool());
+#endif
+    if (!parsedValue || !range.atEnd())
+        return nullptr;
+
+    return parsedValue;
+}
+
+RefPtr<CSSValue> CSSPropertyParserWorkerSafe::parseFontFaceUnicodeRange(const String& string, ScriptExecutionContext& context)
+{
+    CSSParserImpl parser(parserContext(context), string);
+    CSSParserTokenRange range = parser.tokenizer()->tokenRange();
+    range.consumeWhitespace();
+    if (range.atEnd())
+        return nullptr;
+    auto parsedValue = CSSPropertyParserHelpersWorkerSafe::consumeFontFaceUnicodeRange(range);
+    if (!parsedValue || !range.atEnd())
+        return nullptr;
+
+    return parsedValue;
+}
+
+RefPtr<CSSValue> CSSPropertyParserWorkerSafe::parseFontFaceFeatureSettings(const String& string, ScriptExecutionContext& context)
+{
+    CSSParserImpl parser(parserContext(context), string);
+    CSSParserTokenRange range = parser.tokenizer()->tokenRange();
+    range.consumeWhitespace();
+    if (range.atEnd())
+        return nullptr;
+    auto parsedValue = CSSPropertyParserHelpersWorkerSafe::consumeFontFeatureSettings(range, context.cssValuePool());
+    if (!parsedValue || !range.atEnd())
+        return nullptr;
+
+    return parsedValue;
+}
+
+RefPtr<CSSValue> CSSPropertyParserWorkerSafe::parseFontFaceDisplay(const String& string, ScriptExecutionContext& context)
+{
+    CSSParserImpl parser(parserContext(context), string);
+    CSSParserTokenRange range = parser.tokenizer()->tokenRange();
+    range.consumeWhitespace();
+    if (range.atEnd())
+        return nullptr;
+    auto parsedValue = CSSPropertyParserHelpersWorkerSafe::consumeFontFaceFontDisplay(range, context.cssValuePool());
+    if (!parsedValue || !range.atEnd())
+        return nullptr;
+
+    return parsedValue;
+}
+
+namespace CSSPropertyParserHelpersWorkerSafe {
+
+static RefPtr<CSSValue> consumeFontFaceSrcURI(CSSParserTokenRange& range, const CSSParserContext& context)
+{
+    String url = CSSPropertyParserHelpers::consumeUrlAsStringView(range).toString();
+    if (url.isNull())
+        return nullptr;
+
+    RefPtr<CSSFontFaceSrcValue> uriValue = CSSFontFaceSrcValue::create(context.completeURL(url).string(), context.isContentOpaque ? LoadedFromOpaqueSource::Yes : LoadedFromOpaqueSource::No);
+
+    if (range.peek().functionId() != CSSValueFormat)
+        return uriValue;
+
+    // FIXME: https://drafts.csswg.org/css-fonts says that format() contains a comma-separated list of strings,
+    // but CSSFontFaceSrcValue stores only one format. Allowing one format for now.
+    // FIXME: We're allowing the format to be an identifier as well as a string, because the old
+    // parser did. It's not clear if we need to continue to support this behavior, but we have lots of
+    // layout tests that rely on it.
+    CSSParserTokenRange args = CSSPropertyParserHelpers::consumeFunction(range);
+    const CSSParserToken& arg = args.consumeIncludingWhitespace();
+    if ((arg.type() != StringToken && arg.type() != IdentToken) || !args.atEnd())
+        return nullptr;
+    uriValue->setFormat(arg.value().toString());
+    return uriValue;
+}
+
+static RefPtr<CSSValue> consumeFontFaceSrcLocal(CSSParserTokenRange& range)
+{
+    CSSParserTokenRange args = CSSPropertyParserHelpers::consumeFunction(range);
+    if (args.peek().type() == StringToken) {
+        const CSSParserToken& arg = args.consumeIncludingWhitespace();
+        if (!args.atEnd())
+            return nullptr;
+        return CSSFontFaceSrcValue::createLocal(arg.value().toString());
+    }
+    if (args.peek().type() == IdentToken) {
+        String familyName = concatenateFamilyName(args);
+        if (!args.atEnd())
+            return nullptr;
+        return CSSFontFaceSrcValue::createLocal(familyName);
+    }
+    return nullptr;
+}
+
+RefPtr<CSSValueList> consumeFontFaceSrc(CSSParserTokenRange& range, const CSSParserContext& context)
+{
+    RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
+
+    do {
+        const CSSParserToken& token = range.peek();
+        RefPtr<CSSValue> parsedValue;
+        if (token.functionId() == CSSValueLocal)
+            parsedValue = consumeFontFaceSrcLocal(range);
+        else
+            parsedValue = consumeFontFaceSrcURI(range, context);
+        if (!parsedValue)
+            return nullptr;
+        values->append(parsedValue.releaseNonNull());
+    } while (CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(range));
+    return values;
+}
+
+RefPtr<CSSFontStyleValue> consumeFontStyle(CSSParserTokenRange& range, CSSParserMode cssParserMode, CSSValuePool& pool)
+{
+    if (auto result = CSSPropertyParserHelpers::consumeFontStyleRaw(range, cssParserMode)) {
+#if ENABLE(VARIATION_FONTS)
+        if (result->style == CSSValueOblique && result->angle) {
+            return CSSFontStyleValue::create(pool.createIdentifierValue(CSSValueOblique),
+                pool.createValue(result->angle->value, result->angle->type));
+        }
+#endif
+        return CSSFontStyleValue::create(pool.createIdentifierValue(result->style));
+    }
+    return nullptr;
+}
+
+#if ENABLE(VARIATION_FONTS)
+static RefPtr<CSSPrimitiveValue> consumeFontStyleKeywordValue(CSSParserTokenRange& range, CSSValuePool& pool)
+{
+    return CSSPropertyParserHelpers::consumeIdentWorkerSafe<CSSValueNormal, CSSValueItalic, CSSValueOblique>(range, pool);
+}
+
+RefPtr<CSSFontStyleRangeValue> consumeFontStyleRange(CSSParserTokenRange& range, CSSParserMode cssParserMode, CSSValuePool& pool)
+{
+    auto keyword = consumeFontStyleKeywordValue(range, pool);
+    if (!keyword)
+        return nullptr;
+
+    if (keyword->valueID() != CSSValueOblique || range.atEnd())
+        return CSSFontStyleRangeValue::create(keyword.releaseNonNull());
+
+    // FIXME: This should probably not allow the unitless zero.
+    if (auto firstAngle = CSSPropertyParserHelpers::consumeAngleWorkerSafe(range, cssParserMode, pool, UnitlessQuirk::Forbid, UnitlessZeroQuirk::Allow)) {
+        auto firstAngleInDegrees = firstAngle->doubleValue(CSSUnitType::CSS_DEG);
+        if (!isFontStyleAngleInRange(firstAngleInDegrees))
+            return nullptr;
+        if (range.atEnd()) {
+            auto result = CSSValueList::createSpaceSeparated();
+            result->append(firstAngle.releaseNonNull());
+            return CSSFontStyleRangeValue::create(keyword.releaseNonNull(), WTFMove(result));
+        }
+
+        // FIXME: This should probably not allow the unitless zero.
+        auto secondAngle = CSSPropertyParserHelpers::consumeAngleWorkerSafe(range, cssParserMode, pool, UnitlessQuirk::Forbid, UnitlessZeroQuirk::Allow);
+        if (!secondAngle)
+            return nullptr;
+        auto secondAngleInDegrees = secondAngle->doubleValue(CSSUnitType::CSS_DEG);
+        if (!isFontStyleAngleInRange(secondAngleInDegrees) || firstAngleInDegrees > secondAngleInDegrees)
+            return nullptr;
+        auto result = CSSValueList::createSpaceSeparated();
+        result->append(firstAngle.releaseNonNull());
+        result->append(secondAngle.releaseNonNull());
+        return CSSFontStyleRangeValue::create(keyword.releaseNonNull(), WTFMove(result));
+    }
+
+    return nullptr;
+}
+#endif
+
+static RefPtr<CSSPrimitiveValue> consumeFontWeightAbsoluteKeywordValue(CSSParserTokenRange& range, CSSValuePool& pool)
+{
+    return CSSPropertyParserHelpers::consumeIdentWorkerSafe<CSSValueNormal, CSSValueBold>(range, pool);
+}
+
+#if ENABLE(VARIATION_FONTS)
+RefPtr<CSSValue> consumeFontWeightAbsoluteRange(CSSParserTokenRange& range, CSSValuePool& pool)
+{
+    if (auto result = consumeFontWeightAbsoluteKeywordValue(range, pool))
+        return result;
+    auto firstNumber = CSSPropertyParserHelpers::consumeFontWeightNumberWorkerSafe(range, pool);
+    if (!firstNumber)
+        return nullptr;
+    if (range.atEnd())
+        return firstNumber;
+    auto secondNumber = CSSPropertyParserHelpers::consumeFontWeightNumberWorkerSafe(range, pool);
+    if (!secondNumber || firstNumber->floatValue() > secondNumber->floatValue())
+        return nullptr;
+    auto result = CSSValueList::createSpaceSeparated();
+    result->append(firstNumber.releaseNonNull());
+    result->append(secondNumber.releaseNonNull());
+    return RefPtr<CSSValue>(WTFMove(result));
+}
+#else
+RefPtr<CSSPrimitiveValue> consumeFontWeightAbsolute(CSSParserTokenRange& range, CSSValuePool& pool)
+{
+    if (auto result = consumeFontWeightAbsoluteKeywordValue(range, pool))
+        return result;
+    return CSSPropertyParserHelpers::consumeFontWeightNumberWorkerSafe(range, pool);
+}
+#endif
+
+RefPtr<CSSPrimitiveValue> consumeFontStretchKeywordValue(CSSParserTokenRange& range, CSSValuePool& pool)
+{
+    if (auto valueID = CSSPropertyParserHelpers::consumeFontStretchKeywordValueRaw(range))
+        return pool.createIdentifierValue(*valueID);
+    return nullptr;
+}
+
+#if ENABLE(VARIATION_FONTS)
+static bool fontStretchIsWithinRange(float stretch)
+{
+    return stretch >= 0;
+}
+#endif
+
+RefPtr<CSSPrimitiveValue> consumeFontStretch(CSSParserTokenRange& range, CSSValuePool& pool)
+{
+    if (auto result = consumeFontStretchKeywordValue(range, pool))
+        return result;
+#if ENABLE(VARIATION_FONTS)
+    if (auto percent = CSSPropertyParserHelpers::consumePercentWorkerSafe(range, ValueRangeNonNegative, pool))
+        return fontStretchIsWithinRange(percent->value<float>()) ? percent : nullptr;
+#endif
+    return nullptr;
+}
+
+#if ENABLE(VARIATION_FONTS)
+RefPtr<CSSValue> consumeFontStretchRange(CSSParserTokenRange& range, CSSValuePool& pool)
+{
+    if (auto result = consumeFontStretchKeywordValue(range, pool))
+        return result;
+    auto firstPercent = CSSPropertyParserHelpers::consumePercentWorkerSafe(range, ValueRangeNonNegative, pool);
+    if (!firstPercent || !fontStretchIsWithinRange(firstPercent->value<float>()))
+        return nullptr;
+    if (range.atEnd())
+        return firstPercent;
+    auto secondPercent = CSSPropertyParserHelpers::consumePercentWorkerSafe(range, ValueRangeNonNegative, pool);
+    if (!secondPercent || !fontStretchIsWithinRange(secondPercent->value<float>()) || firstPercent->floatValue() > secondPercent->floatValue())
+        return nullptr;
+    auto result = CSSValueList::createSpaceSeparated();
+    result->append(firstPercent.releaseNonNull());
+    result->append(secondPercent.releaseNonNull());
+    return RefPtr<CSSValue>(WTFMove(result));
+}
+#endif
+
+RefPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParserTokenRange& range)
+{
+    RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
+
+    do {
+        const CSSParserToken& token = range.consumeIncludingWhitespace();
+        if (token.type() != UnicodeRangeToken)
+            return nullptr;
+
+        UChar32 start = token.unicodeRangeStart();
+        UChar32 end = token.unicodeRangeEnd();
+        if (start > end)
+            return nullptr;
+        values->append(CSSUnicodeRangeValue::create(start, end));
+    } while (CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(range));
+
+    return values;
+}
+
+static RefPtr<CSSFontFeatureValue> consumeFontFeatureTag(CSSParserTokenRange& range)
+{
+    // Feature tag name consists of 4-letter characters.
+    static const unsigned tagNameLength = 4;
+
+    const CSSParserToken& token = range.consumeIncludingWhitespace();
+    // Feature tag name comes first
+    if (token.type() != StringToken)
+        return nullptr;
+    if (token.value().length() != tagNameLength)
+        return nullptr;
+    
+    FontTag tag;
+    for (unsigned i = 0; i < tag.size(); ++i) {
+        // Limits the range of characters to 0x20-0x7E, following the tag name rules defiend in the OpenType specification.
+        UChar character = token.value()[i];
+        if (character < 0x20 || character > 0x7E)
+            return nullptr;
+        tag[i] = toASCIILower(character);
+    }
+
+    int tagValue = 1;
+    if (!range.atEnd() && range.peek().type() != CommaToken) {
+        // Feature tag values could follow: <integer> | on | off
+        if (auto integer = CSSPropertyParserHelpers::consumeIntegerRaw(range, 0))
+            tagValue = *integer;
+        else if (range.peek().id() == CSSValueOn || range.peek().id() == CSSValueOff)
+            tagValue = range.consumeIncludingWhitespace().id() == CSSValueOn;
+        else
+            return nullptr;
+    }
+    return CSSFontFeatureValue::create(WTFMove(tag), tagValue);
+}
+
+RefPtr<CSSValue> consumeFontFeatureSettings(CSSParserTokenRange& range, CSSValuePool& pool)
+{
+    if (range.peek().id() == CSSValueNormal)
+        return CSSPropertyParserHelpers::consumeIdentWorkerSafe(range, pool);
+    RefPtr<CSSValueList> settings = CSSValueList::createCommaSeparated();
+    do {
+        RefPtr<CSSFontFeatureValue> fontFeatureValue = consumeFontFeatureTag(range);
+        if (!fontFeatureValue)
+            return nullptr;
+        settings->append(fontFeatureValue.releaseNonNull());
+    } while (CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(range));
+    return settings;
+}
+
+RefPtr<CSSPrimitiveValue> consumeFontFaceFontDisplay(CSSParserTokenRange& range, CSSValuePool& pool)
+{
+    return CSSPropertyParserHelpers::consumeIdentWorkerSafe<CSSValueAuto, CSSValueBlock, CSSValueSwap, CSSValueFallback, CSSValueOptional>(range, pool);
+}
+
+} // namespace CSSPropertyParserHelpersWorkerSafe
+
+} // namespace WebCore
diff --git a/Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.h b/Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.h
new file mode 100644 (file)
index 0000000..016fcd0
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2021 Metrological Group B.V.
+ * Copyright (C) 2021 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "CSSParserContext.h"
+#include <wtf/Optional.h>
+#include <wtf/RefPtr.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class CSSFontStyleValue;
+class CSSFontStyleRangeValue;
+class CSSValue;
+class CSSValueList;
+class CSSValuePool;
+class Color;
+class ScriptExecutionContext;
+
+class CSSPropertyParserWorkerSafe {
+public:
+    static Color parseColor(const String&);
+    static Optional<CSSPropertyParserHelpers::FontRaw> parseFont(const String&, CSSParserMode = HTMLStandardMode);
+
+    static RefPtr<CSSValueList> parseFontFaceSrc(const String&, const CSSParserContext&);
+    static RefPtr<CSSValue> parseFontFaceStyle(const String&, ScriptExecutionContext&);
+    static RefPtr<CSSValue> parseFontFaceWeight(const String&, ScriptExecutionContext&);
+    static RefPtr<CSSValue> parseFontFaceStretch(const String&, ScriptExecutionContext&);
+    static RefPtr<CSSValue> parseFontFaceUnicodeRange(const String&, ScriptExecutionContext&);
+    static RefPtr<CSSValue> parseFontFaceFeatureSettings(const String&, ScriptExecutionContext&);
+    static RefPtr<CSSValue> parseFontFaceDisplay(const String&, ScriptExecutionContext&);
+};
+
+namespace CSSPropertyParserHelpersWorkerSafe {
+
+RefPtr<CSSValueList> consumeFontFaceSrc(CSSParserTokenRange&, const CSSParserContext&);
+RefPtr<CSSFontStyleValue> consumeFontStyle(CSSParserTokenRange&, CSSParserMode, CSSValuePool&);
+RefPtr<CSSPrimitiveValue> consumeFontStretchKeywordValue(CSSParserTokenRange&, CSSValuePool&);
+RefPtr<CSSPrimitiveValue> consumeFontStretch(CSSParserTokenRange&, CSSValuePool&);
+RefPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParserTokenRange&);
+RefPtr<CSSValue> consumeFontFeatureSettings(CSSParserTokenRange&, CSSValuePool&);
+RefPtr<CSSPrimitiveValue> consumeFontFaceFontDisplay(CSSParserTokenRange&, CSSValuePool&);
+
+#if ENABLE(VARIATION_FONTS)
+RefPtr<CSSFontStyleRangeValue> consumeFontStyleRange(CSSParserTokenRange&, CSSParserMode, CSSValuePool&);
+RefPtr<CSSValue> consumeFontWeightAbsoluteRange(CSSParserTokenRange&, CSSValuePool&);
+RefPtr<CSSValue> consumeFontStretchRange(CSSParserTokenRange&, CSSValuePool&);
+#endif
+
+#if !ENABLE(VARIATION_FONTS)
+RefPtr<CSSPrimitiveValue> consumeFontWeightAbsolute(CSSParserTokenRange&, CSSValuePool&);
+#endif
+
+} // namespace CSSPropertyParserHelpersWorkerSafe
+
+} // namespace WebCore
index a86afe1..88aacf3 100644 (file)
@@ -28,6 +28,7 @@
 #include "config.h"
 #include "ScriptExecutionContext.h"
 
+#include "CSSValuePool.h"
 #include "CachedScript.h"
 #include "CommonVM.h"
 #include "DOMTimer.h"
@@ -233,6 +234,11 @@ FontCache& ScriptExecutionContext::fontCache()
     return FontCache::singleton();
 }
 
+CSSValuePool& ScriptExecutionContext::cssValuePool()
+{
+    return CSSValuePool::singleton();
+}
+
 std::unique_ptr<FontLoadRequest> ScriptExecutionContext::fontLoadRequest(String&, bool, bool, LoadedFromOpaqueSource)
 {
     return nullptr;
index c998b12..12ba467 100644 (file)
@@ -62,6 +62,7 @@ namespace WebCore {
 class EventLoop;
 class CachedScript;
 class CSSFontSelector;
+class CSSValuePool;
 class DatabaseContext;
 class EventQueue;
 class EventLoopTaskGroup;
@@ -167,6 +168,7 @@ public:
 
     virtual FontCache& fontCache();
     virtual CSSFontSelector* cssFontSelector() { return nullptr; }
+    virtual CSSValuePool& cssValuePool();
     virtual std::unique_ptr<FontLoadRequest> fontLoadRequest(String& url, bool isSVG, bool isInitiatingElementInUserAgentShadowTree, LoadedFromOpaqueSource);
     virtual void beginLoadingFontSoon(FontLoadRequest&) { }
 
index 141557f..bf27d91 100644 (file)
@@ -34,9 +34,9 @@
 #include "CanvasRenderingContext2D.h"
 
 #include "CSSFontSelector.h"
-#include "CSSParser.h"
 #include "CSSPropertyNames.h"
 #include "CSSPropertyParserHelpers.h"
+#include "CSSPropertyParserWorkerSafe.h"
 #include "Gradient.h"
 #include "ImageBuffer.h"
 #include "ImageData.h"
@@ -125,8 +125,8 @@ void CanvasRenderingContext2D::setFontWithoutUpdatingStyle(const String& newFont
         return;
 
     // According to http://lists.w3.org/Archives/Public/public-html/2009Jul/0947.html,
-    // the "inherit" and "initial" values must be ignored. parseFontWorkerSafe() ignores these.
-    auto fontRaw = CSSParser::parseFontWorkerSafe(newFont, strictToCSSParserMode(!usesCSSCompatibilityParseMode()));
+    // the "inherit" and "initial" values must be ignored. CSSPropertyParserWorkerSafe::parseFont() ignores these.
+    auto fontRaw = CSSPropertyParserWorkerSafe::parseFont(newFont, strictToCSSParserMode(!usesCSSCompatibilityParseMode()));
     if (!fontRaw)
         return;
 
index 918e7c0..b0c6259 100644 (file)
 #include "Gradient.h"
 #include "GraphicsContext.h"
 #include "HTMLCanvasElement.h"
+#include "StyleProperties.h"
+
 #if ENABLE(OFFSCREEN_CANVAS)
+#include "CSSPropertyParserWorkerSafe.h"
 #include "OffscreenCanvas.h"
 #endif
-#include "StyleProperties.h"
 
 #if USE(CG)
 #include <CoreGraphics/CGContext.h>
@@ -57,7 +59,7 @@ Color parseColor(const String& colorString, CanvasBase& canvasBase)
 {
 #if ENABLE(OFFSCREEN_CANVAS)
     if (canvasBase.isOffscreenCanvas())
-        return CSSParser::parseColorWorkerSafe(colorString);
+        return CSSPropertyParserWorkerSafe::parseColor(colorString);
 #else
     UNUSED_PARAM(canvasBase);
 #endif
index 8ae4984..04d98b6 100644 (file)
@@ -36,8 +36,8 @@
 #if ENABLE(OFFSCREEN_CANVAS)
 
 #include "CSSFontSelector.h"
-#include "CSSParser.h"
 #include "CSSPropertyParserHelpers.h"
+#include "CSSPropertyParserWorkerSafe.h"
 #include "RenderStyle.h"
 #include "ScriptExecutionContext.h"
 #include "StyleResolveForFontRaw.h"
@@ -71,8 +71,8 @@ void OffscreenCanvasRenderingContext2D::setFont(const String& newFont)
         return;
 
     // According to http://lists.w3.org/Archives/Public/public-html/2009Jul/0947.html,
-    // the "inherit" and "initial" values must be ignored. parseFontWorkerSafe() ignores these.
-    auto fontRaw = CSSParser::parseFontWorkerSafe(newFont, strictToCSSParserMode(!usesCSSCompatibilityParseMode()));
+    // the "inherit" and "initial" values must be ignored. CSSPropertyParserWorkerSafe::parseFont() ignores these.
+    auto fontRaw = CSSPropertyParserWorkerSafe::parseFont(newFont, strictToCSSParserMode(!usesCSSCompatibilityParseMode()));
     if (!fontRaw)
         return;
 
index ef03cc1..6ebe465 100644 (file)
@@ -121,7 +121,7 @@ public:
     void createImageBitmap(ImageBitmap::Source&&, ImageBitmapOptions&&, ImageBitmap::Promise&&);
     void createImageBitmap(ImageBitmap::Source&&, int sx, int sy, int sw, int sh, ImageBitmapOptions&&, ImageBitmap::Promise&&);
 
-    CSSValuePool& cssValuePool();
+    CSSValuePool& cssValuePool() final;
     CSSFontSelector* cssFontSelector() final;
     FontCache& fontCache() final;