Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/network/TCPServerSocketParent.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "nsIScriptSecurityManager.h"
8
#include "TCPServerSocket.h"
9
#include "TCPServerSocketParent.h"
10
#include "nsJSUtils.h"
11
#include "TCPSocketParent.h"
12
#include "mozilla/Unused.h"
13
#include "mozilla/dom/ContentParent.h"
14
#include "mozilla/dom/TabParent.h"
15
16
namespace mozilla {
17
namespace dom {
18
19
NS_IMPL_CYCLE_COLLECTION(TCPServerSocketParent, mServerSocket)
20
NS_IMPL_CYCLE_COLLECTING_ADDREF(TCPServerSocketParent)
21
NS_IMPL_CYCLE_COLLECTING_RELEASE(TCPServerSocketParent)
22
23
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TCPServerSocketParent)
24
0
  NS_INTERFACE_MAP_ENTRY(nsISupports)
25
0
NS_INTERFACE_MAP_END
26
27
void
28
TCPServerSocketParent::ReleaseIPDLReference()
29
0
{
30
0
  MOZ_ASSERT(mIPCOpen);
31
0
  mIPCOpen = false;
32
0
  this->Release();
33
0
}
34
35
void
36
TCPServerSocketParent::AddIPDLReference()
37
0
{
38
0
  MOZ_ASSERT(!mIPCOpen);
39
0
  mIPCOpen = true;
40
0
  this->AddRef();
41
0
}
42
43
TCPServerSocketParent::TCPServerSocketParent(PNeckoParent* neckoParent,
44
                                             uint16_t aLocalPort,
45
                                             uint16_t aBacklog,
46
                                             bool aUseArrayBuffers)
47
: mNeckoParent(neckoParent)
48
, mIPCOpen(false)
49
0
{
50
0
  mServerSocket = new TCPServerSocket(nullptr, aLocalPort, aUseArrayBuffers, aBacklog);
51
0
  mServerSocket->SetServerBridgeParent(this);
52
0
}
53
54
TCPServerSocketParent::~TCPServerSocketParent()
55
0
{
56
0
}
57
58
void
59
TCPServerSocketParent::Init()
60
0
{
61
0
  NS_ENSURE_SUCCESS_VOID(mServerSocket->Init());
62
0
}
63
64
nsresult
65
TCPServerSocketParent::SendCallbackAccept(TCPSocketParent *socket)
66
0
{
67
0
  socket->AddIPDLReference();
68
0
69
0
  nsresult rv;
70
0
71
0
  nsString host;
72
0
  rv = socket->GetHost(host);
73
0
  if (NS_FAILED(rv)) {
74
0
    NS_ERROR("Failed to get host from nsITCPSocketParent");
75
0
    return NS_ERROR_FAILURE;
76
0
  }
77
0
78
0
  uint16_t port;
79
0
  rv = socket->GetPort(&port);
80
0
  if (NS_FAILED(rv)) {
81
0
    NS_ERROR("Failed to get port from nsITCPSocketParent");
82
0
    return NS_ERROR_FAILURE;
83
0
  }
84
0
85
0
  if (mNeckoParent) {
86
0
    if (mNeckoParent->SendPTCPSocketConstructor(socket, host, port)) {
87
0
      mozilla::Unused << PTCPServerSocketParent::SendCallbackAccept(socket);
88
0
    }
89
0
    else {
90
0
      NS_ERROR("Sending data from PTCPSocketParent was failed.");
91
0
    }
92
0
  }
93
0
  else {
94
0
    NS_ERROR("The member value for NeckoParent is wrong.");
95
0
  }
96
0
  return NS_OK;
97
0
}
98
99
mozilla::ipc::IPCResult
100
TCPServerSocketParent::RecvClose()
101
0
{
102
0
  NS_ENSURE_TRUE(mServerSocket, IPC_OK());
103
0
  mServerSocket->Close();
104
0
  return IPC_OK();
105
0
}
106
107
void
108
TCPServerSocketParent::ActorDestroy(ActorDestroyReason why)
109
0
{
110
0
  if (mServerSocket) {
111
0
    mServerSocket->Close();
112
0
    mServerSocket = nullptr;
113
0
  }
114
0
  mNeckoParent = nullptr;
115
0
}
116
117
mozilla::ipc::IPCResult
118
TCPServerSocketParent::RecvRequestDelete()
119
0
{
120
0
  mozilla::Unused << Send__delete__(this);
121
0
  return IPC_OK();
122
0
}
123
124
void
125
TCPServerSocketParent::OnConnect(TCPServerSocketEvent* event)
126
0
{
127
0
  RefPtr<TCPSocket> socket = event->Socket();
128
0
129
0
  RefPtr<TCPSocketParent> socketParent = new TCPSocketParent();
130
0
  socketParent->SetSocket(socket);
131
0
132
0
  socket->SetSocketBridgeParent(socketParent);
133
0
134
0
  SendCallbackAccept(socketParent);
135
0
}
136
137
} // namespace dom
138
} // namespace mozilla