Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; 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 :
6 : #ifndef mozilla_dom_TCPServerSocket_h
7 : #define mozilla_dom_TCPServerSocket_h
8 :
9 : #include "mozilla/DOMEventTargetHelper.h"
10 : #include "nsIServerSocket.h"
11 :
12 : namespace mozilla {
13 : class ErrorResult;
14 : namespace dom {
15 :
16 : struct ServerSocketOptions;
17 : class GlobalObject;
18 : class TCPSocket;
19 : class TCPSocketChild;
20 : class TCPServerSocketChild;
21 : class TCPServerSocketParent;
22 :
23 : class TCPServerSocket final : public DOMEventTargetHelper
24 : , public nsIServerSocketListener
25 : {
26 : public:
27 : TCPServerSocket(nsIGlobalObject* aGlobal, uint16_t aPort, bool aUseArrayBuffers,
28 : uint16_t aBacklog);
29 :
30 : NS_DECL_ISUPPORTS_INHERITED
31 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(TCPServerSocket, DOMEventTargetHelper)
32 : NS_DECL_NSISERVERSOCKETLISTENER
33 :
34 0 : nsPIDOMWindowInner* GetParentObject() const
35 : {
36 0 : return GetOwner();
37 : }
38 :
39 : virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
40 :
41 : nsresult Init();
42 :
43 : uint16_t LocalPort();
44 : void Close();
45 :
46 : static already_AddRefed<TCPServerSocket>
47 : Constructor(const GlobalObject& aGlobal,
48 : uint16_t aPort,
49 : const ServerSocketOptions& aOptions,
50 : uint16_t aBacklog,
51 : mozilla::ErrorResult& aRv);
52 :
53 0 : IMPL_EVENT_HANDLER(connect);
54 0 : IMPL_EVENT_HANDLER(error);
55 :
56 : // Relay an accepted socket notification from the parent process and
57 : // initialize this object with an existing child actor for the new socket.
58 : nsresult AcceptChildSocket(TCPSocketChild* aSocketChild);
59 : // Associate this object with an IPC actor in the parent process to relay
60 : // notifications to content processes.
61 : void SetServerBridgeParent(TCPServerSocketParent* aBridgeParent);
62 :
63 : private:
64 : ~TCPServerSocket();
65 : // Dispatch a TCPServerSocketEvent event of a given type at this object.
66 : void FireEvent(const nsAString& aType, TCPSocket* aSocket);
67 :
68 : // The server socket associated with this object.
69 : nsCOMPtr<nsIServerSocket> mServerSocket;
70 : // The IPC actor in the content process.
71 : RefPtr<TCPServerSocketChild> mServerBridgeChild;
72 : // The IPC actor in the parent process.
73 : RefPtr<TCPServerSocketParent> mServerBridgeParent;
74 : int32_t mPort;
75 : uint16_t mBacklog;
76 : // True if any accepted sockets should use array buffers for received messages.
77 : bool mUseArrayBuffers;
78 : };
79 :
80 : } // namespace dom
81 : } // namespace mozilla
82 :
83 : #endif // mozilla_dom_TCPServerSocket_h
|