Line data Source code
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/. */
6 :
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/TabChild.h"
13 : #include "nsJSUtils.h"
14 : #include "jsfriendapi.h"
15 :
16 : using mozilla::net::gNeckoChild;
17 :
18 : namespace mozilla {
19 : namespace dom {
20 :
21 0 : NS_IMPL_CYCLE_COLLECTION(TCPServerSocketChildBase, mServerSocket)
22 0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(TCPServerSocketChildBase)
23 0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(TCPServerSocketChildBase)
24 :
25 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TCPServerSocketChildBase)
26 0 : NS_INTERFACE_MAP_ENTRY(nsISupports)
27 0 : NS_INTERFACE_MAP_END
28 :
29 0 : TCPServerSocketChildBase::TCPServerSocketChildBase()
30 0 : : mIPCOpen(false)
31 : {
32 0 : }
33 :
34 0 : TCPServerSocketChildBase::~TCPServerSocketChildBase()
35 : {
36 0 : }
37 :
38 0 : NS_IMETHODIMP_(MozExternalRefCountType) TCPServerSocketChild::Release(void)
39 : {
40 0 : nsrefcnt refcnt = TCPServerSocketChildBase::Release();
41 0 : if (refcnt == 1 && mIPCOpen) {
42 0 : PTCPServerSocketChild::SendRequestDelete();
43 0 : return 1;
44 : }
45 0 : return refcnt;
46 : }
47 :
48 0 : TCPServerSocketChild::TCPServerSocketChild(TCPServerSocket* aServerSocket, uint16_t aLocalPort,
49 : uint16_t aBacklog, bool aUseArrayBuffers,
50 0 : nsIEventTarget* aIPCEventTarget)
51 : {
52 0 : mServerSocket = aServerSocket;
53 0 : if (aIPCEventTarget) {
54 0 : gNeckoChild->SetEventTargetForActor(this, aIPCEventTarget);
55 : }
56 0 : AddIPDLReference();
57 0 : gNeckoChild->SendPTCPServerSocketConstructor(this, aLocalPort, aBacklog, aUseArrayBuffers);
58 0 : }
59 :
60 : void
61 0 : TCPServerSocketChildBase::ReleaseIPDLReference()
62 : {
63 0 : MOZ_ASSERT(mIPCOpen);
64 0 : mIPCOpen = false;
65 0 : this->Release();
66 0 : }
67 :
68 : void
69 0 : TCPServerSocketChildBase::AddIPDLReference()
70 : {
71 0 : MOZ_ASSERT(!mIPCOpen);
72 0 : mIPCOpen = true;
73 0 : this->AddRef();
74 0 : }
75 :
76 0 : TCPServerSocketChild::~TCPServerSocketChild()
77 : {
78 0 : }
79 :
80 : mozilla::ipc::IPCResult
81 0 : TCPServerSocketChild::RecvCallbackAccept(PTCPSocketChild *psocket)
82 : {
83 0 : RefPtr<TCPSocketChild> socket = static_cast<TCPSocketChild*>(psocket);
84 0 : nsresult rv = mServerSocket->AcceptChildSocket(socket);
85 0 : NS_ENSURE_SUCCESS(rv, IPC_OK());
86 0 : return IPC_OK();
87 : }
88 :
89 : void
90 0 : TCPServerSocketChild::Close()
91 : {
92 0 : SendClose();
93 0 : }
94 :
95 : } // namespace dom
96 : } // namespace mozilla
|