#include "services/network/web_bundle/web_bundle_url_loader_factory.h"
#include <optional>
#include "base/functional/callback.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "components/web_package/web_bundle_parser.h"
#include "components/web_package/web_bundle_utils.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "mojo/public/cpp/system/data_pipe.h"
#include "mojo/public/cpp/system/data_pipe_drainer.h"
#include "mojo/public/cpp/system/data_pipe_producer.h"
#include "net/http/http_status_code.h"
#include "services/network/public/cpp/cross_origin_resource_policy.h"
#include "services/network/public/cpp/header_util.h"
#include "services/network/public/cpp/orb/orb_api.h"
#include "services/network/public/cpp/record_ontransfersizeupdate_utils.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/mojom/early_hints.mojom.h"
#include "services/network/public/mojom/http_raw_headers.mojom.h"
#include "services/network/public/mojom/url_loader.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/web_bundle/web_bundle_chunked_buffer.h"
#include "services/network/web_bundle/web_bundle_memory_quota_consumer.h"
namespace network {
namespace {
constexpr size_t kBlockedBodyAllocationSize = …;
void DeleteProducerAndRunCallback(
std::unique_ptr<mojo::DataPipeProducer> producer,
base::OnceCallback<void(MojoResult result)> callback,
MojoResult result) { … }
bool CheckWebBundleServingConstraints(
const network::mojom::URLResponseHead& response_head,
std::string& out_error_message) { … }
class WebBundleURLLoaderClient : public network::mojom::URLLoaderClient { … };
}
class WebBundleURLLoaderFactory::URLLoader : public mojom::URLLoader { … };
class WebBundleURLLoaderFactory::BundleDataSource
: public web_package::mojom::BundleDataSource,
public mojo::DataPipeDrainer::Client { … };
WebBundleURLLoaderFactory::WebBundleURLLoaderFactory(
const GURL& bundle_url,
const ResourceRequest::WebBundleTokenParams& web_bundle_token_params,
mojo::Remote<mojom::WebBundleHandle> web_bundle_handle,
std::unique_ptr<WebBundleMemoryQuotaConsumer>
web_bundle_memory_quota_consumer,
mojo::PendingRemote<mojom::DevToolsObserver> devtools_observer,
std::optional<std::string> devtools_request_id,
const CrossOriginEmbedderPolicy& cross_origin_embedder_policy,
mojom::CrossOriginEmbedderPolicyReporter* coep_reporter)
: … { … }
WebBundleURLLoaderFactory::~WebBundleURLLoaderFactory() { … }
base::WeakPtr<WebBundleURLLoaderFactory>
WebBundleURLLoaderFactory::GetWeakPtr() { … }
bool WebBundleURLLoaderFactory::HasError() const { … }
void WebBundleURLLoaderFactory::SetBundleStream(
mojo::ScopedDataPipeConsumerHandle body) { … }
mojo::PendingRemote<mojom::URLLoaderClient>
WebBundleURLLoaderFactory::MaybeWrapURLLoaderClient(
mojo::PendingRemote<mojom::URLLoaderClient> wrapped) { … }
base::WeakPtr<WebBundleURLLoaderFactory::URLLoader>
WebBundleURLLoaderFactory::CreateURLLoader(
mojo::PendingReceiver<mojom::URLLoader> receiver,
const ResourceRequest& url_request,
mojo::PendingRemote<mojom::URLLoaderClient> client,
mojo::Remote<mojom::TrustedHeaderClient> trusted_header_client,
base::Time request_start_time,
base::TimeTicks request_start_time_ticks,
base::OnceCallback<void(URLLoader*)> delete_me_cleanup) { … }
void WebBundleURLLoaderFactory::StartLoader(base::WeakPtr<URLLoader> loader) { … }
void WebBundleURLLoaderFactory::OnBeforeSendHeadersComplete(
base::WeakPtr<URLLoader> loader,
int result,
const std::optional<net::HttpRequestHeaders>& headers) { … }
void WebBundleURLLoaderFactory::QueueOrStartLoader(
base::WeakPtr<URLLoader> loader) { … }
void WebBundleURLLoaderFactory::StartLoad(base::WeakPtr<URLLoader> loader) { … }
void WebBundleURLLoaderFactory::ReportErrorAndCancelPendingLoaders(
SubresourceWebBundleLoadResult result,
mojom::WebBundleErrorType error,
const std::string& message) { … }
void WebBundleURLLoaderFactory::OnMetadataParsed(
web_package::mojom::BundleMetadataPtr metadata,
web_package::mojom::BundleMetadataParseErrorPtr error) { … }
bool WebBundleURLLoaderFactory::IsAllowedExchangeUrl(const GURL& relative_url) { … }
void WebBundleURLLoaderFactory::OnResponseParsed(
base::WeakPtr<URLLoader> loader,
web_package::mojom::BundleResponsePtr response,
web_package::mojom::BundleResponseParseErrorPtr error) { … }
void WebBundleURLLoaderFactory::OnHeadersReceivedComplete(
base::WeakPtr<URLLoader> loader,
const std::string& original_header,
uint64_t payload_offset,
uint64_t payload_length,
int result,
const std::optional<std::string>& headers,
const std::optional<GURL>& preserve_fragment_on_redirect_url) { … }
void WebBundleURLLoaderFactory::SendResponseToLoader(
base::WeakPtr<URLLoader> loader,
const std::string& headers,
uint64_t payload_offset,
uint64_t payload_length) { … }
void WebBundleURLLoaderFactory::OnMemoryQuotaExceeded() { … }
void WebBundleURLLoaderFactory::OnDataCompleted() { … }
void WebBundleURLLoaderFactory::MaybeReportLoadResult(
SubresourceWebBundleLoadResult result) { … }
void WebBundleURLLoaderFactory::OnWebBundleFetchFailed() { … }
}