#include "extensions/browser/api/web_request/web_request_api_helpers.h"
#include <stddef.h>
#include <stdint.h>
#include <cmath>
#include <string_view>
#include <tuple>
#include <utility>
#include "base/containers/adapters.h"
#include "base/containers/contains.h"
#include "base/containers/fixed_flat_map.h"
#include "base/containers/fixed_flat_set.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/ranges/algorithm.h"
#include "base/stl_util.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/chromeos_buildflags.h"
#include "components/web_cache/browser/web_cache_manager.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "extensions/browser/api/declarative_net_request/constants.h"
#include "extensions/browser/api/declarative_net_request/request_action.h"
#include "extensions/browser/api/extensions_api_client.h"
#include "extensions/browser/api/web_request/web_request_api_constants.h"
#include "extensions/browser/api/web_request/web_request_info.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/common/api/declarative_net_request.h"
#include "extensions/common/extension_id.h"
#include "net/cookies/cookie_util.h"
#include "net/cookies/parsed_cookie.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_util.h"
#include "net/log/net_log_event_type.h"
#include "services/network/public/cpp/features.h"
#include "url/url_constants.h"
Time;
ParsedRequestCookie;
ParsedRequestCookies;
keys;
web_request;
DNRRequestAction;
namespace extension_web_request_api_helpers {
namespace {
dnr_api;
ParsedResponseCookies;
void ClearCacheOnNavigationOnUI() { … }
bool ParseCookieLifetime(const net::ParsedCookie& cookie,
int64_t* seconds_till_expiry) { … }
void RecordRequestHeaderRemoved(RequestHeaderType type) { … }
void RecordRequestHeaderAdded(RequestHeaderType type) { … }
void RecordRequestHeaderChanged(RequestHeaderType type) { … }
void RecordDNRRequestHeaderRemoved(RequestHeaderType type) { … }
void RecordDNRRequestHeaderAdded(RequestHeaderType type) { … }
void RecordDNRRequestHeaderChanged(RequestHeaderType type) { … }
bool IsStringLowerCaseASCII(std::string_view s) { … }
constexpr auto kRequestHeaderEntries = …;
constexpr bool IsValidHeaderName(std::string_view str) { … }
template <typename T>
constexpr bool ValidateHeaderEntries(const T& entries) { … }
static_assert …;
static_assert …;
void RecordRequestHeader(const std::string& header,
void (*record_func)(RequestHeaderType)) { … }
void RecordResponseHeaderChanged(ResponseHeaderType type) { … }
void RecordResponseHeaderAdded(ResponseHeaderType type) { … }
void RecordResponseHeaderRemoved(ResponseHeaderType type) { … }
void RecordDNRResponseHeaderChanged(ResponseHeaderType type) { … }
void RecordDNRResponseHeaderAdded(ResponseHeaderType type) { … }
void RecordDNRResponseHeaderRemoved(ResponseHeaderType type) { … }
constexpr auto kResponseHeaderEntries = …;
void RecordResponseHeader(std::string_view header,
void (*record_func)(ResponseHeaderType)) { … }
static_assert …;
static_assert …;
std::string GetDNRNewRequestHeaderValue(net::HttpRequestHeaders* headers,
const std::string& header_name,
const std::string& header_value,
dnr_api::HeaderOperation operation) { … }
struct DNRHeaderAction { … };
bool ModifyRequestHeadersForAction(
net::HttpRequestHeaders* headers,
const DNRRequestAction& request_action,
std::set<std::string>* removed_headers,
std::set<std::string>* set_headers,
std::map<std::string_view, std::vector<DNRHeaderAction>>* header_actions) { … }
bool ModifyResponseHeadersForAction(
const net::HttpResponseHeaders* original_response_headers,
scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
const DNRRequestAction& request_action,
std::map<std::string_view, std::vector<DNRHeaderAction>>* header_actions) { … }
}
IgnoredAction::IgnoredAction(extensions::ExtensionId extension_id,
web_request::IgnoredActionType action_type)
: … { … }
IgnoredAction::IgnoredAction(IgnoredAction&& rhs) = default;
bool ExtraInfoSpec::InitFromValue(content::BrowserContext* browser_context,
const base::Value& value,
int* extra_info_spec) { … }
RequestCookie::RequestCookie() = default;
RequestCookie::RequestCookie(RequestCookie&& other) = default;
RequestCookie& RequestCookie ::operator=(RequestCookie&& other) = default;
RequestCookie::~RequestCookie() = default;
bool RequestCookie::operator==(const RequestCookie& other) const { … }
RequestCookie RequestCookie::Clone() const { … }
ResponseCookie::ResponseCookie() = default;
ResponseCookie::ResponseCookie(ResponseCookie&& other) = default;
ResponseCookie& ResponseCookie ::operator=(ResponseCookie&& other) = default;
ResponseCookie::~ResponseCookie() = default;
bool ResponseCookie::operator==(const ResponseCookie& other) const { … }
ResponseCookie ResponseCookie::Clone() const { … }
FilterResponseCookie::FilterResponseCookie() = default;
FilterResponseCookie::FilterResponseCookie(FilterResponseCookie&& other) =
default;
FilterResponseCookie& FilterResponseCookie ::operator=(
FilterResponseCookie&& other) = default;
FilterResponseCookie::~FilterResponseCookie() = default;
bool FilterResponseCookie::operator==(const FilterResponseCookie& other) const { … }
FilterResponseCookie FilterResponseCookie::Clone() const { … }
RequestCookieModification::RequestCookieModification() = default;
RequestCookieModification::RequestCookieModification(
RequestCookieModification&& other) = default;
RequestCookieModification& RequestCookieModification ::operator=(
RequestCookieModification&& other) = default;
RequestCookieModification::~RequestCookieModification() = default;
bool RequestCookieModification::operator==(
const RequestCookieModification& other) const { … }
RequestCookieModification RequestCookieModification::Clone() const { … }
ResponseCookieModification::ResponseCookieModification() : … { … }
ResponseCookieModification::ResponseCookieModification(
ResponseCookieModification&& other) = default;
ResponseCookieModification& ResponseCookieModification ::operator=(
ResponseCookieModification&& other) = default;
ResponseCookieModification::~ResponseCookieModification() = default;
bool ResponseCookieModification::operator==(
const ResponseCookieModification& other) const { … }
ResponseCookieModification ResponseCookieModification::Clone() const { … }
EventResponseDelta::EventResponseDelta(
const extensions::ExtensionId& extension_id,
const base::Time& extension_install_time)
: … { … }
EventResponseDelta::EventResponseDelta(EventResponseDelta&& other) = default;
EventResponseDelta& EventResponseDelta ::operator=(EventResponseDelta&& other) =
default;
EventResponseDelta::~EventResponseDelta() = default;
bool InDecreasingExtensionInstallationTimeOrder(const EventResponseDelta& a,
const EventResponseDelta& b) { … }
base::Value::List StringToCharList(const std::string& s) { … }
bool CharListToString(const base::Value::List& list, std::string* out) { … }
EventResponseDelta CalculateOnBeforeRequestDelta(
const extensions::ExtensionId& extension_id,
const base::Time& extension_install_time,
bool cancel,
const GURL& new_url) { … }
EventResponseDelta CalculateOnBeforeSendHeadersDelta(
content::BrowserContext* browser_context,
const extensions::ExtensionId& extension_id,
const base::Time& extension_install_time,
bool cancel,
net::HttpRequestHeaders* old_headers,
net::HttpRequestHeaders* new_headers,
int extra_info_spec) { … }
EventResponseDelta CalculateOnHeadersReceivedDelta(
const extensions::ExtensionId& extension_id,
const base::Time& extension_install_time,
bool cancel,
const GURL& old_url,
const GURL& new_url,
const net::HttpResponseHeaders* old_response_headers,
ResponseHeaders* new_response_headers,
int extra_info_spec) { … }
EventResponseDelta CalculateOnAuthRequiredDelta(
const extensions::ExtensionId& extension_id,
const base::Time& extension_install_time,
bool cancel,
std::optional<net::AuthCredentials> auth_credentials) { … }
void MergeCancelOfResponses(
const EventResponseDeltas& deltas,
std::optional<extensions::ExtensionId>* canceled_by_extension) { … }
static bool MergeRedirectUrlOfResponsesHelper(
const GURL& url,
const EventResponseDeltas& deltas,
GURL* new_url,
IgnoredActions* ignored_actions,
bool consider_only_cancel_scheme_urls) { … }
void MergeRedirectUrlOfResponses(const GURL& url,
const EventResponseDeltas& deltas,
GURL* new_url,
IgnoredActions* ignored_actions) { … }
void MergeOnBeforeRequestResponses(const GURL& url,
const EventResponseDeltas& deltas,
GURL* new_url,
IgnoredActions* ignored_actions) { … }
static bool DoesRequestCookieMatchFilter(
const ParsedRequestCookie& cookie,
const std::optional<RequestCookie>& filter) { … }
static bool MergeAddRequestCookieModifications(
const EventResponseDeltas& deltas,
ParsedRequestCookies* cookies) { … }
static bool MergeEditRequestCookieModifications(
const EventResponseDeltas& deltas,
ParsedRequestCookies* cookies) { … }
static bool MergeRemoveRequestCookieModifications(
const EventResponseDeltas& deltas,
ParsedRequestCookies* cookies) { … }
void MergeCookiesInOnBeforeSendHeadersResponses(
const GURL& url,
const EventResponseDeltas& deltas,
net::HttpRequestHeaders* request_headers) { … }
void MergeOnBeforeSendHeadersResponses(
const extensions::WebRequestInfo& request,
const EventResponseDeltas& deltas,
net::HttpRequestHeaders* request_headers,
IgnoredActions* ignored_actions,
std::set<std::string>* removed_headers,
std::set<std::string>* set_headers,
bool* request_headers_modified,
std::vector<const DNRRequestAction*>* matched_dnr_actions) { … }
static ParsedResponseCookies GetResponseCookies(
scoped_refptr<net::HttpResponseHeaders> override_response_headers) { … }
static void StoreResponseCookies(
const ParsedResponseCookies& cookies,
scoped_refptr<net::HttpResponseHeaders> override_response_headers) { … }
static bool ApplyResponseCookieModification(const ResponseCookie& modification,
net::ParsedCookie* cookie) { … }
static bool DoesResponseCookieMatchFilter(
const net::ParsedCookie& cookie,
const std::optional<FilterResponseCookie>& filter) { … }
static bool MergeAddResponseCookieModifications(
const EventResponseDeltas& deltas,
ParsedResponseCookies* cookies) { … }
static bool MergeEditResponseCookieModifications(
const EventResponseDeltas& deltas,
ParsedResponseCookies* cookies) { … }
static bool MergeRemoveResponseCookieModifications(
const EventResponseDeltas& deltas,
ParsedResponseCookies* cookies) { … }
void MergeCookiesInOnHeadersReceivedResponses(
const GURL& url,
const EventResponseDeltas& deltas,
const net::HttpResponseHeaders* original_response_headers,
scoped_refptr<net::HttpResponseHeaders>* override_response_headers) { … }
static ResponseHeader ToLowerCase(const ResponseHeader& header) { … }
void MergeOnHeadersReceivedResponses(
const extensions::WebRequestInfo& request,
const EventResponseDeltas& deltas,
const net::HttpResponseHeaders* original_response_headers,
scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
GURL* preserve_fragment_on_redirect_url,
IgnoredActions* ignored_actions,
bool* response_headers_modified,
std::vector<const DNRRequestAction*>* matched_dnr_actions) { … }
bool MergeOnAuthRequiredResponses(const EventResponseDeltas& deltas,
net::AuthCredentials* auth_credentials,
IgnoredActions* ignored_actions) { … }
void ClearCacheOnNavigation() { … }
base::Value::Dict CreateHeaderDictionary(const std::string& name,
const std::string& value) { … }
bool ShouldHideRequestHeader(content::BrowserContext* browser_context,
int extra_info_spec,
const std::string& name) { … }
bool ShouldHideResponseHeader(int extra_info_spec, const std::string& name) { … }
void RedirectRequestAfterHeadersReceived(
const GURL& new_url,
net::HttpResponseHeaders& override_response_headers,
GURL* preserve_fragment_on_redirect_url) { … }
}