#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/navigation_body_loader.h"
#include <algorithm>
#include <utility>
#include "base/containers/heap_array.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h"
#include "base/numerics/safe_conversions.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/trace_event/trace_event.h"
#include "mojo/public/cpp/base/big_buffer.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/record_ontransfersizeupdate_utils.h"
#include "services/network/public/cpp/url_loader_completion_status.h"
#include "services/network/public/mojom/early_hints.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/loader/referrer_utils.h"
#include "third_party/blink/public/mojom/loader/code_cache.mojom-blink.h"
#include "third_party/blink/public/mojom/navigation/navigation_params.mojom.h"
#include "third_party/blink/public/platform/resource_load_info_notifier_wrapper.h"
#include "third_party/blink/public/platform/web_url_error.h"
#include "third_party/blink/public/platform/web_url_response.h"
#include "third_party/blink/public/web/web_navigation_params.h"
#include "third_party/blink/renderer/platform/loader/fetch/body_text_decoder.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_base.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_std.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
#include "third_party/blink/renderer/platform/wtf/wtf.h"
#include "third_party/ced/src/compact_enc_det/compact_enc_det.h"
namespace blink {
namespace {
bool ShouldSendDirectlyToPreloadScanner() { … }
size_t GetMaxDataToProcessPerTask() { … }
class HeapArrayOrSize { … };
struct DataChunk { … };
class BodyReader { … };
void ReadFromDataPipeImpl(BodyReader& reader,
mojo::ScopedDataPipeConsumerHandle& handle,
mojo::SimpleWatcher& handle_watcher) { … }
}
class NavigationBodyLoader::OffThreadBodyReader : public BodyReader { … };
void NavigationBodyLoader::OffThreadBodyReaderDeleter::operator()(
const OffThreadBodyReader* ptr) { … }
class NavigationBodyLoader::MainThreadBodyReader : public BodyReader { … };
NavigationBodyLoader::NavigationBodyLoader(
const KURL& original_url,
network::mojom::URLResponseHeadPtr response_head,
mojo::ScopedDataPipeConsumerHandle response_body,
network::mojom::URLLoaderClientEndpointsPtr endpoints,
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
std::unique_ptr<ResourceLoadInfoNotifierWrapper>
resource_load_info_notifier_wrapper)
: … { … }
NavigationBodyLoader::~NavigationBodyLoader() { … }
void NavigationBodyLoader::OnReceiveEarlyHints(
network::mojom::EarlyHintsPtr early_hints) { … }
void NavigationBodyLoader::OnReceiveResponse(
network::mojom::URLResponseHeadPtr head,
mojo::ScopedDataPipeConsumerHandle body,
std::optional<mojo_base::BigBuffer> cached_metadata) { … }
void NavigationBodyLoader::OnReceiveRedirect(
const net::RedirectInfo& redirect_info,
network::mojom::URLResponseHeadPtr head) { … }
void NavigationBodyLoader::OnUploadProgress(int64_t current_position,
int64_t total_size,
OnUploadProgressCallback callback) { … }
void NavigationBodyLoader::OnTransferSizeUpdated(int32_t transfer_size_diff) { … }
void NavigationBodyLoader::OnComplete(
const network::URLLoaderCompletionStatus& status) { … }
void NavigationBodyLoader::SetDefersLoading(WebLoaderFreezeMode mode) { … }
void NavigationBodyLoader::StartLoadingBody(
WebNavigationBodyLoader::Client* client) { … }
void NavigationBodyLoader::StartLoadingBodyInBackground(
std::unique_ptr<BodyTextDecoder> decoder,
bool should_keep_encoded_data) { … }
void NavigationBodyLoader::FlushOffThreadBodyReaderForTesting() { … }
void NavigationBodyLoader::BindURLLoaderAndContinue() { … }
void NavigationBodyLoader::OnConnectionClosed() { … }
void NavigationBodyLoader::OnReadable(MojoResult unused) { … }
void NavigationBodyLoader::ProcessOffThreadData() { … }
void NavigationBodyLoader::ReadFromDataPipe() { … }
void NavigationBodyLoader::NotifyCompletionIfAppropriate() { … }
void NavigationBodyLoader::
BindURLLoaderAndStartLoadingResponseBodyIfPossible() { … }
void WebNavigationBodyLoader::FillNavigationParamsResponseAndBodyLoader(
mojom::CommonNavigationParamsPtr common_params,
mojom::CommitNavigationParamsPtr commit_params,
int request_id,
network::mojom::URLResponseHeadPtr response_head,
mojo::ScopedDataPipeConsumerHandle response_body,
network::mojom::URLLoaderClientEndpointsPtr url_loader_client_endpoints,
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
std::unique_ptr<ResourceLoadInfoNotifierWrapper>
resource_load_info_notifier_wrapper,
bool is_main_frame,
WebNavigationParams* navigation_params,
bool is_ad_frame) { … }
}