diff --git a/dom/moz.build b/dom/moz.build index 0cfc381066a5..21c6e2045857 100644 --- a/dom/moz.build +++ b/dom/moz.build @@ -86,6 +86,7 @@ DIRS += [ "webauthn", "webidl", "webshare", + "webtransport", "xml", "xslt", "xul", diff --git a/dom/streams/ReadableStream.h b/dom/streams/ReadableStream.h index 24581fc7cc0b..b28796df1db3 100644 --- a/dom/streams/ReadableStream.h +++ b/dom/streams/ReadableStream.h @@ -40,13 +40,13 @@ class BodyStreamHolder; class UniqueMessagePortId; class MessagePort; -class ReadableStream final : public nsISupports, public nsWrapperCache { +class ReadableStream : public nsISupports, public nsWrapperCache { public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ReadableStream) protected: - ~ReadableStream(); + virtual ~ReadableStream(); nsCOMPtr mGlobal; diff --git a/dom/webidl/WebTransport.webidl b/dom/webidl/WebTransport.webidl new file mode 100644 index 000000000000..9cc6b450873d --- /dev/null +++ b/dom/webidl/WebTransport.webidl @@ -0,0 +1,94 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* https://w3c.github.io/webtransport */ + +/* https://w3c.github.io/webtransport/#web-transport-configuration */ + +dictionary WebTransportHash { + DOMString algorithm; + BufferSource value; +}; + +dictionary WebTransportOptions { + boolean allowPooling = false; + boolean requireUnreliable = false; + sequence serverCertificateHashes; + WebTransportCongestionControl congestionControl = "default"; +}; + +enum WebTransportCongestionControl { + "default", + "throughput", + "low-latency", +}; + +/* https://w3c.github.io/webtransport/#web-transport-close-info */ + +dictionary WebTransportCloseInfo { + unsigned long closeCode = 0; + DOMString reason = ""; +}; + +/* https://w3c.github.io/webtransport/#web-transport-stats */ + +dictionary WebTransportStats { + DOMHighResTimeStamp timestamp; + unsigned long long bytesSent; + unsigned long long packetsSent; + unsigned long long packetsLost; + unsigned long numOutgoingStreamsCreated; + unsigned long numIncomingStreamsCreated; + unsigned long long bytesReceived; + unsigned long long packetsReceived; + DOMHighResTimeStamp smoothedRtt; + DOMHighResTimeStamp rttVariation; + DOMHighResTimeStamp minRtt; + WebTransportDatagramStats datagrams; +}; + +/* https://w3c.github.io/webtransport/#web-transport-stats%E2%91%A0 */ + +dictionary WebTransportDatagramStats { + DOMHighResTimeStamp timestamp; + unsigned long long expiredOutgoing; + unsigned long long droppedIncoming; + unsigned long long lostOutgoing; +}; + +/* https://w3c.github.io/webtransport/#web-transport */ + +[Exposed=(Window,Worker), SecureContext, Pref="network.webtransport.enabled"] +interface WebTransport { + constructor(USVString url, optional WebTransportOptions options = {}); + + [NewObject] + Promise getStats(); + readonly attribute Promise ready; + readonly attribute WebTransportReliabilityMode reliability; + readonly attribute WebTransportCongestionControl congestionControl; + readonly attribute Promise closed; + undefined close(optional WebTransportCloseInfo closeInfo = {}); + + readonly attribute WebTransportDatagramDuplexStream datagrams; + + [NewObject] + Promise createBidirectionalStream(); + /* a ReadableStream of WebTransportBidirectionalStream objects */ + readonly attribute ReadableStream incomingBidirectionalStreams; + + + /* XXX spec says this should be WebTransportSendStream */ + [NewObject] + Promise createUnidirectionalStream(); + /* a ReadableStream of WebTransportReceiveStream objects */ + readonly attribute ReadableStream incomingUnidirectionalStreams; +}; + +enum WebTransportReliabilityMode { + "pending", + "reliable-only", + "supports-unreliable", +}; diff --git a/dom/webidl/WebTransportDatagramDuplexStream.webidl b/dom/webidl/WebTransportDatagramDuplexStream.webidl new file mode 100644 index 000000000000..50c3233c5b78 --- /dev/null +++ b/dom/webidl/WebTransportDatagramDuplexStream.webidl @@ -0,0 +1,18 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* https://w3c.github.io/webtransport/#duplex-stream */ + +[Exposed=(Window,Worker), SecureContext, Pref="network.webtransport.datagrams.enabled"] +interface WebTransportDatagramDuplexStream { + readonly attribute ReadableStream readable; + readonly attribute WritableStream writable; + + readonly attribute unsigned long maxDatagramSize; + attribute double? incomingMaxAge; + attribute double? outgoingMaxAge; + attribute long incomingHighWaterMark; + attribute long outgoingHighWaterMark; +}; diff --git a/dom/webidl/WebTransportError.webidl b/dom/webidl/WebTransportError.webidl new file mode 100644 index 000000000000..1484d65bf4b9 --- /dev/null +++ b/dom/webidl/WebTransportError.webidl @@ -0,0 +1,24 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* https://w3c.github.io/webtransport/#web-transport-error-interface */ + +[Exposed=(Window,Worker), SecureContext, Pref="network.webtransport.enabled"] +interface WebTransportError : DOMException { + constructor(optional WebTransportErrorInit init = {}); + + readonly attribute WebTransportErrorSource source; + readonly attribute octet? streamErrorCode; +}; + +dictionary WebTransportErrorInit { + [Clamp] octet streamErrorCode; + DOMString message; +}; + +enum WebTransportErrorSource { + "stream", + "session", +}; diff --git a/dom/webidl/WebTransportSendReceiveStream.webidl b/dom/webidl/WebTransportSendReceiveStream.webidl new file mode 100644 index 000000000000..25fea51b7343 --- /dev/null +++ b/dom/webidl/WebTransportSendReceiveStream.webidl @@ -0,0 +1,45 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* https://w3c.github.io/webtransport/#send-stream-stats */ + +dictionary WebTransportSendStreamStats { + DOMHighResTimeStamp timestamp; + unsigned long long bytesWritten; + unsigned long long bytesSent; + unsigned long long bytesAcknowledged; +}; + +/* https://w3c.github.io/webtransport/#receive-stream-stats */ + +dictionary WebTransportReceiveStreamStats { + DOMHighResTimeStamp timestamp; + unsigned long long bytesReceived; + unsigned long long bytesRead; +}; + +/* https://w3c.github.io/webtransport/#receive-stream */ +/* https://w3c.github.io/webtransport/#send-stream */ + +/* +[Exposed=(Window,Worker), SecureContext, Pref="network.webtransport.enabled"] +interface WebTransportSendStream : WritableStream { + Promise getStats(); +}; + +[Exposed=(Window,Worker), SecureContext, Pref="network.webtransport.enabled"] +interface WebTransportReceiveStream : ReadableStream { + Promise getStats(); +}; +*/ + +/* https://w3c.github.io/webtransport/#bidirectional-stream */ + +[Exposed=(Window,Worker), SecureContext, Pref="network.webtransport.enabled"] +interface WebTransportBidirectionalStream { +// XXX spec says these should be WebTransportReceiveStream and WebTransportSendStream + readonly attribute ReadableStream readable; + readonly attribute WritableStream writable; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 76ba0339bf12..d1fadf1c8d63 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -388,6 +388,9 @@ with Files("Worker*"): with Files("Extension*"): BUG_COMPONENT = ("WebExtensions", "General") +with Files("WebTransport*"): + BUG_COMPONENT = ("Core", "Networking") + GENERATED_WEBIDL_FILES = [ "CSS2Properties.webidl", ] @@ -994,6 +997,10 @@ WEBIDL_FILES = [ "WebGPU.webidl", "WebSocket.webidl", "WebTaskScheduling.webidl", + "WebTransport.webidl", + "WebTransportDatagramDuplexStream.webidl", + "WebTransportError.webidl", + "WebTransportSendReceiveStream.webidl", "WebXR.webidl", "WheelEvent.webidl", "WidevineCDMManifest.webidl", diff --git a/dom/webtransport/api/WebTransport.cpp b/dom/webtransport/api/WebTransport.cpp new file mode 100644 index 000000000000..98a6cc45765a --- /dev/null +++ b/dom/webtransport/api/WebTransport.cpp @@ -0,0 +1,104 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "WebTransport.h" +#include "mozilla/Assertions.h" +#include "mozilla/dom/Promise.h" + +namespace mozilla::dom { + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebTransport, mGlobal) + +NS_IMPL_CYCLE_COLLECTING_ADDREF(WebTransport) +NS_IMPL_CYCLE_COLLECTING_RELEASE(WebTransport) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebTransport) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +// WebIDL Boilerplate + +nsIGlobalObject* WebTransport::GetParentObject() const { return mGlobal; } + +JSObject* WebTransport::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) { + return WebTransport_Binding::Wrap(aCx, this, aGivenProto); +} + +// WebIDL Interface + +/* static */ +already_AddRefed WebTransport::Constructor( + const GlobalObject& aGlobal, const nsAString& aUrl, + const WebTransportOptions& aOptions) { + return nullptr; +} + +already_AddRefed WebTransport::GetStats(ErrorResult& aError) { + aError.Throw(NS_ERROR_NOT_IMPLEMENTED); + return nullptr; +} + +already_AddRefed WebTransport::Ready() { + ErrorResult error; + RefPtr promise = Promise::Create(GetParentObject(), error); + if (error.Failed()) { + return nullptr; + } + promise->MaybeRejectWithUndefined(); + return promise.forget(); +} + +WebTransportReliabilityMode WebTransport::Reliability() { + // XXX not implemented + return WebTransportReliabilityMode::Pending; +} + +WebTransportCongestionControl WebTransport::CongestionControl() { + // XXX not implemented + return WebTransportCongestionControl::Default; +} + +already_AddRefed WebTransport::Closed() { + ErrorResult error; + RefPtr promise = Promise::Create(GetParentObject(), error); + if (error.Failed()) { + return nullptr; + } + promise->MaybeRejectWithUndefined(); + return promise.forget(); +} + +void WebTransport::Close(const WebTransportCloseInfo& aOptions) {} + +already_AddRefed WebTransport::Datagrams() { + // XXX not implemented + return nullptr; +} + +already_AddRefed WebTransport::CreateBidirectionalStream( + ErrorResult& aError) { + aError.Throw(NS_ERROR_NOT_IMPLEMENTED); + return nullptr; +} + +already_AddRefed WebTransport::IncomingBidirectionalStreams() { + // XXX not implemented + return nullptr; +} + +already_AddRefed WebTransport::CreateUnidirectionalStream( + ErrorResult& aError) { + aError.Throw(NS_ERROR_NOT_IMPLEMENTED); + return nullptr; +} + +already_AddRefed WebTransport::IncomingUnidirectionalStreams() { + // XXX not implemented + return nullptr; +} + +} // namespace mozilla::dom diff --git a/dom/webtransport/api/WebTransport.h b/dom/webtransport/api/WebTransport.h new file mode 100644 index 000000000000..d9aa243cade3 --- /dev/null +++ b/dom/webtransport/api/WebTransport.h @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef DOM_WEBTRANSPORT_API_WEBTRANSPORT__H_ +#define DOM_WEBTRANSPORT_API_WEBTRANSPORT__H_ + +#include "nsCOMPtr.h" +#include "nsISupports.h" +#include "nsWrapperCache.h" +#include "mozilla/dom/WebTransportBinding.h" + +namespace mozilla::dom { + +class WebTransportDatagramDuplexStream; +class ReadableStream; +class WritableStream; + +class WebTransport final : public nsISupports, public nsWrapperCache { + public: + explicit WebTransport(nsIGlobalObject* aGlobal) : mGlobal(aGlobal) {} + + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(WebTransport) + + // WebIDL Boilerplate + nsIGlobalObject* GetParentObject() const; + + JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + + // WebIDL Interface + static already_AddRefed Constructor( + const GlobalObject& aGlobal, const nsAString& aUrl, + const WebTransportOptions& aOptions); + + already_AddRefed GetStats(ErrorResult& aError); + + already_AddRefed Ready(); + WebTransportReliabilityMode Reliability(); + WebTransportCongestionControl CongestionControl(); + already_AddRefed Closed(); + void Close(const WebTransportCloseInfo& aOptions); + already_AddRefed Datagrams(); + already_AddRefed CreateBidirectionalStream(ErrorResult& aError); + already_AddRefed IncomingBidirectionalStreams(); + already_AddRefed CreateUnidirectionalStream(ErrorResult& aError); + already_AddRefed IncomingUnidirectionalStreams(); + + private: + ~WebTransport() = default; + + nsCOMPtr mGlobal; + // RefPtr mChannel; +}; + +} // namespace mozilla::dom + +#endif diff --git a/dom/webtransport/api/WebTransportBidirectionalStream.cpp b/dom/webtransport/api/WebTransportBidirectionalStream.cpp new file mode 100644 index 000000000000..60f202cd03a7 --- /dev/null +++ b/dom/webtransport/api/WebTransportBidirectionalStream.cpp @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "WebTransportBidirectionalStream.h" +#include "mozilla/dom/Promise.h" + +namespace mozilla::dom { + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebTransportBidirectionalStream, mGlobal) + +NS_IMPL_CYCLE_COLLECTING_ADDREF(WebTransportBidirectionalStream) +NS_IMPL_CYCLE_COLLECTING_RELEASE(WebTransportBidirectionalStream) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebTransportBidirectionalStream) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +// WebIDL Boilerplate + +nsIGlobalObject* WebTransportBidirectionalStream::GetParentObject() const { + return mGlobal; +} + +JSObject* WebTransportBidirectionalStream::WrapObject( + JSContext* aCx, JS::Handle aGivenProto) { + return WebTransportBidirectionalStream_Binding::Wrap(aCx, this, aGivenProto); +} + +// WebIDL Interface + +} // namespace mozilla::dom diff --git a/dom/webtransport/api/WebTransportBidirectionalStream.h b/dom/webtransport/api/WebTransportBidirectionalStream.h new file mode 100644 index 000000000000..0f9e90f7679a --- /dev/null +++ b/dom/webtransport/api/WebTransportBidirectionalStream.h @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef DOM_WEBTRANSPORT_API_WEBTRANSPORTBIDIRECTIONALSTREAM__H_ +#define DOM_WEBTRANSPORT_API_WEBTRANSPORTBIDIRECTIONALSTREAM__H_ + +#include "nsCOMPtr.h" +#include "nsISupports.h" +#include "nsWrapperCache.h" +#include "mozilla/dom/Promise.h" +#include "mozilla/dom/ReadableStream.h" +#include "mozilla/dom/WritableStream.h" +#include "mozilla/dom/WebTransportSendReceiveStreamBinding.h" + +// #include "mozilla/dom/WebTransportReceiveStream.h" +// #include "mozilla/dom/WebTransportSendStream.h" + +namespace mozilla::dom { +class WebTransportBidirectionalStream final : public nsISupports, + public nsWrapperCache { + public: + explicit WebTransportBidirectionalStream(nsIGlobalObject* aGlobal) + : mGlobal(aGlobal) {} + + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(WebTransportBidirectionalStream) + + // WebIDL Boilerplate + nsIGlobalObject* GetParentObject() const; + + JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + + // WebIDL Interface + // XXX spec says these should be WebTransportReceiveStream and + // WebTransportSendStream + // XXX Not implemented + already_AddRefed Readable() { return nullptr; } + already_AddRefed Writable() { return nullptr; } + + private: + ~WebTransportBidirectionalStream() = default; + + nsCOMPtr mGlobal; +}; + +} // namespace mozilla::dom + +#endif diff --git a/dom/webtransport/api/WebTransportDatagramDuplexStream.cpp b/dom/webtransport/api/WebTransportDatagramDuplexStream.cpp new file mode 100644 index 000000000000..e4fac822e556 --- /dev/null +++ b/dom/webtransport/api/WebTransportDatagramDuplexStream.cpp @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "WebTransportDatagramDuplexStream.h" +#include "mozilla/dom/Promise.h" + +namespace mozilla::dom { + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebTransportDatagramDuplexStream, mGlobal, + mReadable, mWritable) + +NS_IMPL_CYCLE_COLLECTING_ADDREF(WebTransportDatagramDuplexStream) +NS_IMPL_CYCLE_COLLECTING_RELEASE(WebTransportDatagramDuplexStream) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebTransportDatagramDuplexStream) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +// WebIDL Boilerplate + +nsIGlobalObject* WebTransportDatagramDuplexStream::GetParentObject() const { + return mGlobal; +} + +JSObject* WebTransportDatagramDuplexStream::WrapObject( + JSContext* aCx, JS::Handle aGivenProto) { + return WebTransportDatagramDuplexStream_Binding::Wrap(aCx, this, aGivenProto); +} + +// WebIDL Interface + +} // namespace mozilla::dom diff --git a/dom/webtransport/api/WebTransportDatagramDuplexStream.h b/dom/webtransport/api/WebTransportDatagramDuplexStream.h new file mode 100644 index 000000000000..1aa895cd5359 --- /dev/null +++ b/dom/webtransport/api/WebTransportDatagramDuplexStream.h @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef DOM_WEBTRANSPORT_API_WEBTRANSPORTDATAGRAMDUPLEXSTREAM__H_ +#define DOM_WEBTRANSPORT_API_WEBTRANSPORTDATAGRAMDUPLEXSTREAM__H_ + +#include "nsCOMPtr.h" +#include "nsISupports.h" +#include "nsWrapperCache.h" +#include "mozilla/dom/Promise.h" +#include "mozilla/dom/ReadableStream.h" +#include "mozilla/dom/WritableStream.h" +#include "mozilla/dom/WebTransportDatagramDuplexStreamBinding.h" + +namespace mozilla::dom { + +class WebTransportDatagramDuplexStream final : public nsISupports, + public nsWrapperCache { + public: + explicit WebTransportDatagramDuplexStream(nsIGlobalObject* aGlobal) + : mGlobal(aGlobal) {} + + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(WebTransportDatagramDuplexStream) + + // WebIDL Boilerplate + nsIGlobalObject* GetParentObject() const; + + JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + + // WebIDL Interface + already_AddRefed Readable() const { + RefPtr result(mReadable); + return result.forget(); + } + already_AddRefed Writable() { + RefPtr result(mWritable); + return result.forget(); + } + // XXX not implemented + uint64_t MaxDatagramSize() const { return 1500; } + Nullable GetIncomingMaxAge() const { return mIncomingMaxAge; } + void SetIncomingMaxAge(const Nullable& aMaxAge) { + mIncomingMaxAge = aMaxAge; + } + Nullable GetOutgoingMaxAge() const { return mOutgoingMaxAge; } + void SetOutgoingMaxAge(const Nullable& aMaxAge) { + mOutgoingMaxAge = aMaxAge; + } + int64_t IncomingHighWaterMark() const { return mIncomingHighWaterMark; } + void SetIncomingHighWaterMark(int64_t aWaterMark) { + mIncomingHighWaterMark = aWaterMark; + } + int64_t OutgoingHighWaterMark() const { return mOutgoingHighWaterMark; } + void SetOutgoingHighWaterMark(int64_t aWaterMark) { + mOutgoingHighWaterMark = aWaterMark; + } + + private: + ~WebTransportDatagramDuplexStream() = default; + + nsCOMPtr mGlobal; + RefPtr mReadable; + RefPtr mWritable; + + Nullable mIncomingMaxAge; + Nullable mOutgoingMaxAge; + int64_t mIncomingHighWaterMark = 0; + int64_t mOutgoingHighWaterMark = 0; +}; + +} // namespace mozilla::dom + +#endif diff --git a/dom/webtransport/api/WebTransportError.cpp b/dom/webtransport/api/WebTransportError.cpp new file mode 100644 index 000000000000..142d98d2b9df --- /dev/null +++ b/dom/webtransport/api/WebTransportError.cpp @@ -0,0 +1,30 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "WebTransportError.h" + +namespace mozilla::dom { + +/* static */ +already_AddRefed WebTransportError::Constructor( + const GlobalObject& aGlobal, const WebTransportErrorInit& aInit) { + nsCString message(""_ns); + if (aInit.mMessage.WasPassed()) { + CopyUTF16toUTF8(aInit.mMessage.Value(), message); + } + RefPtr error(new WebTransportError(message)); + if (aInit.mStreamErrorCode.WasPassed()) { + error->mStreamErrorCode = aInit.mStreamErrorCode.Value(); + } + return error.forget(); +} + +WebTransportErrorSource WebTransportError::Source() { + // XXX Not implemented + return WebTransportErrorSource::Stream; +} + +} // namespace mozilla::dom diff --git a/dom/webtransport/api/WebTransportError.h b/dom/webtransport/api/WebTransportError.h new file mode 100644 index 000000000000..96b195ca0e4f --- /dev/null +++ b/dom/webtransport/api/WebTransportError.h @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef DOM_WEBTRANSPORT_API_WEBTRANSPORTERROR__H_ +#define DOM_WEBTRANSPORT_API_WEBTRANSPORTERROR__H_ + +#include "mozilla/dom/DOMException.h" +#include "mozilla/dom/WebTransportErrorBinding.h" + +namespace mozilla::dom { +class WebTransportError final : public DOMException { + protected: + explicit WebTransportError(const nsACString& aMessage) + : DOMException(NS_OK, aMessage, "stream"_ns, 0) {} + + public: + static already_AddRefed Constructor( + const GlobalObject& aGlobal, const WebTransportErrorInit& aInit); + + WebTransportErrorSource Source(); + Nullable GetStreamErrorCode() const { + return Nullable(mStreamErrorCode); + } + + private: + uint8_t mStreamErrorCode = 0; +}; + +} // namespace mozilla::dom + +#endif diff --git a/dom/webtransport/api/WebTransportReceiveStream.h b/dom/webtransport/api/WebTransportReceiveStream.h new file mode 100644 index 000000000000..013af4342401 --- /dev/null +++ b/dom/webtransport/api/WebTransportReceiveStream.h @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef DOM_WEBTRANSPORT_API_WEBTRANSPORTSENDSTREAM__H_ +#define DOM_WEBTRANSPORT_API_WEBTRANSPORTSENDSTREAM__H_ + +#include "mozilla/dom/ReadableStream.h" + +#if WEBTRANSPORT_STREAM_IMPLEMENTED +namespace mozilla::dom { +class WebTransportReceiveStream final : public ReadableStream { + protected: + WebTransportReceiveStream(); + + public: + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(WebTransportReceiveStream, + ReadableStream) + + already_AddRefed GetStats(); +}; +#else +namespace mozilla::dom { +class WebTransportReceiveStream final : public nsISupports { + protected: + WebTransportReceiveStream(); + + public: + NS_DECL_ISUPPORTS + + already_AddRefed GetStats(); +}; +#endif +} + +#endif diff --git a/dom/webtransport/api/WebTransportSendStream.h b/dom/webtransport/api/WebTransportSendStream.h new file mode 100644 index 000000000000..0de62208b419 --- /dev/null +++ b/dom/webtransport/api/WebTransportSendStream.h @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef DOM_WEBTRANSPORT_API_WEBTRANSPORTSENDSTREAM__H_ +#define DOM_WEBTRANSPORT_API_WEBTRANSPORTSENDSTREAM__H_ + +#include "mozilla/dom/WritableStream.h" + +#if WEBTRANSPORT_STREAM_IMPLEMENTED +namespace mozilla::dom { +class WebTransportSendStream final : public WritableStream { + protected: + WebTransportSendStream(); + + public: + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(WebTransportSendStream, + WritableStream) + + already_AddRefed GetStats(); +}; +#else +namespace mozilla::dom { +class WebTransportSendStream final : public nsISupports { + protected: + WebTransportSendStream(); + + public: + NS_DECL_ISUPPORTS + + already_AddRefed GetStats(); +}; +#endif +} + +#endif diff --git a/dom/webtransport/api/moz.build b/dom/webtransport/api/moz.build new file mode 100644 index 000000000000..33379da89c13 --- /dev/null +++ b/dom/webtransport/api/moz.build @@ -0,0 +1,23 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +EXPORTS.mozilla.dom += [ + "WebTransport.h", + "WebTransportBidirectionalStream.h", + "WebTransportDatagramDuplexStream.h", + "WebTransportError.h", + "WebTransportReceiveStream.h", + "WebTransportSendStream.h", +] + +UNIFIED_SOURCES += [ + "WebTransport.cpp", + "WebTransportBidirectionalStream.cpp", + "WebTransportDatagramDuplexStream.cpp", + "WebTransportError.cpp", +] + +FINAL_LIBRARY = "xul" diff --git a/dom/webtransport/moz.build b/dom/webtransport/moz.build new file mode 100644 index 000000000000..2411556dcce4 --- /dev/null +++ b/dom/webtransport/moz.build @@ -0,0 +1,9 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +DIRS += [ + "api", +] diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index 7dd3c9af49a2..2dffe0d224bd 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -12012,6 +12012,18 @@ value: true mirror: always +# WebTransport +- name: network.webtransport.enabled + type: RelaxedAtomicBool + value: false + mirror: always + +# WebTransport Datagram support +- name: network.webtransport.datagrams.enabled + type: RelaxedAtomicBool + value: false + mirror: always + #--------------------------------------------------------------------------- # Prefs starting with "nglayout." #---------------------------------------------------------------------------