#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/modules/webtransport/web_transport.h"
#include <stdint.h>
#include <optional>
#include <utility>
#include "base/numerics/safe_conversions.h"
#include "base/time/time.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/devtools/console_message.mojom-blink.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/core/v8/to_v8_traits.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_throw_dom_exception.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_arraybuffer_arraybufferview.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_web_transport_close_info.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_web_transport_connection_stats.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_web_transport_datagram_stats.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_web_transport_error.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_web_transport_hash.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_web_transport_options.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/loader/base_fetch_context.h"
#include "third_party/blink/renderer/core/loader/subresource_filter.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/streams/readable_stream.h"
#include "third_party/blink/renderer/core/streams/readable_stream_byob_request.h"
#include "third_party/blink/renderer/core/streams/readable_stream_default_controller_with_script_scope.h"
#include "third_party/blink/renderer/core/streams/underlying_byte_source_base.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_piece.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h"
#include "third_party/blink/renderer/modules/webtransport/bidirectional_stream.h"
#include "third_party/blink/renderer/modules/webtransport/datagram_duplex_stream.h"
#include "third_party/blink/renderer/modules/webtransport/receive_stream.h"
#include "third_party/blink/renderer/modules/webtransport/send_stream.h"
#include "third_party/blink/renderer/modules/webtransport/web_transport_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/heap/persistent.h"
#include "third_party/blink/renderer/platform/heap/visitor.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
#include "third_party/blink/renderer/platform/loader/fetch/unique_identifier.h"
#include "third_party/blink/renderer/platform/timer.h"
#include "third_party/blink/renderer/platform/wtf/functional.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"
#include "v8/include/v8.h"
namespace blink {
namespace {
constexpr base::TimeDelta kDefaultIncomingMaxAge = …;
bool CreateStreamDataPipe(mojo::ScopedDataPipeProducerHandle* producer,
mojo::ScopedDataPipeConsumerHandle* consumer,
ExceptionState& exception_state) { … }
}
class WebTransport::DatagramUnderlyingSink final : public UnderlyingSinkBase { … };
class WebTransport::DatagramUnderlyingSource final
: public UnderlyingByteSourceBase { … };
class WebTransport::StreamVendingUnderlyingSource final
: public UnderlyingSourceBase { … };
class WebTransport::ReceiveStreamVendor final
: public WebTransport::StreamVendingUnderlyingSource::StreamVendor { … };
class WebTransport::BidirectionalStreamVendor final
: public WebTransport::StreamVendingUnderlyingSource::StreamVendor { … };
WebTransport* WebTransport::Create(ScriptState* script_state,
const String& url,
WebTransportOptions* options,
ExceptionState& exception_state) { … }
WebTransport::WebTransport(PassKey,
ScriptState* script_state,
const String& url)
: … { … }
WebTransport::WebTransport(ScriptState* script_state,
const String& url,
ExecutionContext* context)
: … { … }
ScriptPromise<WritableStream> WebTransport::createUnidirectionalStream(
ScriptState* script_state,
ExceptionState& exception_state) { … }
ReadableStream* WebTransport::incomingUnidirectionalStreams() { … }
ScriptPromise<BidirectionalStream> WebTransport::createBidirectionalStream(
ScriptState* script_state,
ExceptionState& exception_state) { … }
ReadableStream* WebTransport::incomingBidirectionalStreams() { … }
DatagramDuplexStream* WebTransport::datagrams() { … }
WritableStream* WebTransport::datagramWritable() { … }
ReadableStream* WebTransport::datagramReadable() { … }
void WebTransport::close(WebTransportCloseInfo* close_info) { … }
void WebTransport::setDatagramWritableQueueExpirationDuration(double duration) { … }
ScriptPromise<IDLUndefined> WebTransport::ready(ScriptState* script_state) { … }
ScriptPromise<WebTransportCloseInfo> WebTransport::closed(
ScriptState* script_state) { … }
ScriptPromise<WebTransportConnectionStats> WebTransport::getStats(
ScriptState* script_state) { … }
void WebTransport::OnConnectionEstablished(
mojo::PendingRemote<network::mojom::blink::WebTransport> web_transport,
mojo::PendingReceiver<network::mojom::blink::WebTransportClient>
client_receiver,
network::mojom::blink::HttpResponseHeadersPtr response_headers,
network::mojom::blink::WebTransportStatsPtr initial_stats) { … }
WebTransport::~WebTransport() = default;
void WebTransport::OnHandshakeFailed(
network::mojom::blink::WebTransportErrorPtr error) { … }
void WebTransport::OnDatagramReceived(base::span<const uint8_t> data) { … }
void WebTransport::OnIncomingStreamClosed(uint32_t stream_id,
bool fin_received) { … }
void WebTransport::OnReceivedResetStream(uint32_t stream_id,
uint32_t stream_error_code) { … }
void WebTransport::OnReceivedStopSending(uint32_t stream_id,
uint32_t stream_error_code) { … }
void WebTransport::OnClosed(
network::mojom::blink::WebTransportCloseInfoPtr close_info,
network::mojom::blink::WebTransportStatsPtr final_stats) { … }
void WebTransport::OnOutgoingStreamClosed(uint32_t stream_id) { … }
void WebTransport::ContextDestroyed() { … }
bool WebTransport::HasPendingActivity() const { … }
void WebTransport::SendFin(uint32_t stream_id) { … }
void WebTransport::ResetStream(uint32_t stream_id, uint32_t code) { … }
void WebTransport::StopSending(uint32_t stream_id, uint32_t code) { … }
void WebTransport::ForgetIncomingStream(uint32_t stream_id) { … }
void WebTransport::ForgetOutgoingStream(uint32_t stream_id) { … }
void WebTransport::Trace(Visitor* visitor) const { … }
void WebTransport::Init(const String& url_for_diagnostics,
const WebTransportOptions& options,
ExceptionState& exception_state) { … }
bool WebTransport::DoesSubresourceFilterBlockConnection(const KURL& url) { … }
void WebTransport::Dispose() { … }
void WebTransport::Cleanup(WebTransportCloseInfo* info,
v8::Local<v8::Value> error,
bool abruptly) { … }
void WebTransport::OnConnectionError() { … }
void WebTransport::RejectPendingStreamResolvers(v8::Local<v8::Value> error) { … }
void WebTransport::HandlePendingGetStatsResolvers(v8::Local<v8::Value> error) { … }
void WebTransport::OnCreateSendStreamResponse(
ScriptPromiseResolver<WritableStream>* resolver,
mojo::ScopedDataPipeProducerHandle producer,
bool succeeded,
uint32_t stream_id) { … }
void WebTransport::OnCreateBidirectionalStreamResponse(
ScriptPromiseResolver<BidirectionalStream>* resolver,
mojo::ScopedDataPipeProducerHandle outgoing_producer,
mojo::ScopedDataPipeConsumerHandle incoming_consumer,
bool succeeded,
uint32_t stream_id) { … }
void WebTransport::OnGetStatsResponse(
network::mojom::blink::WebTransportStatsPtr stats) { … }
WebTransportConnectionStats* WebTransport::ConvertStatsFromMojom(
network::mojom::blink::WebTransportStatsPtr in) { … }
}