chromium/third_party/blink/renderer/bindings/core/v8/script_decoder.h

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

#ifndef THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_SCRIPT_DECODER_H_
#define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_SCRIPT_DECODER_H_

#include <memory>
#include <optional>
#include <tuple>

#include "base/location.h"
#include "base/task/sequenced_task_runner.h"
#include "mojo/public/cpp/system/data_pipe.h"
#include "mojo/public/cpp/system/data_pipe_drainer.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/bindings/parkable_string.h"
#include "third_party/blink/renderer/platform/crypto.h"
#include "third_party/blink/renderer/platform/heap/cross_thread_handle.h"
#include "third_party/blink/renderer/platform/wtf/deque.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/shared_buffer.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace blink {

class ResponseBodyLoaderClient;
class ScriptDecoder;
class ScriptDecoderWithClient;
class TextResourceDecoder;

struct CORE_EXPORT ScriptDecoderDeleter {};
ScriptDecoderPtr;

// ScriptDecoder decodes and hashes the script source on a worker thread. The
// OnDecodeFinishedCallback will receive the raw data and the decoded data.
// This class will be used for decoding script sources without a
// ResponseBodyLoaderClient when Blink receives the response on the background
// thread (BackgroundResourceFetch feature).
// TODO(crbug.com/328297266): Consider removing this class, and use the decoded
// text by V8.
class CORE_EXPORT ScriptDecoder {};

class DataPipeScriptDecoder;
struct CORE_EXPORT DataPipeScriptDecoderDeleter {};

DataPipeScriptDecoderPtr;

// DataPipeScriptDecoder decodes and hashes the script source of a Mojo data
// pipe on a worker thread. The OnDecodeFinishedCallback will receive the raw
// data and the decoded data.
// Currently this class is used only when BackgroundCodeCacheDecoderStart
// feature is enabled.
class CORE_EXPORT DataPipeScriptDecoder final
    : public mojo::DataPipeDrainer::Client {};

struct CORE_EXPORT ScriptDecoderWithClientDeleter {};
ScriptDecoderWithClientPtr;

// ScriptDecoderWithClient decodes and hashes the script source on a worker
// thread, and then forwards the data to the client on the client thread.
// TODO(crbug.com/328297266): Consider removing this class, and use the decoded
// text by V8.
class CORE_EXPORT ScriptDecoderWithClient {};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_SCRIPT_DECODER_H_