chromium/third_party/blink/renderer/platform/loader/fetch/url_loader/navigation_body_loader.cc

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#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() {}

// Returns the maximum data size to process in TakeData(). Returning 0 means
// process all the data available.
size_t GetMaxDataToProcessPerTask() {}

// Either 1) owns the original, encoded data (if
// `should_keep_encoded_data` was passed to `StartLoadingBodyInBackground()`)
// or, or 2) just stores the data size (if `!should_keep_encoded_data`).
class HeapArrayOrSize {};

// A chunk of data read by the OffThreadBodyReader. This will be created on a
// background thread and processed on the main thread.
struct DataChunk {};

// This interface abstracts out the logic for consuming the response body and
// allows calling ReadFromDataPipeImpl() on either the main thread or a
// background thread.
class BodyReader {};

void ReadFromDataPipeImpl(BodyReader& reader,
                          mojo::ScopedDataPipeConsumerHandle& handle,
                          mojo::SimpleWatcher& handle_watcher) {}

}  // namespace

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() {}

// static
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) {}

}  // namespace blink