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 "chrome/browser/media/router/presentation_service_delegate_impl.h" | 5 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <unordered_map> | 8 #include <unordered_map> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/containers/small_map.h" | 12 #include "base/containers/small_map.h" |
13 #include "base/guid.h" | 13 #include "base/guid.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "chrome/browser/media/router/browser_presentation_connection_proxy.h" |
16 #include "chrome/browser/media/router/create_presentation_connection_request.h" | 17 #include "chrome/browser/media/router/create_presentation_connection_request.h" |
17 #include "chrome/browser/media/router/media_route.h" | 18 #include "chrome/browser/media/router/media_route.h" |
18 #include "chrome/browser/media/router/media_router.h" | 19 #include "chrome/browser/media/router/media_router.h" |
19 #include "chrome/browser/media/router/media_router_dialog_controller.h" | 20 #include "chrome/browser/media/router/media_router_dialog_controller.h" |
20 #include "chrome/browser/media/router/media_router_factory.h" | 21 #include "chrome/browser/media/router/media_router_factory.h" |
21 #include "chrome/browser/media/router/media_sink.h" | 22 #include "chrome/browser/media/router/media_sink.h" |
22 #include "chrome/browser/media/router/media_source_helper.h" | 23 #include "chrome/browser/media/router/media_source_helper.h" |
23 #include "chrome/browser/media/router/offscreen_presentation_manager.h" | 24 #include "chrome/browser/media/router/offscreen_presentation_manager.h" |
24 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" | 25 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" |
25 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" | 26 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 void RemoveConnection(const std::string& presentation_id, | 157 void RemoveConnection(const std::string& presentation_id, |
157 const MediaRoute::Id& route_id); | 158 const MediaRoute::Id& route_id); |
158 | 159 |
159 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; | 160 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; |
160 | 161 |
161 void OnPresentationSessionStarted( | 162 void OnPresentationSessionStarted( |
162 const content::PresentationSessionInfo& session, | 163 const content::PresentationSessionInfo& session, |
163 const MediaRoute& route); | 164 const MediaRoute& route); |
164 void OnPresentationServiceDelegateDestroyed() const; | 165 void OnPresentationServiceDelegateDestroyed() const; |
165 | 166 |
| 167 bool IsOffscreenPresentation(const std::string& presentation_id) const; |
| 168 void ConnectToPresentation( |
| 169 const content::PresentationSessionInfo& session, |
| 170 content::PresentationConnectionPtr controller_connection_ptr, |
| 171 content::PresentationConnectionRequest receiver_connection_request); |
| 172 |
166 private: | 173 private: |
167 MediaSource GetMediaSourceFromListener( | 174 MediaSource GetMediaSourceFromListener( |
168 content::PresentationScreenAvailabilityListener* listener) const; | 175 content::PresentationScreenAvailabilityListener* listener) const; |
169 base::SmallMap<std::map<std::string, MediaRoute::Id>> | 176 base::SmallMap<std::map<std::string, MediaRoute>> presentation_id_to_route_; |
170 presentation_id_to_route_id_; | |
171 base::SmallMap< | 177 base::SmallMap< |
172 std::map<std::string, std::unique_ptr<PresentationMediaSinksObserver>>> | 178 std::map<std::string, std::unique_ptr<PresentationMediaSinksObserver>>> |
173 url_to_sinks_observer_; | 179 url_to_sinks_observer_; |
174 std::unordered_map< | 180 std::unordered_map< |
175 MediaRoute::Id, | 181 MediaRoute::Id, |
176 std::unique_ptr<PresentationConnectionStateSubscription>> | 182 std::unique_ptr<PresentationConnectionStateSubscription>> |
177 connection_state_subscriptions_; | 183 connection_state_subscriptions_; |
178 std::unordered_map< | 184 std::unordered_map< |
179 MediaRoute::Id, | 185 MediaRoute::Id, |
180 std::unique_ptr<PresentationSessionMessagesObserver>> | 186 std::unique_ptr<PresentationSessionMessagesObserver>> |
181 session_messages_observers_; | 187 session_messages_observers_; |
| 188 std::unordered_map<MediaRoute::Id, |
| 189 std::unique_ptr<BrowserPresentationConnectionProxy>> |
| 190 browser_connection_proxies_; |
182 | 191 |
183 RenderFrameHostId render_frame_host_id_; | 192 RenderFrameHostId render_frame_host_id_; |
184 | 193 |
185 // References to the owning WebContents, and the corresponding MediaRouter. | 194 // References to the owning WebContents, and the corresponding MediaRouter. |
186 content::WebContents* web_contents_; | 195 content::WebContents* web_contents_; |
187 MediaRouter* router_; | 196 MediaRouter* router_; |
188 }; | 197 }; |
189 | 198 |
190 PresentationFrame::PresentationFrame( | 199 PresentationFrame::PresentationFrame( |
191 const RenderFrameHostId& render_frame_host_id, | 200 const RenderFrameHostId& render_frame_host_id, |
192 content::WebContents* web_contents, | 201 content::WebContents* web_contents, |
193 MediaRouter* router) | 202 MediaRouter* router) |
194 : render_frame_host_id_(render_frame_host_id), | 203 : render_frame_host_id_(render_frame_host_id), |
195 web_contents_(web_contents), | 204 web_contents_(web_contents), |
196 router_(router) { | 205 router_(router) { |
197 DCHECK(web_contents_); | 206 DCHECK(web_contents_); |
198 DCHECK(router_); | 207 DCHECK(router_); |
199 } | 208 } |
200 | 209 |
201 PresentationFrame::~PresentationFrame() { | 210 PresentationFrame::~PresentationFrame() { |
202 } | 211 } |
203 | 212 |
204 void PresentationFrame::OnPresentationSessionStarted( | 213 void PresentationFrame::OnPresentationSessionStarted( |
205 const content::PresentationSessionInfo& session, | 214 const content::PresentationSessionInfo& session, |
206 const MediaRoute& route) { | 215 const MediaRoute& route) { |
207 presentation_id_to_route_id_[session.presentation_id] = | 216 presentation_id_to_route_.insert( |
208 route.media_route_id(); | 217 std::make_pair(session.presentation_id, route)); |
209 } | 218 } |
210 | 219 |
211 const MediaRoute::Id PresentationFrame::GetRouteId( | 220 const MediaRoute::Id PresentationFrame::GetRouteId( |
212 const std::string& presentation_id) const { | 221 const std::string& presentation_id) const { |
213 auto it = presentation_id_to_route_id_.find(presentation_id); | 222 auto it = presentation_id_to_route_.find(presentation_id); |
214 return it != presentation_id_to_route_id_.end() ? it->second : ""; | 223 return it != presentation_id_to_route_.end() ? it->second.media_route_id() |
| 224 : ""; |
215 } | 225 } |
216 | 226 |
217 bool PresentationFrame::SetScreenAvailabilityListener( | 227 bool PresentationFrame::SetScreenAvailabilityListener( |
218 content::PresentationScreenAvailabilityListener* listener) { | 228 content::PresentationScreenAvailabilityListener* listener) { |
219 MediaSource source(GetMediaSourceFromListener(listener)); | 229 MediaSource source(GetMediaSourceFromListener(listener)); |
220 auto& sinks_observer = url_to_sinks_observer_[source.id()]; | 230 auto& sinks_observer = url_to_sinks_observer_[source.id()]; |
221 if (sinks_observer && sinks_observer->listener() == listener) | 231 if (sinks_observer && sinks_observer->listener() == listener) |
222 return false; | 232 return false; |
223 | 233 |
224 sinks_observer.reset(new PresentationMediaSinksObserver( | 234 sinks_observer.reset(new PresentationMediaSinksObserver( |
(...skipping 20 matching lines...) Expand all Loading... |
245 } | 255 } |
246 return false; | 256 return false; |
247 } | 257 } |
248 | 258 |
249 bool PresentationFrame::HasScreenAvailabilityListenerForTest( | 259 bool PresentationFrame::HasScreenAvailabilityListenerForTest( |
250 const MediaSource::Id& source_id) const { | 260 const MediaSource::Id& source_id) const { |
251 return url_to_sinks_observer_.find(source_id) != url_to_sinks_observer_.end(); | 261 return url_to_sinks_observer_.find(source_id) != url_to_sinks_observer_.end(); |
252 } | 262 } |
253 | 263 |
254 void PresentationFrame::Reset() { | 264 void PresentationFrame::Reset() { |
255 for (const auto& pid_route_id : presentation_id_to_route_id_) | 265 auto offscreen_presentation_manager = |
256 router_->DetachRoute(pid_route_id.second); | 266 OffscreenPresentationManagerFactory::GetOrCreateForWebContents( |
| 267 web_contents_); |
257 | 268 |
258 presentation_id_to_route_id_.clear(); | 269 for (const auto& pid_route : presentation_id_to_route_) { |
| 270 if (IsOffscreenPresentation(pid_route.first)) { |
| 271 offscreen_presentation_manager->UnregisterOffscreenPresentationController( |
| 272 pid_route.first, render_frame_host_id_); |
| 273 } |
| 274 router_->DetachRoute(pid_route.second.media_route_id()); |
| 275 } |
| 276 |
| 277 presentation_id_to_route_.clear(); |
259 url_to_sinks_observer_.clear(); | 278 url_to_sinks_observer_.clear(); |
260 connection_state_subscriptions_.clear(); | 279 connection_state_subscriptions_.clear(); |
261 session_messages_observers_.clear(); | 280 session_messages_observers_.clear(); |
| 281 browser_connection_proxies_.clear(); |
262 } | 282 } |
263 | 283 |
264 void PresentationFrame::RemoveConnection(const std::string& presentation_id, | 284 void PresentationFrame::RemoveConnection(const std::string& presentation_id, |
265 const MediaRoute::Id& route_id) { | 285 const MediaRoute::Id& route_id) { |
266 // Remove the presentation id mapping so a later call to Reset is a no-op. | 286 // Remove the presentation id mapping so a later call to Reset is a no-op. |
267 presentation_id_to_route_id_.erase(presentation_id); | 287 presentation_id_to_route_.erase(presentation_id); |
268 | 288 |
269 // We no longer need to observe route messages. | 289 // We no longer need to observe route messages. |
270 session_messages_observers_.erase(route_id); | 290 session_messages_observers_.erase(route_id); |
271 | 291 |
| 292 browser_connection_proxies_.erase(route_id); |
272 // We keep the PresentationConnectionStateChangedCallback registered with MR | 293 // We keep the PresentationConnectionStateChangedCallback registered with MR |
273 // so the MRP can tell us when terminate() completed. | 294 // so the MRP can tell us when terminate() completed. |
274 } | 295 } |
275 | 296 |
276 void PresentationFrame::ListenForConnectionStateChange( | 297 void PresentationFrame::ListenForConnectionStateChange( |
277 const content::PresentationSessionInfo& connection, | 298 const content::PresentationSessionInfo& connection, |
278 const content::PresentationConnectionStateChangedCallback& | 299 const content::PresentationConnectionStateChangedCallback& |
279 state_changed_cb) { | 300 state_changed_cb) { |
280 auto it = presentation_id_to_route_id_.find(connection.presentation_id); | 301 auto it = presentation_id_to_route_.find(connection.presentation_id); |
281 if (it == presentation_id_to_route_id_.end()) { | 302 if (it == presentation_id_to_route_.end()) { |
282 DLOG(ERROR) << __func__ << "route id not found for presentation: " | 303 DLOG(ERROR) << __func__ << "route id not found for presentation: " |
283 << connection.presentation_id; | 304 << connection.presentation_id; |
284 return; | 305 return; |
285 } | 306 } |
286 | 307 |
287 const MediaRoute::Id& route_id = it->second; | 308 const MediaRoute::Id& route_id = it->second.media_route_id(); |
288 if (connection_state_subscriptions_.find(route_id) != | 309 if (connection_state_subscriptions_.find(route_id) != |
289 connection_state_subscriptions_.end()) { | 310 connection_state_subscriptions_.end()) { |
290 DLOG(ERROR) << __func__ | 311 DLOG(ERROR) << __func__ |
291 << "Already listening connection state change for route: " | 312 << "Already listening connection state change for route: " |
292 << route_id; | 313 << route_id; |
293 return; | 314 return; |
294 } | 315 } |
295 | 316 |
296 connection_state_subscriptions_.insert(std::make_pair( | 317 connection_state_subscriptions_.insert(std::make_pair( |
297 route_id, router_->AddPresentationConnectionStateChangedCallback( | 318 route_id, router_->AddPresentationConnectionStateChangedCallback( |
298 it->second, state_changed_cb))); | 319 route_id, state_changed_cb))); |
299 } | 320 } |
300 | 321 |
301 void PresentationFrame::ListenForSessionMessages( | 322 void PresentationFrame::ListenForSessionMessages( |
302 const content::PresentationSessionInfo& session, | 323 const content::PresentationSessionInfo& session, |
303 const content::PresentationConnectionMessageCallback& message_cb) { | 324 const content::PresentationConnectionMessageCallback& message_cb) { |
304 auto it = presentation_id_to_route_id_.find(session.presentation_id); | 325 auto it = presentation_id_to_route_.find(session.presentation_id); |
305 if (it == presentation_id_to_route_id_.end()) { | 326 if (it == presentation_id_to_route_.end()) { |
306 DVLOG(2) << "ListenForSessionMessages: no route for " | 327 DVLOG(2) << "ListenForSessionMessages: no route for " |
307 << session.presentation_id; | 328 << session.presentation_id; |
308 return; | 329 return; |
309 } | 330 } |
310 | 331 |
311 const MediaRoute::Id& route_id = it->second; | 332 if (it->second.is_offscreen_presentation()) { |
| 333 DVLOG(2) << "ListenForSessionMessages: do not listen for offscreen " |
| 334 << "presentation [id]: " << session.presentation_id; |
| 335 return; |
| 336 } |
| 337 |
| 338 const MediaRoute::Id& route_id = it->second.media_route_id(); |
312 if (session_messages_observers_.find(route_id) != | 339 if (session_messages_observers_.find(route_id) != |
313 session_messages_observers_.end()) { | 340 session_messages_observers_.end()) { |
314 DLOG(ERROR) << __func__ | 341 DLOG(ERROR) << __func__ |
315 << "Already listening for session messages for route: " | 342 << "Already listening for session messages for route: " |
316 << route_id; | 343 << route_id; |
317 return; | 344 return; |
318 } | 345 } |
319 | 346 |
320 session_messages_observers_.insert(std::make_pair( | 347 session_messages_observers_.insert(std::make_pair( |
321 route_id, base::MakeUnique<PresentationSessionMessagesObserver>( | 348 route_id, base::MakeUnique<PresentationSessionMessagesObserver>( |
322 router_, it->second, message_cb))); | 349 router_, route_id, message_cb))); |
323 } | 350 } |
324 | 351 |
325 MediaSource PresentationFrame::GetMediaSourceFromListener( | 352 MediaSource PresentationFrame::GetMediaSourceFromListener( |
326 content::PresentationScreenAvailabilityListener* listener) const { | 353 content::PresentationScreenAvailabilityListener* listener) const { |
327 // If the default presentation URL is empty then fall back to tab mirroring. | 354 // If the default presentation URL is empty then fall back to tab mirroring. |
328 return listener->GetAvailabilityUrl().is_empty() | 355 return listener->GetAvailabilityUrl().is_empty() |
329 ? MediaSourceForTab(SessionTabHelper::IdForTab(web_contents_)) | 356 ? MediaSourceForTab(SessionTabHelper::IdForTab(web_contents_)) |
330 : MediaSourceForPresentationUrl(listener->GetAvailabilityUrl()); | 357 : MediaSourceForPresentationUrl(listener->GetAvailabilityUrl()); |
331 } | 358 } |
332 | 359 |
| 360 bool PresentationFrame::IsOffscreenPresentation( |
| 361 const std::string& presentation_id) const { |
| 362 const auto it = presentation_id_to_route_.find(presentation_id); |
| 363 if (it == presentation_id_to_route_.end()) { |
| 364 DLOG(WARNING) << "No route for [presentation_id]: " << presentation_id; |
| 365 return false; |
| 366 } |
| 367 |
| 368 return it->second.is_offscreen_presentation(); |
| 369 } |
| 370 |
| 371 void PresentationFrame::ConnectToPresentation( |
| 372 const content::PresentationSessionInfo& session, |
| 373 content::PresentationConnectionPtr controller_connection_ptr, |
| 374 content::PresentationConnectionRequest receiver_connection_request) { |
| 375 const auto pid_route_it = |
| 376 presentation_id_to_route_.find(session.presentation_id); |
| 377 |
| 378 if (pid_route_it == presentation_id_to_route_.end()) { |
| 379 DLOG(WARNING) << "No route for [presentation_id]: " |
| 380 << session.presentation_id; |
| 381 return; |
| 382 } |
| 383 |
| 384 if (IsOffscreenPresentation(session.presentation_id)) { |
| 385 auto* const offscreen_presentation_manager = |
| 386 OffscreenPresentationManagerFactory::GetOrCreateForWebContents( |
| 387 web_contents_); |
| 388 offscreen_presentation_manager->RegisterOffscreenPresentationController( |
| 389 session.presentation_id, session.presentation_url, |
| 390 render_frame_host_id_, std::move(controller_connection_ptr), |
| 391 std::move(receiver_connection_request)); |
| 392 } else { |
| 393 DVLOG(2) |
| 394 << "Creating BrowserPresentationConnectionProxy for [presentation_id]: " |
| 395 << session.presentation_id; |
| 396 MediaRoute::Id route_id = pid_route_it->second.media_route_id(); |
| 397 auto* proxy = new BrowserPresentationConnectionProxy( |
| 398 router_, route_id, std::move(receiver_connection_request), |
| 399 std::move(controller_connection_ptr)); |
| 400 |
| 401 browser_connection_proxies_.insert( |
| 402 std::make_pair(route_id, base::WrapUnique(proxy))); |
| 403 } |
| 404 } |
| 405 |
333 // Used by PresentationServiceDelegateImpl to manage PresentationFrames. | 406 // Used by PresentationServiceDelegateImpl to manage PresentationFrames. |
334 class PresentationFrameManager { | 407 class PresentationFrameManager { |
335 public: | 408 public: |
336 PresentationFrameManager(content::WebContents* web_contents, | 409 PresentationFrameManager(content::WebContents* web_contents, |
337 MediaRouter* router); | 410 MediaRouter* router); |
338 ~PresentationFrameManager(); | 411 ~PresentationFrameManager(); |
339 | 412 |
340 // Mirror corresponding APIs in PresentationServiceDelegateImpl. | 413 // Mirror corresponding APIs in PresentationServiceDelegateImpl. |
341 bool SetScreenAvailabilityListener( | 414 bool SetScreenAvailabilityListener( |
342 const RenderFrameHostId& render_frame_host_id, | 415 const RenderFrameHostId& render_frame_host_id, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 | 454 |
382 void OnPresentationSessionStarted( | 455 void OnPresentationSessionStarted( |
383 const RenderFrameHostId& render_frame_host_id, | 456 const RenderFrameHostId& render_frame_host_id, |
384 const content::PresentationSessionInfo& session, | 457 const content::PresentationSessionInfo& session, |
385 const MediaRoute& route); | 458 const MediaRoute& route); |
386 void OnDefaultPresentationSessionStarted( | 459 void OnDefaultPresentationSessionStarted( |
387 const PresentationRequest& request, | 460 const PresentationRequest& request, |
388 const content::PresentationSessionInfo& session, | 461 const content::PresentationSessionInfo& session, |
389 const MediaRoute& route); | 462 const MediaRoute& route); |
390 | 463 |
| 464 void ConnectToPresentation( |
| 465 const RenderFrameHostId& render_frame_host_id, |
| 466 const content::PresentationSessionInfo& session, |
| 467 content::PresentationConnectionPtr controller_connection_ptr, |
| 468 content::PresentationConnectionRequest receiver_connection_request); |
| 469 |
391 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, | 470 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, |
392 const std::string& presentation_id) const; | 471 const std::string& presentation_id) const; |
393 | 472 |
394 const PresentationRequest* default_presentation_request() const { | 473 const PresentationRequest* default_presentation_request() const { |
395 return default_presentation_request_.get(); | 474 return default_presentation_request_.get(); |
396 } | 475 } |
397 | 476 |
398 private: | 477 private: |
399 PresentationFrame* GetOrAddPresentationFrame( | 478 PresentationFrame* GetOrAddPresentationFrame( |
400 const RenderFrameHostId& render_frame_host_id); | 479 const RenderFrameHostId& render_frame_host_id); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 const content::PresentationSessionInfo& session, | 537 const content::PresentationSessionInfo& session, |
459 const MediaRoute& route) { | 538 const MediaRoute& route) { |
460 OnPresentationSessionStarted(request.render_frame_host_id(), session, route); | 539 OnPresentationSessionStarted(request.render_frame_host_id(), session, route); |
461 | 540 |
462 if (default_presentation_request_ && | 541 if (default_presentation_request_ && |
463 default_presentation_request_->Equals(request)) { | 542 default_presentation_request_->Equals(request)) { |
464 default_presentation_started_callback_.Run(session); | 543 default_presentation_started_callback_.Run(session); |
465 } | 544 } |
466 } | 545 } |
467 | 546 |
| 547 void PresentationFrameManager::ConnectToPresentation( |
| 548 const RenderFrameHostId& render_frame_host_id, |
| 549 const content::PresentationSessionInfo& session, |
| 550 content::PresentationConnectionPtr controller_connection_ptr, |
| 551 content::PresentationConnectionRequest receiver_connection_request) { |
| 552 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); |
| 553 presentation_frame->ConnectToPresentation( |
| 554 session, std::move(controller_connection_ptr), |
| 555 std::move(receiver_connection_request)); |
| 556 } |
| 557 |
468 const MediaRoute::Id PresentationFrameManager::GetRouteId( | 558 const MediaRoute::Id PresentationFrameManager::GetRouteId( |
469 const RenderFrameHostId& render_frame_host_id, | 559 const RenderFrameHostId& render_frame_host_id, |
470 const std::string& presentation_id) const { | 560 const std::string& presentation_id) const { |
471 const auto it = presentation_frames_.find(render_frame_host_id); | 561 const auto it = presentation_frames_.find(render_frame_host_id); |
472 return it != presentation_frames_.end() | 562 return it != presentation_frames_.end() |
473 ? it->second->GetRouteId(presentation_id) : MediaRoute::Id(); | 563 ? it->second->GetRouteId(presentation_id) : MediaRoute::Id(); |
474 } | 564 } |
475 | 565 |
476 bool PresentationFrameManager::SetScreenAvailabilityListener( | 566 bool PresentationFrameManager::SetScreenAvailabilityListener( |
477 const RenderFrameHostId& render_frame_host_id, | 567 const RenderFrameHostId& render_frame_host_id, |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 int render_process_id, | 975 int render_process_id, |
886 int render_frame_id, | 976 int render_frame_id, |
887 const content::PresentationSessionInfo& connection, | 977 const content::PresentationSessionInfo& connection, |
888 const content::PresentationConnectionStateChangedCallback& | 978 const content::PresentationConnectionStateChangedCallback& |
889 state_changed_cb) { | 979 state_changed_cb) { |
890 frame_manager_->ListenForConnectionStateChange( | 980 frame_manager_->ListenForConnectionStateChange( |
891 RenderFrameHostId(render_process_id, render_frame_id), connection, | 981 RenderFrameHostId(render_process_id, render_frame_id), connection, |
892 state_changed_cb); | 982 state_changed_cb); |
893 } | 983 } |
894 | 984 |
895 void PresentationServiceDelegateImpl::ConnectToOffscreenPresentation( | 985 void PresentationServiceDelegateImpl::ConnectToPresentation( |
896 int render_process_id, | 986 int render_process_id, |
897 int render_frame_id, | 987 int render_frame_id, |
898 const content::PresentationSessionInfo& session, | 988 const content::PresentationSessionInfo& session, |
899 content::PresentationConnectionPtr controller_connection_ptr, | 989 content::PresentationConnectionPtr controller_connection_ptr, |
900 content::PresentationConnectionRequest receiver_connection_request) { | 990 content::PresentationConnectionRequest receiver_connection_request) { |
901 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 991 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
902 auto* const offscreen_presentation_manager = | 992 frame_manager_->ConnectToPresentation(render_frame_host_id, session, |
903 OffscreenPresentationManagerFactory::GetOrCreateForWebContents( | 993 std::move(controller_connection_ptr), |
904 web_contents_); | 994 std::move(receiver_connection_request)); |
905 offscreen_presentation_manager->RegisterOffscreenPresentationController( | |
906 session.presentation_id, session.presentation_url, render_frame_host_id, | |
907 std::move(controller_connection_ptr), | |
908 std::move(receiver_connection_request)); | |
909 } | 995 } |
910 | 996 |
911 void PresentationServiceDelegateImpl::OnRouteResponse( | 997 void PresentationServiceDelegateImpl::OnRouteResponse( |
912 const PresentationRequest& presentation_request, | 998 const PresentationRequest& presentation_request, |
913 const RouteRequestResult& result) { | 999 const RouteRequestResult& result) { |
914 if (!result.route() || | 1000 if (!result.route() || |
915 !base::ContainsValue(presentation_request.presentation_urls(), | 1001 !base::ContainsValue(presentation_request.presentation_urls(), |
916 result.presentation_url())) { | 1002 result.presentation_url())) { |
917 return; | 1003 return; |
918 } | 1004 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 const base::ListValue* origins = | 1055 const base::ListValue* origins = |
970 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) | 1056 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) |
971 ->GetPrefs() | 1057 ->GetPrefs() |
972 ->GetList(prefs::kMediaRouterTabMirroringSources); | 1058 ->GetList(prefs::kMediaRouterTabMirroringSources); |
973 return origins && | 1059 return origins && |
974 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); | 1060 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); |
975 } | 1061 } |
976 #endif // !defined(OS_ANDROID) | 1062 #endif // !defined(OS_ANDROID) |
977 | 1063 |
978 } // namespace media_router | 1064 } // namespace media_router |
OLD | NEW |