WebSocketChannelChild.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_net_WebSocketChannelChild_h
  6. #define mozilla_net_WebSocketChannelChild_h
  7. #include "mozilla/net/PWebSocketChild.h"
  8. #include "mozilla/net/BaseWebSocketChannel.h"
  9. #include "nsString.h"
  10. namespace mozilla {
  11. namespace net {
  12. class ChannelEvent;
  13. class ChannelEventQueue;
  14. class WebSocketChannelChild final : public BaseWebSocketChannel,
  15. public PWebSocketChild
  16. {
  17. public:
  18. explicit WebSocketChannelChild(bool aSecure);
  19. NS_DECL_THREADSAFE_ISUPPORTS
  20. NS_DECL_NSITHREADRETARGETABLEREQUEST
  21. // nsIWebSocketChannel methods BaseWebSocketChannel didn't implement for us
  22. //
  23. NS_IMETHOD AsyncOpen(nsIURI *aURI, const nsACString &aOrigin,
  24. uint64_t aInnerWindowID,
  25. nsIWebSocketListener *aListener,
  26. nsISupports *aContext) override;
  27. NS_IMETHOD Close(uint16_t code, const nsACString & reason) override;
  28. NS_IMETHOD SendMsg(const nsACString &aMsg) override;
  29. NS_IMETHOD SendBinaryMsg(const nsACString &aMsg) override;
  30. NS_IMETHOD SendBinaryStream(nsIInputStream *aStream, uint32_t aLength) override;
  31. nsresult SendBinaryStream(OptionalInputStreamParams *aStream, uint32_t aLength);
  32. NS_IMETHOD GetSecurityInfo(nsISupports **aSecurityInfo) override;
  33. void AddIPDLReference();
  34. void ReleaseIPDLReference();
  35. // Off main thread URI access.
  36. void GetEffectiveURL(nsAString& aEffectiveURL) const override;
  37. bool IsEncrypted() const override;
  38. private:
  39. ~WebSocketChannelChild();
  40. bool RecvOnStart(const nsCString& aProtocol, const nsCString& aExtensions,
  41. const nsString& aEffectiveURL, const bool& aSecure) override;
  42. bool RecvOnStop(const nsresult& aStatusCode) override;
  43. bool RecvOnMessageAvailable(const nsCString& aMsg) override;
  44. bool RecvOnBinaryMessageAvailable(const nsCString& aMsg) override;
  45. bool RecvOnAcknowledge(const uint32_t& aSize) override;
  46. bool RecvOnServerClose(const uint16_t& aCode, const nsCString &aReason) override;
  47. void OnStart(const nsCString& aProtocol, const nsCString& aExtensions,
  48. const nsString& aEffectiveURL, const bool& aSecure);
  49. void OnStop(const nsresult& aStatusCode);
  50. void OnMessageAvailable(const nsCString& aMsg);
  51. void OnBinaryMessageAvailable(const nsCString& aMsg);
  52. void OnAcknowledge(const uint32_t& aSize);
  53. void OnServerClose(const uint16_t& aCode, const nsCString& aReason);
  54. void AsyncOpenFailed();
  55. void DispatchToTargetThread(ChannelEvent *aChannelEvent);
  56. bool IsOnTargetThread();
  57. void MaybeReleaseIPCObject();
  58. RefPtr<ChannelEventQueue> mEventQ;
  59. nsString mEffectiveURL;
  60. // This variable is protected by mutex.
  61. enum {
  62. Opened,
  63. Closing,
  64. Closed
  65. } mIPCState;
  66. mozilla::Mutex mMutex;
  67. friend class StartEvent;
  68. friend class StopEvent;
  69. friend class MessageEvent;
  70. friend class AcknowledgeEvent;
  71. friend class ServerCloseEvent;
  72. friend class AsyncOpenFailedEvent;
  73. };
  74. } // namespace net
  75. } // namespace mozilla
  76. #endif // mozilla_net_WebSocketChannelChild_h