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))); |
|
dcheng
2017/01/26 04:16:32
Nit: Use {} here as well to prevent the most vexin
steimel
2017/01/27 00:28:59
Done.
| |
| 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 20 matching lines...) Expand all Loading... | |
| 310 OnDefaultPresentationChanged( | 310 OnDefaultPresentationChanged( |
| 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, presentation_request_->frame_origin()); |
| 321 presentation_request_->frame_url().GetOrigin()); | |
| 322 // Register for MediaRoute updates. NOTE(mfoltz): If there are multiple | 321 // 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 | 322 // 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 | 323 // 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 | 324 // Cast-specific for the forseeable future, it may be simpler to plumb a new |
| 326 // observer API for this case. | 325 // observer API for this case. |
| 327 const MediaSource source_for_route_observer = | 326 const MediaSource source_for_route_observer = |
| 328 GetSourceForRouteObserver(sources); | 327 GetSourceForRouteObserver(sources); |
| 329 routes_observer_.reset(new UIMediaRoutesObserver( | 328 routes_observer_.reset(new UIMediaRoutesObserver( |
| 330 router_, source_for_route_observer.id(), | 329 router_, source_for_route_observer.id(), |
| 331 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this)))); | 330 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this)))); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 ui_initialized_ = true; | 382 ui_initialized_ = true; |
| 384 | 383 |
| 385 // Register for Issue updates. | 384 // Register for Issue updates. |
| 386 issues_observer_.reset(new UIIssuesObserver(router_, this)); | 385 issues_observer_.reset(new UIIssuesObserver(router_, this)); |
| 387 issues_observer_->Init(); | 386 issues_observer_->Init(); |
| 388 } | 387 } |
| 389 | 388 |
| 390 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, | 389 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, |
| 391 MediaCastMode cast_mode) { | 390 MediaCastMode cast_mode) { |
| 392 MediaSource::Id source_id; | 391 MediaSource::Id source_id; |
| 393 GURL origin; | 392 url::Origin origin; |
| 394 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 393 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 395 base::TimeDelta timeout; | 394 base::TimeDelta timeout; |
| 396 bool incognito; | 395 bool incognito; |
| 397 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin, | 396 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin, |
| 398 &route_response_callbacks, &timeout, &incognito)) { | 397 &route_response_callbacks, &timeout, &incognito)) { |
| 399 SendIssueForUnableToCast(cast_mode); | 398 SendIssueForUnableToCast(cast_mode); |
| 400 return false; | 399 return false; |
| 401 } | 400 } |
| 402 router_->CreateRoute(source_id, sink_id, origin, initiator_, | 401 router_->CreateRoute(source_id, sink_id, origin, initiator_, |
| 403 route_response_callbacks, timeout, incognito); | 402 route_response_callbacks, timeout, incognito); |
| 404 return true; | 403 return true; |
| 405 } | 404 } |
| 406 | 405 |
| 407 bool MediaRouterUI::SetRouteParameters( | 406 bool MediaRouterUI::SetRouteParameters( |
| 408 const MediaSink::Id& sink_id, | 407 const MediaSink::Id& sink_id, |
| 409 MediaCastMode cast_mode, | 408 MediaCastMode cast_mode, |
| 410 MediaSource::Id* source_id, | 409 MediaSource::Id* source_id, |
| 411 GURL* origin, | 410 url::Origin* origin, |
| 412 std::vector<MediaRouteResponseCallback>* route_response_callbacks, | 411 std::vector<MediaRouteResponseCallback>* route_response_callbacks, |
| 413 base::TimeDelta* timeout, | 412 base::TimeDelta* timeout, |
| 414 bool* incognito) { | 413 bool* incognito) { |
| 415 DCHECK(query_result_manager_.get()); | 414 DCHECK(query_result_manager_.get()); |
| 416 DCHECK(initiator_); | 415 DCHECK(initiator_); |
| 417 | 416 |
| 418 // Note that there is a rarely-encountered bug, where the MediaCastMode to | 417 // Note that there is a rarely-encountered bug, where the MediaCastMode to |
| 419 // MediaSource mapping could have been updated, between when the user clicked | 418 // 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 | 419 // 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 | 420 // 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 | 421 // MediaSource, and that it occurs very rarely in practice, we leave it as-is |
| 423 // for now. | 422 // for now. |
| 424 std::unique_ptr<MediaSource> source = | 423 std::unique_ptr<MediaSource> source = |
| 425 query_result_manager_->GetSourceForCastModeAndSink(cast_mode, sink_id); | 424 query_result_manager_->GetSourceForCastModeAndSink(cast_mode, sink_id); |
| 426 if (!source) { | 425 if (!source) { |
| 427 LOG(ERROR) << "No corresponding MediaSource for cast mode " | 426 LOG(ERROR) << "No corresponding MediaSource for cast mode " |
| 428 << static_cast<int>(cast_mode) << " and sink " << sink_id; | 427 << static_cast<int>(cast_mode) << " and sink " << sink_id; |
| 429 return false; | 428 return false; |
| 430 } | 429 } |
| 431 *source_id = source->id(); | 430 *source_id = source->id(); |
| 432 | 431 |
| 433 bool for_default_source = cast_mode == MediaCastMode::DEFAULT; | 432 bool for_default_source = cast_mode == MediaCastMode::DEFAULT; |
| 434 if (for_default_source && !presentation_request_) { | 433 if (for_default_source && !presentation_request_) { |
| 435 DLOG(ERROR) << "Requested to create a route for presentation, but " | 434 DLOG(ERROR) << "Requested to create a route for presentation, but " |
| 436 << "presentation request is missing."; | 435 << "presentation request is missing."; |
| 437 return false; | 436 return false; |
| 438 } | 437 } |
| 439 | 438 |
| 440 current_route_request_id_ = ++route_request_counter_; | 439 current_route_request_id_ = ++route_request_counter_; |
| 441 *origin = for_default_source ? presentation_request_->frame_url().GetOrigin() | 440 *origin = for_default_source |
| 442 : GURL(chrome::kChromeUIMediaRouterURL); | 441 ? presentation_request_->frame_origin() |
| 442 : url::Origin(GURL(chrome::kChromeUIMediaRouterURL)); | |
| 443 DVLOG(1) << "DoCreateRoute: origin: " << *origin; | 443 DVLOG(1) << "DoCreateRoute: origin: " << *origin; |
| 444 | 444 |
| 445 // There are 3 cases. In cases (1) and (3) the MediaRouterUI will need to be | 445 // 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. | 446 // notified. In case (2) the dialog will be closed. |
| 447 // (1) Non-presentation route request (e.g., mirroring). No additional | 447 // (1) Non-presentation route request (e.g., mirroring). No additional |
| 448 // notification necessary. | 448 // notification necessary. |
| 449 // (2) Presentation route request for a Presentation API startSession call. | 449 // (2) Presentation route request for a Presentation API startSession call. |
| 450 // The startSession (CreatePresentationConnectionRequest) will need to be | 450 // The startSession (CreatePresentationConnectionRequest) will need to be |
| 451 // answered with the route response. | 451 // answered with the route response. |
| 452 // (3) Browser-initiated presentation route request. If successful, | 452 // (3) Browser-initiated presentation route request. If successful, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 478 | 478 |
| 479 *timeout = GetRouteRequestTimeout(cast_mode); | 479 *timeout = GetRouteRequestTimeout(cast_mode); |
| 480 *incognito = Profile::FromWebUI(web_ui())->IsOffTheRecord(); | 480 *incognito = Profile::FromWebUI(web_ui())->IsOffTheRecord(); |
| 481 | 481 |
| 482 return true; | 482 return true; |
| 483 } | 483 } |
| 484 | 484 |
| 485 bool MediaRouterUI::ConnectRoute(const MediaSink::Id& sink_id, | 485 bool MediaRouterUI::ConnectRoute(const MediaSink::Id& sink_id, |
| 486 const MediaRoute::Id& route_id) { | 486 const MediaRoute::Id& route_id) { |
| 487 MediaSource::Id source_id; | 487 MediaSource::Id source_id; |
| 488 GURL origin; | 488 url::Origin origin; |
| 489 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 489 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 490 base::TimeDelta timeout; | 490 base::TimeDelta timeout; |
| 491 bool incognito; | 491 bool incognito; |
| 492 if (!SetRouteParameters(sink_id, MediaCastMode::DEFAULT, &source_id, &origin, | 492 if (!SetRouteParameters(sink_id, MediaCastMode::DEFAULT, &source_id, &origin, |
| 493 &route_response_callbacks, &timeout, &incognito)) { | 493 &route_response_callbacks, &timeout, &incognito)) { |
| 494 SendIssueForUnableToCast(MediaCastMode::DEFAULT); | 494 SendIssueForUnableToCast(MediaCastMode::DEFAULT); |
| 495 return false; | 495 return false; |
| 496 } | 496 } |
| 497 router_->ConnectRouteByRouteId(source_id, route_id, origin, initiator_, | 497 router_->ConnectRouteByRouteId(source_id, route_id, origin, initiator_, |
| 498 route_response_callbacks, timeout, incognito); | 498 route_response_callbacks, timeout, incognito); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 Close(); | 644 Close(); |
| 645 } | 645 } |
| 646 | 646 |
| 647 void MediaRouterUI::OnSearchSinkResponseReceived( | 647 void MediaRouterUI::OnSearchSinkResponseReceived( |
| 648 MediaCastMode cast_mode, | 648 MediaCastMode cast_mode, |
| 649 const MediaSink::Id& found_sink_id) { | 649 const MediaSink::Id& found_sink_id) { |
| 650 DVLOG(1) << "OnSearchSinkResponseReceived"; | 650 DVLOG(1) << "OnSearchSinkResponseReceived"; |
| 651 handler_->ReturnSearchResult(found_sink_id); | 651 handler_->ReturnSearchResult(found_sink_id); |
| 652 | 652 |
| 653 MediaSource::Id source_id; | 653 MediaSource::Id source_id; |
| 654 GURL origin; | 654 url::Origin origin; |
| 655 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 655 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 656 base::TimeDelta timeout; | 656 base::TimeDelta timeout; |
| 657 bool incognito; | 657 bool incognito; |
| 658 if (!SetRouteParameters(found_sink_id, cast_mode, &source_id, &origin, | 658 if (!SetRouteParameters(found_sink_id, cast_mode, &source_id, &origin, |
| 659 &route_response_callbacks, &timeout, &incognito)) { | 659 &route_response_callbacks, &timeout, &incognito)) { |
| 660 SendIssueForUnableToCast(cast_mode); | 660 SendIssueForUnableToCast(cast_mode); |
| 661 return; | 661 return; |
| 662 } | 662 } |
| 663 router_->CreateRoute(source_id, found_sink_id, origin, initiator_, | 663 router_->CreateRoute(source_id, found_sink_id, origin, initiator_, |
| 664 route_response_callbacks, timeout, incognito); | 664 route_response_callbacks, timeout, incognito); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 699 (cast_mode == MediaCastMode::DESKTOP_MIRROR) | 699 (cast_mode == MediaCastMode::DESKTOP_MIRROR) |
| 700 ? l10n_util::GetStringUTF8( | 700 ? l10n_util::GetStringUTF8( |
| 701 IDS_MEDIA_ROUTER_ISSUE_UNABLE_TO_CAST_DESKTOP) | 701 IDS_MEDIA_ROUTER_ISSUE_UNABLE_TO_CAST_DESKTOP) |
| 702 : l10n_util::GetStringUTF8( | 702 : l10n_util::GetStringUTF8( |
| 703 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); | 703 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); |
| 704 AddIssue(IssueInfo(issue_title, IssueInfo::Action::DISMISS, | 704 AddIssue(IssueInfo(issue_title, IssueInfo::Action::DISMISS, |
| 705 IssueInfo::Severity::WARNING)); | 705 IssueInfo::Severity::WARNING)); |
| 706 } | 706 } |
| 707 | 707 |
| 708 GURL MediaRouterUI::GetFrameURL() const { | 708 GURL MediaRouterUI::GetFrameURL() const { |
| 709 return presentation_request_ ? presentation_request_->frame_url() : GURL(); | 709 return presentation_request_ ? presentation_request_->frame_origin().GetURL() |
| 710 : GURL(); | |
| 710 } | 711 } |
| 711 | 712 |
| 712 std::string MediaRouterUI::GetPresentationRequestSourceName() const { | 713 std::string MediaRouterUI::GetPresentationRequestSourceName() const { |
| 713 GURL gurl = GetFrameURL(); | 714 GURL gurl = GetFrameURL(); |
| 714 return gurl.SchemeIs(extensions::kExtensionScheme) | 715 return gurl.SchemeIs(extensions::kExtensionScheme) |
| 715 ? GetExtensionName(gurl, extensions::ExtensionRegistry::Get( | 716 ? GetExtensionName(gurl, extensions::ExtensionRegistry::Get( |
| 716 Profile::FromWebUI(web_ui()))) | 717 Profile::FromWebUI(web_ui()))) |
| 717 : GetHostFromURL(gurl); | 718 : GetHostFromURL(gurl); |
| 718 } | 719 } |
| 719 | 720 |
| (...skipping 40 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 |