#include "components/url_matcher/url_matcher.h"
#include <algorithm>
#include <iterator>
#include <utility>
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/memory/ptr_util.h"
#include "base/notreached.h"
#include "url/gurl.h"
#include "url/url_canon.h"
MatcherStringPattern;
SubstringSetMatcher;
namespace url_matcher {
namespace {
bool IsRegexCriterion(URLMatcherCondition::Criterion criterion) { … }
bool IsOriginAndPathRegexCriterion(URLMatcherCondition::Criterion criterion) { … }
bool IsMatcherEmpty(const std::unique_ptr<SubstringSetMatcher>& matcher) { … }
}
URLMatcherCondition::URLMatcherCondition()
: … { … }
URLMatcherCondition::~URLMatcherCondition() { … }
URLMatcherCondition::URLMatcherCondition(
Criterion criterion,
const MatcherStringPattern* string_pattern)
: … { … }
URLMatcherCondition::URLMatcherCondition(const URLMatcherCondition& rhs)
: … { … }
URLMatcherCondition& URLMatcherCondition::operator=(
const URLMatcherCondition& rhs) { … }
bool URLMatcherCondition::operator<(const URLMatcherCondition& rhs) const { … }
bool URLMatcherCondition::IsFullURLCondition() const { … }
bool URLMatcherCondition::IsRegexCondition() const { … }
bool URLMatcherCondition::IsOriginAndPathRegexCondition() const { … }
bool URLMatcherCondition::IsMatch(
const std::set<MatcherStringPattern::ID>& matching_patterns,
const GURL& url) const { … }
namespace {
const char kBeginningOfURL[] = …;
const char kEndOfDomain[] = …;
const char kEndOfPath[] = …;
const char kQueryComponentDelimiter[] = …;
const char kEndOfURL[] = …;
const char kQuerySeparator = …;
}
URLMatcherConditionFactory::URLMatcherConditionFactory() = default;
URLMatcherConditionFactory::~URLMatcherConditionFactory() = default;
std::string URLMatcherConditionFactory::CanonicalizeURLForComponentSearches(
const GURL& url) const { … }
URLMatcherCondition URLMatcherConditionFactory::CreateHostPrefixCondition(
const std::string& prefix) { … }
URLMatcherCondition URLMatcherConditionFactory::CreateHostSuffixCondition(
const std::string& suffix) { … }
URLMatcherCondition URLMatcherConditionFactory::CreateHostContainsCondition(
const std::string& str) { … }
URLMatcherCondition URLMatcherConditionFactory::CreateHostEqualsCondition(
const std::string& str) { … }
URLMatcherCondition URLMatcherConditionFactory::CreatePathPrefixCondition(
const std::string& prefix) { … }
URLMatcherCondition URLMatcherConditionFactory::CreatePathSuffixCondition(
const std::string& suffix) { … }
URLMatcherCondition URLMatcherConditionFactory::CreatePathContainsCondition(
const std::string& str) { … }
URLMatcherCondition URLMatcherConditionFactory::CreatePathEqualsCondition(
const std::string& str) { … }
URLMatcherCondition URLMatcherConditionFactory::CreateQueryPrefixCondition(
const std::string& prefix) { … }
URLMatcherCondition URLMatcherConditionFactory::CreateQuerySuffixCondition(
const std::string& suffix) { … }
URLMatcherCondition URLMatcherConditionFactory::CreateQueryContainsCondition(
const std::string& str) { … }
URLMatcherCondition URLMatcherConditionFactory::CreateQueryEqualsCondition(
const std::string& str) { … }
URLMatcherCondition
URLMatcherConditionFactory::CreateHostSuffixPathPrefixCondition(
const std::string& host_suffix,
const std::string& path_prefix) { … }
URLMatcherCondition
URLMatcherConditionFactory::CreateHostEqualsPathPrefixCondition(
const std::string& host,
const std::string& path_prefix) { … }
std::string URLMatcherConditionFactory::CanonicalizeURLForFullSearches(
const GURL& url) const { … }
static std::string CanonicalizeURLForRegexSearchesHelper(const GURL& url,
bool clear_query) { … }
std::string URLMatcherConditionFactory::CanonicalizeURLForRegexSearches(
const GURL& url) const { … }
std::string
URLMatcherConditionFactory::CanonicalizeURLForOriginAndPathRegexSearches(
const GURL& url) const { … }
URLMatcherCondition URLMatcherConditionFactory::CreateURLPrefixCondition(
const std::string& prefix) { … }
URLMatcherCondition URLMatcherConditionFactory::CreateURLSuffixCondition(
const std::string& suffix) { … }
URLMatcherCondition URLMatcherConditionFactory::CreateURLContainsCondition(
const std::string& str) { … }
URLMatcherCondition URLMatcherConditionFactory::CreateURLEqualsCondition(
const std::string& str) { … }
URLMatcherCondition URLMatcherConditionFactory::CreateURLMatchesCondition(
const std::string& regex) { … }
URLMatcherCondition
URLMatcherConditionFactory::CreateOriginAndPathMatchesCondition(
const std::string& regex) { … }
void URLMatcherConditionFactory::ForgetUnusedPatterns(
const std::set<MatcherStringPattern::ID>& used_patterns) { … }
bool URLMatcherConditionFactory::IsEmpty() const { … }
URLMatcherCondition URLMatcherConditionFactory::CreateCondition(
URLMatcherCondition::Criterion criterion,
const std::string& pattern) { … }
std::string URLMatcherConditionFactory::CanonicalizeHostSuffix(
const std::string& suffix) const { … }
std::string URLMatcherConditionFactory::CanonicalizeHostPrefix(
const std::string& prefix) const { … }
std::string URLMatcherConditionFactory::CanonicalizeHostname(
const std::string& hostname) const { … }
std::string URLMatcherConditionFactory::CanonicalizeQuery(
std::string query,
bool prepend_beginning_of_query_component,
bool append_end_of_query_component) const { … }
base::MatcherStringPattern::ID URLMatcherConditionFactory::GetNextID() { … }
bool URLMatcherConditionFactory::MatcherStringPatternPointerCompare::operator()(
MatcherStringPattern* lhs,
MatcherStringPattern* rhs) const { … }
URLQueryElementMatcherCondition::URLQueryElementMatcherCondition(
const std::string& key,
const std::string& value,
QueryValueMatchType query_value_match_type,
QueryElementType query_element_type,
Type match_type,
URLMatcherConditionFactory* factory) { … }
URLQueryElementMatcherCondition::URLQueryElementMatcherCondition(
const URLQueryElementMatcherCondition& other) = default;
URLQueryElementMatcherCondition::~URLQueryElementMatcherCondition() { … }
bool URLQueryElementMatcherCondition::operator<(
const URLQueryElementMatcherCondition& rhs) const { … }
bool URLQueryElementMatcherCondition::IsMatch(
const std::string& url_for_component_searches) const { … }
URLMatcherSchemeFilter::URLMatcherSchemeFilter(const std::string& filter)
: … { … }
URLMatcherSchemeFilter::URLMatcherSchemeFilter(
const std::vector<std::string>& filters)
: … { … }
URLMatcherSchemeFilter::~URLMatcherSchemeFilter() { … }
bool URLMatcherSchemeFilter::IsMatch(const GURL& url) const { … }
URLMatcherPortFilter::URLMatcherPortFilter(
const std::vector<URLMatcherPortFilter::Range>& ranges)
: … { … }
URLMatcherPortFilter::~URLMatcherPortFilter() { … }
bool URLMatcherPortFilter::IsMatch(const GURL& url) const { … }
URLMatcherPortFilter::Range URLMatcherPortFilter::CreateRange(int from,
int to) { … }
URLMatcherPortFilter::Range URLMatcherPortFilter::CreateRange(int port) { … }
URLMatcherCidrBlockFilter::URLMatcherCidrBlockFilter(
const std::vector<URLMatcherCidrBlockFilter::CidrBlock>& cidr_blocks)
: … { … }
URLMatcherCidrBlockFilter::~URLMatcherCidrBlockFilter() = default;
bool URLMatcherCidrBlockFilter::IsMatch(const GURL& url) const { … }
base::expected<URLMatcherCidrBlockFilter::CidrBlock, std::string>
URLMatcherCidrBlockFilter::CreateCidrBlock(const std::string& entry) { … }
URLMatcherConditionSet::~URLMatcherConditionSet() { … }
URLMatcherConditionSet::URLMatcherConditionSet(
base::MatcherStringPattern::ID id,
const Conditions& conditions)
: … { … }
URLMatcherConditionSet::URLMatcherConditionSet(
base::MatcherStringPattern::ID id,
const Conditions& conditions,
std::unique_ptr<URLMatcherSchemeFilter> scheme_filter,
std::unique_ptr<URLMatcherPortFilter> port_filter,
std::unique_ptr<URLMatcherCidrBlockFilter> cidr_block_filter)
: … { … }
URLMatcherConditionSet::URLMatcherConditionSet(
base::MatcherStringPattern::ID id,
const Conditions& conditions,
const QueryConditions& query_conditions,
std::unique_ptr<URLMatcherSchemeFilter> scheme_filter,
std::unique_ptr<URLMatcherPortFilter> port_filter)
: … { … }
bool URLMatcherConditionSet::IsMatch(
const std::set<MatcherStringPattern::ID>& matching_patterns,
const GURL& url) const { … }
bool URLMatcherConditionSet::IsMatch(
const std::set<MatcherStringPattern::ID>& matching_patterns,
const GURL& url,
const std::string& url_for_component_searches) const { … }
URLMatcher::URLMatcher() { … }
URLMatcher::~URLMatcher() { … }
void URLMatcher::AddConditionSets(
const URLMatcherConditionSet::Vector& condition_sets) { … }
void URLMatcher::RemoveConditionSets(
const std::vector<base::MatcherStringPattern::ID>& condition_set_ids) { … }
void URLMatcher::ClearUnusedConditionSets() { … }
std::set<base::MatcherStringPattern::ID> URLMatcher::MatchURL(
const GURL& url) const { … }
bool URLMatcher::IsEmpty() const { … }
void URLMatcher::UpdateSubstringSetMatcher(bool full_url_conditions) { … }
void URLMatcher::UpdateRegexSetMatcher() { … }
void URLMatcher::UpdateTriggers() { … }
void URLMatcher::UpdateConditionFactory() { … }
void URLMatcher::UpdateInternalDatastructures() { … }
}