1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/network/src/TCPServerSocketChild.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,115 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "TCPServerSocketChild.h" 1.9 +#include "TCPSocketChild.h" 1.10 +#include "mozilla/net/NeckoChild.h" 1.11 +#include "mozilla/dom/PBrowserChild.h" 1.12 +#include "mozilla/dom/TabChild.h" 1.13 +#include "nsIDOMTCPSocket.h" 1.14 +#include "nsJSUtils.h" 1.15 +#include "jsfriendapi.h" 1.16 + 1.17 +using mozilla::net::gNeckoChild; 1.18 + 1.19 +namespace mozilla { 1.20 +namespace dom { 1.21 + 1.22 +NS_IMPL_CYCLE_COLLECTION(TCPServerSocketChildBase, mServerSocket) 1.23 +NS_IMPL_CYCLE_COLLECTING_ADDREF(TCPServerSocketChildBase) 1.24 +NS_IMPL_CYCLE_COLLECTING_RELEASE(TCPServerSocketChildBase) 1.25 + 1.26 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TCPServerSocketChildBase) 1.27 + NS_INTERFACE_MAP_ENTRY(nsITCPServerSocketChild) 1.28 + NS_INTERFACE_MAP_ENTRY(nsISupports) 1.29 +NS_INTERFACE_MAP_END 1.30 + 1.31 +TCPServerSocketChildBase::TCPServerSocketChildBase() 1.32 +: mIPCOpen(false) 1.33 +{ 1.34 +} 1.35 + 1.36 +TCPServerSocketChildBase::~TCPServerSocketChildBase() 1.37 +{ 1.38 +} 1.39 + 1.40 +NS_IMETHODIMP_(MozExternalRefCountType) TCPServerSocketChild::Release(void) 1.41 +{ 1.42 + nsrefcnt refcnt = TCPServerSocketChildBase::Release(); 1.43 + if (refcnt == 1 && mIPCOpen) { 1.44 + PTCPServerSocketChild::SendRequestDelete(); 1.45 + return 1; 1.46 + } 1.47 + return refcnt; 1.48 +} 1.49 + 1.50 +TCPServerSocketChild::TCPServerSocketChild() 1.51 +{ 1.52 +} 1.53 + 1.54 +NS_IMETHODIMP 1.55 +TCPServerSocketChild::Listen(nsITCPServerSocketInternal* aServerSocket, uint16_t aLocalPort, 1.56 + uint16_t aBacklog, const nsAString & aBinaryType, JSContext* aCx) 1.57 +{ 1.58 + mServerSocket = aServerSocket; 1.59 + AddIPDLReference(); 1.60 + gNeckoChild->SendPTCPServerSocketConstructor(this, aLocalPort, aBacklog, nsString(aBinaryType)); 1.61 + return NS_OK; 1.62 +} 1.63 + 1.64 +void 1.65 +TCPServerSocketChildBase::ReleaseIPDLReference() 1.66 +{ 1.67 + MOZ_ASSERT(mIPCOpen); 1.68 + mIPCOpen = false; 1.69 + this->Release(); 1.70 +} 1.71 + 1.72 +void 1.73 +TCPServerSocketChildBase::AddIPDLReference() 1.74 +{ 1.75 + MOZ_ASSERT(!mIPCOpen); 1.76 + mIPCOpen = true; 1.77 + this->AddRef(); 1.78 +} 1.79 + 1.80 +TCPServerSocketChild::~TCPServerSocketChild() 1.81 +{ 1.82 +} 1.83 + 1.84 +bool 1.85 +TCPServerSocketChild::RecvCallbackAccept(PTCPSocketChild *psocket) 1.86 +{ 1.87 + TCPSocketChild* socket = static_cast<TCPSocketChild*>(psocket); 1.88 + 1.89 + nsresult rv = mServerSocket->CallListenerAccept(static_cast<nsITCPSocketChild*>(socket)); 1.90 + if (NS_FAILED(rv)) { 1.91 + NS_WARNING("CallListenerAccept threw exception."); 1.92 + } 1.93 + return true; 1.94 +} 1.95 + 1.96 +bool 1.97 +TCPServerSocketChild::RecvCallbackError(const nsString& aMessage, 1.98 + const nsString& aFilename, 1.99 + const uint32_t& aLineNumber, 1.100 + const uint32_t& aColumnNumber) 1.101 +{ 1.102 + nsresult rv = mServerSocket->CallListenerError(aMessage, aFilename, 1.103 + aLineNumber, aColumnNumber); 1.104 + if (NS_FAILED(rv)) { 1.105 + NS_WARNING("CallListenerError threw exception."); 1.106 + } 1.107 + return true; 1.108 +} 1.109 + 1.110 +NS_IMETHODIMP 1.111 +TCPServerSocketChild::Close() 1.112 +{ 1.113 + SendClose(); 1.114 + return NS_OK; 1.115 +} 1.116 + 1.117 +} // namespace dom 1.118 +} // namespace mozilla