| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 class MediaRouterUI::UIIssuesObserver : public IssuesObserver { | 110 class MediaRouterUI::UIIssuesObserver : public IssuesObserver { |
| 111 public: | 111 public: |
| 112 UIIssuesObserver(MediaRouter* router, MediaRouterUI* ui) | 112 UIIssuesObserver(MediaRouter* router, MediaRouterUI* ui) |
| 113 : IssuesObserver(router), ui_(ui) { | 113 : IssuesObserver(router), ui_(ui) { |
| 114 DCHECK(ui); | 114 DCHECK(ui); |
| 115 } | 115 } |
| 116 | 116 |
| 117 ~UIIssuesObserver() override {} | 117 ~UIIssuesObserver() override {} |
| 118 | 118 |
| 119 // IssuesObserver implementation. | 119 // IssuesObserver implementation. |
| 120 void OnIssueUpdated(const Issue* issue) override { ui_->SetIssue(issue); } | 120 void OnIssue(const Issue& issue) override { ui_->SetIssue(issue); } |
| 121 void OnIssuesCleared() override { ui_->ClearIssue(); } |
| 121 | 122 |
| 122 private: | 123 private: |
| 123 // Reference back to the owning MediaRouterUI instance. | 124 // Reference back to the owning MediaRouterUI instance. |
| 124 MediaRouterUI* ui_; | 125 MediaRouterUI* ui_; |
| 125 | 126 |
| 126 DISALLOW_COPY_AND_ASSIGN(UIIssuesObserver); | 127 DISALLOW_COPY_AND_ASSIGN(UIIssuesObserver); |
| 127 }; | 128 }; |
| 128 | 129 |
| 129 MediaRouterUI::UIMediaRoutesObserver::UIMediaRoutesObserver( | 130 MediaRouterUI::UIMediaRoutesObserver::UIMediaRoutesObserver( |
| 130 MediaRouter* router, | 131 MediaRouter* router, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 AddMediaRouterUIResources(html_source.get()); | 172 AddMediaRouterUIResources(html_source.get()); |
| 172 // Ownership of |html_source| is transferred to the BrowserContext. | 173 // Ownership of |html_source| is transferred to the BrowserContext. |
| 173 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), | 174 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), |
| 174 html_source.release()); | 175 html_source.release()); |
| 175 | 176 |
| 176 // Ownership of |handler_| is transferred to |web_ui|. | 177 // Ownership of |handler_| is transferred to |web_ui|. |
| 177 web_ui->AddMessageHandler(handler_); | 178 web_ui->AddMessageHandler(handler_); |
| 178 } | 179 } |
| 179 | 180 |
| 180 MediaRouterUI::~MediaRouterUI() { | 181 MediaRouterUI::~MediaRouterUI() { |
| 181 if (issues_observer_) issues_observer_->UnregisterObserver(); | |
| 182 | |
| 183 if (query_result_manager_.get()) query_result_manager_->RemoveObserver(this); | 182 if (query_result_manager_.get()) query_result_manager_->RemoveObserver(this); |
| 184 if (presentation_service_delegate_.get()) | 183 if (presentation_service_delegate_.get()) |
| 185 presentation_service_delegate_->RemoveDefaultPresentationRequestObserver( | 184 presentation_service_delegate_->RemoveDefaultPresentationRequestObserver( |
| 186 this); | 185 this); |
| 187 // If |create_session_request_| still exists, then it means presentation route | 186 // If |create_session_request_| still exists, then it means presentation route |
| 188 // request was never attempted. | 187 // request was never attempted. |
| 189 if (create_session_request_) { | 188 if (create_session_request_) { |
| 190 bool presentation_sinks_available = std::any_of( | 189 bool presentation_sinks_available = std::any_of( |
| 191 sinks_.begin(), sinks_.end(), [](const MediaSinkWithCastModes& sink) { | 190 sinks_.begin(), sinks_.end(), [](const MediaSinkWithCastModes& sink) { |
| 192 return base::ContainsValue(sink.cast_modes, MediaCastMode::DEFAULT); | 191 return base::ContainsValue(sink.cast_modes, MediaCastMode::DEFAULT); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 delegate->GetWebDialogDelegate()->OnDialogClosed(std::string()); | 361 delegate->GetWebDialogDelegate()->OnDialogClosed(std::string()); |
| 363 delegate->OnDialogCloseFromWebUI(); | 362 delegate->OnDialogCloseFromWebUI(); |
| 364 } | 363 } |
| 365 } | 364 } |
| 366 | 365 |
| 367 void MediaRouterUI::UIInitialized() { | 366 void MediaRouterUI::UIInitialized() { |
| 368 TRACE_EVENT_NESTABLE_ASYNC_END0("media_router", "UI", initiator_); | 367 TRACE_EVENT_NESTABLE_ASYNC_END0("media_router", "UI", initiator_); |
| 369 ui_initialized_ = true; | 368 ui_initialized_ = true; |
| 370 | 369 |
| 371 // Register for Issue updates. | 370 // Register for Issue updates. |
| 372 if (!issues_observer_) | 371 issues_observer_.reset(new UIIssuesObserver(router_, this)); |
| 373 issues_observer_.reset(new UIIssuesObserver(router_, this)); | 372 issues_observer_->Init(); |
| 374 issues_observer_->RegisterObserver(); | |
| 375 } | 373 } |
| 376 | 374 |
| 377 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, | 375 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, |
| 378 MediaCastMode cast_mode) { | 376 MediaCastMode cast_mode) { |
| 379 MediaSource::Id source_id; | 377 MediaSource::Id source_id; |
| 380 GURL origin; | 378 GURL origin; |
| 381 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 379 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 382 base::TimeDelta timeout; | 380 base::TimeDelta timeout; |
| 383 bool incognito; | 381 bool incognito; |
| 384 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin, | 382 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 } | 481 } |
| 484 router_->ConnectRouteByRouteId(source_id, route_id, origin, initiator_, | 482 router_->ConnectRouteByRouteId(source_id, route_id, origin, initiator_, |
| 485 route_response_callbacks, timeout, incognito); | 483 route_response_callbacks, timeout, incognito); |
| 486 return true; | 484 return true; |
| 487 } | 485 } |
| 488 | 486 |
| 489 void MediaRouterUI::CloseRoute(const MediaRoute::Id& route_id) { | 487 void MediaRouterUI::CloseRoute(const MediaRoute::Id& route_id) { |
| 490 router_->TerminateRoute(route_id); | 488 router_->TerminateRoute(route_id); |
| 491 } | 489 } |
| 492 | 490 |
| 493 void MediaRouterUI::AddIssue(const Issue& issue) { router_->AddIssue(issue); } | 491 void MediaRouterUI::AddIssue(const IssueInfo& issue) { |
| 492 router_->AddIssue(issue); |
| 493 } |
| 494 | 494 |
| 495 void MediaRouterUI::ClearIssue(const std::string& issue_id) { | 495 void MediaRouterUI::ClearIssue(const Issue::Id& issue_id) { |
| 496 router_->ClearIssue(issue_id); | 496 router_->ClearIssue(issue_id); |
| 497 } | 497 } |
| 498 | 498 |
| 499 void MediaRouterUI::SearchSinksAndCreateRoute( | 499 void MediaRouterUI::SearchSinksAndCreateRoute( |
| 500 const MediaSink::Id& sink_id, | 500 const MediaSink::Id& sink_id, |
| 501 const std::string& search_criteria, | 501 const std::string& search_criteria, |
| 502 const std::string& domain, | 502 const std::string& domain, |
| 503 MediaCastMode cast_mode) { | 503 MediaCastMode cast_mode) { |
| 504 std::unique_ptr<MediaSource> source = | 504 std::unique_ptr<MediaSource> source = |
| 505 query_result_manager_->GetSourceForCastModeAndSink(cast_mode, sink_id); | 505 query_result_manager_->GetSourceForCastModeAndSink(cast_mode, sink_id); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 const icu::Collator* collator_ptr = collator_.get(); | 551 const icu::Collator* collator_ptr = collator_.get(); |
| 552 std::sort(sinks_.begin(), sinks_.end(), | 552 std::sort(sinks_.begin(), sinks_.end(), |
| 553 [collator_ptr](const MediaSinkWithCastModes& sink1, | 553 [collator_ptr](const MediaSinkWithCastModes& sink1, |
| 554 const MediaSinkWithCastModes& sink2) { | 554 const MediaSinkWithCastModes& sink2) { |
| 555 return sink1.sink.CompareUsingCollator(sink2.sink, collator_ptr); | 555 return sink1.sink.CompareUsingCollator(sink2.sink, collator_ptr); |
| 556 }); | 556 }); |
| 557 | 557 |
| 558 if (ui_initialized_) handler_->UpdateSinks(sinks_); | 558 if (ui_initialized_) handler_->UpdateSinks(sinks_); |
| 559 } | 559 } |
| 560 | 560 |
| 561 void MediaRouterUI::SetIssue(const Issue* issue) { | 561 void MediaRouterUI::SetIssue(const Issue& issue) { |
| 562 if (ui_initialized_) handler_->UpdateIssue(issue); | 562 if (ui_initialized_) handler_->UpdateIssue(issue); |
| 563 } | 563 } |
| 564 | 564 |
| 565 void MediaRouterUI::ClearIssue() { |
| 566 if (ui_initialized_) |
| 567 handler_->ClearIssue(); |
| 568 } |
| 569 |
| 565 void MediaRouterUI::OnRoutesUpdated( | 570 void MediaRouterUI::OnRoutesUpdated( |
| 566 const std::vector<MediaRoute>& routes, | 571 const std::vector<MediaRoute>& routes, |
| 567 const std::vector<MediaRoute::Id>& joinable_route_ids) { | 572 const std::vector<MediaRoute::Id>& joinable_route_ids) { |
| 568 routes_.clear(); | 573 routes_.clear(); |
| 569 joinable_route_ids_.clear(); | 574 joinable_route_ids_.clear(); |
| 570 | 575 |
| 571 for (const MediaRoute& route : routes) { | 576 for (const MediaRoute& route : routes) { |
| 572 if (route.for_display()) { | 577 if (route.for_display()) { |
| 573 #ifndef NDEBUG | 578 #ifndef NDEBUG |
| 574 for (const MediaRoute& existing_route : routes_) { | 579 for (const MediaRoute& existing_route : routes_) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); | 664 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); |
| 660 break; | 665 break; |
| 661 case DESKTOP_MIRROR: | 666 case DESKTOP_MIRROR: |
| 662 issue_title = l10n_util::GetStringUTF8( | 667 issue_title = l10n_util::GetStringUTF8( |
| 663 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_DESKTOP); | 668 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_DESKTOP); |
| 664 break; | 669 break; |
| 665 default: | 670 default: |
| 666 NOTREACHED(); | 671 NOTREACHED(); |
| 667 } | 672 } |
| 668 | 673 |
| 669 Issue issue(issue_title, std::string(), | 674 AddIssue(IssueInfo(issue_title, IssueInfo::Action::DISMISS, |
| 670 IssueAction(IssueAction::TYPE_DISMISS), | 675 IssueInfo::Severity::NOTIFICATION)); |
| 671 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION, | |
| 672 false, -1); | |
| 673 AddIssue(issue); | |
| 674 } | 676 } |
| 675 | 677 |
| 676 void MediaRouterUI::SendIssueForUnableToCast(MediaCastMode cast_mode) { | 678 void MediaRouterUI::SendIssueForUnableToCast(MediaCastMode cast_mode) { |
| 677 // For a generic error, claim a tab error unless it was specifically desktop | 679 // For a generic error, claim a tab error unless it was specifically desktop |
| 678 // mirroring. | 680 // mirroring. |
| 679 std::string issue_title = | 681 std::string issue_title = |
| 680 (cast_mode == MediaCastMode::DESKTOP_MIRROR) | 682 (cast_mode == MediaCastMode::DESKTOP_MIRROR) |
| 681 ? l10n_util::GetStringUTF8( | 683 ? l10n_util::GetStringUTF8( |
| 682 IDS_MEDIA_ROUTER_ISSUE_UNABLE_TO_CAST_DESKTOP) | 684 IDS_MEDIA_ROUTER_ISSUE_UNABLE_TO_CAST_DESKTOP) |
| 683 : l10n_util::GetStringUTF8( | 685 : l10n_util::GetStringUTF8( |
| 684 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); | 686 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); |
| 685 AddIssue(Issue(issue_title, std::string(), | 687 AddIssue(IssueInfo(issue_title, IssueInfo::Action::DISMISS, |
| 686 IssueAction(IssueAction::TYPE_DISMISS), | 688 IssueInfo::Severity::WARNING)); |
| 687 std::vector<IssueAction>(), std::string(), Issue::WARNING, | |
| 688 false, -1)); | |
| 689 } | 689 } |
| 690 | 690 |
| 691 GURL MediaRouterUI::GetFrameURL() const { | 691 GURL MediaRouterUI::GetFrameURL() const { |
| 692 return presentation_request_ ? presentation_request_->frame_url() : GURL(); | 692 return presentation_request_ ? presentation_request_->frame_url() : GURL(); |
| 693 } | 693 } |
| 694 | 694 |
| 695 std::string MediaRouterUI::GetPresentationRequestSourceName() const { | 695 std::string MediaRouterUI::GetPresentationRequestSourceName() const { |
| 696 GURL gurl = GetFrameURL(); | 696 GURL gurl = GetFrameURL(); |
| 697 return gurl.SchemeIs(extensions::kExtensionScheme) | 697 return gurl.SchemeIs(extensions::kExtensionScheme) |
| 698 ? GetExtensionName(gurl, extensions::ExtensionRegistry::Get( | 698 ? GetExtensionName(gurl, extensions::ExtensionRegistry::Get( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 } | 739 } |
| 740 | 740 |
| 741 std::string MediaRouterUI::GetSerializedInitiatorOrigin() const { | 741 std::string MediaRouterUI::GetSerializedInitiatorOrigin() const { |
| 742 url::Origin origin = initiator_ | 742 url::Origin origin = initiator_ |
| 743 ? url::Origin(initiator_->GetLastCommittedURL()) | 743 ? url::Origin(initiator_->GetLastCommittedURL()) |
| 744 : url::Origin(); | 744 : url::Origin(); |
| 745 return origin.Serialize(); | 745 return origin.Serialize(); |
| 746 } | 746 } |
| 747 | 747 |
| 748 } // namespace media_router | 748 } // namespace media_router |
| OLD | NEW |