dom/network/src/TCPServerSocketChild.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial