chromium/third_party/blink/renderer/modules/peerconnection/rtc_data_channel.cc

/*
 * Copyright (C) 2012 Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1.  Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 * 2.  Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "third_party/blink/renderer/modules/peerconnection/rtc_data_channel.h"

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

#include "base/containers/span.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "components/webrtc/thread_wrapper.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/core/events/message_event.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/fileapi/blob.h"
#include "third_party/blink/renderer/core/fileapi/file_error.h"
#include "third_party/blink/renderer/core/fileapi/file_reader_client.h"
#include "third_party/blink/renderer/core/fileapi/file_reader_loader.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/inspector/console_message.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/peerconnection/adapters/web_rtc_cross_thread_copier.h"
#include "third_party/blink/renderer/modules/peerconnection/rtc_error_event.h"
#include "third_party/blink/renderer/modules/peerconnection/rtc_peer_connection.h"
#include "third_party/blink/renderer/modules/peerconnection/rtc_peer_connection_handler.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/scheduling_policy.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_base.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_std.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/thread_safe_ref_counted.h"
#include "third_party/webrtc/api/priority.h"

namespace WTF {

template <>
struct CrossThreadCopier<rtc::scoped_refptr<webrtc::DataChannelInterface>>
    : public CrossThreadCopierPassThrough<
          rtc::scoped_refptr<webrtc::DataChannelInterface>> {};

}  // namespace WTF

namespace blink {

namespace {

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class DataChannelCounters {};

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class DataChannelAggregateType {};

void IncrementCounter(DataChannelCounters counter) {}

void IncrementCounters(const webrtc::DataChannelInterface& channel) {}

void RecordMessageSent(const webrtc::DataChannelInterface& channel,
                       size_t num_bytes) {}

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class DataChannelSctpErrorCode {};

void IncrementErrorCounter(const webrtc::RTCError& error) {}

}  // namespace

static void ThrowNotOpenException(ExceptionState* exception_state) {}

static void ThrowSendBufferFullException(ExceptionState* exception_state) {}

RTCDataChannel::Observer::Observer(
    scoped_refptr<base::SingleThreadTaskRunner> main_thread,
    RTCDataChannel* blink_channel,
    rtc::scoped_refptr<webrtc::DataChannelInterface> channel)
    :{}

RTCDataChannel::Observer::~Observer() {}

const rtc::scoped_refptr<webrtc::DataChannelInterface>&
RTCDataChannel::Observer::channel() const {}

bool RTCDataChannel::Observer::is_registered() const {}

void RTCDataChannel::Observer::Unregister() {}

void RTCDataChannel::Observer::OnStateChange() {}

void RTCDataChannel::Observer::OnBufferedAmountChange(uint64_t sent_data_size) {}

void RTCDataChannel::Observer::OnMessage(const webrtc::DataBuffer& buffer) {}

bool RTCDataChannel::Observer::IsOkToCallOnTheNetworkThread() {}

void RTCDataChannel::Observer::OnStateChangeImpl(
    webrtc::DataChannelInterface::DataState state) {}

void RTCDataChannel::Observer::OnBufferedAmountChangeImpl(
    unsigned sent_data_size) {}

void RTCDataChannel::Observer::OnMessageImpl(webrtc::DataBuffer buffer) {}

// static
void RTCDataChannel::EnsureThreadWrappersForWorkerThread() {}

RTCDataChannel::RTCDataChannel(
    ExecutionContext* context,
    rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel)
    :{}

RTCDataChannel::~RTCDataChannel() {}

void RTCDataChannel::RegisterObserver() {}

String RTCDataChannel::label() const {}

bool RTCDataChannel::reliable() const {}

bool RTCDataChannel::ordered() const {}

std::optional<uint16_t> RTCDataChannel::maxPacketLifeTime() const {}

std::optional<uint16_t> RTCDataChannel::maxRetransmits() const {}

String RTCDataChannel::protocol() const {}

bool RTCDataChannel::negotiated() const {}

std::optional<uint16_t> RTCDataChannel::id() const {}

String RTCDataChannel::priority() const {}

String RTCDataChannel::readyState() const {}

unsigned RTCDataChannel::bufferedAmount() const {}

unsigned RTCDataChannel::bufferedAmountLowThreshold() const {}

void RTCDataChannel::setBufferedAmountLowThreshold(unsigned threshold) {}

String RTCDataChannel::binaryType() const {}

void RTCDataChannel::setBinaryType(const String& binary_type,
                                   ExceptionState& exception_state) {}

bool RTCDataChannel::ValidateSendLength(uint64_t length,
                                        ExceptionState& exception_state) {}

void RTCDataChannel::send(const String& data, ExceptionState& exception_state) {}

void RTCDataChannel::send(DOMArrayBuffer* data,
                          ExceptionState& exception_state) {}

void RTCDataChannel::send(NotShared<DOMArrayBufferView> data,
                          ExceptionState& exception_state) {}

void RTCDataChannel::send(Blob* data, ExceptionState& exception_state) {}

void RTCDataChannel::close() {}

bool RTCDataChannel::IsTransferable() {}

rtc::scoped_refptr<webrtc::DataChannelInterface>
RTCDataChannel::TransferUnderlyingChannel() {}

const AtomicString& RTCDataChannel::InterfaceName() const {}

ExecutionContext* RTCDataChannel::GetExecutionContext() const {}

void RTCDataChannel::ContextDestroyed() {}

// ActiveScriptWrappable
bool RTCDataChannel::HasPendingActivity() const {}

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

void RTCDataChannel::SetStateToOpenWithoutEvent() {}

void RTCDataChannel::DispatchOpenEvent() {}

void RTCDataChannel::OnStateChange(
    webrtc::DataChannelInterface::DataState state) {}

void RTCDataChannel::OnBufferedAmountChange(unsigned sent_data_size) {}

void RTCDataChannel::OnMessage(webrtc::DataBuffer buffer) {}

void RTCDataChannel::Dispose() {}

const rtc::scoped_refptr<webrtc::DataChannelInterface>&
RTCDataChannel::channel() const {}

void RTCDataChannel::SendRawData(const char* data, size_t length) {}

void RTCDataChannel::SendDataBuffer(webrtc::DataBuffer data_buffer) {}

void RTCDataChannel::CreateFeatureHandleForScheduler() {}

void RTCDataChannel::ProcessSendQueue() {}

void RTCDataChannel::PendingMessage::Trace(Visitor* visitor) const {}

void RTCDataChannel::BlobReader::DidFinishLoading(FileReaderData data) {}

void RTCDataChannel::BlobReader::DidFail(FileErrorCode error) {}

RTCDataChannel::BlobReader::BlobReader(ExecutionContext* context,
                                       RTCDataChannel* data_channel,
                                       PendingMessage* message)
    :{}

RTCDataChannel::BlobReader::~BlobReader() = default;

void RTCDataChannel::BlobReader::Start(Blob* blob) {}

void RTCDataChannel::BlobReader::Trace(Visitor* visitor) const {}

bool RTCDataChannel::BlobReader::HasFinishedLoading() const {}

void RTCDataChannel::BlobReader::ContextDestroyed() {}

}  // namespace blink