OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/css/parser/CSSPropertyParser.h" | 5 #include "core/css/parser/CSSPropertyParser.h" |
6 | 6 |
7 #include "core/StylePropertyShorthand.h" | 7 #include "core/StylePropertyShorthand.h" |
8 #include "core/css/CSSBasicShapeValues.h" | 8 #include "core/css/CSSBasicShapeValues.h" |
9 #include "core/css/CSSBorderImage.h" | 9 #include "core/css/CSSBorderImage.h" |
10 #include "core/css/CSSContentDistributionValue.h" | 10 #include "core/css/CSSContentDistributionValue.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 addProperty(property, value, important); | 86 addProperty(property, value, important); |
87 return; | 87 return; |
88 } | 88 } |
89 | 89 |
90 ShorthandScope scope(this, property); | 90 ShorthandScope scope(this, property); |
91 const CSSPropertyID* longhands = shorthand.properties(); | 91 const CSSPropertyID* longhands = shorthand.properties(); |
92 for (unsigned i = 0; i < shorthandLength; ++i) | 92 for (unsigned i = 0; i < shorthandLength; ++i) |
93 addProperty(longhands[i], value, important); | 93 addProperty(longhands[i], value, important); |
94 } | 94 } |
95 | 95 |
96 static bool hasInvalidNumericValues(const CSSParserTokenRange& range) | |
97 { | |
98 for (const CSSParserToken& token : range) { | |
99 CSSParserTokenType type = token.type(); | |
100 if ((type == NumberToken || type == DimensionToken || type == Percentage
Token) | |
101 && !CSSPropertyParser::isValidNumericValue(token.numericValue())) | |
102 return true; | |
103 } | |
104 return false; | |
105 } | |
106 | |
107 bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import
ant, | 96 bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import
ant, |
108 const CSSParserTokenRange& range, const CSSParserContext& context, | 97 const CSSParserTokenRange& range, const CSSParserContext& context, |
109 HeapVector<CSSProperty, 256>& parsedProperties, StyleRule::RuleType ruleType
) | 98 HeapVector<CSSProperty, 256>& parsedProperties, StyleRule::RuleType ruleType
) |
110 { | 99 { |
111 if (hasInvalidNumericValues(range)) | |
112 return false; | |
113 int parsedPropertiesSize = parsedProperties.size(); | 100 int parsedPropertiesSize = parsedProperties.size(); |
114 | 101 |
115 CSSPropertyParser parser(range, context, &parsedProperties); | 102 CSSPropertyParser parser(range, context, &parsedProperties); |
116 CSSPropertyID resolvedProperty = resolveCSSPropertyID(unresolvedProperty); | 103 CSSPropertyID resolvedProperty = resolveCSSPropertyID(unresolvedProperty); |
117 bool parseSuccess; | 104 bool parseSuccess; |
118 | 105 |
119 if (ruleType == StyleRule::Viewport) { | 106 if (ruleType == StyleRule::Viewport) { |
120 parseSuccess = (RuntimeEnabledFeatures::cssViewportEnabled() || isUAShee
tBehavior(context.mode())) | 107 parseSuccess = (RuntimeEnabledFeatures::cssViewportEnabled() || isUAShee
tBehavior(context.mode())) |
121 && parser.parseViewportDescriptor(resolvedProperty, important); | 108 && parser.parseViewportDescriptor(resolvedProperty, important); |
122 } else if (ruleType == StyleRule::FontFace) { | 109 } else if (ruleType == StyleRule::FontFace) { |
123 parseSuccess = parser.parseFontFaceDescriptor(resolvedProperty); | 110 parseSuccess = parser.parseFontFaceDescriptor(resolvedProperty); |
124 } else { | 111 } else { |
125 parseSuccess = parser.parseValueStart(unresolvedProperty, important); | 112 parseSuccess = parser.parseValueStart(unresolvedProperty, important); |
126 } | 113 } |
127 | 114 |
128 // This doesn't count UA style sheets | 115 // This doesn't count UA style sheets |
129 if (parseSuccess && context.useCounter()) | 116 if (parseSuccess && context.useCounter()) |
130 context.useCounter()->count(context.mode(), unresolvedProperty); | 117 context.useCounter()->count(context.mode(), unresolvedProperty); |
131 | 118 |
132 if (!parseSuccess) | 119 if (!parseSuccess) |
133 parsedProperties.shrink(parsedPropertiesSize); | 120 parsedProperties.shrink(parsedPropertiesSize); |
134 | 121 |
135 return parseSuccess; | 122 return parseSuccess; |
136 } | 123 } |
137 | 124 |
138 CSSValue* CSSPropertyParser::parseSingleValue( | 125 CSSValue* CSSPropertyParser::parseSingleValue( |
139 CSSPropertyID property, const CSSParserTokenRange& range, const CSSParserCon
text& context) | 126 CSSPropertyID property, const CSSParserTokenRange& range, const CSSParserCon
text& context) |
140 { | 127 { |
141 if (hasInvalidNumericValues(range)) | |
142 return nullptr; | |
143 CSSPropertyParser parser(range, context, nullptr); | 128 CSSPropertyParser parser(range, context, nullptr); |
144 CSSValue* value = parser.parseSingleValue(property); | 129 CSSValue* value = parser.parseSingleValue(property); |
145 if (!value || !parser.m_range.atEnd()) | 130 if (!value || !parser.m_range.atEnd()) |
146 return nullptr; | 131 return nullptr; |
147 return value; | 132 return value; |
148 } | 133 } |
149 | 134 |
150 bool CSSPropertyParser::isValidNumericValue(double value) | |
151 { | |
152 return std::isfinite(value) | |
153 && value >= -std::numeric_limits<float>::max() | |
154 && value <= std::numeric_limits<float>::max(); | |
155 } | |
156 | |
157 bool CSSPropertyParser::parseValueStart(CSSPropertyID unresolvedProperty, bool i
mportant) | 135 bool CSSPropertyParser::parseValueStart(CSSPropertyID unresolvedProperty, bool i
mportant) |
158 { | 136 { |
159 if (consumeCSSWideKeyword(unresolvedProperty, important)) | 137 if (consumeCSSWideKeyword(unresolvedProperty, important)) |
160 return true; | 138 return true; |
161 | 139 |
162 CSSParserTokenRange originalRange = m_range; | 140 CSSParserTokenRange originalRange = m_range; |
163 CSSPropertyID propertyId = resolveCSSPropertyID(unresolvedProperty); | 141 CSSPropertyID propertyId = resolveCSSPropertyID(unresolvedProperty); |
164 | 142 |
165 if (isShorthandProperty(propertyId)) { | 143 if (isShorthandProperty(propertyId)) { |
166 if (parseShorthand(unresolvedProperty, important)) | 144 if (parseShorthand(unresolvedProperty, important)) |
(...skipping 4800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4967 return consumeGridTemplateShorthand(important); | 4945 return consumeGridTemplateShorthand(important); |
4968 case CSSPropertyGrid: | 4946 case CSSPropertyGrid: |
4969 return consumeGridShorthand(important); | 4947 return consumeGridShorthand(important); |
4970 default: | 4948 default: |
4971 m_currentShorthand = oldShorthand; | 4949 m_currentShorthand = oldShorthand; |
4972 return false; | 4950 return false; |
4973 } | 4951 } |
4974 } | 4952 } |
4975 | 4953 |
4976 } // namespace blink | 4954 } // namespace blink |
OLD | NEW |