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