From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/webtransport/parent/WebTransportParent.h | 114 +++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 dom/webtransport/parent/WebTransportParent.h (limited to 'dom/webtransport/parent/WebTransportParent.h') diff --git a/dom/webtransport/parent/WebTransportParent.h b/dom/webtransport/parent/WebTransportParent.h new file mode 100644 index 0000000000..8b1b1a6867 --- /dev/null +++ b/dom/webtransport/parent/WebTransportParent.h @@ -0,0 +1,114 @@ +/* -*- 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_PARENT_WEBTRANSPORTPARENT_H_ +#define DOM_WEBTRANSPORT_PARENT_WEBTRANSPORTPARENT_H_ + +#include "ErrorList.h" +#include "mozilla/dom/ClientIPCTypes.h" +#include "mozilla/dom/FlippedOnce.h" +#include "mozilla/dom/PWebTransportParent.h" +#include "mozilla/ipc/Endpoint.h" +#include "mozilla/ipc/PBackgroundSharedTypes.h" +#include "nsISupports.h" +#include "nsIPrincipal.h" +#include "nsIWebTransport.h" +#include "nsIWebTransportStream.h" +#include "nsTHashMap.h" + +namespace mozilla::dom { + +enum class WebTransportReliabilityMode : uint8_t; + +class WebTransportParent : public PWebTransportParent, + public WebTransportSessionEventListener { + using IPCResult = mozilla::ipc::IPCResult; + + public: + WebTransportParent() = default; + + NS_DECL_THREADSAFE_ISUPPORTS + NS_DECL_WEBTRANSPORTSESSIONEVENTLISTENER + + void Create(const nsAString& aURL, nsIPrincipal* aPrincipal, + const mozilla::Maybe& aClientInfo, + const bool& aDedicated, const bool& aRequireUnreliable, + const uint32_t& aCongestionControl, + nsTArray&& aServerCertHashes, + Endpoint&& aParentEndpoint, + std::function)>&& + aResolver); + + IPCResult RecvClose(const uint32_t& aCode, const nsACString& aReason); + + IPCResult RecvSetSendOrder(uint64_t aStreamId, Maybe aSendOrder); + + IPCResult RecvCreateUnidirectionalStream( + Maybe aSendOrder, + CreateUnidirectionalStreamResolver&& aResolver); + IPCResult RecvCreateBidirectionalStream( + Maybe aSendOrder, CreateBidirectionalStreamResolver&& aResolver); + + ::mozilla::ipc::IPCResult RecvOutgoingDatagram( + nsTArray&& aData, const TimeStamp& aExpirationTime, + OutgoingDatagramResolver&& aResolver); + + ::mozilla::ipc::IPCResult RecvGetMaxDatagramSize( + GetMaxDatagramSizeResolver&& aResolver); + + void ActorDestroy(ActorDestroyReason aWhy) override; + + class OnResetOrStopSendingCallback final { + public: + explicit OnResetOrStopSendingCallback( + std::function&& aCallback) + : mCallback(std::move(aCallback)) {} + ~OnResetOrStopSendingCallback() = default; + + void OnResetOrStopSending(nsresult aError) { mCallback(aError); } + + private: + std::function mCallback; + }; + + protected: + virtual ~WebTransportParent(); + + private: + void NotifyRemoteClosed(bool aCleanly, uint32_t aErrorCode, + const nsACString& aReason); + + using ResolveType = std::tuple; + nsCOMPtr mSocketThread; + Atomic mSessionReady{false}; + + mozilla::Mutex mMutex{"WebTransportParent::mMutex"}; + std::function mResolver MOZ_GUARDED_BY(mMutex); + // This is needed because mResolver is resolved on the background thread and + // OnSessionClosed is called on the socket thread. + std::function mExecuteAfterResolverCallback MOZ_GUARDED_BY(mMutex); + OutgoingDatagramResolver mOutgoingDatagramResolver; + GetMaxDatagramSizeResolver mMaxDatagramSizeResolver; + FlippedOnce mClosed MOZ_GUARDED_BY(mMutex); + + nsCOMPtr mWebTransport; + nsCOMPtr mOwningEventTarget; + + // What we need to be able to lookup by streamId + template + struct StreamHash { + OnResetOrStopSendingCallback mCallback; + nsCOMPtr mStream; + }; + nsTHashMap> + mBidiStreamCallbackMap; + nsTHashMap> + mUniStreamCallbackMap; +}; + +} // namespace mozilla::dom + +#endif // DOM_WEBTRANSPORT_PARENT_WEBTRANSPORTPARENT_H_ -- cgit v1.2.3