/* -*- 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" #include "mozilla/dom/WebTransportChild.h" namespace mozilla::dom { class WebTransportDatagramDuplexStream; class ReadableStream; class WritableStream; class WebTransport final : public nsISupports, public nsWrapperCache { public: explicit WebTransport(nsIGlobalObject* aGlobal); NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(WebTransport) enum class WebTransportState { CONNECTING, CONNECTED, CLOSED, FAILED }; bool Init(const GlobalObject& aGlobal, const nsAString& aUrl, const WebTransportOptions& aOptions, ErrorResult& aError); void ResolveWaitingConnection(WebTransportReliabilityMode aReliability, WebTransportChild* aChild); void RejectWaitingConnection(nsresult aRv); bool ParseURL(const nsAString& aURL) const; // 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, ErrorResult& aRv); 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(); void Shutdown() {} private: ~WebTransport() { // Should be empty by this point, because we should always have run cleanup: // https://w3c.github.io/webtransport/#webtransport-procedures MOZ_ASSERT(mSendStreams.IsEmpty()); MOZ_ASSERT(mReceiveStreams.IsEmpty()); // If this WebTransport was destroyed without being closed properly, make // sure to clean up the channel. if (mChild) { mChild->Shutdown(); } } nsCOMPtr mGlobal; RefPtr mChild; // Spec-defined slots: // ordered sets, but we can't have duplicates, and this spec only appends. // Order is visible due to // https://w3c.github.io/webtransport/#webtransport-procedures step 10: "For // each sendStream in sendStreams, error sendStream with error." // XXX Use nsTArray.h for now, but switch to OrderHashSet/Table for release to // improve remove performance (if needed) nsTArray> mSendStreams; nsTArray> mReceiveStreams; WebTransportState mState; RefPtr mReady; WebTransportReliabilityMode mReliability; // These are created in the constructor RefPtr mIncomingUnidirectionalStreams; RefPtr mIncomingBidirectionalStreams; RefPtr mDatagrams; RefPtr mClosed; }; } // namespace mozilla::dom #endif