Chromium Code Reviews| 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/ui/webui/media_router/media_router_ui.h" | 5 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <unordered_map> | 9 #include <unordered_map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 icu::Collator::createInstance(icu::Locale(locale.c_str()), error)); | 269 icu::Collator::createInstance(icu::Locale(locale.c_str()), error)); |
| 270 if (U_FAILURE(error)) { | 270 if (U_FAILURE(error)) { |
| 271 DLOG(ERROR) << "Failed to create collator for locale " << locale; | 271 DLOG(ERROR) << "Failed to create collator for locale " << locale; |
| 272 collator_.reset(); | 272 collator_.reset(); |
| 273 } | 273 } |
| 274 | 274 |
| 275 query_result_manager_.reset(new QueryResultManager(router_)); | 275 query_result_manager_.reset(new QueryResultManager(router_)); |
| 276 query_result_manager_->AddObserver(this); | 276 query_result_manager_->AddObserver(this); |
| 277 | 277 |
| 278 // Use a placeholder URL as origin for mirroring. | 278 // Use a placeholder URL as origin for mirroring. |
| 279 GURL origin(chrome::kChromeUIMediaRouterURL); | 279 url::Origin origin((GURL(chrome::kChromeUIMediaRouterURL))); |
|
mark a. foltz
2017/01/17 21:30:45
Extra ()
steimel
2017/01/18 01:52:35
The extra () are needed or else I get a compile er
| |
| 280 | 280 |
| 281 // Desktop mirror mode is always available. | 281 // Desktop mirror mode is always available. |
| 282 query_result_manager_->SetSourcesForCastMode( | 282 query_result_manager_->SetSourcesForCastMode( |
| 283 MediaCastMode::DESKTOP_MIRROR, {MediaSourceForDesktop()}, origin); | 283 MediaCastMode::DESKTOP_MIRROR, {MediaSourceForDesktop()}, origin); |
| 284 initiator_ = initiator; | 284 initiator_ = initiator; |
| 285 SessionID::id_type tab_id = SessionTabHelper::IdForTab(initiator); | 285 SessionID::id_type tab_id = SessionTabHelper::IdForTab(initiator); |
| 286 if (tab_id != -1) { | 286 if (tab_id != -1) { |
| 287 MediaSource mirroring_source(MediaSourceForTab(tab_id)); | 287 MediaSource mirroring_source(MediaSourceForTab(tab_id)); |
| 288 query_result_manager_->SetSourcesForCastMode(MediaCastMode::TAB_MIRROR, | 288 query_result_manager_->SetSourcesForCastMode(MediaCastMode::TAB_MIRROR, |
| 289 {mirroring_source}, origin); | 289 {mirroring_source}, origin); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 311 create_session_request_->presentation_request()); | 311 create_session_request_->presentation_request()); |
| 312 } | 312 } |
| 313 } | 313 } |
| 314 | 314 |
| 315 void MediaRouterUI::OnDefaultPresentationChanged( | 315 void MediaRouterUI::OnDefaultPresentationChanged( |
| 316 const PresentationRequest& presentation_request) { | 316 const PresentationRequest& presentation_request) { |
| 317 std::vector<MediaSource> sources = presentation_request.GetMediaSources(); | 317 std::vector<MediaSource> sources = presentation_request.GetMediaSources(); |
| 318 presentation_request_.reset(new PresentationRequest(presentation_request)); | 318 presentation_request_.reset(new PresentationRequest(presentation_request)); |
| 319 query_result_manager_->SetSourcesForCastMode( | 319 query_result_manager_->SetSourcesForCastMode( |
| 320 MediaCastMode::DEFAULT, sources, | 320 MediaCastMode::DEFAULT, sources, |
| 321 presentation_request_->frame_url().GetOrigin()); | 321 url::Origin(presentation_request_->frame_url().GetOrigin())); |
| 322 // Register for MediaRoute updates. NOTE(mfoltz): If there are multiple | 322 // Register for MediaRoute updates. NOTE(mfoltz): If there are multiple |
| 323 // sources that can be connected to via the dialog, this will break. We will | 323 // sources that can be connected to via the dialog, this will break. We will |
| 324 // need to observe multiple sources (keyed by sinks) in that case. As this is | 324 // need to observe multiple sources (keyed by sinks) in that case. As this is |
| 325 // Cast-specific for the forseeable future, it may be simpler to plumb a new | 325 // Cast-specific for the forseeable future, it may be simpler to plumb a new |
| 326 // observer API for this case. | 326 // observer API for this case. |
| 327 const MediaSource source_for_route_observer = | 327 const MediaSource source_for_route_observer = |
| 328 GetSourceForRouteObserver(sources); | 328 GetSourceForRouteObserver(sources); |
| 329 routes_observer_.reset(new UIMediaRoutesObserver( | 329 routes_observer_.reset(new UIMediaRoutesObserver( |
| 330 router_, source_for_route_observer.id(), | 330 router_, source_for_route_observer.id(), |
| 331 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this)))); | 331 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this)))); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 ui_initialized_ = true; | 383 ui_initialized_ = true; |
| 384 | 384 |
| 385 // Register for Issue updates. | 385 // Register for Issue updates. |
| 386 issues_observer_.reset(new UIIssuesObserver(router_, this)); | 386 issues_observer_.reset(new UIIssuesObserver(router_, this)); |
| 387 issues_observer_->Init(); | 387 issues_observer_->Init(); |
| 388 } | 388 } |
| 389 | 389 |
| 390 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, | 390 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, |
| 391 MediaCastMode cast_mode) { | 391 MediaCastMode cast_mode) { |
| 392 MediaSource::Id source_id; | 392 MediaSource::Id source_id; |
| 393 GURL origin; | 393 url::Origin origin; |
| 394 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 394 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 395 base::TimeDelta timeout; | 395 base::TimeDelta timeout; |
| 396 bool incognito; | 396 bool incognito; |
| 397 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin, | 397 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin, |
| 398 &route_response_callbacks, &timeout, &incognito)) { | 398 &route_response_callbacks, &timeout, &incognito)) { |
| 399 SendIssueForUnableToCast(cast_mode); | 399 SendIssueForUnableToCast(cast_mode); |
| 400 return false; | 400 return false; |
| 401 } | 401 } |
| 402 router_->CreateRoute(source_id, sink_id, origin, initiator_, | 402 router_->CreateRoute(source_id, sink_id, origin, initiator_, |
| 403 route_response_callbacks, timeout, incognito); | 403 route_response_callbacks, timeout, incognito); |
| 404 return true; | 404 return true; |
| 405 } | 405 } |
| 406 | 406 |
| 407 bool MediaRouterUI::SetRouteParameters( | 407 bool MediaRouterUI::SetRouteParameters( |
| 408 const MediaSink::Id& sink_id, | 408 const MediaSink::Id& sink_id, |
| 409 MediaCastMode cast_mode, | 409 MediaCastMode cast_mode, |
| 410 MediaSource::Id* source_id, | 410 MediaSource::Id* source_id, |
| 411 GURL* origin, | 411 url::Origin* origin, |
| 412 std::vector<MediaRouteResponseCallback>* route_response_callbacks, | 412 std::vector<MediaRouteResponseCallback>* route_response_callbacks, |
| 413 base::TimeDelta* timeout, | 413 base::TimeDelta* timeout, |
| 414 bool* incognito) { | 414 bool* incognito) { |
| 415 DCHECK(query_result_manager_.get()); | 415 DCHECK(query_result_manager_.get()); |
| 416 DCHECK(initiator_); | 416 DCHECK(initiator_); |
| 417 | 417 |
| 418 // Note that there is a rarely-encountered bug, where the MediaCastMode to | 418 // Note that there is a rarely-encountered bug, where the MediaCastMode to |
| 419 // MediaSource mapping could have been updated, between when the user clicked | 419 // MediaSource mapping could have been updated, between when the user clicked |
| 420 // on the UI to start a create route request, and when this function is | 420 // on the UI to start a create route request, and when this function is |
| 421 // called. However, since the user does not have visibility into the | 421 // called. However, since the user does not have visibility into the |
| 422 // MediaSource, and that it occurs very rarely in practice, we leave it as-is | 422 // MediaSource, and that it occurs very rarely in practice, we leave it as-is |
| 423 // for now. | 423 // for now. |
| 424 std::unique_ptr<MediaSource> source = | 424 std::unique_ptr<MediaSource> source = |
| 425 query_result_manager_->GetSourceForCastModeAndSink(cast_mode, sink_id); | 425 query_result_manager_->GetSourceForCastModeAndSink(cast_mode, sink_id); |
| 426 if (!source) { | 426 if (!source) { |
| 427 LOG(ERROR) << "No corresponding MediaSource for cast mode " | 427 LOG(ERROR) << "No corresponding MediaSource for cast mode " |
| 428 << static_cast<int>(cast_mode) << " and sink " << sink_id; | 428 << static_cast<int>(cast_mode) << " and sink " << sink_id; |
| 429 return false; | 429 return false; |
| 430 } | 430 } |
| 431 *source_id = source->id(); | 431 *source_id = source->id(); |
| 432 | 432 |
| 433 bool for_default_source = cast_mode == MediaCastMode::DEFAULT; | 433 bool for_default_source = cast_mode == MediaCastMode::DEFAULT; |
| 434 if (for_default_source && !presentation_request_) { | 434 if (for_default_source && !presentation_request_) { |
| 435 DLOG(ERROR) << "Requested to create a route for presentation, but " | 435 DLOG(ERROR) << "Requested to create a route for presentation, but " |
| 436 << "presentation request is missing."; | 436 << "presentation request is missing."; |
| 437 return false; | 437 return false; |
| 438 } | 438 } |
| 439 | 439 |
| 440 current_route_request_id_ = ++route_request_counter_; | 440 current_route_request_id_ = ++route_request_counter_; |
| 441 *origin = for_default_source ? presentation_request_->frame_url().GetOrigin() | 441 *origin = for_default_source |
| 442 : GURL(chrome::kChromeUIMediaRouterURL); | 442 ? url::Origin(presentation_request_->frame_url().GetOrigin()) |
| 443 : url::Origin(GURL(chrome::kChromeUIMediaRouterURL)); | |
| 443 DVLOG(1) << "DoCreateRoute: origin: " << *origin; | 444 DVLOG(1) << "DoCreateRoute: origin: " << *origin; |
| 444 | 445 |
| 445 // There are 3 cases. In cases (1) and (3) the MediaRouterUI will need to be | 446 // There are 3 cases. In cases (1) and (3) the MediaRouterUI will need to be |
| 446 // notified. In case (2) the dialog will be closed. | 447 // notified. In case (2) the dialog will be closed. |
| 447 // (1) Non-presentation route request (e.g., mirroring). No additional | 448 // (1) Non-presentation route request (e.g., mirroring). No additional |
| 448 // notification necessary. | 449 // notification necessary. |
| 449 // (2) Presentation route request for a Presentation API startSession call. | 450 // (2) Presentation route request for a Presentation API startSession call. |
| 450 // The startSession (CreatePresentationConnectionRequest) will need to be | 451 // The startSession (CreatePresentationConnectionRequest) will need to be |
| 451 // answered with the route response. | 452 // answered with the route response. |
| 452 // (3) Browser-initiated presentation route request. If successful, | 453 // (3) Browser-initiated presentation route request. If successful, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 478 | 479 |
| 479 *timeout = GetRouteRequestTimeout(cast_mode); | 480 *timeout = GetRouteRequestTimeout(cast_mode); |
| 480 *incognito = Profile::FromWebUI(web_ui())->IsOffTheRecord(); | 481 *incognito = Profile::FromWebUI(web_ui())->IsOffTheRecord(); |
| 481 | 482 |
| 482 return true; | 483 return true; |
| 483 } | 484 } |
| 484 | 485 |
| 485 bool MediaRouterUI::ConnectRoute(const MediaSink::Id& sink_id, | 486 bool MediaRouterUI::ConnectRoute(const MediaSink::Id& sink_id, |
| 486 const MediaRoute::Id& route_id) { | 487 const MediaRoute::Id& route_id) { |
| 487 MediaSource::Id source_id; | 488 MediaSource::Id source_id; |
| 488 GURL origin; | 489 url::Origin origin; |
| 489 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 490 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 490 base::TimeDelta timeout; | 491 base::TimeDelta timeout; |
| 491 bool incognito; | 492 bool incognito; |
| 492 if (!SetRouteParameters(sink_id, MediaCastMode::DEFAULT, &source_id, &origin, | 493 if (!SetRouteParameters(sink_id, MediaCastMode::DEFAULT, &source_id, &origin, |
| 493 &route_response_callbacks, &timeout, &incognito)) { | 494 &route_response_callbacks, &timeout, &incognito)) { |
| 494 SendIssueForUnableToCast(MediaCastMode::DEFAULT); | 495 SendIssueForUnableToCast(MediaCastMode::DEFAULT); |
| 495 return false; | 496 return false; |
| 496 } | 497 } |
| 497 router_->ConnectRouteByRouteId(source_id, route_id, origin, initiator_, | 498 router_->ConnectRouteByRouteId(source_id, route_id, origin, initiator_, |
| 498 route_response_callbacks, timeout, incognito); | 499 route_response_callbacks, timeout, incognito); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 Close(); | 645 Close(); |
| 645 } | 646 } |
| 646 | 647 |
| 647 void MediaRouterUI::OnSearchSinkResponseReceived( | 648 void MediaRouterUI::OnSearchSinkResponseReceived( |
| 648 MediaCastMode cast_mode, | 649 MediaCastMode cast_mode, |
| 649 const MediaSink::Id& found_sink_id) { | 650 const MediaSink::Id& found_sink_id) { |
| 650 DVLOG(1) << "OnSearchSinkResponseReceived"; | 651 DVLOG(1) << "OnSearchSinkResponseReceived"; |
| 651 handler_->ReturnSearchResult(found_sink_id); | 652 handler_->ReturnSearchResult(found_sink_id); |
| 652 | 653 |
| 653 MediaSource::Id source_id; | 654 MediaSource::Id source_id; |
| 654 GURL origin; | 655 url::Origin origin; |
| 655 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 656 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 656 base::TimeDelta timeout; | 657 base::TimeDelta timeout; |
| 657 bool incognito; | 658 bool incognito; |
| 658 if (!SetRouteParameters(found_sink_id, cast_mode, &source_id, &origin, | 659 if (!SetRouteParameters(found_sink_id, cast_mode, &source_id, &origin, |
| 659 &route_response_callbacks, &timeout, &incognito)) { | 660 &route_response_callbacks, &timeout, &incognito)) { |
| 660 SendIssueForUnableToCast(cast_mode); | 661 SendIssueForUnableToCast(cast_mode); |
| 661 return; | 662 return; |
| 662 } | 663 } |
| 663 router_->CreateRoute(source_id, found_sink_id, origin, initiator_, | 664 router_->CreateRoute(source_id, found_sink_id, origin, initiator_, |
| 664 route_response_callbacks, timeout, incognito); | 665 route_response_callbacks, timeout, incognito); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 760 } | 761 } |
| 761 | 762 |
| 762 std::string MediaRouterUI::GetSerializedInitiatorOrigin() const { | 763 std::string MediaRouterUI::GetSerializedInitiatorOrigin() const { |
| 763 url::Origin origin = initiator_ | 764 url::Origin origin = initiator_ |
| 764 ? url::Origin(initiator_->GetLastCommittedURL()) | 765 ? url::Origin(initiator_->GetLastCommittedURL()) |
| 765 : url::Origin(); | 766 : url::Origin(); |
| 766 return origin.Serialize(); | 767 return origin.Serialize(); |
| 767 } | 768 } |
| 768 | 769 |
| 769 } // namespace media_router | 770 } // namespace media_router |
| OLD | NEW |