1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_TCPServerSocket_h
8 #define mozilla_dom_TCPServerSocket_h
10 #include "mozilla/DOMEventTargetHelper.h"
11 #include "nsIServerSocket.h"
17 struct ServerSocketOptions
;
21 class TCPServerSocketChild
;
22 class TCPServerSocketParent
;
24 class TCPServerSocket final
: public DOMEventTargetHelper
,
25 public nsIServerSocketListener
{
27 TCPServerSocket(nsIGlobalObject
* aGlobal
, uint16_t aPort
,
28 bool aUseArrayBuffers
, uint16_t aBacklog
);
30 NS_DECL_ISUPPORTS_INHERITED
31 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(TCPServerSocket
,
33 NS_DECL_NSISERVERSOCKETLISTENER
35 nsPIDOMWindowInner
* GetParentObject() const { return GetOwner(); }
37 virtual JSObject
* WrapObject(JSContext
* aCx
,
38 JS::Handle
<JSObject
*> aGivenProto
) override
;
42 uint16_t LocalPort() const;
45 static already_AddRefed
<TCPServerSocket
> Constructor(
46 const GlobalObject
& aGlobal
, uint16_t aPort
,
47 const ServerSocketOptions
& aOptions
, uint16_t aBacklog
,
48 mozilla::ErrorResult
& aRv
);
50 IMPL_EVENT_HANDLER(connect
);
51 IMPL_EVENT_HANDLER(error
);
53 // Relay an accepted socket notification from the parent process and
54 // initialize this object with an existing child actor for the new socket.
55 nsresult
AcceptChildSocket(TCPSocketChild
* aSocketChild
);
56 // Associate this object with an IPC actor in the parent process to relay
57 // notifications to content processes.
58 void SetServerBridgeParent(TCPServerSocketParent
* aBridgeParent
);
62 // Dispatch a TCPServerSocketEvent event of a given type at this object.
63 void FireEvent(const nsAString
& aType
, TCPSocket
* aSocket
);
65 // The server socket associated with this object.
66 nsCOMPtr
<nsIServerSocket
> mServerSocket
;
67 // The IPC actor in the content process.
68 RefPtr
<TCPServerSocketChild
> mServerBridgeChild
;
69 // The IPC actor in the parent process.
70 RefPtr
<TCPServerSocketParent
> mServerBridgeParent
;
73 // True if any accepted sockets should use array buffers for received
75 bool mUseArrayBuffers
;
79 } // namespace mozilla
81 #endif // mozilla_dom_TCPServerSocket_h