BaseWebSocketChannel.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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_BaseWebSocketChannel_h
  6. #define mozilla_net_BaseWebSocketChannel_h
  7. #include "nsIWebSocketChannel.h"
  8. #include "nsIWebSocketListener.h"
  9. #include "nsIProtocolHandler.h"
  10. #include "nsIThread.h"
  11. #include "nsIThreadRetargetableRequest.h"
  12. #include "nsCOMPtr.h"
  13. #include "nsString.h"
  14. namespace mozilla {
  15. namespace net {
  16. const static int32_t kDefaultWSPort = 80;
  17. const static int32_t kDefaultWSSPort = 443;
  18. class BaseWebSocketChannel : public nsIWebSocketChannel,
  19. public nsIProtocolHandler,
  20. public nsIThreadRetargetableRequest
  21. {
  22. public:
  23. BaseWebSocketChannel();
  24. NS_DECL_NSIPROTOCOLHANDLER
  25. NS_DECL_NSITHREADRETARGETABLEREQUEST
  26. NS_IMETHOD QueryInterface(const nsIID & uuid, void **result) override = 0;
  27. NS_IMETHOD_(MozExternalRefCountType ) AddRef(void) override = 0;
  28. NS_IMETHOD_(MozExternalRefCountType ) Release(void) override = 0;
  29. // Partial implementation of nsIWebSocketChannel
  30. //
  31. NS_IMETHOD GetOriginalURI(nsIURI **aOriginalURI) override;
  32. NS_IMETHOD GetURI(nsIURI **aURI) override;
  33. NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor **aNotificationCallbacks) override;
  34. NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor *aNotificationCallbacks) override;
  35. NS_IMETHOD GetLoadGroup(nsILoadGroup **aLoadGroup) override;
  36. NS_IMETHOD SetLoadGroup(nsILoadGroup *aLoadGroup) override;
  37. NS_IMETHOD SetLoadInfo(nsILoadInfo *aLoadInfo) override;
  38. NS_IMETHOD GetLoadInfo(nsILoadInfo **aLoadInfo) override;
  39. NS_IMETHOD GetExtensions(nsACString &aExtensions) override;
  40. NS_IMETHOD GetProtocol(nsACString &aProtocol) override;
  41. NS_IMETHOD SetProtocol(const nsACString &aProtocol) override;
  42. NS_IMETHOD GetPingInterval(uint32_t *aSeconds) override;
  43. NS_IMETHOD SetPingInterval(uint32_t aSeconds) override;
  44. NS_IMETHOD GetPingTimeout(uint32_t *aSeconds) override;
  45. NS_IMETHOD SetPingTimeout(uint32_t aSeconds) override;
  46. NS_IMETHOD InitLoadInfo(nsIDOMNode* aLoadingNode, nsIPrincipal* aLoadingPrincipal,
  47. nsIPrincipal* aTriggeringPrincipal, uint32_t aSecurityFlags,
  48. uint32_t aContentPolicyType) override;
  49. NS_IMETHOD GetSerial(uint32_t* aSerial) override;
  50. NS_IMETHOD SetSerial(uint32_t aSerial) override;
  51. NS_IMETHOD SetServerParameters(nsITransportProvider* aProvider,
  52. const nsACString& aNegotiatedExtensions) override;
  53. // Off main thread URI access.
  54. virtual void GetEffectiveURL(nsAString& aEffectiveURL) const = 0;
  55. virtual bool IsEncrypted() const = 0;
  56. class ListenerAndContextContainer final
  57. {
  58. public:
  59. NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ListenerAndContextContainer)
  60. ListenerAndContextContainer(nsIWebSocketListener* aListener,
  61. nsISupports* aContext);
  62. nsCOMPtr<nsIWebSocketListener> mListener;
  63. nsCOMPtr<nsISupports> mContext;
  64. private:
  65. ~ListenerAndContextContainer();
  66. };
  67. protected:
  68. nsCOMPtr<nsIURI> mOriginalURI;
  69. nsCOMPtr<nsIURI> mURI;
  70. RefPtr<ListenerAndContextContainer> mListenerMT;
  71. nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
  72. nsCOMPtr<nsILoadGroup> mLoadGroup;
  73. nsCOMPtr<nsILoadInfo> mLoadInfo;
  74. nsCOMPtr<nsIEventTarget> mTargetThread;
  75. nsCOMPtr<nsITransportProvider> mServerTransportProvider;
  76. nsCString mProtocol;
  77. nsCString mOrigin;
  78. nsCString mNegotiatedExtensions;
  79. uint32_t mWasOpened : 1;
  80. uint32_t mClientSetPingInterval : 1;
  81. uint32_t mClientSetPingTimeout : 1;
  82. Atomic<bool> mEncrypted;
  83. bool mPingForced;
  84. bool mIsServerSide;
  85. uint32_t mPingInterval; /* milliseconds */
  86. uint32_t mPingResponseTimeout; /* milliseconds */
  87. uint32_t mSerial;
  88. };
  89. } // namespace net
  90. } // namespace mozilla
  91. #endif // mozilla_net_BaseWebSocketChannel_h