tor-browser

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

TCPSocketChild.h (2275B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      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 mozilla_dom_TCPSocketChild_h
      8 #define mozilla_dom_TCPSocketChild_h
      9 
     10 #include "js/TypeDecls.h"
     11 #include "mozilla/dom/TypedArray.h"
     12 #include "mozilla/net/PTCPSocketChild.h"
     13 #include "nsCOMPtr.h"
     14 #include "nsCycleCollectionParticipant.h"
     15 
     16 class nsITCPSocketCallback;
     17 
     18 namespace IPC {
     19 bool DeserializeArrayBuffer(JSContext* cx, const nsTArray<uint8_t>& aBuffer,
     20                            JS::MutableHandle<JS::Value> aVal);
     21 }
     22 
     23 namespace mozilla::dom {
     24 
     25 class TCPSocket;
     26 
     27 class TCPSocketChildBase : public nsISupports {
     28 public:
     29  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TCPSocketChildBase)
     30  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     31 
     32  void AddIPDLReference();
     33  void ReleaseIPDLReference();
     34 
     35 protected:
     36  TCPSocketChildBase();
     37  virtual ~TCPSocketChildBase();
     38 
     39  nsCOMPtr<nsITCPSocketCallback> mSocket;
     40  bool mIPCOpen;
     41 };
     42 
     43 class TCPSocketChild : public mozilla::net::PTCPSocketChild,
     44                       public TCPSocketChildBase {
     45 public:
     46  NS_IMETHOD_(MozExternalRefCountType) Release() override;
     47 
     48  TCPSocketChild(const nsAString& aHost, const uint16_t& aPort,
     49                 nsISerialEventTarget* aTarget);
     50  ~TCPSocketChild();
     51 
     52  void SendOpen(nsITCPSocketCallback* aSocket, bool aUseSSL,
     53                bool aUseArrayBuffers);
     54  void SendSend(const nsACString& aData);
     55  void SendSend(nsTArray<uint8_t>&& aData);
     56  void SetSocket(TCPSocket* aSocket);
     57 
     58  void GetHost(nsAString& aHost);
     59  void GetPort(uint16_t* aPort) const;
     60 
     61  mozilla::ipc::IPCResult RecvCallback(const nsString& aType,
     62                                       const CallbackData& aData,
     63                                       const uint32_t& aReadyState);
     64  mozilla::ipc::IPCResult RecvRequestDelete();
     65  mozilla::ipc::IPCResult RecvUpdateBufferedAmount(
     66      const uint32_t& aBufferred, const uint32_t& aTrackingNumber);
     67 
     68 private:
     69  nsString mHost;
     70  uint16_t mPort;
     71  nsCOMPtr<nsISerialEventTarget> mIPCEventTarget;
     72 };
     73 
     74 }  // namespace mozilla::dom
     75 
     76 #endif