michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "TCPServerSocketChild.h" michael@0: #include "TCPSocketChild.h" michael@0: #include "mozilla/net/NeckoChild.h" michael@0: #include "mozilla/dom/PBrowserChild.h" michael@0: #include "mozilla/dom/TabChild.h" michael@0: #include "nsIDOMTCPSocket.h" michael@0: #include "nsJSUtils.h" michael@0: #include "jsfriendapi.h" michael@0: michael@0: using mozilla::net::gNeckoChild; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: NS_IMPL_CYCLE_COLLECTION(TCPServerSocketChildBase, mServerSocket) michael@0: NS_IMPL_CYCLE_COLLECTING_ADDREF(TCPServerSocketChildBase) michael@0: NS_IMPL_CYCLE_COLLECTING_RELEASE(TCPServerSocketChildBase) michael@0: michael@0: NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TCPServerSocketChildBase) michael@0: NS_INTERFACE_MAP_ENTRY(nsITCPServerSocketChild) michael@0: NS_INTERFACE_MAP_ENTRY(nsISupports) michael@0: NS_INTERFACE_MAP_END michael@0: michael@0: TCPServerSocketChildBase::TCPServerSocketChildBase() michael@0: : mIPCOpen(false) michael@0: { michael@0: } michael@0: michael@0: TCPServerSocketChildBase::~TCPServerSocketChildBase() michael@0: { michael@0: } michael@0: michael@0: NS_IMETHODIMP_(MozExternalRefCountType) TCPServerSocketChild::Release(void) michael@0: { michael@0: nsrefcnt refcnt = TCPServerSocketChildBase::Release(); michael@0: if (refcnt == 1 && mIPCOpen) { michael@0: PTCPServerSocketChild::SendRequestDelete(); michael@0: return 1; michael@0: } michael@0: return refcnt; michael@0: } michael@0: michael@0: TCPServerSocketChild::TCPServerSocketChild() michael@0: { michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: TCPServerSocketChild::Listen(nsITCPServerSocketInternal* aServerSocket, uint16_t aLocalPort, michael@0: uint16_t aBacklog, const nsAString & aBinaryType, JSContext* aCx) michael@0: { michael@0: mServerSocket = aServerSocket; michael@0: AddIPDLReference(); michael@0: gNeckoChild->SendPTCPServerSocketConstructor(this, aLocalPort, aBacklog, nsString(aBinaryType)); michael@0: return NS_OK; michael@0: } michael@0: michael@0: void michael@0: TCPServerSocketChildBase::ReleaseIPDLReference() michael@0: { michael@0: MOZ_ASSERT(mIPCOpen); michael@0: mIPCOpen = false; michael@0: this->Release(); michael@0: } michael@0: michael@0: void michael@0: TCPServerSocketChildBase::AddIPDLReference() michael@0: { michael@0: MOZ_ASSERT(!mIPCOpen); michael@0: mIPCOpen = true; michael@0: this->AddRef(); michael@0: } michael@0: michael@0: TCPServerSocketChild::~TCPServerSocketChild() michael@0: { michael@0: } michael@0: michael@0: bool michael@0: TCPServerSocketChild::RecvCallbackAccept(PTCPSocketChild *psocket) michael@0: { michael@0: TCPSocketChild* socket = static_cast(psocket); michael@0: michael@0: nsresult rv = mServerSocket->CallListenerAccept(static_cast(socket)); michael@0: if (NS_FAILED(rv)) { michael@0: NS_WARNING("CallListenerAccept threw exception."); michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: TCPServerSocketChild::RecvCallbackError(const nsString& aMessage, michael@0: const nsString& aFilename, michael@0: const uint32_t& aLineNumber, michael@0: const uint32_t& aColumnNumber) michael@0: { michael@0: nsresult rv = mServerSocket->CallListenerError(aMessage, aFilename, michael@0: aLineNumber, aColumnNumber); michael@0: if (NS_FAILED(rv)) { michael@0: NS_WARNING("CallListenerError threw exception."); michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: TCPServerSocketChild::Close() michael@0: { michael@0: SendClose(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla