TCPSocketParent.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_TCPSocketParent_h
  6. #define mozilla_dom_TCPSocketParent_h
  7. #include "mozilla/dom/TCPSocketBinding.h"
  8. #include "mozilla/net/PTCPSocketParent.h"
  9. #include "nsCycleCollectionParticipant.h"
  10. #include "nsCOMPtr.h"
  11. #include "nsISocketFilter.h"
  12. #include "js/TypeDecls.h"
  13. #define TCPSOCKETPARENT_CID \
  14. { 0x4e7246c6, 0xa8b3, 0x426d, { 0x9c, 0x17, 0x76, 0xda, 0xb1, 0xe1, 0xe1, 0x4a } }
  15. namespace mozilla {
  16. namespace dom {
  17. class TCPSocket;
  18. class TCPSocketParentBase : public nsISupports
  19. {
  20. public:
  21. NS_DECL_CYCLE_COLLECTION_CLASS(TCPSocketParentBase)
  22. NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  23. void AddIPDLReference();
  24. void ReleaseIPDLReference();
  25. protected:
  26. TCPSocketParentBase();
  27. virtual ~TCPSocketParentBase();
  28. RefPtr<TCPSocket> mSocket;
  29. bool mIPCOpen;
  30. };
  31. class TCPSocketParent : public mozilla::net::PTCPSocketParent
  32. , public TCPSocketParentBase
  33. {
  34. public:
  35. NS_IMETHOD_(MozExternalRefCountType) Release() override;
  36. TCPSocketParent() {}
  37. virtual bool RecvOpen(const nsString& aHost, const uint16_t& aPort,
  38. const bool& useSSL, const bool& aUseArrayBuffers) override;
  39. virtual bool RecvOpenBind(const nsCString& aRemoteHost,
  40. const uint16_t& aRemotePort,
  41. const nsCString& aLocalAddr,
  42. const uint16_t& aLocalPort,
  43. const bool& aUseSSL,
  44. const bool& aUseArrayBuffers,
  45. const nsCString& aFilter) override;
  46. virtual bool RecvStartTLS() override;
  47. virtual bool RecvSuspend() override;
  48. virtual bool RecvResume() override;
  49. virtual bool RecvClose() override;
  50. virtual bool RecvData(const SendableData& aData,
  51. const uint32_t& aTrackingNumber) override;
  52. virtual bool RecvRequestDelete() override;
  53. bool GetInIsolatedMozBrowser();
  54. void FireErrorEvent(const nsAString& aName, const nsAString& aType, TCPReadyState aReadyState);
  55. void FireEvent(const nsAString& aType, TCPReadyState aReadyState);
  56. void FireArrayBufferDataEvent(nsTArray<uint8_t>& aBuffer, TCPReadyState aReadyState);
  57. void FireStringDataEvent(const nsACString& aData, TCPReadyState aReadyState);
  58. void SetSocket(TCPSocket *socket);
  59. nsresult GetHost(nsAString& aHost);
  60. nsresult GetPort(uint16_t* aPort);
  61. private:
  62. virtual uint32_t GetAppId();
  63. virtual void ActorDestroy(ActorDestroyReason why) override;
  64. void SendEvent(const nsAString& aType, CallbackData aData, TCPReadyState aReadyState);
  65. nsresult SetFilter(const nsCString& aFilter);
  66. nsCOMPtr<nsISocketFilter> mFilter;
  67. };
  68. } // namespace dom
  69. } // namespace mozilla
  70. #endif