#include "extensions/browser/api/declarative_webrequest/webrequest_action.h"
#include <limits>
#include <utility>
#include "base/check_op.h"
#include "base/lazy_instance.h"
#include "base/notreached.h"
#include "base/strings/string_util.h"
#include "base/values.h"
#include "content/public/common/url_constants.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/web_request/web_request_api_constants.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_permissions.h"
#include "extensions/browser/extension_navigation_ui_data.h"
#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_id.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/http/http_util.h"
#include "third_party/abseil-cpp/absl/strings/ascii.h"
#include "third_party/re2/src/re2/re2.h"
EventResponseDelta;
namespace extensions {
helpers;
keys;
namespace {
const char kIgnoreRulesRequiresParameterError[] = …;
const char kTransparentImageUrl[] = …;
const char kEmptyDocumentUrl[] = …;
#define INPUT_FORMAT_VALIDATE(test) …
helpers::RequestCookie ParseRequestCookie(const base::Value::Dict& dict) { … }
void ParseResponseCookieImpl(const base::Value::Dict& dict,
helpers::ResponseCookie* cookie) { … }
helpers::ResponseCookie ParseResponseCookie(const base::Value::Dict& dict) { … }
helpers::FilterResponseCookie ParseFilterResponseCookie(
const base::Value::Dict& dict) { … }
template <class T>
scoped_refptr<const WebRequestAction> CallConstructorFactoryMethod(
const std::string& instance_type,
const base::Value::Dict& value,
std::string* error,
bool* bad_message) { … }
scoped_refptr<const WebRequestAction> CreateRedirectRequestAction(
const std::string& instance_type,
const base::Value::Dict& value,
std::string* error,
bool* bad_message) { … }
scoped_refptr<const WebRequestAction> CreateRedirectRequestByRegExAction(
const std::string& instance_type,
const base::Value::Dict& value,
std::string* error,
bool* bad_message) { … }
scoped_refptr<const WebRequestAction> CreateSetRequestHeaderAction(
const std::string& instance_type,
const base::Value::Dict& dict,
std::string* error,
bool* bad_message) { … }
scoped_refptr<const WebRequestAction> CreateRemoveRequestHeaderAction(
const std::string& instance_type,
const base::Value::Dict& value,
std::string* error,
bool* bad_message) { … }
scoped_refptr<const WebRequestAction> CreateAddResponseHeaderAction(
const std::string& instance_type,
const base::Value::Dict& dict,
std::string* error,
bool* bad_message) { … }
scoped_refptr<const WebRequestAction> CreateRemoveResponseHeaderAction(
const std::string& instance_type,
const base::Value::Dict& dict,
std::string* error,
bool* bad_message) { … }
scoped_refptr<const WebRequestAction> CreateIgnoreRulesAction(
const std::string& instance_type,
const base::Value::Dict& value,
std::string* error,
bool* bad_message) { … }
scoped_refptr<const WebRequestAction> CreateRequestCookieAction(
const std::string& instance_type,
const base::Value::Dict& value,
std::string* error,
bool* bad_message) { … }
scoped_refptr<const WebRequestAction> CreateResponseCookieAction(
const std::string& instance_type,
const base::Value::Dict& value,
std::string* error,
bool* bad_message) { … }
scoped_refptr<const WebRequestAction> CreateSendMessageToExtensionAction(
const std::string& name,
const base::Value::Dict& value,
std::string* error,
bool* bad_message) { … }
struct WebRequestActionFactory { … };
base::LazyInstance<WebRequestActionFactory>::Leaky
g_web_request_action_factory = …;
}
WebRequestAction::~WebRequestAction() = default;
bool WebRequestAction::Equals(const WebRequestAction* other) const { … }
bool WebRequestAction::HasPermission(ApplyInfo* apply_info,
const ExtensionId& extension_id) const { … }
scoped_refptr<const WebRequestAction> WebRequestAction::Create(
content::BrowserContext* browser_context,
const Extension* extension,
const base::Value::Dict& json_action,
std::string* error,
bool* bad_message) { … }
void WebRequestAction::Apply(const ExtensionId& extension_id,
base::Time extension_install_time,
ApplyInfo* apply_info) const { … }
WebRequestAction::WebRequestAction(int stages,
Type type,
int minimum_priority,
HostPermissionsStrategy strategy)
: … { … }
WebRequestCancelAction::WebRequestCancelAction()
: … { … }
WebRequestCancelAction::~WebRequestCancelAction() = default;
std::string WebRequestCancelAction::GetName() const { … }
std::optional<EventResponseDelta> WebRequestCancelAction::CreateDelta(
const WebRequestData& request_data,
const ExtensionId& extension_id,
const base::Time& extension_install_time) const { … }
WebRequestRedirectAction::WebRequestRedirectAction(const GURL& redirect_url)
: … { … }
WebRequestRedirectAction::~WebRequestRedirectAction() = default;
bool WebRequestRedirectAction::Equals(const WebRequestAction* other) const { … }
std::string WebRequestRedirectAction::GetName() const { … }
std::optional<EventResponseDelta> WebRequestRedirectAction::CreateDelta(
const WebRequestData& request_data,
const ExtensionId& extension_id,
const base::Time& extension_install_time) const { … }
WebRequestRedirectToTransparentImageAction::
WebRequestRedirectToTransparentImageAction()
: … { … }
WebRequestRedirectToTransparentImageAction::
~WebRequestRedirectToTransparentImageAction() { … }
std::string WebRequestRedirectToTransparentImageAction::GetName() const { … }
std::optional<EventResponseDelta>
WebRequestRedirectToTransparentImageAction::CreateDelta(
const WebRequestData& request_data,
const ExtensionId& extension_id,
const base::Time& extension_install_time) const { … }
WebRequestRedirectToEmptyDocumentAction::
WebRequestRedirectToEmptyDocumentAction()
: … { … }
WebRequestRedirectToEmptyDocumentAction::
~WebRequestRedirectToEmptyDocumentAction() { … }
std::string WebRequestRedirectToEmptyDocumentAction::GetName() const { … }
std::optional<EventResponseDelta>
WebRequestRedirectToEmptyDocumentAction::CreateDelta(
const WebRequestData& request_data,
const ExtensionId& extension_id,
const base::Time& extension_install_time) const { … }
WebRequestRedirectByRegExAction::WebRequestRedirectByRegExAction(
std::unique_ptr<RE2> from_pattern,
const std::string& to_pattern)
: … { … }
WebRequestRedirectByRegExAction::~WebRequestRedirectByRegExAction() = default;
std::string WebRequestRedirectByRegExAction::PerlToRe2Style(
const std::string& perl) { … }
bool WebRequestRedirectByRegExAction::Equals(
const WebRequestAction* other) const { … }
std::string WebRequestRedirectByRegExAction::GetName() const { … }
std::optional<EventResponseDelta> WebRequestRedirectByRegExAction::CreateDelta(
const WebRequestData& request_data,
const ExtensionId& extension_id,
const base::Time& extension_install_time) const { … }
WebRequestSetRequestHeaderAction::WebRequestSetRequestHeaderAction(
const std::string& name,
const std::string& value)
: … { … }
WebRequestSetRequestHeaderAction::~WebRequestSetRequestHeaderAction() = default;
bool WebRequestSetRequestHeaderAction::Equals(
const WebRequestAction* other) const { … }
std::string WebRequestSetRequestHeaderAction::GetName() const { … }
std::optional<EventResponseDelta> WebRequestSetRequestHeaderAction::CreateDelta(
const WebRequestData& request_data,
const ExtensionId& extension_id,
const base::Time& extension_install_time) const { … }
WebRequestRemoveRequestHeaderAction::WebRequestRemoveRequestHeaderAction(
const std::string& name)
: … { … }
WebRequestRemoveRequestHeaderAction::~WebRequestRemoveRequestHeaderAction() =
default;
bool WebRequestRemoveRequestHeaderAction::Equals(
const WebRequestAction* other) const { … }
std::string WebRequestRemoveRequestHeaderAction::GetName() const { … }
std::optional<EventResponseDelta>
WebRequestRemoveRequestHeaderAction::CreateDelta(
const WebRequestData& request_data,
const ExtensionId& extension_id,
const base::Time& extension_install_time) const { … }
WebRequestAddResponseHeaderAction::WebRequestAddResponseHeaderAction(
const std::string& name,
const std::string& value)
: … { … }
WebRequestAddResponseHeaderAction::~WebRequestAddResponseHeaderAction() =
default;
bool WebRequestAddResponseHeaderAction::Equals(
const WebRequestAction* other) const { … }
std::string WebRequestAddResponseHeaderAction::GetName() const { … }
std::optional<EventResponseDelta>
WebRequestAddResponseHeaderAction::CreateDelta(
const WebRequestData& request_data,
const ExtensionId& extension_id,
const base::Time& extension_install_time) const { … }
WebRequestRemoveResponseHeaderAction::WebRequestRemoveResponseHeaderAction(
const std::string& name,
const std::string& value,
bool has_value)
: … { … }
WebRequestRemoveResponseHeaderAction::~WebRequestRemoveResponseHeaderAction() =
default;
bool WebRequestRemoveResponseHeaderAction::Equals(
const WebRequestAction* other) const { … }
std::string WebRequestRemoveResponseHeaderAction::GetName() const { … }
std::optional<EventResponseDelta>
WebRequestRemoveResponseHeaderAction::CreateDelta(
const WebRequestData& request_data,
const ExtensionId& extension_id,
const base::Time& extension_install_time) const { … }
WebRequestIgnoreRulesAction::WebRequestIgnoreRulesAction(
int minimum_priority,
const std::string& ignore_tag)
: … { … }
WebRequestIgnoreRulesAction::~WebRequestIgnoreRulesAction() = default;
bool WebRequestIgnoreRulesAction::Equals(const WebRequestAction* other) const { … }
std::string WebRequestIgnoreRulesAction::GetName() const { … }
std::optional<EventResponseDelta> WebRequestIgnoreRulesAction::CreateDelta(
const WebRequestData& request_data,
const ExtensionId& extension_id,
const base::Time& extension_install_time) const { … }
WebRequestRequestCookieAction::WebRequestRequestCookieAction(
RequestCookieModification request_cookie_modification)
: … { … }
WebRequestRequestCookieAction::~WebRequestRequestCookieAction() = default;
bool WebRequestRequestCookieAction::Equals(
const WebRequestAction* other) const { … }
std::string WebRequestRequestCookieAction::GetName() const { … }
std::optional<EventResponseDelta> WebRequestRequestCookieAction::CreateDelta(
const WebRequestData& request_data,
const ExtensionId& extension_id,
const base::Time& extension_install_time) const { … }
WebRequestResponseCookieAction::WebRequestResponseCookieAction(
ResponseCookieModification response_cookie_modification)
: … { … }
WebRequestResponseCookieAction::~WebRequestResponseCookieAction() = default;
bool WebRequestResponseCookieAction::Equals(
const WebRequestAction* other) const { … }
std::string WebRequestResponseCookieAction::GetName() const { … }
std::optional<EventResponseDelta> WebRequestResponseCookieAction::CreateDelta(
const WebRequestData& request_data,
const ExtensionId& extension_id,
const base::Time& extension_install_time) const { … }
WebRequestSendMessageToExtensionAction::WebRequestSendMessageToExtensionAction(
const std::string& message)
: … { … }
WebRequestSendMessageToExtensionAction::
~WebRequestSendMessageToExtensionAction() { … }
bool WebRequestSendMessageToExtensionAction::Equals(
const WebRequestAction* other) const { … }
std::string WebRequestSendMessageToExtensionAction::GetName() const { … }
std::optional<EventResponseDelta>
WebRequestSendMessageToExtensionAction::CreateDelta(
const WebRequestData& request_data,
const ExtensionId& extension_id,
const base::Time& extension_install_time) const { … }
}