Bug 1853814 [wpt PR 42017] - LoAF: Expose script URL for promise resolvers, a=testonly
[gecko.git] / dom / network / TCPServerSocketChild.cpp
blob544c5391ee0c3e9699132ccd6516280238379ceb
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 #include "TCPServerSocketChild.h"
8 #include "TCPSocketChild.h"
9 #include "TCPServerSocket.h"
10 #include "mozilla/net/NeckoChild.h"
11 #include "mozilla/dom/PBrowserChild.h"
12 #include "mozilla/dom/BrowserChild.h"
13 #include "nsJSUtils.h"
14 #include "jsfriendapi.h"
16 using mozilla::net::gNeckoChild;
18 namespace mozilla::dom {
20 NS_IMPL_CYCLE_COLLECTION(TCPServerSocketChildBase, mServerSocket)
21 NS_IMPL_CYCLE_COLLECTING_ADDREF(TCPServerSocketChildBase)
22 NS_IMPL_CYCLE_COLLECTING_RELEASE(TCPServerSocketChildBase)
24 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TCPServerSocketChildBase)
25 NS_INTERFACE_MAP_ENTRY(nsISupports)
26 NS_INTERFACE_MAP_END
28 TCPServerSocketChildBase::TCPServerSocketChildBase() : mIPCOpen(false) {}
30 TCPServerSocketChildBase::~TCPServerSocketChildBase() = default;
32 NS_IMETHODIMP_(MozExternalRefCountType) TCPServerSocketChild::Release(void) {
33 nsrefcnt refcnt = TCPServerSocketChildBase::Release();
34 if (refcnt == 1 && mIPCOpen) {
35 PTCPServerSocketChild::SendRequestDelete();
36 return 1;
38 return refcnt;
41 TCPServerSocketChild::TCPServerSocketChild(TCPServerSocket* aServerSocket,
42 uint16_t aLocalPort,
43 uint16_t aBacklog,
44 bool aUseArrayBuffers) {
45 mServerSocket = aServerSocket;
46 AddIPDLReference();
47 gNeckoChild->SendPTCPServerSocketConstructor(this, aLocalPort, aBacklog,
48 aUseArrayBuffers);
51 void TCPServerSocketChildBase::ReleaseIPDLReference() {
52 MOZ_ASSERT(mIPCOpen);
53 mIPCOpen = false;
54 this->Release();
57 void TCPServerSocketChildBase::AddIPDLReference() {
58 MOZ_ASSERT(!mIPCOpen);
59 mIPCOpen = true;
60 this->AddRef();
63 TCPServerSocketChild::~TCPServerSocketChild() = default;
65 mozilla::ipc::IPCResult TCPServerSocketChild::RecvCallbackAccept(
66 PTCPSocketChild* psocket) {
67 RefPtr<TCPSocketChild> socket = static_cast<TCPSocketChild*>(psocket);
68 nsresult rv = mServerSocket->AcceptChildSocket(socket);
69 NS_ENSURE_SUCCESS(rv, IPC_OK());
70 return IPC_OK();
73 void TCPServerSocketChild::Close() { SendClose(); }
75 } // namespace mozilla::dom