#include "content/browser/web_package/signed_exchange_cert_fetcher.h"
#include <optional>
#include "base/containers/span.h"
#include "base/feature_list.h"
#include "base/format_macros.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/trace_event/trace_event.h"
#include "content/browser/data_url_loader_factory.h"
#include "content/browser/web_package/signed_exchange_consts.h"
#include "content/browser/web_package/signed_exchange_devtools_proxy.h"
#include "content/browser/web_package/signed_exchange_utils.h"
#include "ipc/ipc_message.h"
#include "mojo/public/cpp/system/simple_watcher.h"
#include "net/base/ip_endpoint.h"
#include "net/base/load_flags.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_status_code.h"
#include "services/network/public/cpp/record_ontransfersizeupdate_utils.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/single_request_url_loader_factory.h"
#include "services/network/public/mojom/early_hints.mojom.h"
#include "services/network/public/mojom/fetch_api.mojom-shared.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/blink/public/common/loader/throttling_url_loader.h"
#include "third_party/blink/public/common/loader/url_loader_throttle.h"
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom-shared.h"
#include "url/origin.h"
namespace content {
namespace {
constexpr char kCertChainMimeType[] = …;
const size_t kMaxCertSizeForSignedExchange = …;
static size_t g_max_cert_size_for_signed_exchange = …;
void ResetMaxCertSizeForTest() { … }
const net::NetworkTrafficAnnotationTag kCertFetcherTrafficAnnotation = …;
}
std::unique_ptr<SignedExchangeCertFetcher>
SignedExchangeCertFetcher::CreateAndStart(
scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory,
std::vector<std::unique_ptr<blink::URLLoaderThrottle>> throttles,
const GURL& cert_url,
bool force_fetch,
CertificateCallback callback,
SignedExchangeDevToolsProxy* devtools_proxy,
const std::optional<base::UnguessableToken>& throttling_profile_id,
net::IsolationInfo isolation_info,
const std::optional<url::Origin>& initiator) { … }
SignedExchangeCertFetcher::SignedExchangeCertFetcher(
scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory,
std::vector<std::unique_ptr<blink::URLLoaderThrottle>> throttles,
const GURL& cert_url,
bool force_fetch,
CertificateCallback callback,
SignedExchangeDevToolsProxy* devtools_proxy,
const std::optional<base::UnguessableToken>& throttling_profile_id,
net::IsolationInfo isolation_info,
const std::optional<url::Origin>& initiator)
: … { … }
SignedExchangeCertFetcher::~SignedExchangeCertFetcher() = default;
void SignedExchangeCertFetcher::Start() { … }
void SignedExchangeCertFetcher::Abort() { … }
void SignedExchangeCertFetcher::OnHandleReady(MojoResult result) { … }
void SignedExchangeCertFetcher::OnDataComplete() { … }
void SignedExchangeCertFetcher::OnReceiveEarlyHints(
network::mojom::EarlyHintsPtr early_hints) { … }
void SignedExchangeCertFetcher::OnReceiveResponse(
network::mojom::URLResponseHeadPtr head,
mojo::ScopedDataPipeConsumerHandle body,
std::optional<mojo_base::BigBuffer> cached_metadata) { … }
void SignedExchangeCertFetcher::OnReceiveRedirect(
const net::RedirectInfo& redirect_info,
network::mojom::URLResponseHeadPtr head) { … }
void SignedExchangeCertFetcher::OnUploadProgress(
int64_t current_position,
int64_t total_size,
OnUploadProgressCallback callback) { … }
void SignedExchangeCertFetcher::OnTransferSizeUpdated(
int32_t transfer_size_diff) { … }
void SignedExchangeCertFetcher::OnComplete(
const network::URLLoaderCompletionStatus& status) { … }
void SignedExchangeCertFetcher::OnDataURLRequest(
const network::ResourceRequest& resource_request,
mojo::PendingReceiver<network::mojom::URLLoader> url_loader_receiver,
mojo::PendingRemote<network::mojom::URLLoaderClient>
url_loader_client_remote) { … }
void SignedExchangeCertFetcher::MaybeNotifyCompletionToDevtools(
const network::URLLoaderCompletionStatus& status) { … }
base::ScopedClosureRunner SignedExchangeCertFetcher::SetMaxCertSizeForTest(
size_t max_cert_size) { … }
}