Bumping manifests a=b2g-bump
[gecko.git] / dom / network / TCPServerSocketChild.cpp
blob05bccbef113576ea0b8cea5ccaf18908fdec8de1
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/. */
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"
14 using mozilla::net::gNeckoChild;
16 namespace mozilla {
17 namespace dom {
19 NS_IMPL_CYCLE_COLLECTION(TCPServerSocketChildBase, mServerSocket)
20 NS_IMPL_CYCLE_COLLECTING_ADDREF(TCPServerSocketChildBase)
21 NS_IMPL_CYCLE_COLLECTING_RELEASE(TCPServerSocketChildBase)
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
28 TCPServerSocketChildBase::TCPServerSocketChildBase()
29 : mIPCOpen(false)
33 TCPServerSocketChildBase::~TCPServerSocketChildBase()
37 NS_IMETHODIMP_(MozExternalRefCountType) TCPServerSocketChild::Release(void)
39 nsrefcnt refcnt = TCPServerSocketChildBase::Release();
40 if (refcnt == 1 && mIPCOpen) {
41 PTCPServerSocketChild::SendRequestDelete();
42 return 1;
44 return refcnt;
47 TCPServerSocketChild::TCPServerSocketChild()
51 NS_IMETHODIMP
52 TCPServerSocketChild::Listen(nsITCPServerSocketInternal* aServerSocket, uint16_t aLocalPort,
53 uint16_t aBacklog, const nsAString & aBinaryType, JSContext* aCx)
55 mServerSocket = aServerSocket;
56 AddIPDLReference();
57 gNeckoChild->SendPTCPServerSocketConstructor(this, aLocalPort, aBacklog, nsString(aBinaryType));
58 return NS_OK;
61 void
62 TCPServerSocketChildBase::ReleaseIPDLReference()
64 MOZ_ASSERT(mIPCOpen);
65 mIPCOpen = false;
66 this->Release();
69 void
70 TCPServerSocketChildBase::AddIPDLReference()
72 MOZ_ASSERT(!mIPCOpen);
73 mIPCOpen = true;
74 this->AddRef();
77 TCPServerSocketChild::~TCPServerSocketChild()
81 bool
82 TCPServerSocketChild::RecvCallbackAccept(PTCPSocketChild *psocket)
84 TCPSocketChild* socket = static_cast<TCPSocketChild*>(psocket);
86 nsresult rv = mServerSocket->CallListenerAccept(static_cast<nsITCPSocketChild*>(socket));
87 if (NS_FAILED(rv)) {
88 NS_WARNING("CallListenerAccept threw exception.");
90 return true;
93 bool
94 TCPServerSocketChild::RecvCallbackError(const nsString& aMessage,
95 const nsString& aFilename,
96 const uint32_t& aLineNumber,
97 const uint32_t& aColumnNumber)
99 nsresult rv = mServerSocket->CallListenerError(aMessage, aFilename,
100 aLineNumber, aColumnNumber);
101 if (NS_FAILED(rv)) {
102 NS_WARNING("CallListenerError threw exception.");
104 return true;
107 NS_IMETHODIMP
108 TCPServerSocketChild::Close()
110 SendClose();
111 return NS_OK;
114 } // namespace dom
115 } // namespace mozilla