chromium/third_party/blink/renderer/modules/websockets/websocket_stream.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.

#include "third_party/blink/renderer/modules/websockets/websocket_stream.h"

#include <memory>
#include <string>
#include <utility>

#include "third_party/blink/renderer/bindings/core/v8/capture_source_location.h"
#include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_throw_dom_exception.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_websocket_close_info.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_websocket_error.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_websocket_open_info.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_websocket_stream_options.h"
#include "third_party/blink/renderer/core/dom/abort_signal.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/streams/readable_stream.h"
#include "third_party/blink/renderer/core/streams/readable_stream_default_controller_with_script_scope.h"
#include "third_party/blink/renderer/core/streams/underlying_sink_base.h"
#include "third_party/blink/renderer/core/streams/underlying_source_base.h"
#include "third_party/blink/renderer/core/streams/writable_stream.h"
#include "third_party/blink/renderer/core/streams/writable_stream_default_controller.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h"
#include "third_party/blink/renderer/modules/websockets/websocket_channel_impl.h"
#include "third_party/blink/renderer/modules/websockets/websocket_error.h"
#include "third_party/blink/renderer/platform/bindings/exception_code.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/bindings/v8_binding.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"

namespace blink {

namespace {

// This is used in several places, so use a constant to avoid typos.
constexpr char kWebSocketNotCleanlyClosedErrorMessage[] =;

}  // namespace

class WebSocketStream::UnderlyingSource final : public UnderlyingSourceBase {};

class WebSocketStream::UnderlyingSink final : public UnderlyingSinkBase {};

ScriptPromiseUntyped WebSocketStream::UnderlyingSource::Pull(
    ScriptState* script_state,
    ExceptionState&) {}

ScriptPromiseUntyped WebSocketStream::UnderlyingSource::Cancel(
    ScriptState* script_state,
    ScriptValue reason,
    ExceptionState& exception_state) {}

void WebSocketStream::UnderlyingSource::DidReceiveTextMessage(
    const String& string) {}

void WebSocketStream::UnderlyingSource::DidReceiveBinaryMessage(
    const Vector<base::span<const char>>& data) {}

void WebSocketStream::UnderlyingSource::DidStartClosingHandshake() {}

void WebSocketStream::UnderlyingSource::DidCloseCleanly(uint16_t code,
                                                        const String& reason) {}

void WebSocketStream::UnderlyingSource::CloseWithError(
    v8::Local<v8::Value> error) {}

ScriptPromise<IDLUndefined> WebSocketStream::UnderlyingSink::start(
    ScriptState* script_state,
    WritableStreamDefaultController*,
    ExceptionState& exception_state) {}

ScriptPromise<IDLUndefined> WebSocketStream::UnderlyingSink::write(
    ScriptState* script_state,
    ScriptValue chunk,
    WritableStreamDefaultController*,
    ExceptionState& exception_state) {}

ScriptPromise<IDLUndefined> WebSocketStream::UnderlyingSink::close(
    ScriptState* script_state,
    ExceptionState& exception_state) {}

ScriptPromise<IDLUndefined> WebSocketStream::UnderlyingSink::abort(
    ScriptState* script_state,
    ScriptValue reason,
    ExceptionState& exception_state) {}

void WebSocketStream::UnderlyingSink::DidStartClosingHandshake() {}

void WebSocketStream::UnderlyingSink::DidCloseCleanly(uint16_t code,
                                                      const String& reason) {}

void WebSocketStream::UnderlyingSink::CloseWithError(
    v8::Local<v8::Value> error) {}

void WebSocketStream::UnderlyingSink::ErrorControllerBecauseClosed() {}

void WebSocketStream::UnderlyingSink::FinishWriteCallback(
    ScriptPromiseResolver<IDLUndefined>* resolver) {}

void WebSocketStream::UnderlyingSink::ResolveClose(bool was_clean) {}

void WebSocketStream::UnderlyingSink::SendArrayBuffer(
    ScriptState* script_state,
    DOMArrayBuffer* buffer,
    size_t offset,
    size_t length,
    ScriptPromiseResolver<IDLUndefined>* resolver,
    base::OnceClosure callback) {}

void WebSocketStream::UnderlyingSink::SendString(
    ScriptState* script_state,
    v8::Local<v8::Value> v8chunk,
    ScriptPromiseResolver<IDLUndefined>* resolver,
    base::OnceClosure callback) {}

WebSocketStream* WebSocketStream::Create(ScriptState* script_state,
                                         const String& url,
                                         WebSocketStreamOptions* options,
                                         ExceptionState& exception_state) {}

WebSocketStream* WebSocketStream::CreateForTesting(
    ScriptState* script_state,
    const String& url,
    WebSocketStreamOptions* options,
    WebSocketChannel* channel,
    ExceptionState& exception_state) {}

WebSocketStream* WebSocketStream::CreateInternal(
    ScriptState* script_state,
    const String& url,
    WebSocketStreamOptions* options,
    WebSocketChannel* channel,
    ExceptionState& exception_state) {}

WebSocketStream::WebSocketStream(ExecutionContext* execution_context,
                                 ScriptState* script_state)
    :{}

WebSocketStream::~WebSocketStream() = default;

ScriptPromise<WebSocketOpenInfo> WebSocketStream::opened(
    ScriptState* script_state) const {}

ScriptPromise<WebSocketCloseInfo> WebSocketStream::closed(
    ScriptState* script_state) const {}

void WebSocketStream::close(WebSocketCloseInfo* info,
                            ExceptionState& exception_state) {}

void WebSocketStream::DidConnect(const String& subprotocol,
                                 const String& extensions) {}

void WebSocketStream::DidReceiveTextMessage(const String& string) {}

void WebSocketStream::DidReceiveBinaryMessage(
    const Vector<base::span<const char>>& data) {}

void WebSocketStream::DidError() {}

void WebSocketStream::DidConsumeBufferedAmount(uint64_t consumed) {}

void WebSocketStream::DidStartClosingHandshake() {}

void WebSocketStream::DidClose(
    ClosingHandshakeCompletionStatus closing_handshake_completion,
    uint16_t code,
    const String& reason) {}

void WebSocketStream::ContextDestroyed() {}

bool WebSocketStream::HasPendingActivity() const {}

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

void WebSocketStream::Connect(ScriptState* script_state,
                              const String& url,
                              WebSocketStreamOptions* options,
                              ExceptionState& exception_state) {}

// If |maybe_reason| contains a valid code and reason, then closes with it,
// otherwise closes with unspecified code and reason.
void WebSocketStream::CloseMaybeWithReason(ScriptValue maybe_reason,
                                           ExceptionState& exception_state) {}

void WebSocketStream::CloseWithUnspecifiedCode(
    ExceptionState& exception_state) {}

void WebSocketStream::CloseInternal(std::optional<uint16_t> code,
                                    const String& reason,
                                    ExceptionState& exception_state) {}

v8::Local<v8::Value> WebSocketStream::CreateWebSocketError(
    String message,
    std::optional<uint16_t> close_code,
    String reason) {}

void WebSocketStream::OnAbort() {}

WebSocketCloseInfo* WebSocketStream::MakeCloseInfo(uint16_t close_code,
                                                   const String& reason) {}

}  // namespace blink