1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_IP_PROTECTION_COMMON_IP_PROTECTION_PROXY_DELEGATE_H_
#define COMPONENTS_IP_PROTECTION_COMMON_IP_PROTECTION_PROXY_DELEGATE_H_
#include <cstddef>
#include <string>
#include "base/gtest_prod_util.h"
#include "base/memory/raw_ref.h"
#include "base/memory/weak_ptr.h"
#include "net/base/net_errors.h"
#include "net/base/network_anonymization_key.h"
#include "net/base/proxy_chain.h"
#include "net/base/proxy_delegate.h"
#include "net/proxy_resolution/proxy_retry_info.h"
class GURL;
namespace net {
class HttpRequestHeaders;
class ProxyResolutionService;
class ProxyList;
struct ProxyRetryInfo;
} // namespace net
namespace ip_protection {
class IpProtectionCore;
enum class ProxyResolutionResult;
// IpProtectionProxyDelegate is used to support IP protection, by injecting
// proxies for requests where IP should be protected.
class IpProtectionProxyDelegate : public net::ProxyDelegate {
public:
// The `ip_protection_core` must be non-null.
explicit IpProtectionProxyDelegate(IpProtectionCore* ip_protection_core);
IpProtectionProxyDelegate(const IpProtectionProxyDelegate&) = delete;
IpProtectionProxyDelegate& operator=(const IpProtectionProxyDelegate&) =
delete;
~IpProtectionProxyDelegate() override;
// net::ProxyDelegate implementation:
void OnResolveProxy(
const GURL& url,
const net::NetworkAnonymizationKey& network_anonymization_key,
const std::string& method,
const net::ProxyRetryInfoMap& proxy_retry_info,
net::ProxyInfo* result) override;
void OnSuccessfulRequestAfterFailures(
const net::ProxyRetryInfoMap& proxy_retry_info) override;
void OnFallback(const net::ProxyChain& bad_chain, int net_error) override;
net::Error OnBeforeTunnelRequest(
const net::ProxyChain& proxy_chain,
size_t chain_index,
net::HttpRequestHeaders* extra_headers) override;
net::Error OnTunnelHeadersReceived(
const net::ProxyChain& proxy_chain,
size_t chain_index,
const net::HttpResponseHeaders& response_headers) override;
void SetProxyResolutionService(
net::ProxyResolutionService* proxy_resolution_service) override;
bool AliasRequiresProxyOverride(
const std::string scheme,
const std::vector<std::string>& dns_aliases,
const net::NetworkAnonymizationKey& network_anonymization_key) override;
private:
friend class IpProtectionProxyDelegateTest;
FRIEND_TEST_ALL_PREFIXES(IpProtectionProxyDelegateTest, MergeProxyRules);
// Note: the order of the return values must match the order of the enum
// values in ProxyResolutionResult so that existing metric data is not
// affected when we add a new enum value.
// TODO(crbug.com/403156545): Refactor this so that we can make calls more
// efficiently.
ProxyResolutionResult ClassifyRequest(
const GURL& url,
const net::NetworkAnonymizationKey& network_anonymization_key,
net::ProxyInfo* result);
// Returns the equivalent of replacing all DIRECT proxies in
// `existing_proxy_list` with the proxies in `custom_proxy_list`.
static net::ProxyList MergeProxyRules(
const net::ProxyList& existing_proxy_list,
const net::ProxyList& custom_proxy_list);
// Returns PRT header value (for Sec-Probabilistic-Reveal-Token) if
// successful. Returns nullopt in case of failure.
std::optional<std::string> GetPRTHeaderValue(
const GURL& url,
const net::SchemefulSite& top_frame_site) const;
const raw_ref<IpProtectionCore> ip_protection_core_;
base::WeakPtrFactory<IpProtectionProxyDelegate> weak_factory_{this};
};
} // namespace ip_protection
#endif // COMPONENTS_IP_PROTECTION_COMMON_IP_PROTECTION_PROXY_DELEGATE_H_
|