From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- dom/media/webrtc/transport/ipc/WebrtcTCPSocket.h | 104 +++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 dom/media/webrtc/transport/ipc/WebrtcTCPSocket.h (limited to 'dom/media/webrtc/transport/ipc/WebrtcTCPSocket.h') diff --git a/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.h b/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.h new file mode 100644 index 0000000000..632ba47d32 --- /dev/null +++ b/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.h @@ -0,0 +1,104 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set sw=2 ts=8 et tw=80 ft=cpp : */ +/* 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 webrtc_tcp_socket_h__ +#define webrtc_tcp_socket_h__ + +#include + +#include "nsCOMPtr.h" +#include "nsIAsyncInputStream.h" +#include "nsIAsyncOutputStream.h" +#include "nsIAuthPromptProvider.h" +#include "nsIHttpChannelInternal.h" +#include "nsIInterfaceRequestor.h" +#include "nsIStreamListener.h" +#include "nsStringFwd.h" +#include "nsTArray.h" +#include "nsIProtocolProxyCallback.h" +#include "mozilla/net/WebrtcProxyConfig.h" + +class nsISocketTransport; + +namespace mozilla::net { + +class WebrtcTCPSocketCallback; +class WebrtcTCPData; + +class WebrtcTCPSocket : public nsIHttpUpgradeListener, + public nsIStreamListener, + public nsIInputStreamCallback, + public nsIOutputStreamCallback, + public nsIInterfaceRequestor, + public nsIAuthPromptProvider, + public nsIProtocolProxyCallback { + public: + NS_DECL_NSIHTTPUPGRADELISTENER + NS_DECL_NSIINPUTSTREAMCALLBACK + NS_DECL_NSIINTERFACEREQUESTOR + NS_DECL_NSIOUTPUTSTREAMCALLBACK + NS_DECL_NSIREQUESTOBSERVER + NS_DECL_NSISTREAMLISTENER + NS_DECL_THREADSAFE_ISUPPORTS + NS_FORWARD_SAFE_NSIAUTHPROMPTPROVIDER(mAuthProvider) + NS_DECL_NSIPROTOCOLPROXYCALLBACK + + explicit WebrtcTCPSocket(WebrtcTCPSocketCallback* aCallbacks); + + void SetTabId(dom::TabId aTabId); + nsresult Open(const nsACString& aHost, const int& aPort, + const nsACString& aLocalAddress, const int& aLocalPort, + bool aUseTls, + const Maybe& aProxyConfig); + nsresult Write(nsTArray&& aBytes); + nsresult Close(); + + size_t CountUnwrittenBytes() const; + + protected: + virtual ~WebrtcTCPSocket(); + + // protected for gtests + virtual void InvokeOnClose(nsresult aReason); + virtual void InvokeOnConnected(); + virtual void InvokeOnRead(nsTArray&& aReadData); + + RefPtr mProxyCallbacks; + + private: + bool mClosed; + bool mOpened; + nsCOMPtr mURI; + bool mTls = false; + Maybe mProxyConfig; + nsCString mLocalAddress; + uint16_t mLocalPort = 0; + nsCString mProxyType; + + nsresult DoProxyConfigLookup(); + nsresult OpenWithHttpProxy(); + void OpenWithoutHttpProxy(nsIProxyInfo* aSocksProxyInfo); + void FinishOpen(); + void EnqueueWrite_s(nsTArray&& aWriteData); + + void CloseWithReason(nsresult aReason); + + size_t mWriteOffset; + std::list mWriteQueue; + nsCOMPtr mAuthProvider; + + // Indicates that the channel is CONNECTed + nsCOMPtr mTransport; + nsCOMPtr mSocketIn; + nsCOMPtr mSocketOut; + nsCOMPtr mMainThread; + nsCOMPtr mSocketThread; + nsCOMPtr mProxyRequest; +}; + +} // namespace mozilla::net + +#endif // webrtc_tcp_socket_h__ -- cgit v1.2.3