OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/presentation/presentation_dispatcher.h" | 5 #include "content/renderer/presentation/presentation_dispatcher.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/common/presentation/presentation_service.mojom.h" | 8 #include "content/common/presentation/presentation_service.mojom.h" |
9 #include "content/public/common/service_registry.h" | 9 #include "content/public/common/service_registry.h" |
10 #include "content/public/renderer/render_frame.h" | 10 #include "content/public/renderer/render_frame.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 case presentation::PRESENTATION_ERROR_TYPE_SESSION_REQUEST_CANCELLED: | 26 case presentation::PRESENTATION_ERROR_TYPE_SESSION_REQUEST_CANCELLED: |
27 return blink::WebPresentationError::ErrorTypeSessionRequestCancelled; | 27 return blink::WebPresentationError::ErrorTypeSessionRequestCancelled; |
28 case presentation::PRESENTATION_ERROR_TYPE_NO_PRESENTATION_FOUND: | 28 case presentation::PRESENTATION_ERROR_TYPE_NO_PRESENTATION_FOUND: |
29 return blink::WebPresentationError::ErrorTypeNoPresentationFound; | 29 return blink::WebPresentationError::ErrorTypeNoPresentationFound; |
30 case presentation::PRESENTATION_ERROR_TYPE_UNKNOWN: | 30 case presentation::PRESENTATION_ERROR_TYPE_UNKNOWN: |
31 default: | 31 default: |
32 return blink::WebPresentationError::ErrorTypeUnknown; | 32 return blink::WebPresentationError::ErrorTypeUnknown; |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
| 36 blink::WebPresentationSessionState GetWebPresentationSessionStateFromMojo( |
| 37 presentation::PresentationSessionState mojoSessionState) { |
| 38 switch (mojoSessionState) { |
| 39 case presentation::PRESENTATION_SESSION_STATE_CONNECTED: |
| 40 return blink::WebPresentationSessionState::Connected; |
| 41 case presentation::PRESENTATION_SESSION_STATE_DISCONNECTED: |
| 42 return blink::WebPresentationSessionState::Disconnected; |
| 43 } |
| 44 |
| 45 NOTREACHED(); |
| 46 return blink::WebPresentationSessionState::Disconnected; |
| 47 } |
| 48 |
36 GURL GetPresentationURLFromFrame(content::RenderFrame* frame) { | 49 GURL GetPresentationURLFromFrame(content::RenderFrame* frame) { |
37 DCHECK(frame); | 50 DCHECK(frame); |
38 | 51 |
39 GURL url(frame->GetWebFrame()->document().defaultPresentationURL()); | 52 GURL url(frame->GetWebFrame()->document().defaultPresentationURL()); |
40 return url.is_valid() ? url : GURL(); | 53 return url.is_valid() ? url : GURL(); |
41 } | 54 } |
42 | 55 |
43 } // namespace | 56 } // namespace |
44 | 57 |
45 namespace content { | 58 namespace content { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 presentation::PresentationSessionInfoPtr session_info) { | 167 presentation::PresentationSessionInfoPtr session_info) { |
155 if (!controller_) | 168 if (!controller_) |
156 return; | 169 return; |
157 | 170 |
158 // Reset the callback to get the next event. | 171 // Reset the callback to get the next event. |
159 presentation_service_->ListenForDefaultSessionStart(base::Bind( | 172 presentation_service_->ListenForDefaultSessionStart(base::Bind( |
160 &PresentationDispatcher::OnDefaultSessionStarted, | 173 &PresentationDispatcher::OnDefaultSessionStarted, |
161 base::Unretained(this))); | 174 base::Unretained(this))); |
162 | 175 |
163 DCHECK(!session_info.is_null()); | 176 DCHECK(!session_info.is_null()); |
164 PresentationSessionDispatcher* session_dispatcher = | |
165 new PresentationSessionDispatcher(session_info.Pass()); | |
166 presentation_session_dispatchers_.push_back(session_dispatcher); | |
167 controller_->didStartDefaultSession( | 177 controller_->didStartDefaultSession( |
168 new PresentationSessionClient(session_dispatcher)); | 178 new PresentationSessionClient(session_info.Pass())); |
169 } | 179 } |
170 | 180 |
171 void PresentationDispatcher::OnSessionCreated( | 181 void PresentationDispatcher::OnSessionCreated( |
172 blink::WebPresentationSessionClientCallbacks* callback, | 182 blink::WebPresentationSessionClientCallbacks* callback, |
173 presentation::PresentationSessionInfoPtr session_info, | 183 presentation::PresentationSessionInfoPtr session_info, |
174 presentation::PresentationErrorPtr error) { | 184 presentation::PresentationErrorPtr error) { |
175 DCHECK(callback); | 185 DCHECK(callback); |
176 if (!error.is_null()) { | 186 if (!error.is_null()) { |
177 DCHECK(session_info.is_null()); | 187 DCHECK(session_info.is_null()); |
178 callback->onError(new blink::WebPresentationError( | 188 callback->onError(new blink::WebPresentationError( |
179 GetWebPresentationErrorTypeFromMojo(error->error_type), | 189 GetWebPresentationErrorTypeFromMojo(error->error_type), |
180 blink::WebString::fromUTF8(error->message))); | 190 blink::WebString::fromUTF8(error->message))); |
181 return; | 191 return; |
182 } | 192 } |
183 | 193 |
184 DCHECK(!session_info.is_null()); | 194 DCHECK(!session_info.is_null()); |
185 PresentationSessionDispatcher* session_dispatcher = | 195 callback->onSuccess(new PresentationSessionClient(session_info.Pass())); |
186 new PresentationSessionDispatcher(session_info.Pass()); | 196 } |
187 presentation_session_dispatchers_.push_back(session_dispatcher); | 197 |
188 callback->onSuccess(new PresentationSessionClient(session_dispatcher)); | 198 void PresentationDispatcher::OnSessionStateChange( |
| 199 presentation::PresentationSessionInfoPtr session_info, |
| 200 presentation::PresentationSessionState session_state) { |
| 201 if (!controller_) |
| 202 return; |
| 203 |
| 204 presentation_service_->ListenForSessionStateChange(base::Bind( |
| 205 &PresentationDispatcher::OnSessionStateChange, |
| 206 base::Unretained(this))); |
| 207 |
| 208 DCHECK(!session_info.is_null()); |
| 209 controller_->didChangeSessionState( |
| 210 new PresentationSessionClient(session_info.Pass()), |
| 211 GetWebPresentationSessionStateFromMojo(session_state)); |
189 } | 212 } |
190 | 213 |
191 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { | 214 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { |
192 if (presentation_service_.get()) | 215 if (presentation_service_.get()) |
193 return; | 216 return; |
194 | 217 |
195 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | 218 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
196 &presentation_service_); | 219 &presentation_service_); |
197 presentation_service_->ListenForDefaultSessionStart(base::Bind( | 220 presentation_service_->ListenForDefaultSessionStart(base::Bind( |
198 &PresentationDispatcher::OnDefaultSessionStarted, | 221 &PresentationDispatcher::OnDefaultSessionStarted, |
199 base::Unretained(this))); | 222 base::Unretained(this))); |
| 223 presentation_service_->ListenForSessionStateChange(base::Bind( |
| 224 &PresentationDispatcher::OnSessionStateChange, |
| 225 base::Unretained(this))); |
200 } | 226 } |
201 | 227 |
202 } // namespace content | 228 } // namespace content |
OLD | NEW |