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