dom/network/src/TCPServerSocketChild.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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)
    30 {
    31 }
    33 TCPServerSocketChildBase::~TCPServerSocketChildBase()
    34 {
    35 }
    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 }
    47 TCPServerSocketChild::TCPServerSocketChild()
    48 {
    49 }
    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 }
    61 void
    62 TCPServerSocketChildBase::ReleaseIPDLReference()
    63 {
    64   MOZ_ASSERT(mIPCOpen);
    65   mIPCOpen = false;
    66   this->Release();
    67 }
    69 void
    70 TCPServerSocketChildBase::AddIPDLReference()
    71 {
    72   MOZ_ASSERT(!mIPCOpen);
    73   mIPCOpen = true;
    74   this->AddRef();
    75 }
    77 TCPServerSocketChild::~TCPServerSocketChild()
    78 {
    79 }
    81 bool
    82 TCPServerSocketChild::RecvCallbackAccept(PTCPSocketChild *psocket)
    83 {
    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.");
    89   }
    90   return true;
    91 }
    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 }
   107 NS_IMETHODIMP
   108 TCPServerSocketChild::Close()
   109 {
   110   SendClose();
   111   return NS_OK;
   112 }
   114 } // namespace dom
   115 } // namespace mozilla

mercurial