chromium/content/browser/worker_host/worker_script_loader.cc

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

#include "content/browser/worker_host/worker_script_loader.h"

#include "base/functional/bind.h"
#include "content/browser/loader/navigation_loader_interceptor.h"
#include "content/browser/loader/response_head_update_params.h"
#include "content/browser/service_worker/service_worker_client.h"
#include "content/browser/service_worker/service_worker_main_resource_handle.h"
#include "content/browser/service_worker/service_worker_main_resource_loader_interceptor.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/load_timing_info.h"
#include "net/url_request/redirect_util.h"
#include "services/network/public/cpp/record_ontransfersizeupdate_utils.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/url_loader_completion_status.h"
#include "services/network/public/mojom/early_hints.mojom.h"

namespace content {

WorkerScriptLoader::WorkerScriptLoader(
    int process_id,
    const DedicatedOrSharedWorkerToken& worker_token,
    int32_t request_id,
    uint32_t options,
    const network::ResourceRequest& resource_request,
    const net::IsolationInfo& isolation_info,
    mojo::PendingRemote<network::mojom::URLLoaderClient> client,
    base::WeakPtr<ServiceWorkerMainResourceHandle> service_worker_handle,
    const BrowserContextGetter& browser_context_getter,
    scoped_refptr<network::SharedURLLoaderFactory> default_loader_factory,
    const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
    :{}

WorkerScriptLoader::~WorkerScriptLoader() {}

base::WeakPtr<WorkerScriptLoader> WorkerScriptLoader::GetWeakPtr() {}

void WorkerScriptLoader::Abort() {}

void WorkerScriptLoader::Start() {}

void WorkerScriptLoader::MaybeStartLoader(
    ServiceWorkerMainResourceLoaderInterceptor* interceptor,
    std::optional<NavigationLoaderInterceptor::Result> interceptor_result) {}

void WorkerScriptLoader::LoadFromNetwork() {}

// URLLoader -------------------------------------------------------------------
// When this class gets a FollowRedirect IPC from the renderer, it restarts with
// the new URL.

void WorkerScriptLoader::FollowRedirect(
    const std::vector<std::string>& removed_headers,
    const net::HttpRequestHeaders& modified_headers,
    const net::HttpRequestHeaders& modified_cors_exempt_headers,
    const std::optional<GURL>& new_url) {}

// Below we make a small effort to support the other URLLoader functions by
// forwarding to the current |url_loader_| if any, but don't bother queuing
// state or propagating state to a new URLLoader upon redirect.
void WorkerScriptLoader::SetPriority(net::RequestPriority priority,
                                     int32_t intra_priority_value) {}

void WorkerScriptLoader::PauseReadingBodyFromNet() {}

void WorkerScriptLoader::ResumeReadingBodyFromNet() {}
// URLLoader end --------------------------------------------------------------

// URLLoaderClient ------------------------------------------------------------
// This class forwards any client messages to the outer client in the renderer.
// Additionally, on redirects it saves the redirect info so if the renderer
// calls FollowRedirect(), it can do so.

void WorkerScriptLoader::OnReceiveEarlyHints(
    network::mojom::EarlyHintsPtr early_hints) {}

void WorkerScriptLoader::OnReceiveResponse(
    network::mojom::URLResponseHeadPtr response_head,
    mojo::ScopedDataPipeConsumerHandle body,
    std::optional<mojo_base::BigBuffer> cached_metadata) {}

void WorkerScriptLoader::OnReceiveRedirect(
    const net::RedirectInfo& redirect_info,
    network::mojom::URLResponseHeadPtr response_head) {}

void WorkerScriptLoader::OnUploadProgress(
    int64_t current_position,
    int64_t total_size,
    OnUploadProgressCallback ack_callback) {}

void WorkerScriptLoader::OnTransferSizeUpdated(int32_t transfer_size_diff) {}

void WorkerScriptLoader::OnComplete(
    const network::URLLoaderCompletionStatus& status) {}

// URLLoaderClient end ---------------------------------------------------------

void WorkerScriptLoader::OnFetcherCallbackCalled() {}

// `CommitCompleted()` with `net::OK` must not be called before
// `WorkerScriptFetcher::callback_` to ensure the order:
// 1. `ServiceWorkerContainerHost` pipes are passed to the renderer process
//    inside `WorkerScriptFetcher::callback_`
// 2. `ServiceWorkerClient::SetExecutionReady()` is called inside
//    `WorkerScriptLoader::CommitCompleted()`
// 3. `client_->OnComplete()` is called which eventually triggers worker
//    top-level script evaluation on the renderer process.
// (Note that non-OK `CommitCompleted()` can be called without 1 or 3)
void WorkerScriptLoader::CommitCompleted() {}

}  // namespace content