Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/presentation/ipc/PresentationBuilderParent.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 "DCPresentationChannelDescription.h"
8
#include "PresentationBuilderParent.h"
9
#include "PresentationSessionInfo.h"
10
11
namespace mozilla {
12
namespace dom {
13
14
namespace {
15
16
class PresentationSessionTransportIPC final :
17
  public nsIPresentationSessionTransport
18
{
19
public:
20
  NS_DECL_ISUPPORTS
21
  NS_DECL_NSIPRESENTATIONSESSIONTRANSPORT
22
23
  PresentationSessionTransportIPC(PresentationParent* aParent,
24
                                  const nsAString& aSessionId,
25
                                  uint8_t aRole)
26
    : mParent(aParent)
27
    , mSessionId(aSessionId)
28
    , mRole(aRole)
29
0
  {
30
0
    MOZ_ASSERT(mParent);
31
0
  }
32
33
private:
34
0
  virtual ~PresentationSessionTransportIPC() = default;
35
36
  RefPtr<PresentationParent> mParent;
37
  nsString mSessionId;
38
  uint8_t mRole;
39
};
40
41
NS_IMPL_ISUPPORTS(PresentationSessionTransportIPC,
42
                  nsIPresentationSessionTransport)
43
44
NS_IMETHODIMP
45
PresentationSessionTransportIPC::GetCallback(
46
                           nsIPresentationSessionTransportCallback** aCallback)
47
0
{
48
0
  return NS_OK;
49
0
}
50
51
NS_IMETHODIMP
52
PresentationSessionTransportIPC::SetCallback(
53
                            nsIPresentationSessionTransportCallback* aCallback)
54
0
{
55
0
  if (aCallback) {
56
0
    aCallback->NotifyTransportReady();
57
0
  }
58
0
  return NS_OK;
59
0
}
60
61
NS_IMETHODIMP
62
PresentationSessionTransportIPC::GetSelfAddress(nsINetAddr** aSelfAddress)
63
0
{
64
0
  MOZ_ASSERT(false, "Not expected.");
65
0
  return NS_ERROR_FAILURE;
66
0
}
67
68
NS_IMETHODIMP
69
PresentationSessionTransportIPC::EnableDataNotification()
70
0
{
71
0
  return NS_OK;
72
0
}
73
74
NS_IMETHODIMP
75
PresentationSessionTransportIPC::Send(const nsAString& aData)
76
0
{
77
0
  return NS_OK;
78
0
}
79
80
NS_IMETHODIMP
81
PresentationSessionTransportIPC::SendBinaryMsg(const nsACString& aData)
82
0
{
83
0
  return NS_OK;
84
0
}
85
86
NS_IMETHODIMP
87
PresentationSessionTransportIPC::SendBlob(Blob* aBlob)
88
0
{
89
0
  return NS_OK;
90
0
}
91
92
NS_IMETHODIMP
93
PresentationSessionTransportIPC::Close(nsresult aReason)
94
0
{
95
0
  if (NS_WARN_IF(!mParent->SendNotifyCloseSessionTransport(mSessionId,
96
0
                                                           mRole,
97
0
                                                           aReason))) {
98
0
    return NS_ERROR_FAILURE;
99
0
  }
100
0
101
0
  return NS_OK;
102
0
}
103
104
} // anonymous namespace
105
106
NS_IMPL_ISUPPORTS(PresentationBuilderParent,
107
                  nsIPresentationSessionTransportBuilder,
108
                  nsIPresentationDataChannelSessionTransportBuilder)
109
110
PresentationBuilderParent::PresentationBuilderParent(PresentationParent* aParent)
111
  : mParent(aParent)
112
0
{
113
0
}
114
115
PresentationBuilderParent::~PresentationBuilderParent()
116
0
{
117
0
  if (mNeedDestroyActor) {
118
0
    Unused << NS_WARN_IF(!Send__delete__(this));
119
0
  }
120
0
}
121
122
NS_IMETHODIMP
123
PresentationBuilderParent::BuildDataChannelTransport(
124
                      uint8_t aRole,
125
                      mozIDOMWindow* aWindow, /* unused */
126
                      nsIPresentationSessionTransportBuilderListener* aListener)
127
0
{
128
0
  mBuilderListener = aListener;
129
0
130
0
  RefPtr<PresentationSessionInfo> info = static_cast<PresentationSessionInfo*>(aListener);
131
0
  nsAutoString sessionId(info->GetSessionId());
132
0
  if (NS_WARN_IF(!mParent->SendPPresentationBuilderConstructor(this,
133
0
                                                               sessionId,
134
0
                                                               aRole))) {
135
0
    return NS_ERROR_FAILURE;
136
0
  }
137
0
  mIPCSessionTransport = new PresentationSessionTransportIPC(mParent,
138
0
                                                             sessionId,
139
0
                                                             aRole);
140
0
  mNeedDestroyActor = true;
141
0
  mParent = nullptr;
142
0
  return NS_OK;
143
0
}
144
145
NS_IMETHODIMP
146
PresentationBuilderParent::OnIceCandidate(const nsAString& aCandidate)
147
0
{
148
0
  if (NS_WARN_IF(!SendOnIceCandidate(nsString(aCandidate)))){
149
0
    return NS_ERROR_FAILURE;
150
0
  }
151
0
  return NS_OK;
152
0
}
153
154
NS_IMETHODIMP
155
PresentationBuilderParent::OnOffer(nsIPresentationChannelDescription* aDescription)
156
0
{
157
0
  nsAutoString SDP;
158
0
  nsresult rv = aDescription->GetDataChannelSDP(SDP);
159
0
  if (NS_WARN_IF(NS_FAILED(rv))) {
160
0
    return rv;
161
0
  }
162
0
163
0
  if (NS_WARN_IF(!SendOnOffer(SDP))){
164
0
    return NS_ERROR_FAILURE;
165
0
  }
166
0
  return NS_OK;
167
0
}
168
169
NS_IMETHODIMP
170
PresentationBuilderParent::OnAnswer(nsIPresentationChannelDescription* aDescription)
171
0
{
172
0
  nsAutoString SDP;
173
0
  nsresult rv = aDescription->GetDataChannelSDP(SDP);
174
0
  if (NS_WARN_IF(NS_FAILED(rv))) {
175
0
    return rv;
176
0
  }
177
0
178
0
  if (NS_WARN_IF(!SendOnAnswer(SDP))){
179
0
    return NS_ERROR_FAILURE;
180
0
  }
181
0
  return NS_OK;
182
0
}
183
184
NS_IMETHODIMP
185
PresentationBuilderParent::NotifyDisconnected(nsresult aReason)
186
0
{
187
0
  return NS_OK;
188
0
}
189
190
void
191
PresentationBuilderParent::ActorDestroy(ActorDestroyReason aWhy)
192
0
{
193
0
  mNeedDestroyActor = false;
194
0
  mParent = nullptr;
195
0
  mBuilderListener = nullptr;
196
0
}
197
198
mozilla::ipc::IPCResult
199
PresentationBuilderParent::RecvSendOffer(const nsString& aSDP)
200
0
{
201
0
  RefPtr<DCPresentationChannelDescription> description =
202
0
    new DCPresentationChannelDescription(aSDP);
203
0
  if (NS_WARN_IF(!mBuilderListener ||
204
0
                 NS_FAILED(mBuilderListener->SendOffer(description)))) {
205
0
    return IPC_FAIL_NO_REASON(this);
206
0
  }
207
0
  return IPC_OK();
208
0
}
209
210
mozilla::ipc::IPCResult
211
PresentationBuilderParent::RecvSendAnswer(const nsString& aSDP)
212
0
{
213
0
  RefPtr<DCPresentationChannelDescription> description =
214
0
    new DCPresentationChannelDescription(aSDP);
215
0
  if (NS_WARN_IF(!mBuilderListener ||
216
0
                 NS_FAILED(mBuilderListener->SendAnswer(description)))) {
217
0
    return IPC_FAIL_NO_REASON(this);
218
0
  }
219
0
  return IPC_OK();
220
0
}
221
222
mozilla::ipc::IPCResult
223
PresentationBuilderParent::RecvSendIceCandidate(const nsString& aCandidate)
224
0
{
225
0
  if (NS_WARN_IF(!mBuilderListener ||
226
0
                 NS_FAILED(mBuilderListener->SendIceCandidate(aCandidate)))) {
227
0
    return IPC_FAIL_NO_REASON(this);
228
0
  }
229
0
  return IPC_OK();
230
0
}
231
232
mozilla::ipc::IPCResult
233
PresentationBuilderParent::RecvClose(const nsresult& aReason)
234
0
{
235
0
  if (NS_WARN_IF(!mBuilderListener ||
236
0
                 NS_FAILED(mBuilderListener->Close(aReason)))) {
237
0
    return IPC_FAIL_NO_REASON(this);
238
0
  }
239
0
  return IPC_OK();
240
0
}
241
242
// Delegate to nsIPresentationSessionTransportBuilderListener
243
mozilla::ipc::IPCResult
244
PresentationBuilderParent::RecvOnSessionTransport()
245
0
{
246
0
  RefPtr<PresentationBuilderParent> kungFuDeathGrip = this;
247
0
  Unused <<
248
0
    NS_WARN_IF(!mBuilderListener ||
249
0
               NS_FAILED(mBuilderListener->OnSessionTransport(mIPCSessionTransport)));
250
0
  return IPC_OK();
251
0
}
252
253
mozilla::ipc::IPCResult
254
PresentationBuilderParent::RecvOnSessionTransportError(const nsresult& aReason)
255
0
{
256
0
  if (NS_WARN_IF(!mBuilderListener ||
257
0
                 NS_FAILED(mBuilderListener->OnError(aReason)))) {
258
0
    return IPC_FAIL_NO_REASON(this);
259
0
  }
260
0
  return IPC_OK();
261
0
}
262
263
} // namespace dom
264
} // namespace mozilla