#include "extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.h"
#include <stddef.h>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/lazy_instance.h"
#include "base/memory/ptr_util.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/values.h"
#include "extensions/browser/api/declarative/deduping_factory.h"
#include "extensions/browser/api/declarative_webrequest/request_stage.h"
#include "extensions/browser/api/declarative_webrequest/webrequest_condition.h"
#include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
#include "extensions/browser/api/extensions_api_client.h"
#include "extensions/browser/api/web_request/web_request_api_helpers.h"
#include "extensions/browser/api/web_request/web_request_info.h"
#include "extensions/browser/api/web_request/web_request_resource_type.h"
#include "extensions/common/error_utils.h"
#include "net/base/net_errors.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_util.h"
CaseInsensitiveCompareASCII;
Value;
helpers;
keys;
namespace extensions {
namespace {
const char kInvalidValue[] = …;
struct WebRequestConditionAttributeFactory { … };
base::LazyInstance<WebRequestConditionAttributeFactory>::Leaky
g_web_request_condition_attribute_factory = …;
}
WebRequestConditionAttribute::WebRequestConditionAttribute() = default;
WebRequestConditionAttribute::~WebRequestConditionAttribute() = default;
bool WebRequestConditionAttribute::Equals(
const WebRequestConditionAttribute* other) const { … }
scoped_refptr<const WebRequestConditionAttribute>
WebRequestConditionAttribute::Create(
const std::string& name,
const base::Value* value,
std::string* error) { … }
WebRequestConditionAttributeResourceType::
WebRequestConditionAttributeResourceType(
const std::vector<WebRequestResourceType>& types)
: … { … }
WebRequestConditionAttributeResourceType::
~WebRequestConditionAttributeResourceType() { … }
scoped_refptr<const WebRequestConditionAttribute>
WebRequestConditionAttributeResourceType::Create(
const std::string& instance_type,
const base::Value* value,
std::string* error,
bool* bad_message) { … }
int WebRequestConditionAttributeResourceType::GetStages() const { … }
bool WebRequestConditionAttributeResourceType::IsFulfilled(
const WebRequestData& request_data) const { … }
WebRequestConditionAttribute::Type
WebRequestConditionAttributeResourceType::GetType() const { … }
std::string WebRequestConditionAttributeResourceType::GetName() const { … }
bool WebRequestConditionAttributeResourceType::Equals(
const WebRequestConditionAttribute* other) const { … }
WebRequestConditionAttributeContentType::
WebRequestConditionAttributeContentType(
const std::vector<std::string>& content_types,
bool inclusive)
: … { … }
WebRequestConditionAttributeContentType::
~WebRequestConditionAttributeContentType() { … }
scoped_refptr<const WebRequestConditionAttribute>
WebRequestConditionAttributeContentType::Create(
const std::string& name,
const base::Value* value,
std::string* error,
bool* bad_message) { … }
int WebRequestConditionAttributeContentType::GetStages() const { … }
bool WebRequestConditionAttributeContentType::IsFulfilled(
const WebRequestData& request_data) const { … }
WebRequestConditionAttribute::Type
WebRequestConditionAttributeContentType::GetType() const { … }
std::string WebRequestConditionAttributeContentType::GetName() const { … }
bool WebRequestConditionAttributeContentType::Equals(
const WebRequestConditionAttribute* other) const { … }
class HeaderMatcher { … };
HeaderMatcher::~HeaderMatcher() = default;
std::unique_ptr<const HeaderMatcher> HeaderMatcher::Create(
const base::Value::List& tests) { … }
bool HeaderMatcher::TestNameValue(const std::string& name,
const std::string& value) const { … }
HeaderMatcher::HeaderMatcher(
std::vector<std::unique_ptr<const HeaderMatchTest>> tests)
: … { … }
std::unique_ptr<HeaderMatcher::StringMatchTest>
HeaderMatcher::StringMatchTest::Create(const base::Value& data,
MatchType type,
bool case_sensitive) { … }
HeaderMatcher::StringMatchTest::~StringMatchTest() = default;
bool HeaderMatcher::StringMatchTest::Matches(
const std::string& str) const { … }
HeaderMatcher::StringMatchTest::StringMatchTest(const std::string& data,
MatchType type,
bool case_sensitive)
: … { … }
HeaderMatcher::HeaderMatchTest::HeaderMatchTest(
std::vector<std::unique_ptr<const StringMatchTest>> name_match,
std::vector<std::unique_ptr<const StringMatchTest>> value_match)
: … { … }
HeaderMatcher::HeaderMatchTest::~HeaderMatchTest() = default;
std::unique_ptr<const HeaderMatcher::HeaderMatchTest>
HeaderMatcher::HeaderMatchTest::Create(const base::Value::Dict& tests) { … }
bool HeaderMatcher::HeaderMatchTest::Matches(const std::string& name,
const std::string& value) const { … }
WebRequestConditionAttributeRequestHeaders::
WebRequestConditionAttributeRequestHeaders(
std::unique_ptr<const HeaderMatcher> header_matcher,
bool positive)
: … { … }
WebRequestConditionAttributeRequestHeaders::
~WebRequestConditionAttributeRequestHeaders() { … }
namespace {
std::unique_ptr<const HeaderMatcher> PrepareHeaderMatcher(
const std::string& name,
const base::Value* value,
std::string* error) { … }
}
scoped_refptr<const WebRequestConditionAttribute>
WebRequestConditionAttributeRequestHeaders::Create(
const std::string& name,
const base::Value* value,
std::string* error,
bool* bad_message) { … }
int WebRequestConditionAttributeRequestHeaders::GetStages() const { … }
bool WebRequestConditionAttributeRequestHeaders::IsFulfilled(
const WebRequestData& request_data) const { … }
WebRequestConditionAttribute::Type
WebRequestConditionAttributeRequestHeaders::GetType() const { … }
std::string WebRequestConditionAttributeRequestHeaders::GetName() const { … }
bool WebRequestConditionAttributeRequestHeaders::Equals(
const WebRequestConditionAttribute* other) const { … }
WebRequestConditionAttributeResponseHeaders::
WebRequestConditionAttributeResponseHeaders(
std::unique_ptr<const HeaderMatcher> header_matcher,
bool positive)
: … { … }
WebRequestConditionAttributeResponseHeaders::
~WebRequestConditionAttributeResponseHeaders() { … }
scoped_refptr<const WebRequestConditionAttribute>
WebRequestConditionAttributeResponseHeaders::Create(
const std::string& name,
const base::Value* value,
std::string* error,
bool* bad_message) { … }
int WebRequestConditionAttributeResponseHeaders::GetStages() const { … }
bool WebRequestConditionAttributeResponseHeaders::IsFulfilled(
const WebRequestData& request_data) const { … }
WebRequestConditionAttribute::Type
WebRequestConditionAttributeResponseHeaders::GetType() const { … }
std::string WebRequestConditionAttributeResponseHeaders::GetName() const { … }
bool WebRequestConditionAttributeResponseHeaders::Equals(
const WebRequestConditionAttribute* other) const { … }
WebRequestConditionAttributeStages::
WebRequestConditionAttributeStages(int allowed_stages)
: … { … }
WebRequestConditionAttributeStages::
~WebRequestConditionAttributeStages() { … }
namespace {
bool ParseListOfStages(const base::Value& value, int* out_stages) { … }
}
scoped_refptr<const WebRequestConditionAttribute>
WebRequestConditionAttributeStages::Create(const std::string& name,
const base::Value* value,
std::string* error,
bool* bad_message) { … }
int WebRequestConditionAttributeStages::GetStages() const { … }
bool WebRequestConditionAttributeStages::IsFulfilled(
const WebRequestData& request_data) const { … }
WebRequestConditionAttribute::Type
WebRequestConditionAttributeStages::GetType() const { … }
std::string WebRequestConditionAttributeStages::GetName() const { … }
bool WebRequestConditionAttributeStages::Equals(
const WebRequestConditionAttribute* other) const { … }
}