WebSocketChannelChild.h (4513B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set sw=2 ts=8 et 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 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_net_WebSocketChannelChild_h 8 #define mozilla_net_WebSocketChannelChild_h 9 10 #include "mozilla/net/NeckoTargetHolder.h" 11 #include "mozilla/net/PWebSocketChild.h" 12 #include "mozilla/net/BaseWebSocketChannel.h" 13 #include "nsString.h" 14 15 namespace mozilla { 16 17 namespace net { 18 19 class ChannelEvent; 20 class ChannelEventQueue; 21 class MessageEvent; 22 23 class WebSocketChannelChild final : public BaseWebSocketChannel, 24 public PWebSocketChild, 25 public NeckoTargetHolder { 26 friend class PWebSocketChild; 27 28 public: 29 explicit WebSocketChannelChild(bool aEncrypted); 30 31 NS_DECL_THREADSAFE_ISUPPORTS 32 33 // nsIWebSocketChannel methods BaseWebSocketChannel didn't implement for us 34 // 35 NS_IMETHOD AsyncOpen(nsIURI* aURI, const nsACString& aOrigin, 36 JS::Handle<JS::Value> aOriginAttributes, 37 uint64_t aInnerWindowID, nsIWebSocketListener* aListener, 38 nsISupports* aContext, JSContext* aCx) override; 39 NS_IMETHOD AsyncOpenNative(nsIURI* aURI, const nsACString& aOrigin, 40 const OriginAttributes& aOriginAttributes, 41 uint64_t aInnerWindowID, 42 nsIWebSocketListener* aListener, 43 nsISupports* aContext) override; 44 NS_IMETHOD Close(uint16_t code, const nsACString& reason) override; 45 NS_IMETHOD SendMsg(const nsACString& aMsg) override; 46 NS_IMETHOD SendBinaryMsg(const nsACString& aMsg) override; 47 NS_IMETHOD SendBinaryStream(nsIInputStream* aStream, 48 uint32_t aLength) override; 49 NS_IMETHOD GetSecurityInfo(nsITransportSecurityInfo** aSecurityInfo) override; 50 51 void AddIPDLReference(); 52 void ReleaseIPDLReference(); 53 54 // Off main thread URI access. 55 void GetEffectiveURL(nsAString& aEffectiveURL) const override; 56 bool IsEncrypted() const override; 57 58 private: 59 ~WebSocketChannelChild(); 60 61 mozilla::ipc::IPCResult RecvOnStart(const nsACString& aProtocol, 62 const nsACString& aExtensions, 63 const nsAString& aEffectiveURL, 64 const bool& aEncrypted, 65 const uint64_t& aHttpChannelId); 66 mozilla::ipc::IPCResult RecvOnStop(const nsresult& aStatusCode); 67 mozilla::ipc::IPCResult RecvOnMessageAvailable(const nsACString& aMsg, 68 const bool& aMoreData); 69 mozilla::ipc::IPCResult RecvOnBinaryMessageAvailable(const nsACString& aMsg, 70 const bool& aMoreData); 71 mozilla::ipc::IPCResult RecvOnAcknowledge(const uint32_t& aSize); 72 mozilla::ipc::IPCResult RecvOnServerClose(const uint16_t& aCode, 73 const nsACString& aReason); 74 75 void OnStart(const nsACString& aProtocol, const nsACString& aExtensions, 76 const nsAString& aEffectiveURL, const bool& aEncrypted, 77 const uint64_t& aHttpChannelId); 78 void OnStop(const nsresult& aStatusCode); 79 void OnMessageAvailable(const nsACString& aMsg); 80 void OnBinaryMessageAvailable(const nsACString& aMsg); 81 void OnAcknowledge(const uint32_t& aSize); 82 void OnServerClose(const uint16_t& aCode, const nsACString& aReason); 83 void AsyncOpenFailed(); 84 85 void MaybeReleaseIPCObject(); 86 87 // This function tries to get a labeled event target for |mNeckoTarget|. 88 void SetupNeckoTarget(); 89 90 bool RecvOnMessageAvailableInternal(const nsACString& aMsg, bool aMoreData, 91 bool aBinary); 92 93 void OnError(); 94 95 RefPtr<ChannelEventQueue> mEventQ; 96 nsString mEffectiveURL; 97 nsCString mReceivedMsgBuffer; 98 99 // This variable is protected by mutex. 100 enum { Opened, Closing, Closed } mIPCState; 101 102 mozilla::Mutex mMutex MOZ_UNANNOTATED; 103 104 friend class StartEvent; 105 friend class StopEvent; 106 friend class MessageEvent; 107 friend class AcknowledgeEvent; 108 friend class ServerCloseEvent; 109 friend class AsyncOpenFailedEvent; 110 friend class OnErrorEvent; 111 }; 112 113 } // namespace net 114 } // namespace mozilla 115 116 #endif // mozilla_net_WebSocketChannelChild_h