tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WebrtcTCPSocketWrapper.h (2282B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set sw=2 ts=8 et tw=80 ft=cpp : */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef webrtc_tcp_socket_wrapper__
      8 #define webrtc_tcp_socket_wrapper__
      9 
     10 #include <memory>
     11 
     12 #include "mozilla/net/WebrtcTCPSocketCallback.h"
     13 #include "nsCOMPtr.h"
     14 #include "nsTArray.h"
     15 
     16 class nsIEventTarget;
     17 
     18 namespace mozilla {
     19 
     20 class NrSocketProxyConfig;
     21 
     22 namespace net {
     23 
     24 class WebrtcTCPSocketChild;
     25 
     26 /**
     27 * WebrtcTCPSocketWrapper is a protector class for mtransport and IPDL.
     28 * mtransport and IPDL cannot include headers from each other due to conflicting
     29 * typedefs. Also it helps users by dispatching calls to the appropriate thread
     30 * based on mtransport's and IPDL's threading requirements.
     31 *
     32 * WebrtcTCPSocketWrapper is only used in the child process.
     33 * WebrtcTCPSocketWrapper does not dispatch for the parent process.
     34 * WebrtcTCPSocketCallback calls are dispatched to the STS thread.
     35 * IPDL calls are dispatched to the main thread.
     36 */
     37 class WebrtcTCPSocketWrapper : public WebrtcTCPSocketCallback {
     38 public:
     39  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebrtcTCPSocketWrapper, override)
     40 
     41  explicit WebrtcTCPSocketWrapper(WebrtcTCPSocketCallback* aCallbacks);
     42 
     43  virtual void AsyncOpen(const nsCString& aHost, const int& aPort,
     44                         const nsCString& aLocalAddress, const int& aLocalPort,
     45                         bool aUseTls,
     46                         const std::shared_ptr<NrSocketProxyConfig>& aConfig);
     47  virtual void SendWrite(nsTArray<uint8_t>&& aReadData);
     48  virtual void Close();
     49 
     50  // WebrtcTCPSocketCallback
     51  virtual void OnClose(nsresult aReason) override;
     52  virtual void OnConnected(const nsACString& aProxyType) override;
     53  virtual void OnRead(nsTArray<uint8_t>&& aReadData) override;
     54 
     55 protected:
     56  RefPtr<WebrtcTCPSocketCallback> mProxyCallbacks;
     57  RefPtr<WebrtcTCPSocketChild> mWebrtcTCPSocket;
     58 
     59  nsCOMPtr<nsIEventTarget> mMainThread;
     60  nsCOMPtr<nsIEventTarget> mSocketThread;
     61 
     62  virtual ~WebrtcTCPSocketWrapper();
     63 };
     64 
     65 }  // namespace net
     66 }  // namespace mozilla
     67 
     68 #endif  // webrtc_tcp_socket_wrapper__