diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/webtransport/parent/WebTransportParent.h | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/webtransport/parent/WebTransportParent.h')
-rw-r--r-- | dom/webtransport/parent/WebTransportParent.h | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/dom/webtransport/parent/WebTransportParent.h b/dom/webtransport/parent/WebTransportParent.h new file mode 100644 index 0000000000..1f38bb6b62 --- /dev/null +++ b/dom/webtransport/parent/WebTransportParent.h @@ -0,0 +1,100 @@ +/* -*- 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 "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<IPCClientInfo>& aClientInfo, + const bool& aDedicated, const bool& aRequireUnreliable, + const uint32_t& aCongestionControl, + // Sequence<WebTransportHash>* aServerCertHashes, + Endpoint<PWebTransportParent>&& aParentEndpoint, + std::function<void(std::tuple<const nsresult&, const uint8_t&>)>&& + aResolver); + + IPCResult RecvClose(const uint32_t& aCode, const nsACString& aReason); + + IPCResult RecvCreateUnidirectionalStream( + Maybe<int64_t> aSendOrder, + CreateUnidirectionalStreamResolver&& aResolver); + IPCResult RecvCreateBidirectionalStream( + Maybe<int64_t> aSendOrder, CreateBidirectionalStreamResolver&& aResolver); + + ::mozilla::ipc::IPCResult RecvOutgoingDatagram( + nsTArray<uint8_t>&& 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<void(nsresult)>&& aCallback) + : mCallback(std::move(aCallback)) {} + ~OnResetOrStopSendingCallback() = default; + + void OnResetOrStopSending(nsresult aError) { mCallback(aError); } + + private: + std::function<void(nsresult)> mCallback; + }; + + protected: + virtual ~WebTransportParent(); + + private: + void NotifyRemoteClosed(uint32_t aErrorCode, const nsACString& aReason); + + using ResolveType = std::tuple<const nsresult&, const uint8_t&>; + nsCOMPtr<nsISerialEventTarget> mSocketThread; + Atomic<bool> mSessionReady{false}; + + mozilla::Mutex mMutex{"WebTransportParent::mMutex"}; + std::function<void(ResolveType)> 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<void()> mExecuteAfterResolverCallback MOZ_GUARDED_BY(mMutex); + OutgoingDatagramResolver mOutgoingDatagramResolver; + GetMaxDatagramSizeResolver mMaxDatagramSizeResolver; + FlippedOnce<false> mClosed MOZ_GUARDED_BY(mMutex); + + nsCOMPtr<nsIWebTransport> mWebTransport; + nsCOMPtr<nsIEventTarget> mOwningEventTarget; + nsTHashMap<nsUint64HashKey, OnResetOrStopSendingCallback> mStreamCallbackMap; +}; + +} // namespace mozilla::dom + +#endif // DOM_WEBTRANSPORT_PARENT_WEBTRANSPORTPARENT_H_ |