TCPSocketParent.h (2543B)
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_TCPSocketParent_h 8 #define mozilla_dom_TCPSocketParent_h 9 10 #include "js/TypeDecls.h" 11 #include "mozilla/dom/TCPSocketBinding.h" 12 #include "mozilla/net/PTCPSocketParent.h" 13 #include "nsCOMPtr.h" 14 #include "nsCycleCollectionParticipant.h" 15 16 #define TCPSOCKETPARENT_CID \ 17 {0x4e7246c6, 0xa8b3, 0x426d, {0x9c, 0x17, 0x76, 0xda, 0xb1, 0xe1, 0xe1, 0x4a}} 18 19 namespace mozilla::dom { 20 21 class TCPSocket; 22 23 class TCPSocketParentBase : public nsISupports { 24 public: 25 NS_DECL_CYCLE_COLLECTION_CLASS(TCPSocketParentBase) 26 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 27 28 void AddIPDLReference(); 29 void ReleaseIPDLReference(); 30 31 bool IPCOpen() const { return mIPCOpen; } 32 33 protected: 34 TCPSocketParentBase(); 35 virtual ~TCPSocketParentBase(); 36 37 RefPtr<TCPSocket> mSocket; 38 bool mIPCOpen; 39 }; 40 41 class TCPSocketParent : public mozilla::net::PTCPSocketParent, 42 public TCPSocketParentBase { 43 public: 44 NS_IMETHOD_(MozExternalRefCountType) Release() override; 45 46 TCPSocketParent() = default; 47 48 mozilla::ipc::IPCResult RecvOpen(const nsString& aHost, const uint16_t& aPort, 49 const bool& useSSL, 50 const bool& aUseArrayBuffers); 51 52 mozilla::ipc::IPCResult RecvStartTLS(); 53 mozilla::ipc::IPCResult RecvSuspend(); 54 mozilla::ipc::IPCResult RecvResume(); 55 mozilla::ipc::IPCResult RecvClose(); 56 mozilla::ipc::IPCResult RecvData(const SendableData& aData); 57 mozilla::ipc::IPCResult RecvRequestDelete(); 58 59 void FireErrorEvent(const nsAString& aName, const nsAString& aType, 60 nsresult aError, TCPReadyState aReadyState); 61 void FireEvent(const nsAString& aType, TCPReadyState aReadyState); 62 void FireArrayBufferDataEvent(nsTArray<uint8_t>& aBuffer, 63 TCPReadyState aReadyState); 64 void FireStringDataEvent(const nsACString& aData, TCPReadyState aReadyState); 65 66 void SetSocket(TCPSocket* socket); 67 nsresult GetHost(nsAString& aHost); 68 nsresult GetPort(uint16_t* aPort); 69 70 private: 71 virtual void ActorDestroy(ActorDestroyReason why) override; 72 void SendEvent(const nsAString& aType, CallbackData aData, 73 TCPReadyState aReadyState); 74 }; 75 76 } // namespace mozilla::dom 77 78 #endif