#include "extensions/browser/api/web_request/web_request_api.h"
#include <stddef.h>
#include <memory>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/json/json_writer.h"
#include "base/lazy_instance.h"
#include "base/memory/raw_ptr.h"
#include "base/not_fatal_until.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/safe_browsing/core/common/features.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "extensions/browser/api/declarative_net_request/utils.h"
#include "extensions/browser/api/web_request/extension_web_request_event_router.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_proxying_url_loader_factory.h"
#include "extensions/browser/api/web_request/web_request_proxying_websocket.h"
#include "extensions/browser/api/web_request/web_request_proxying_webtransport.h"
#include "extensions/browser/browser_frame_context_data.h"
#include "extensions/browser/browser_process_context_data.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_navigation_ui_data.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/process_map.h"
#include "extensions/browser/warning_service.h"
#include "extensions/browser/warning_set.h"
#include "extensions/common/api/web_request.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_api.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/features/feature.h"
#include "extensions/common/features/feature_provider.h"
#include "extensions/common/mojom/context_type.mojom.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/common/url_pattern.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "net/base/auth.h"
#include "net/cookies/site_for_cookies.h"
#include "net/http/http_util.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "services/network/public/mojom/web_transport.mojom.h"
#include "url/gurl.h"
#if BUILDFLAG(ENABLE_GUEST_VIEW)
#include "extensions/browser/guest_view/web_view/web_view_guest.h"
#endif
BrowserThread;
ExtraInfoSpec;
APIPermissionID;
helpers;
keys;
URLLoaderFactoryType;
namespace extensions {
web_request;
namespace {
bool FromHeaderDictionary(const base::Value::Dict& header_value,
std::string* name,
std::string* out_value) { … }
bool HasAnyWebRequestPermissions(const Extension* extension) { … }
enum class WebRequestEventListenerFlag { … };
}
void WebRequestAPI::Proxy::HandleAuthRequest(
const net::AuthChallengeInfo& auth_info,
scoped_refptr<net::HttpResponseHeaders> response_headers,
int32_t request_id,
AuthRequestCallback callback) { … }
WebRequestAPI::ProxySet::ProxySet() { … }
WebRequestAPI::ProxySet::~ProxySet() { … }
void WebRequestAPI::ProxySet::AddProxy(std::unique_ptr<Proxy> proxy) { … }
void WebRequestAPI::ProxySet::RemoveProxy(Proxy* proxy) { … }
void WebRequestAPI::ProxySet::AssociateProxyWithRequestId(
Proxy* proxy,
const content::GlobalRequestID& id) { … }
void WebRequestAPI::ProxySet::DisassociateProxyWithRequestId(
Proxy* proxy,
const content::GlobalRequestID& id) { … }
WebRequestAPI::Proxy* WebRequestAPI::ProxySet::GetProxyFromRequestId(
const content::GlobalRequestID& id) { … }
void WebRequestAPI::ProxySet::MaybeProxyAuthRequest(
const net::AuthChallengeInfo& auth_info,
scoped_refptr<net::HttpResponseHeaders> response_headers,
const content::GlobalRequestID& request_id,
AuthRequestCallback callback) { … }
void WebRequestAPI::ProxySet::OnDNRExtensionUnloaded(
const Extension* extension) { … }
WebRequestAPI::RequestIDGenerator::RequestIDGenerator() = default;
WebRequestAPI::RequestIDGenerator::~RequestIDGenerator() = default;
int64_t WebRequestAPI::RequestIDGenerator::Generate(
int32_t routing_id,
int32_t network_service_request_id) { … }
void WebRequestAPI::RequestIDGenerator::SaveID(
int32_t routing_id,
int32_t network_service_request_id,
uint64_t request_id) { … }
WebRequestAPI::WebRequestAPI(content::BrowserContext* context)
: … { … }
WebRequestAPI::~WebRequestAPI() = default;
void WebRequestAPI::Shutdown() { … }
static base::LazyInstance<
BrowserContextKeyedAPIFactory<WebRequestAPI>>::DestructorAtExit g_factory = …;
BrowserContextKeyedAPIFactory<WebRequestAPI>*
WebRequestAPI::GetFactoryInstance() { … }
void WebRequestAPI::OnListenerRemoved(const EventListenerInfo& details) { … }
bool WebRequestAPI::MaybeProxyURLLoaderFactory(
content::BrowserContext* browser_context,
content::RenderFrameHost* frame,
int render_process_id,
URLLoaderFactoryType type,
std::optional<int64_t> navigation_id,
ukm::SourceIdObj ukm_source_id,
network::URLLoaderFactoryBuilder& factory_builder,
mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*
header_client,
scoped_refptr<base::SequencedTaskRunner> navigation_response_task_runner,
const url::Origin& request_initiator) { … }
bool WebRequestAPI::MaybeProxyAuthRequest(
content::BrowserContext* browser_context,
const net::AuthChallengeInfo& auth_info,
scoped_refptr<net::HttpResponseHeaders> response_headers,
const content::GlobalRequestID& request_id,
bool is_main_frame,
AuthRequestCallback callback,
WebViewGuest* web_view_guest) { … }
void WebRequestAPI::ProxyWebSocket(
content::RenderFrameHost* frame,
content::ContentBrowserClient::WebSocketFactory factory,
const GURL& url,
const net::SiteForCookies& site_for_cookies,
const std::optional<std::string>& user_agent,
mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
handshake_client) { … }
void WebRequestAPI::ProxyWebTransport(
content::RenderProcessHost& render_process_host,
int frame_routing_id,
const GURL& url,
const url::Origin& initiator_origin,
mojo::PendingRemote<network::mojom::WebTransportHandshakeClient>
handshake_client,
content::ContentBrowserClient::WillCreateWebTransportCallback callback) { … }
void WebRequestAPI::ForceProxyForTesting() { … }
bool WebRequestAPI::MayHaveProxies() const { … }
bool WebRequestAPI::MayHaveWebsocketProxiesForExtensionTelemetry() const { … }
bool WebRequestAPI::IsAvailableToWebViewEmbedderFrame(
content::RenderFrameHost* render_frame_host) const { … }
bool WebRequestAPI::HasExtraHeadersListenerForTesting() { … }
void WebRequestAPI::UpdateMayHaveProxies() { … }
void WebRequestAPI::OnExtensionLoaded(content::BrowserContext* browser_context,
const Extension* extension) { … }
void WebRequestAPI::OnExtensionUnloaded(
content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionReason reason) { … }
void WebRequestAPI::UpdateActiveListener(
void* browser_context_id,
WebRequestEventRouter::ListenerUpdateType update_type,
const ExtensionId& extension_id,
const std::string& sub_event_name,
int worker_thread_id,
int64_t service_worker_version_id) { … }
void WebRequestAPI::RemoveLazyListener(content::BrowserContext* browser_context,
const ExtensionId& extension_id,
const std::string& sub_event_name) { … }
class ClearCacheQuotaHeuristic : public QuotaLimitHeuristic { … };
bool ClearCacheQuotaHeuristic::Apply(Bucket* bucket,
const base::TimeTicks& event_time) { … }
void ClearCacheQuotaHeuristic::OnPageLoad(Bucket* bucket) { … }
ExtensionFunction::ResponseAction
WebRequestInternalAddEventListenerFunction::Run() { … }
void WebRequestInternalEventHandledFunction::OnError(
const std::string& event_name,
const std::string& sub_event_name,
uint64_t request_id,
int render_process_id,
int web_view_instance_id,
std::unique_ptr<WebRequestEventRouter::EventResponse> response) { … }
ExtensionFunction::ResponseAction
WebRequestInternalEventHandledFunction::Run() { … }
void WebRequestHandlerBehaviorChangedFunction::GetQuotaLimitHeuristics(
QuotaLimitHeuristics* heuristics) const { … }
void WebRequestHandlerBehaviorChangedFunction::OnQuotaExceeded(
std::string violation_error) { … }
ExtensionFunction::ResponseAction
WebRequestHandlerBehaviorChangedFunction::Run() { … }
}