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

// Copyright 2014 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_STREAMER_H_
#define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_SCRIPT_STREAMER_H_

#include <memory>
#include <tuple>

#include "base/check_op.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/single_thread_task_runner.h"
#include "mojo/public/cpp/system/data_pipe.h"
#include "third_party/blink/public/mojom/script/script_type.mojom-blink-forward.h"
#include "third_party/blink/renderer/bindings/core/v8/script_decoder.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/html/parser/text_resource_decoder.h"
#include "third_party/blink/renderer/core/script/script_scheduling_type.h"
#include "third_party/blink/renderer/platform/bindings/parkable_string.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/heap/prefinalizer.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/background_response_processor.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/thread_safe_ref_counted.h"
#include "v8/include/v8.h"

namespace mojo {
class SimpleWatcher;
}

namespace blink {

namespace v8_compile_hints {
class CompileHintsForStreaming;
class V8LocalCompileHintsConsumer;
}  // namespace v8_compile_hints

class ScriptResource;
class SourceStream;
class ResponseBodyLoaderClient;

// Base class for streaming scripts. Subclasses should expose streamed script
// data by overriding the Source() method.
class CORE_EXPORT ScriptStreamer : public GarbageCollected<ScriptStreamer> {};

// ResourceScriptStreamer streams incomplete script data to V8 so that it can be
// parsed while it's loaded. ScriptResource holds a reference to
// ResourceScriptStreamer. If the Document and the ClassicPendingScript are
// destroyed while the streaming is in progress, and ScriptStreamer handles it
// gracefully.
class CORE_EXPORT ResourceScriptStreamer final : public ScriptStreamer {};

// BackgroundInlineScriptStreamer allows parsing and compiling inline scripts in
// the background before they have been parsed by the HTML parser. Use
// InlineScriptStreamer::From() to create a ScriptStreamer from this class.
class CORE_EXPORT BackgroundInlineScriptStreamer final
    : public WTF::ThreadSafeRefCounted<BackgroundInlineScriptStreamer> {};

// ScriptStreamer is garbage collected so must be created on the main thread.
// This class wraps a BackgroundInlineScriptStreamer to be used on the main
// thread.
class CORE_EXPORT InlineScriptStreamer final : public ScriptStreamer {};

// BackgroundResourceScriptStreamer allows starting the script parser from the
// background thread of BackgroundURLLoader. MaybeStartProcessingResponse()
// method of `background_processor_` is called by the BackgroundURLLoader on the
// background thread, and triggers the script parser on another background
// thread.
class CORE_EXPORT BackgroundResourceScriptStreamer : public ScriptStreamer {};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_SCRIPT_STREAMER_H_