| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 class MediaRouterUI::UIIssuesObserver : public IssuesObserver { | 119 class MediaRouterUI::UIIssuesObserver : public IssuesObserver { |
| 120 public: | 120 public: |
| 121 UIIssuesObserver(MediaRouter* router, MediaRouterUI* ui) | 121 UIIssuesObserver(MediaRouter* router, MediaRouterUI* ui) |
| 122 : IssuesObserver(router), ui_(ui) { | 122 : IssuesObserver(router), ui_(ui) { |
| 123 DCHECK(ui); | 123 DCHECK(ui); |
| 124 } | 124 } |
| 125 | 125 |
| 126 ~UIIssuesObserver() override {} | 126 ~UIIssuesObserver() override {} |
| 127 | 127 |
| 128 // IssuesObserver implementation. | 128 // IssuesObserver implementation. |
| 129 void OnIssueUpdated(const Issue* issue) override { ui_->SetIssue(issue); } | 129 void OnIssue(const Issue& issue) override { ui_->SetIssue(issue); } |
| 130 void OnIssuesCleared() override { ui_->ClearIssue(); } |
| 130 | 131 |
| 131 private: | 132 private: |
| 132 // Reference back to the owning MediaRouterUI instance. | 133 // Reference back to the owning MediaRouterUI instance. |
| 133 MediaRouterUI* ui_; | 134 MediaRouterUI* ui_; |
| 134 | 135 |
| 135 DISALLOW_COPY_AND_ASSIGN(UIIssuesObserver); | 136 DISALLOW_COPY_AND_ASSIGN(UIIssuesObserver); |
| 136 }; | 137 }; |
| 137 | 138 |
| 138 MediaRouterUI::UIMediaRoutesObserver::UIMediaRoutesObserver( | 139 MediaRouterUI::UIMediaRoutesObserver::UIMediaRoutesObserver( |
| 139 MediaRouter* router, | 140 MediaRouter* router, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 AddMediaRouterUIResources(html_source.get()); | 181 AddMediaRouterUIResources(html_source.get()); |
| 181 // Ownership of |html_source| is transferred to the BrowserContext. | 182 // Ownership of |html_source| is transferred to the BrowserContext. |
| 182 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), | 183 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), |
| 183 html_source.release()); | 184 html_source.release()); |
| 184 | 185 |
| 185 // Ownership of |handler_| is transferred to |web_ui|. | 186 // Ownership of |handler_| is transferred to |web_ui|. |
| 186 web_ui->AddMessageHandler(handler_); | 187 web_ui->AddMessageHandler(handler_); |
| 187 } | 188 } |
| 188 | 189 |
| 189 MediaRouterUI::~MediaRouterUI() { | 190 MediaRouterUI::~MediaRouterUI() { |
| 190 if (issues_observer_) issues_observer_->UnregisterObserver(); | |
| 191 | |
| 192 if (query_result_manager_.get()) query_result_manager_->RemoveObserver(this); | 191 if (query_result_manager_.get()) query_result_manager_->RemoveObserver(this); |
| 193 if (presentation_service_delegate_.get()) | 192 if (presentation_service_delegate_.get()) |
| 194 presentation_service_delegate_->RemoveDefaultPresentationRequestObserver( | 193 presentation_service_delegate_->RemoveDefaultPresentationRequestObserver( |
| 195 this); | 194 this); |
| 196 // If |create_session_request_| still exists, then it means presentation route | 195 // If |create_session_request_| still exists, then it means presentation route |
| 197 // request was never attempted. | 196 // request was never attempted. |
| 198 if (create_session_request_) { | 197 if (create_session_request_) { |
| 199 bool presentation_sinks_available = std::any_of( | 198 bool presentation_sinks_available = std::any_of( |
| 200 sinks_.begin(), sinks_.end(), [](const MediaSinkWithCastModes& sink) { | 199 sinks_.begin(), sinks_.end(), [](const MediaSinkWithCastModes& sink) { |
| 201 return base::ContainsValue(sink.cast_modes, MediaCastMode::DEFAULT); | 200 return base::ContainsValue(sink.cast_modes, MediaCastMode::DEFAULT); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 delegate->GetWebDialogDelegate()->OnDialogClosed(std::string()); | 375 delegate->GetWebDialogDelegate()->OnDialogClosed(std::string()); |
| 377 delegate->OnDialogCloseFromWebUI(); | 376 delegate->OnDialogCloseFromWebUI(); |
| 378 } | 377 } |
| 379 } | 378 } |
| 380 | 379 |
| 381 void MediaRouterUI::UIInitialized() { | 380 void MediaRouterUI::UIInitialized() { |
| 382 TRACE_EVENT_NESTABLE_ASYNC_END0("media_router", "UI", initiator_); | 381 TRACE_EVENT_NESTABLE_ASYNC_END0("media_router", "UI", initiator_); |
| 383 ui_initialized_ = true; | 382 ui_initialized_ = true; |
| 384 | 383 |
| 385 // Register for Issue updates. | 384 // Register for Issue updates. |
| 386 if (!issues_observer_) | 385 issues_observer_.reset(new UIIssuesObserver(router_, this)); |
| 387 issues_observer_.reset(new UIIssuesObserver(router_, this)); | 386 issues_observer_->Init(); |
| 388 issues_observer_->RegisterObserver(); | |
| 389 } | 387 } |
| 390 | 388 |
| 391 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, | 389 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, |
| 392 MediaCastMode cast_mode) { | 390 MediaCastMode cast_mode) { |
| 393 MediaSource::Id source_id; | 391 MediaSource::Id source_id; |
| 394 GURL origin; | 392 GURL origin; |
| 395 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 393 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 396 base::TimeDelta timeout; | 394 base::TimeDelta timeout; |
| 397 bool incognito; | 395 bool incognito; |
| 398 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin, | 396 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 } | 495 } |
| 498 router_->ConnectRouteByRouteId(source_id, route_id, origin, initiator_, | 496 router_->ConnectRouteByRouteId(source_id, route_id, origin, initiator_, |
| 499 route_response_callbacks, timeout, incognito); | 497 route_response_callbacks, timeout, incognito); |
| 500 return true; | 498 return true; |
| 501 } | 499 } |
| 502 | 500 |
| 503 void MediaRouterUI::CloseRoute(const MediaRoute::Id& route_id) { | 501 void MediaRouterUI::CloseRoute(const MediaRoute::Id& route_id) { |
| 504 router_->TerminateRoute(route_id); | 502 router_->TerminateRoute(route_id); |
| 505 } | 503 } |
| 506 | 504 |
| 507 void MediaRouterUI::AddIssue(const Issue& issue) { router_->AddIssue(issue); } | 505 void MediaRouterUI::AddIssue(const IssueInfo& issue) { |
| 506 router_->AddIssue(issue); |
| 507 } |
| 508 | 508 |
| 509 void MediaRouterUI::ClearIssue(const std::string& issue_id) { | 509 void MediaRouterUI::ClearIssue(const Issue::Id& issue_id) { |
| 510 router_->ClearIssue(issue_id); | 510 router_->ClearIssue(issue_id); |
| 511 } | 511 } |
| 512 | 512 |
| 513 void MediaRouterUI::SearchSinksAndCreateRoute( | 513 void MediaRouterUI::SearchSinksAndCreateRoute( |
| 514 const MediaSink::Id& sink_id, | 514 const MediaSink::Id& sink_id, |
| 515 const std::string& search_criteria, | 515 const std::string& search_criteria, |
| 516 const std::string& domain, | 516 const std::string& domain, |
| 517 MediaCastMode cast_mode) { | 517 MediaCastMode cast_mode) { |
| 518 std::unique_ptr<MediaSource> source = | 518 std::unique_ptr<MediaSource> source = |
| 519 query_result_manager_->GetSourceForCastModeAndSink(cast_mode, sink_id); | 519 query_result_manager_->GetSourceForCastModeAndSink(cast_mode, sink_id); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 const std::vector<MediaSinkWithCastModes>& sinks) { | 562 const std::vector<MediaSinkWithCastModes>& sinks) { |
| 563 sinks_ = sinks; | 563 sinks_ = sinks; |
| 564 | 564 |
| 565 const icu::Collator* collator_ptr = collator_.get(); | 565 const icu::Collator* collator_ptr = collator_.get(); |
| 566 std::sort(sinks_.begin(), sinks_.end(), | 566 std::sort(sinks_.begin(), sinks_.end(), |
| 567 [collator_ptr](const MediaSinkWithCastModes& sink1, | 567 [collator_ptr](const MediaSinkWithCastModes& sink1, |
| 568 const MediaSinkWithCastModes& sink2) { | 568 const MediaSinkWithCastModes& sink2) { |
| 569 return sink1.sink.CompareUsingCollator(sink2.sink, collator_ptr); | 569 return sink1.sink.CompareUsingCollator(sink2.sink, collator_ptr); |
| 570 }); | 570 }); |
| 571 | 571 |
| 572 if (ui_initialized_) handler_->UpdateSinks(sinks_); | 572 if (ui_initialized_) |
| 573 handler_->UpdateSinks(sinks_); |
| 573 } | 574 } |
| 574 | 575 |
| 575 void MediaRouterUI::SetIssue(const Issue* issue) { | 576 void MediaRouterUI::SetIssue(const Issue& issue) { |
| 576 if (ui_initialized_) handler_->UpdateIssue(issue); | 577 if (ui_initialized_) |
| 578 handler_->UpdateIssue(issue); |
| 579 } |
| 580 |
| 581 void MediaRouterUI::ClearIssue() { |
| 582 if (ui_initialized_) |
| 583 handler_->ClearIssue(); |
| 577 } | 584 } |
| 578 | 585 |
| 579 void MediaRouterUI::OnRoutesUpdated( | 586 void MediaRouterUI::OnRoutesUpdated( |
| 580 const std::vector<MediaRoute>& routes, | 587 const std::vector<MediaRoute>& routes, |
| 581 const std::vector<MediaRoute::Id>& joinable_route_ids) { | 588 const std::vector<MediaRoute::Id>& joinable_route_ids) { |
| 582 routes_.clear(); | 589 routes_.clear(); |
| 583 joinable_route_ids_.clear(); | 590 joinable_route_ids_.clear(); |
| 584 | 591 |
| 585 for (const MediaRoute& route : routes) { | 592 for (const MediaRoute& route : routes) { |
| 586 if (route.for_display()) { | 593 if (route.for_display()) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); | 680 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); |
| 674 break; | 681 break; |
| 675 case DESKTOP_MIRROR: | 682 case DESKTOP_MIRROR: |
| 676 issue_title = l10n_util::GetStringUTF8( | 683 issue_title = l10n_util::GetStringUTF8( |
| 677 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_DESKTOP); | 684 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_DESKTOP); |
| 678 break; | 685 break; |
| 679 default: | 686 default: |
| 680 NOTREACHED(); | 687 NOTREACHED(); |
| 681 } | 688 } |
| 682 | 689 |
| 683 Issue issue(issue_title, std::string(), | 690 AddIssue(IssueInfo(issue_title, IssueInfo::Action::DISMISS, |
| 684 IssueAction(IssueAction::TYPE_DISMISS), | 691 IssueInfo::Severity::NOTIFICATION)); |
| 685 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION, | |
| 686 false, -1); | |
| 687 AddIssue(issue); | |
| 688 } | 692 } |
| 689 | 693 |
| 690 void MediaRouterUI::SendIssueForUnableToCast(MediaCastMode cast_mode) { | 694 void MediaRouterUI::SendIssueForUnableToCast(MediaCastMode cast_mode) { |
| 691 // For a generic error, claim a tab error unless it was specifically desktop | 695 // For a generic error, claim a tab error unless it was specifically desktop |
| 692 // mirroring. | 696 // mirroring. |
| 693 std::string issue_title = | 697 std::string issue_title = |
| 694 (cast_mode == MediaCastMode::DESKTOP_MIRROR) | 698 (cast_mode == MediaCastMode::DESKTOP_MIRROR) |
| 695 ? l10n_util::GetStringUTF8( | 699 ? l10n_util::GetStringUTF8( |
| 696 IDS_MEDIA_ROUTER_ISSUE_UNABLE_TO_CAST_DESKTOP) | 700 IDS_MEDIA_ROUTER_ISSUE_UNABLE_TO_CAST_DESKTOP) |
| 697 : l10n_util::GetStringUTF8( | 701 : l10n_util::GetStringUTF8( |
| 698 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); | 702 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); |
| 699 AddIssue(Issue(issue_title, std::string(), | 703 AddIssue(IssueInfo(issue_title, IssueInfo::Action::DISMISS, |
| 700 IssueAction(IssueAction::TYPE_DISMISS), | 704 IssueInfo::Severity::WARNING)); |
| 701 std::vector<IssueAction>(), std::string(), Issue::WARNING, | |
| 702 false, -1)); | |
| 703 } | 705 } |
| 704 | 706 |
| 705 GURL MediaRouterUI::GetFrameURL() const { | 707 GURL MediaRouterUI::GetFrameURL() const { |
| 706 return presentation_request_ ? presentation_request_->frame_url() : GURL(); | 708 return presentation_request_ ? presentation_request_->frame_url() : GURL(); |
| 707 } | 709 } |
| 708 | 710 |
| 709 std::string MediaRouterUI::GetPresentationRequestSourceName() const { | 711 std::string MediaRouterUI::GetPresentationRequestSourceName() const { |
| 710 GURL gurl = GetFrameURL(); | 712 GURL gurl = GetFrameURL(); |
| 711 return gurl.SchemeIs(extensions::kExtensionScheme) | 713 return gurl.SchemeIs(extensions::kExtensionScheme) |
| 712 ? GetExtensionName(gurl, extensions::ExtensionRegistry::Get( | 714 ? GetExtensionName(gurl, extensions::ExtensionRegistry::Get( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 } | 755 } |
| 754 | 756 |
| 755 std::string MediaRouterUI::GetSerializedInitiatorOrigin() const { | 757 std::string MediaRouterUI::GetSerializedInitiatorOrigin() const { |
| 756 url::Origin origin = initiator_ | 758 url::Origin origin = initiator_ |
| 757 ? url::Origin(initiator_->GetLastCommittedURL()) | 759 ? url::Origin(initiator_->GetLastCommittedURL()) |
| 758 : url::Origin(); | 760 : url::Origin(); |
| 759 return origin.Serialize(); | 761 return origin.Serialize(); |
| 760 } | 762 } |
| 761 | 763 |
| 762 } // namespace media_router | 764 } // namespace media_router |
| OLD | NEW |