chromium/third_party/blink/renderer/modules/shared_storage/shared_storage_worklet_global_scope.cc

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

#include "third_party/blink/renderer/modules/shared_storage/shared_storage_worklet_global_scope.h"

#include <stdint.h>

#include <memory>
#include <utility>

#include "base/check.h"
#include "base/check_op.h"
#include "base/functional/callback.h"
#include "gin/converter.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/mojom/url_loader_factory.mojom-blink.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/shared_storage/module_script_downloader.h"
#include "third_party/blink/public/common/shared_storage/shared_storage_utils.h"
#include "third_party/blink/public/mojom/private_aggregation/private_aggregation_host.mojom-blink.h"
#include "third_party/blink/public/mojom/shared_storage/shared_storage_worklet_service.mojom-blink.h"
#include "third_party/blink/public/platform/cross_variant_mojo_util.h"
#include "third_party/blink/public/platform/web_url_response.h"
#include "third_party/blink/renderer/bindings/core/v8/idl_types.h"
#include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h"
#include "third_party/blink/renderer/bindings/core/v8/script_function.h"
#include "third_party/blink/renderer/bindings/core/v8/serialization/unpacked_serialized_script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_no_argument_constructor.h"
#include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_run_function_for_shared_storage_run_operation.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_run_function_for_shared_storage_select_url_operation.h"
#include "third_party/blink/renderer/core/context_features/context_feature_settings.h"
#include "third_party/blink/renderer/core/script/classic_script.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
#include "third_party/blink/renderer/core/workers/threaded_messaging_proxy_base.h"
#include "third_party/blink/renderer/modules/crypto/crypto.h"
#include "third_party/blink/renderer/modules/shared_storage/private_aggregation.h"
#include "third_party/blink/renderer/modules/shared_storage/shared_storage.h"
#include "third_party/blink/renderer/modules/shared_storage/shared_storage_operation_definition.h"
#include "third_party/blink/renderer/modules/shared_storage/shared_storage_worklet_thread.h"
#include "third_party/blink/renderer/platform/bindings/callback_method_retriever.h"
#include "third_party/blink/renderer/platform/loader/fetch/script_cached_metadata_handler.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/code_cache_fetcher.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "v8/include/v8-context.h"
#include "v8/include/v8-isolate.h"
#include "v8/include/v8-local-handle.h"
#include "v8/include/v8-primitive.h"
#include "v8/include/v8-value.h"

namespace blink {

namespace {

std::optional<ScriptValue> Deserialize(
    v8::Isolate* isolate,
    ExecutionContext* execution_context,
    const BlinkCloneableMessage& serialized_data) {}

// We try to use .stack property so that the error message contains a stack
// trace, but otherwise fallback to .toString().
String ExceptionToString(ScriptState* script_state,
                         v8::Local<v8::Value> exception) {}

struct UnresolvedSelectURLRequest final
    : public GarbageCollected<UnresolvedSelectURLRequest> {};

struct UnresolvedRunRequest final
    : public GarbageCollected<UnresolvedRunRequest> {};

class SelectURLResolutionSuccessCallback final
    : public ScriptFunction::Callable {};

class SelectURLResolutionFailureCallback final
    : public ScriptFunction::Callable {};

class RunResolutionSuccessCallback final : public ScriptFunction::Callable {};

class RunResolutionFailureCallback final : public ScriptFunction::Callable {};

}  // namespace

SharedStorageWorkletGlobalScope::SharedStorageWorkletGlobalScope(
    std::unique_ptr<GlobalScopeCreationParams> creation_params,
    WorkerThread* thread)
    :{}

SharedStorageWorkletGlobalScope::~SharedStorageWorkletGlobalScope() = default;

void SharedStorageWorkletGlobalScope::BindSharedStorageWorkletService(
    mojo::PendingReceiver<mojom::blink::SharedStorageWorkletService> receiver,
    base::OnceClosure disconnect_handler) {}

void SharedStorageWorkletGlobalScope::Register(
    const String& name,
    V8NoArgumentConstructor* operation_ctor,
    ExceptionState& exception_state) {}

void SharedStorageWorkletGlobalScope::OnConsoleApiMessage(
    mojom::ConsoleMessageLevel level,
    const String& message,
    SourceLocation* location) {}

void SharedStorageWorkletGlobalScope::NotifyContextDestroyed() {}

void SharedStorageWorkletGlobalScope::Trace(Visitor* visitor) const {}

void SharedStorageWorkletGlobalScope::Initialize(
    mojo::PendingAssociatedRemote<
        mojom::blink::SharedStorageWorkletServiceClient> client,
    bool private_aggregation_permissions_policy_allowed,
    const String& embedder_context) {}

void SharedStorageWorkletGlobalScope::AddModule(
    mojo::PendingRemote<network::mojom::blink::URLLoaderFactory>
        pending_url_loader_factory,
    const KURL& script_source_url,
    AddModuleCallback callback) {}

void SharedStorageWorkletGlobalScope::RunURLSelectionOperation(
    const String& name,
    const Vector<KURL>& urls,
    BlinkCloneableMessage serialized_data,
    mojom::blink::PrivateAggregationOperationDetailsPtr pa_operation_details,
    RunURLSelectionOperationCallback callback) {}

void SharedStorageWorkletGlobalScope::RunOperation(
    const String& name,
    BlinkCloneableMessage serialized_data,
    mojom::blink::PrivateAggregationOperationDetailsPtr pa_operation_details,
    RunOperationCallback callback) {}

SharedStorage* SharedStorageWorkletGlobalScope::sharedStorage(
    ScriptState* script_state,
    ExceptionState& exception_state) {}

PrivateAggregation* SharedStorageWorkletGlobalScope::privateAggregation(
    ScriptState* script_state,
    ExceptionState& exception_state) {}

Crypto* SharedStorageWorkletGlobalScope::crypto(
    ScriptState* script_state,
    ExceptionState& exception_state) {}

// Returns the unique ID for the currently running operation.
int64_t SharedStorageWorkletGlobalScope::GetCurrentOperationId() {}

void SharedStorageWorkletGlobalScope::OnModuleScriptDownloaded(
    const KURL& script_source_url,
    mojom::blink::SharedStorageWorkletService::AddModuleCallback callback,
    std::unique_ptr<std::string> response_body,
    std::string error_message,
    network::mojom::URLResponseHeadPtr response_head) {}

void SharedStorageWorkletGlobalScope::DidReceiveCachedCode() {}

void SharedStorageWorkletGlobalScope::RecordAddModuleFinished() {}

bool SharedStorageWorkletGlobalScope::PerformCommonOperationChecks(
    const String& operation_name,
    String& error_message,
    SharedStorageOperationDefinition*& operation_definition) {}

base::OnceClosure SharedStorageWorkletGlobalScope::StartOperation(
    mojom::blink::PrivateAggregationOperationDetailsPtr pa_operation_details) {}

void SharedStorageWorkletGlobalScope::FinishOperation(int64_t operation_id) {}

PrivateAggregation*
SharedStorageWorkletGlobalScope::GetOrCreatePrivateAggregation() {}

}  // namespace blink