#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/core/css/parser/css_parser_impl.h"
#include <bitset>
#include <limits>
#include <memory>
#include <utility>
#include "base/cpu.h"
#include "third_party/blink/renderer/core/animation/timeline_offset.h"
#include "third_party/blink/renderer/core/core_probes_inl.h"
#include "third_party/blink/renderer/core/css/css_custom_ident_value.h"
#include "third_party/blink/renderer/core/css/css_font_family_value.h"
#include "third_party/blink/renderer/core/css/css_keyframes_rule.h"
#include "third_party/blink/renderer/core/css/css_position_try_rule.h"
#include "third_party/blink/renderer/core/css/css_primitive_value_mappings.h"
#include "third_party/blink/renderer/core/css/css_selector.h"
#include "third_party/blink/renderer/core/css/css_style_sheet.h"
#include "third_party/blink/renderer/core/css/css_syntax_string_parser.h"
#include "third_party/blink/renderer/core/css/css_unparsed_declaration_value.h"
#include "third_party/blink/renderer/core/css/parser/at_rule_descriptor_parser.h"
#include "third_party/blink/renderer/core/css/parser/container_query_parser.h"
#include "third_party/blink/renderer/core/css/parser/css_at_rule_id.h"
#include "third_party/blink/renderer/core/css/parser/css_lazy_parsing_state.h"
#include "third_party/blink/renderer/core/css/parser/css_lazy_property_parser_impl.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_observer.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_token_stream.h"
#include "third_party/blink/renderer/core/css/parser/css_property_parser.h"
#include "third_party/blink/renderer/core/css/parser/css_selector_parser.h"
#include "third_party/blink/renderer/core/css/parser/css_supports_parser.h"
#include "third_party/blink/renderer/core/css/parser/css_tokenizer.h"
#include "third_party/blink/renderer/core/css/parser/css_variable_parser.h"
#include "third_party/blink/renderer/core/css/parser/find_length_of_declaration_list-inl.h"
#include "third_party/blink/renderer/core/css/parser/media_query_parser.h"
#include "third_party/blink/renderer/core/css/properties/css_parsing_utils.h"
#include "third_party/blink/renderer/core/css/property_registry.h"
#include "third_party/blink/renderer/core/css/style_rule_counter_style.h"
#include "third_party/blink/renderer/core/css/style_rule_font_feature_values.h"
#include "third_party/blink/renderer/core/css/style_rule_font_palette_values.h"
#include "third_party/blink/renderer/core/css/style_rule_import.h"
#include "third_party/blink/renderer/core/css/style_rule_keyframe.h"
#include "third_party/blink/renderer/core/css/style_rule_namespace.h"
#include "third_party/blink/renderer/core/css/style_rule_nested_declarations.h"
#include "third_party/blink/renderer/core/css/style_sheet_contents.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/frame/local_frame_ukm_aggregator.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
#include "third_party/blink/renderer/platform/wtf/text/text_position.h"
swap;
namespace blink {
namespace {
AtomicString ConsumeStringOrURI(CSSParserTokenStream& stream) { … }
StyleRuleBase::LayerName ConsumeCascadeLayerName(CSSParserTokenStream& stream) { … }
StyleRule::RuleType RuleTypeForMutableDeclaration(
MutableCSSPropertyValueSet* declaration) { … }
std::optional<StyleRuleFontFeature::FeatureType> ToStyleRuleFontFeatureType(
CSSAtRuleID rule_id) { … }
}
CSSParserImpl::CSSParserImpl(const CSSParserContext* context,
StyleSheetContents* style_sheet)
: … { … }
MutableCSSPropertyValueSet::SetResult CSSParserImpl::ParseValue(
MutableCSSPropertyValueSet* declaration,
CSSPropertyID unresolved_property,
StringView string,
bool important,
const CSSParserContext* context) { … }
MutableCSSPropertyValueSet::SetResult CSSParserImpl::ParseVariableValue(
MutableCSSPropertyValueSet* declaration,
const AtomicString& property_name,
StringView value,
bool important,
const CSSParserContext* context,
bool is_animation_tainted) { … }
static inline void FilterProperties(
bool important,
const HeapVector<CSSPropertyValue, 64>& input,
HeapVector<CSSPropertyValue, 64>& output,
wtf_size_t& unused_entries,
std::bitset<kNumCSSProperties>& seen_properties,
HashSet<AtomicString>& seen_custom_properties) { … }
static ImmutableCSSPropertyValueSet* CreateCSSPropertyValueSet(
HeapVector<CSSPropertyValue, 64>& parsed_properties,
CSSParserMode mode,
const Document* document) { … }
ImmutableCSSPropertyValueSet* CSSParserImpl::ParseInlineStyleDeclaration(
const String& string,
Element* element) { … }
ImmutableCSSPropertyValueSet* CSSParserImpl::ParseInlineStyleDeclaration(
const String& string,
CSSParserMode parser_mode,
SecureContextMode secure_context_mode,
const Document* document) { … }
bool CSSParserImpl::ParseDeclarationList(
MutableCSSPropertyValueSet* declaration,
const String& string,
const CSSParserContext* context) { … }
StyleRuleBase* CSSParserImpl::ParseRule(const String& string,
const CSSParserContext* context,
CSSNestingType nesting_type,
StyleRule* parent_rule_for_nesting,
StyleSheetContents* style_sheet,
AllowedRulesType allowed_rules) { … }
ParseSheetResult CSSParserImpl::ParseStyleSheet(
const String& string,
const CSSParserContext* context,
StyleSheetContents* style_sheet,
CSSDeferPropertyParsing defer_property_parsing,
bool allow_import_rules) { … }
CSSSelectorList* CSSParserImpl::ParsePageSelector(
CSSParserTokenStream& stream,
StyleSheetContents* style_sheet,
const CSSParserContext& context) { … }
std::unique_ptr<Vector<KeyframeOffset>> CSSParserImpl::ParseKeyframeKeyList(
const CSSParserContext* context,
const String& key_list) { … }
String CSSParserImpl::ParseCustomPropertyName(const String& name_text) { … }
bool CSSParserImpl::ConsumeSupportsDeclaration(CSSParserTokenStream& stream) { … }
void CSSParserImpl::ParseDeclarationListForInspector(
const String& declaration,
const CSSParserContext* context,
CSSParserObserver& observer) { … }
void CSSParserImpl::ParseStyleSheetForInspector(const String& string,
const CSSParserContext* context,
StyleSheetContents* style_sheet,
CSSParserObserver& observer) { … }
CSSPropertyValueSet* CSSParserImpl::ParseDeclarationListForLazyStyle(
const String& string,
wtf_size_t offset,
const CSSParserContext* context) { … }
static CSSParserImpl::AllowedRulesType ComputeNewAllowedRules(
CSSParserImpl::AllowedRulesType allowed_rules,
StyleRuleBase* rule) { … }
template <typename T>
bool CSSParserImpl::ConsumeRuleList(CSSParserTokenStream& stream,
RuleListType rule_list_type,
CSSNestingType nesting_type,
StyleRule* parent_rule_for_nesting,
const T callback) { … }
CSSParserTokenRange ConsumeAtRulePrelude(CSSParserTokenStream& stream) { … }
bool CSSParserImpl::ConsumeEndOfPreludeForAtRuleWithoutBlock(
CSSParserTokenStream& stream,
CSSAtRuleID id) { … }
bool CSSParserImpl::ConsumeEndOfPreludeForAtRuleWithBlock(
CSSParserTokenStream& stream,
CSSAtRuleID id) { … }
void CSSParserImpl::ConsumeErroneousAtRule(CSSParserTokenStream& stream,
CSSAtRuleID id) { … }
StyleRuleBase* CSSParserImpl::ConsumeAtRule(
CSSParserTokenStream& stream,
AllowedRulesType allowed_rules,
CSSNestingType nesting_type,
StyleRule* parent_rule_for_nesting) { … }
StyleRuleBase* CSSParserImpl::ConsumeAtRuleContents(
CSSAtRuleID id,
CSSParserTokenStream& stream,
AllowedRulesType allowed_rules,
CSSNestingType nesting_type,
StyleRule* parent_rule_for_nesting) { … }
StyleRuleBase* CSSParserImpl::ConsumeQualifiedRule(
CSSParserTokenStream& stream,
AllowedRulesType allowed_rules,
CSSNestingType nesting_type,
StyleRule* parent_rule_for_nesting) { … }
StyleRulePageMargin* CSSParserImpl::ConsumePageMarginRule(
CSSAtRuleID rule_id,
CSSParserTokenStream& stream) { … }
StyleRuleCharset* CSSParserImpl::ConsumeCharsetRule(
CSSParserTokenStream& stream) { … }
static CSSParserTokenOffsets ReparseForOffsets(
const StringView prelude,
const CSSParserTokenRange range) { … }
StyleRuleImport* CSSParserImpl::ConsumeImportRule(
const AtomicString& uri,
CSSParserTokenStream& stream) { … }
StyleRuleNamespace* CSSParserImpl::ConsumeNamespaceRule(
CSSParserTokenStream& stream) { … }
StyleRule* CSSParserImpl::CreateImplicitNestedRule(
CSSNestingType nesting_type,
StyleRule* parent_rule_for_nesting) { … }
namespace {
HeapVector<CSSSelector> CopySelectors(const CSSSelector* selector_list) { … }
HeapVector<CSSSelector> WhereScopeSelector() { … }
}
StyleRuleNestedDeclarations* CSSParserImpl::CreateNestedDeclarationsRule(
CSSNestingType nesting_type,
const CSSSelector* selector_list,
wtf_size_t start_index,
wtf_size_t end_index) { … }
void CSSParserImpl::EmitNestedDeclarationsRuleIfNeeded(
CSSNestingType nesting_type,
StyleRule* parent_rule_for_nesting,
wtf_size_t start_index,
HeapVector<Member<StyleRuleBase>, 4>& child_rules) { … }
StyleRuleMedia* CSSParserImpl::ConsumeMediaRule(
CSSParserTokenStream& stream,
CSSNestingType nesting_type,
StyleRule* parent_rule_for_nesting) { … }
StyleRuleSupports* CSSParserImpl::ConsumeSupportsRule(
CSSParserTokenStream& stream,
CSSNestingType nesting_type,
StyleRule* parent_rule_for_nesting) { … }
StyleRuleStartingStyle* CSSParserImpl::ConsumeStartingStyleRule(
CSSParserTokenStream& stream,
CSSNestingType nesting_type,
StyleRule* parent_rule_for_nesting) { … }
StyleRuleFontFace* CSSParserImpl::ConsumeFontFaceRule(
CSSParserTokenStream& stream) { … }
StyleRuleKeyframes* CSSParserImpl::ConsumeKeyframesRule(
bool webkit_prefixed,
CSSParserTokenStream& stream) { … }
StyleRuleFontFeature* CSSParserImpl::ConsumeFontFeatureRule(
CSSAtRuleID rule_id,
CSSParserTokenStream& stream) { … }
StyleRuleFontFeatureValues* CSSParserImpl::ConsumeFontFeatureValuesRule(
CSSParserTokenStream& stream) { … }
StyleRulePage* CSSParserImpl::ConsumePageRule(CSSParserTokenStream& stream) { … }
StyleRuleProperty* CSSParserImpl::ConsumePropertyRule(
CSSParserTokenStream& stream) { … }
StyleRuleCounterStyle* CSSParserImpl::ConsumeCounterStyleRule(
CSSParserTokenStream& stream) { … }
StyleRuleFontPaletteValues* CSSParserImpl::ConsumeFontPaletteValuesRule(
CSSParserTokenStream& stream) { … }
StyleRuleBase* CSSParserImpl::ConsumeScopeRule(
CSSParserTokenStream& stream,
CSSNestingType nesting_type,
StyleRule* parent_rule_for_nesting) { … }
StyleRuleViewTransition* CSSParserImpl::ConsumeViewTransitionRule(
CSSParserTokenStream& stream) { … }
StyleRuleContainer* CSSParserImpl::ConsumeContainerRule(
CSSParserTokenStream& stream,
CSSNestingType nesting_type,
StyleRule* parent_rule_for_nesting) { … }
StyleRuleBase* CSSParserImpl::ConsumeLayerRule(
CSSParserTokenStream& stream,
CSSNestingType nesting_type,
StyleRule* parent_rule_for_nesting) { … }
StyleRulePositionTry* CSSParserImpl::ConsumePositionTryRule(
CSSParserTokenStream& stream) { … }
static std::optional<StyleRuleFunction::Type> ParseFunctionType(
StringView type_name) { … }
StyleRuleFunction* CSSParserImpl::ConsumeFunctionRule(
CSSParserTokenStream& stream) { … }
StyleRuleMixin* CSSParserImpl::ConsumeMixinRule(CSSParserTokenStream& stream) { … }
StyleRuleApplyMixin* CSSParserImpl::ConsumeApplyMixinRule(
CSSParserTokenStream& stream) { … }
std::optional<Vector<StyleRuleFunction::Parameter>>
CSSParserImpl::ConsumeFunctionParameters(CSSParserTokenStream& stream) { … }
StyleRuleKeyframe* CSSParserImpl::ConsumeKeyframeStyleRule(
const CSSParserTokenRange prelude,
const RangeOffset& prelude_offset,
CSSParserTokenStream& block) { … }
static bool MayContainNestedRules(const String& text,
wtf_size_t offset,
wtf_size_t length) { … }
StyleRule* CSSParserImpl::ConsumeStyleRule(
CSSParserTokenStream& stream,
CSSNestingType nesting_type,
StyleRule* parent_rule_for_nesting,
bool semicolon_aborts_nested_selector) { … }
StyleRule* CSSParserImpl::ConsumeStyleRuleContents(
base::span<CSSSelector> selector_vector,
CSSParserTokenStream& stream) { … }
void CSSParserImpl::ConsumeDeclarationList(
CSSParserTokenStream& stream,
StyleRule::RuleType rule_type,
CSSNestingType nesting_type,
StyleRule* parent_rule_for_nesting,
wtf_size_t nested_declarations_start_index,
HeapVector<Member<StyleRuleBase>, 4>* child_rules) { … }
void CSSParserImpl::ConsumeRuleListOrNestedDeclarationList(
CSSParserTokenStream& stream,
bool is_nested_group_rule,
CSSNestingType nesting_type,
StyleRule* parent_rule_for_nesting,
HeapVector<Member<StyleRuleBase>, 4>* child_rules) { … }
StyleRuleBase* CSSParserImpl::ConsumeNestedRule(
std::optional<CSSAtRuleID> id,
StyleRule::RuleType parent_rule_type,
CSSParserTokenStream& stream,
CSSNestingType nesting_type,
StyleRule* parent_rule_for_nesting) { … }
bool CSSParserImpl::ConsumeDeclaration(CSSParserTokenStream& stream,
StyleRule::RuleType rule_type) { … }
bool CSSParserImpl::ConsumeVariableValue(CSSParserTokenStream& stream,
const AtomicString& variable_name,
bool allow_important_annotation,
bool is_animation_tainted) { … }
void CSSParserImpl::ConsumeDeclarationValue(CSSParserTokenStream& stream,
CSSPropertyID unresolved_property,
bool is_in_declaration_list,
StyleRule::RuleType rule_type) { … }
std::unique_ptr<Vector<KeyframeOffset>> CSSParserImpl::ConsumeKeyframeKeyList(
const CSSParserContext* context,
CSSParserTokenRange range) { … }
const MediaQuerySet* CSSParserImpl::CachedMediaQuerySet(
String prelude_string,
CSSParserTokenRange prelude,
const CSSParserTokenOffsets& offsets) { … }
CSSParserMode CSSParserImpl::GetMode() const { … }
}