|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #include "TCPServerSocketChild.h" |
|
6 #include "TCPSocketChild.h" |
|
7 #include "mozilla/net/NeckoChild.h" |
|
8 #include "mozilla/dom/PBrowserChild.h" |
|
9 #include "mozilla/dom/TabChild.h" |
|
10 #include "nsIDOMTCPSocket.h" |
|
11 #include "nsJSUtils.h" |
|
12 #include "jsfriendapi.h" |
|
13 |
|
14 using mozilla::net::gNeckoChild; |
|
15 |
|
16 namespace mozilla { |
|
17 namespace dom { |
|
18 |
|
19 NS_IMPL_CYCLE_COLLECTION(TCPServerSocketChildBase, mServerSocket) |
|
20 NS_IMPL_CYCLE_COLLECTING_ADDREF(TCPServerSocketChildBase) |
|
21 NS_IMPL_CYCLE_COLLECTING_RELEASE(TCPServerSocketChildBase) |
|
22 |
|
23 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TCPServerSocketChildBase) |
|
24 NS_INTERFACE_MAP_ENTRY(nsITCPServerSocketChild) |
|
25 NS_INTERFACE_MAP_ENTRY(nsISupports) |
|
26 NS_INTERFACE_MAP_END |
|
27 |
|
28 TCPServerSocketChildBase::TCPServerSocketChildBase() |
|
29 : mIPCOpen(false) |
|
30 { |
|
31 } |
|
32 |
|
33 TCPServerSocketChildBase::~TCPServerSocketChildBase() |
|
34 { |
|
35 } |
|
36 |
|
37 NS_IMETHODIMP_(MozExternalRefCountType) TCPServerSocketChild::Release(void) |
|
38 { |
|
39 nsrefcnt refcnt = TCPServerSocketChildBase::Release(); |
|
40 if (refcnt == 1 && mIPCOpen) { |
|
41 PTCPServerSocketChild::SendRequestDelete(); |
|
42 return 1; |
|
43 } |
|
44 return refcnt; |
|
45 } |
|
46 |
|
47 TCPServerSocketChild::TCPServerSocketChild() |
|
48 { |
|
49 } |
|
50 |
|
51 NS_IMETHODIMP |
|
52 TCPServerSocketChild::Listen(nsITCPServerSocketInternal* aServerSocket, uint16_t aLocalPort, |
|
53 uint16_t aBacklog, const nsAString & aBinaryType, JSContext* aCx) |
|
54 { |
|
55 mServerSocket = aServerSocket; |
|
56 AddIPDLReference(); |
|
57 gNeckoChild->SendPTCPServerSocketConstructor(this, aLocalPort, aBacklog, nsString(aBinaryType)); |
|
58 return NS_OK; |
|
59 } |
|
60 |
|
61 void |
|
62 TCPServerSocketChildBase::ReleaseIPDLReference() |
|
63 { |
|
64 MOZ_ASSERT(mIPCOpen); |
|
65 mIPCOpen = false; |
|
66 this->Release(); |
|
67 } |
|
68 |
|
69 void |
|
70 TCPServerSocketChildBase::AddIPDLReference() |
|
71 { |
|
72 MOZ_ASSERT(!mIPCOpen); |
|
73 mIPCOpen = true; |
|
74 this->AddRef(); |
|
75 } |
|
76 |
|
77 TCPServerSocketChild::~TCPServerSocketChild() |
|
78 { |
|
79 } |
|
80 |
|
81 bool |
|
82 TCPServerSocketChild::RecvCallbackAccept(PTCPSocketChild *psocket) |
|
83 { |
|
84 TCPSocketChild* socket = static_cast<TCPSocketChild*>(psocket); |
|
85 |
|
86 nsresult rv = mServerSocket->CallListenerAccept(static_cast<nsITCPSocketChild*>(socket)); |
|
87 if (NS_FAILED(rv)) { |
|
88 NS_WARNING("CallListenerAccept threw exception."); |
|
89 } |
|
90 return true; |
|
91 } |
|
92 |
|
93 bool |
|
94 TCPServerSocketChild::RecvCallbackError(const nsString& aMessage, |
|
95 const nsString& aFilename, |
|
96 const uint32_t& aLineNumber, |
|
97 const uint32_t& aColumnNumber) |
|
98 { |
|
99 nsresult rv = mServerSocket->CallListenerError(aMessage, aFilename, |
|
100 aLineNumber, aColumnNumber); |
|
101 if (NS_FAILED(rv)) { |
|
102 NS_WARNING("CallListenerError threw exception."); |
|
103 } |
|
104 return true; |
|
105 } |
|
106 |
|
107 NS_IMETHODIMP |
|
108 TCPServerSocketChild::Close() |
|
109 { |
|
110 SendClose(); |
|
111 return NS_OK; |
|
112 } |
|
113 |
|
114 } // namespace dom |
|
115 } // namespace mozilla |