/src/mozilla-central/dom/presentation/ipc/PresentationBuilderChild.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 "nsComponentManagerUtils.h" |
9 | | #include "nsGlobalWindow.h" |
10 | | #include "PresentationBuilderChild.h" |
11 | | #include "PresentationIPCService.h" |
12 | | #include "nsServiceManagerUtils.h" |
13 | | #include "mozilla/Unused.h" |
14 | | |
15 | | namespace mozilla { |
16 | | namespace dom { |
17 | | |
18 | | NS_IMPL_ISUPPORTS(PresentationBuilderChild, |
19 | | nsIPresentationSessionTransportBuilderListener) |
20 | | |
21 | | PresentationBuilderChild::PresentationBuilderChild(const nsString& aSessionId, |
22 | | uint8_t aRole) |
23 | | : mSessionId(aSessionId) |
24 | | , mRole(aRole) |
25 | 0 | { |
26 | 0 | } |
27 | | |
28 | | nsresult PresentationBuilderChild::Init() |
29 | 0 | { |
30 | 0 | mBuilder = do_CreateInstance("@mozilla.org/presentation/datachanneltransportbuilder;1"); |
31 | 0 | if (NS_WARN_IF(!mBuilder)) { |
32 | 0 | return NS_ERROR_NOT_AVAILABLE; |
33 | 0 | } |
34 | 0 | |
35 | 0 | uint64_t windowId = 0; |
36 | 0 |
|
37 | 0 | nsCOMPtr<nsIPresentationService> service = |
38 | 0 | do_GetService(PRESENTATION_SERVICE_CONTRACTID); |
39 | 0 | if (NS_WARN_IF(!service)) { |
40 | 0 | return NS_ERROR_NOT_AVAILABLE; |
41 | 0 | } |
42 | 0 | |
43 | 0 | if (NS_WARN_IF(NS_FAILED(service->GetWindowIdBySessionId( |
44 | 0 | mSessionId, |
45 | 0 | mRole, |
46 | 0 | &windowId)))) { |
47 | 0 | return NS_ERROR_NOT_AVAILABLE; |
48 | 0 | } |
49 | 0 | |
50 | 0 | nsPIDOMWindowInner* window = nsGlobalWindowInner::GetInnerWindowWithId(windowId)->AsInner(); |
51 | 0 | if (NS_WARN_IF(!window)) { |
52 | 0 | return NS_ERROR_NOT_AVAILABLE; |
53 | 0 | } |
54 | 0 | |
55 | 0 | return mBuilder->BuildDataChannelTransport(mRole, window, this); |
56 | 0 | } |
57 | | |
58 | | void |
59 | | PresentationBuilderChild::ActorDestroy(ActorDestroyReason aWhy) |
60 | 0 | { |
61 | 0 | mBuilder = nullptr; |
62 | 0 | mActorDestroyed = true; |
63 | 0 | } |
64 | | |
65 | | mozilla::ipc::IPCResult |
66 | | PresentationBuilderChild::RecvOnOffer(const nsString& aSDP) |
67 | 0 | { |
68 | 0 | if (NS_WARN_IF(!mBuilder)) { |
69 | 0 | return IPC_FAIL_NO_REASON(this); |
70 | 0 | } |
71 | 0 | RefPtr<DCPresentationChannelDescription> description = |
72 | 0 | new DCPresentationChannelDescription(aSDP); |
73 | 0 |
|
74 | 0 | if (NS_WARN_IF(NS_FAILED(mBuilder->OnOffer(description)))) { |
75 | 0 | return IPC_FAIL_NO_REASON(this); |
76 | 0 | } |
77 | 0 | return IPC_OK(); |
78 | 0 | } |
79 | | |
80 | | mozilla::ipc::IPCResult |
81 | | PresentationBuilderChild::RecvOnAnswer(const nsString& aSDP) |
82 | 0 | { |
83 | 0 | if (NS_WARN_IF(!mBuilder)) { |
84 | 0 | return IPC_FAIL_NO_REASON(this); |
85 | 0 | } |
86 | 0 | RefPtr<DCPresentationChannelDescription> description = |
87 | 0 | new DCPresentationChannelDescription(aSDP); |
88 | 0 |
|
89 | 0 | if (NS_WARN_IF(NS_FAILED(mBuilder->OnAnswer(description)))) { |
90 | 0 | return IPC_FAIL_NO_REASON(this); |
91 | 0 | } |
92 | 0 | return IPC_OK(); |
93 | 0 | } |
94 | | |
95 | | mozilla::ipc::IPCResult |
96 | | PresentationBuilderChild::RecvOnIceCandidate(const nsString& aCandidate) |
97 | 0 | { |
98 | 0 | if (NS_WARN_IF(mBuilder && NS_FAILED(mBuilder->OnIceCandidate(aCandidate)))) { |
99 | 0 | return IPC_FAIL_NO_REASON(this); |
100 | 0 | } |
101 | 0 | return IPC_OK(); |
102 | 0 | } |
103 | | |
104 | | // nsPresentationSessionTransportBuilderListener |
105 | | NS_IMETHODIMP |
106 | | PresentationBuilderChild::OnSessionTransport(nsIPresentationSessionTransport* aTransport) |
107 | 0 | { |
108 | 0 | if (NS_WARN_IF(mActorDestroyed || !SendOnSessionTransport())){ |
109 | 0 | return NS_ERROR_FAILURE; |
110 | 0 | } |
111 | 0 | |
112 | 0 | nsCOMPtr<nsIPresentationService> service = |
113 | 0 | do_GetService(PRESENTATION_SERVICE_CONTRACTID); |
114 | 0 | NS_WARNING_ASSERTION(service, "no presentation service"); |
115 | 0 | if (service) { |
116 | 0 | Unused << NS_WARN_IF(NS_FAILED(static_cast<PresentationIPCService*>(service.get())-> |
117 | 0 | NotifySessionTransport(mSessionId, mRole, aTransport))); |
118 | 0 | } |
119 | 0 | mBuilder = nullptr; |
120 | 0 | return NS_OK; |
121 | 0 | } |
122 | | |
123 | | NS_IMETHODIMP |
124 | | PresentationBuilderChild::OnError(nsresult reason) |
125 | 0 | { |
126 | 0 | mBuilder = nullptr; |
127 | 0 |
|
128 | 0 | if (NS_WARN_IF(mActorDestroyed || !SendOnSessionTransportError(reason))){ |
129 | 0 | return NS_ERROR_FAILURE; |
130 | 0 | } |
131 | 0 | return NS_OK; |
132 | 0 | } |
133 | | |
134 | | NS_IMETHODIMP |
135 | | PresentationBuilderChild::SendOffer(nsIPresentationChannelDescription* aOffer) |
136 | 0 | { |
137 | 0 | nsAutoString SDP; |
138 | 0 | nsresult rv = aOffer->GetDataChannelSDP(SDP); |
139 | 0 | if (NS_WARN_IF(NS_FAILED(rv))) { |
140 | 0 | return rv; |
141 | 0 | } |
142 | 0 | |
143 | 0 | if (NS_WARN_IF(mActorDestroyed || !SendSendOffer(SDP))){ |
144 | 0 | return NS_ERROR_FAILURE; |
145 | 0 | } |
146 | 0 | return NS_OK; |
147 | 0 | } |
148 | | |
149 | | NS_IMETHODIMP |
150 | | PresentationBuilderChild::SendAnswer(nsIPresentationChannelDescription* aAnswer) |
151 | 0 | { |
152 | 0 | nsAutoString SDP; |
153 | 0 | nsresult rv = aAnswer->GetDataChannelSDP(SDP); |
154 | 0 | if (NS_WARN_IF(NS_FAILED(rv))) { |
155 | 0 | return rv; |
156 | 0 | } |
157 | 0 | |
158 | 0 | if (NS_WARN_IF(mActorDestroyed || !SendSendAnswer(SDP))){ |
159 | 0 | return NS_ERROR_FAILURE; |
160 | 0 | } |
161 | 0 | return NS_OK; |
162 | 0 | } |
163 | | |
164 | | NS_IMETHODIMP |
165 | | PresentationBuilderChild::SendIceCandidate(const nsAString& candidate) |
166 | 0 | { |
167 | 0 | if (NS_WARN_IF(mActorDestroyed || !SendSendIceCandidate(nsString(candidate)))) { |
168 | 0 | return NS_ERROR_FAILURE; |
169 | 0 | } |
170 | 0 | return NS_OK; |
171 | 0 | } |
172 | | |
173 | | NS_IMETHODIMP |
174 | | PresentationBuilderChild::Close(nsresult reason) |
175 | 0 | { |
176 | 0 | if (NS_WARN_IF(mActorDestroyed || !SendClose(reason))) { |
177 | 0 | return NS_ERROR_FAILURE; |
178 | 0 | } |
179 | 0 | return NS_OK; |
180 | 0 | } |
181 | | |
182 | | } // namespace dom |
183 | | } // namespace mozilla |
184 | | |