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::WebPresentationSessionClient::SessionState | |
37 GetWebPresentationSessionStateFromMojo( | |
38 presentation::PresentationSessionState mojoSessionState) { | |
39 switch (mojoSessionState) { | |
40 case presentation::PRESENTATION_SESSION_STATE_CONNECTED: | |
41 return blink::WebPresentationSessionClient::SessionStateConnected; | |
42 case presentation::PRESENTATION_SESSION_STATE_DISCONNECTED: | |
43 return blink::WebPresentationSessionClient::SessionStateDisconnected; | |
44 default: | |
Peter Beverloo
2015/03/20 19:13:39
Are there more than two options in the generated e
whywhat
2015/03/24 19:20:57
Done.
| |
45 return blink::WebPresentationSessionClient::SessionStateUnknown; | |
46 } | |
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 DCHECK(!session_info.is_null()); | |
202 controller_->didChangeSessionState( | |
imcheng
2015/03/20 23:01:46
Does controller_ hold references to multiple Prese
whywhat
2015/03/24 19:20:58
Presentation has a set of PresentationSession obje
| |
203 new PresentationSessionClient(session_info.Pass()), | |
Peter Beverloo
2015/03/20 19:13:39
It would be nice if you could document in the WebP
whywhat
2015/03/24 19:20:57
It would be nice to read this comment before submi
| |
204 GetWebPresentationSessionStateFromMojo(session_state)); | |
189 } | 205 } |
190 | 206 |
191 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { | 207 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { |
192 if (presentation_service_.get()) | 208 if (presentation_service_.get()) |
193 return; | 209 return; |
194 | 210 |
195 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | 211 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
196 &presentation_service_); | 212 &presentation_service_); |
197 presentation_service_->ListenForDefaultSessionStart(base::Bind( | 213 presentation_service_->ListenForDefaultSessionStart(base::Bind( |
198 &PresentationDispatcher::OnDefaultSessionStarted, | 214 &PresentationDispatcher::OnDefaultSessionStarted, |
199 base::Unretained(this))); | 215 base::Unretained(this))); |
216 presentation_service_->ListenForSessionStateChange(base::Bind( | |
217 &PresentationDispatcher::OnSessionStateChange, | |
imcheng
2015/03/20 23:01:46
How does PresentationServiceImpl know which sessio
whywhat
2015/03/24 19:20:58
PresentationServiceImpl should call the callback f
| |
218 base::Unretained(this))); | |
200 } | 219 } |
201 | 220 |
202 } // namespace content | 221 } // namespace content |
OLD | NEW |