#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/core/css/rule_set.h"
#include <memory>
#include <type_traits>
#include <vector>
#include "base/containers/contains.h"
#include "base/substring_set_matcher/substring_set_matcher.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/renderer/core/css/css_font_selector.h"
#include "third_party/blink/renderer/core/css/css_selector.h"
#include "third_party/blink/renderer/core/css/css_selector_list.h"
#include "third_party/blink/renderer/core/css/robin_hood_map-inl.h"
#include "third_party/blink/renderer/core/css/seeker.h"
#include "third_party/blink/renderer/core/css/selector_checker-inl.h"
#include "third_party/blink/renderer/core/css/selector_checker.h"
#include "third_party/blink/renderer/core/css/selector_filter.h"
#include "third_party/blink/renderer/core/css/style_rule_import.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/html/shadow/shadow_element_names.h"
#include "third_party/blink/renderer/core/html/track/text_track_cue.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/inspector/invalidation_set_to_selector_map.h"
#include "third_party/blink/renderer/core/style/computed_style_constants.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
MatcherStringPattern;
SubstringSetMatcher;
namespace blink {
template <class T>
static void AddRuleToIntervals(const T* value,
unsigned position,
HeapVector<RuleSet::Interval<T>>& intervals);
static void UnmarkAsCoveredByBucketing(CSSSelector& selector);
static inline ValidPropertyFilter DetermineValidPropertyFilter(
const AddRuleFlags add_rule_flags,
const CSSSelector& selector) { … }
static bool SelectorListHasLinkOrVisited(const CSSSelector* selector_list) { … }
static bool StyleScopeHasLinkOrVisited(const StyleScope* style_scope) { … }
static unsigned DetermineLinkMatchType(const AddRuleFlags add_rule_flags,
const CSSSelector& selector,
const StyleScope* style_scope) { … }
RuleData::RuleData(StyleRule* rule,
unsigned selector_index,
unsigned position,
const StyleScope* style_scope,
AddRuleFlags add_rule_flags,
Vector<unsigned>& bloom_hash_backing)
: … { … }
void RuleData::ComputeEntirelyCoveredByBucketing() { … }
void RuleData::ResetEntirelyCoveredByBucketing() { … }
void RuleData::ComputeBloomFilterHashes(const StyleScope* style_scope,
Vector<unsigned>& bloom_hash_backing) { … }
void RuleData::MovedToDifferentRuleSet(const Vector<unsigned>& old_backing,
Vector<unsigned>& new_backing,
unsigned new_position) { … }
void RuleSet::AddToRuleSet(const AtomicString& key,
RuleMap& map,
const RuleData& rule_data) { … }
void RuleSet::AddToRuleSet(HeapVector<RuleData>& rules,
const RuleData& rule_data) { … }
static void ExtractSelectorValues(const CSSSelector* selector,
AtomicString& id,
AtomicString& class_name,
AtomicString& attr_name,
AtomicString& attr_value,
bool& is_exact_attr,
AtomicString& custom_pseudo_element_name,
AtomicString& tag_name,
AtomicString& part_name,
AtomicString& picker_name,
CSSSelector::PseudoType& pseudo_type) { … }
static const CSSSelector* ExtractBestSelectorValues(
const CSSSelector& component,
AtomicString& id,
AtomicString& class_name,
AtomicString& attr_name,
AtomicString& attr_value,
bool& is_exact_attr,
AtomicString& custom_pseudo_element_name,
AtomicString& tag_name,
AtomicString& part_name,
AtomicString& picker_name,
CSSSelector::PseudoType& pseudo_type) { … }
template <class Func>
static void MarkAsCoveredByBucketing(CSSSelector& selector,
Func&& should_mark_func) { … }
static void UnmarkAsCoveredByBucketing(CSSSelector& selector) { … }
template <RuleSet::BucketCoverage bucket_coverage>
void RuleSet::FindBestRuleSetAndAdd(CSSSelector& component,
const RuleData& rule_data) { … }
void RuleSet::AddRule(StyleRule* rule,
unsigned selector_index,
AddRuleFlags add_rule_flags,
const ContainerQuery* container_query,
const CascadeLayer* cascade_layer,
const StyleScope* style_scope) { … }
void RuleSet::AddRuleToLayerIntervals(const CascadeLayer* cascade_layer,
unsigned position) { … }
template <class T>
static void AddRuleToIntervals(const T* value,
unsigned position,
HeapVector<RuleSet::Interval<T>>& intervals) { … }
void RuleSet::AddPageRule(StyleRulePage* rule) { … }
void RuleSet::AddFontFaceRule(StyleRuleFontFace* rule) { … }
void RuleSet::AddKeyframesRule(StyleRuleKeyframes* rule) { … }
void RuleSet::AddPropertyRule(StyleRuleProperty* rule) { … }
void RuleSet::AddCounterStyleRule(StyleRuleCounterStyle* rule) { … }
void RuleSet::AddFontPaletteValuesRule(StyleRuleFontPaletteValues* rule) { … }
void RuleSet::AddFontFeatureValuesRule(StyleRuleFontFeatureValues* rule) { … }
void RuleSet::AddPositionTryRule(StyleRulePositionTry* rule) { … }
void RuleSet::AddFunctionRule(StyleRuleFunction* rule) { … }
void RuleSet::AddViewTransitionRule(StyleRuleViewTransition* rule) { … }
void RuleSet::AddChildRules(StyleRule* parent_rule,
const HeapVector<Member<StyleRuleBase>>& rules,
const MediaQueryEvaluator& medium,
AddRuleFlags add_rule_flags,
const ContainerQuery* container_query,
CascadeLayer* cascade_layer,
const StyleScope* style_scope,
bool within_mixin) { … }
bool RuleSet::MatchMediaForAddRules(const MediaQueryEvaluator& evaluator,
const MediaQuerySet* media_queries) { … }
void RuleSet::AddRulesFromSheet(StyleSheetContents* sheet,
const MediaQueryEvaluator& medium,
CascadeLayer* cascade_layer) { … }
const StyleRule* FindParentIfUsed(const CSSSelector* selector) { … }
static bool IncludeRule(const StyleRule* style_rule,
const HeapHashSet<Member<StyleRule>>& only_include) { … }
void RuleSet::NewlyAddedFromDifferentRuleSet(const RuleData& old_rule_data,
const StyleScope* style_scope,
const RuleSet& old_rule_set,
RuleData& new_rule_data) { … }
void RuleSet::AddFilteredRulesFromOtherBucket(
const RuleSet& other,
const HeapVector<RuleData>& src,
const HeapHashSet<Member<StyleRule>>& only_include,
HeapVector<RuleData>* dst) { … }
void RuleSet::AddFilteredRulesFromOtherSet(
const RuleSet& other,
const HeapHashSet<Member<StyleRule>>& only_include) { … }
void RuleSet::AddStyleRule(StyleRule* style_rule,
StyleRule* parent_rule,
const MediaQueryEvaluator& medium,
AddRuleFlags add_rule_flags,
bool within_mixin,
const ContainerQuery* container_query,
CascadeLayer* cascade_layer,
const StyleScope* style_scope) { … }
CascadeLayer* RuleSet::GetOrAddSubLayer(CascadeLayer* cascade_layer,
const StyleRuleBase::LayerName& name) { … }
bool RuleMap::Add(const AtomicString& key, const RuleData& rule_data) { … }
void RuleMap::Compact() { … }
void RuleMap::Uncompact() { … }
void RuleMap::AddFilteredRulesFromOtherSet(
const RuleMap& other,
const HeapHashSet<Member<StyleRule>>& only_include,
const RuleSet& old_rule_set,
RuleSet& new_rule_set) { … }
static wtf_size_t GetMinimumRulesetSizeForSubstringMatcher() { … }
bool RuleSet::CanIgnoreEntireList(base::span<const RuleData> list,
const AtomicString& key,
const AtomicString& value) const { … }
void RuleSet::CreateSubstringMatchers(
RuleMap& attr_map,
RuleSet::SubstringMatcherMap& substring_matcher_map) { … }
void RuleSet::CompactRules() { … }
#if EXPENSIVE_DCHECKS_ARE_ON()
namespace {
bool AllowSamePosition(const RuleData& current, const RuleData& previous) { … }
template <class RuleList>
bool IsRuleListSorted(const RuleList& rules) { … }
}
void RuleSet::AssertRuleListsSorted() const { … }
#endif
bool RuleSet::DidMediaQueryResultsChange(
const MediaQueryEvaluator& evaluator) const { … }
const CascadeLayer* RuleSet::GetLayerForTest(const RuleData& rule) const { … }
void RuleData::Trace(Visitor* visitor) const { … }
template <class T>
void RuleSet::Interval<T>::Trace(Visitor* visitor) const { … }
void RuleSet::Trace(Visitor* visitor) const { … }
#if DCHECK_IS_ON()
void RuleSet::Show() const { … }
#endif
}