| 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 AddMediaRouterUIResources(html_source.get()); | 189 AddMediaRouterUIResources(html_source.get()); |
| 190 // Ownership of |html_source| is transferred to the BrowserContext. | 190 // Ownership of |html_source| is transferred to the BrowserContext. |
| 191 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), | 191 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), |
| 192 html_source.release()); | 192 html_source.release()); |
| 193 | 193 |
| 194 // Ownership of |handler_| is transferred to |web_ui|. | 194 // Ownership of |handler_| is transferred to |web_ui|. |
| 195 web_ui->AddMessageHandler(handler_); | 195 web_ui->AddMessageHandler(handler_); |
| 196 } | 196 } |
| 197 | 197 |
| 198 MediaRouterUI::~MediaRouterUI() { | 198 MediaRouterUI::~MediaRouterUI() { |
| 199 if (issues_observer_) issues_observer_->UnregisterObserver(); | |
| 200 | |
| 201 if (query_result_manager_.get()) query_result_manager_->RemoveObserver(this); | 199 if (query_result_manager_.get()) query_result_manager_->RemoveObserver(this); |
| 202 if (presentation_service_delegate_.get()) | 200 if (presentation_service_delegate_.get()) |
| 203 presentation_service_delegate_->RemoveDefaultPresentationRequestObserver( | 201 presentation_service_delegate_->RemoveDefaultPresentationRequestObserver( |
| 204 this); | 202 this); |
| 205 // If |create_session_request_| still exists, then it means presentation route | 203 // If |create_session_request_| still exists, then it means presentation route |
| 206 // request was never attempted. | 204 // request was never attempted. |
| 207 if (create_session_request_) { | 205 if (create_session_request_) { |
| 208 bool presentation_sinks_available = std::any_of( | 206 bool presentation_sinks_available = std::any_of( |
| 209 sinks_.begin(), sinks_.end(), [](const MediaSinkWithCastModes& sink) { | 207 sinks_.begin(), sinks_.end(), [](const MediaSinkWithCastModes& sink) { |
| 210 return base::ContainsValue(sink.cast_modes, MediaCastMode::DEFAULT); | 208 return base::ContainsValue(sink.cast_modes, MediaCastMode::DEFAULT); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 delegate->GetWebDialogDelegate()->OnDialogClosed(std::string()); | 354 delegate->GetWebDialogDelegate()->OnDialogClosed(std::string()); |
| 357 delegate->OnDialogCloseFromWebUI(); | 355 delegate->OnDialogCloseFromWebUI(); |
| 358 } | 356 } |
| 359 } | 357 } |
| 360 | 358 |
| 361 void MediaRouterUI::UIInitialized() { | 359 void MediaRouterUI::UIInitialized() { |
| 362 TRACE_EVENT_NESTABLE_ASYNC_END0("media_router", "UI", initiator_); | 360 TRACE_EVENT_NESTABLE_ASYNC_END0("media_router", "UI", initiator_); |
| 363 ui_initialized_ = true; | 361 ui_initialized_ = true; |
| 364 | 362 |
| 365 // Register for Issue updates. | 363 // Register for Issue updates. |
| 366 if (!issues_observer_) | 364 issues_observer_.reset(new UIIssuesObserver(router_, this)); |
| 367 issues_observer_.reset(new UIIssuesObserver(router_, this)); | 365 issues_observer_->Init(); |
| 368 issues_observer_->RegisterObserver(); | |
| 369 } | 366 } |
| 370 | 367 |
| 371 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, | 368 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, |
| 372 MediaCastMode cast_mode) { | 369 MediaCastMode cast_mode) { |
| 373 MediaSource::Id source_id; | 370 MediaSource::Id source_id; |
| 374 GURL origin; | 371 GURL origin; |
| 375 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 372 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 376 base::TimeDelta timeout; | 373 base::TimeDelta timeout; |
| 377 bool incognito; | 374 bool incognito; |
| 378 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin, | 375 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 } | 474 } |
| 478 router_->ConnectRouteByRouteId(source_id, route_id, origin, initiator_, | 475 router_->ConnectRouteByRouteId(source_id, route_id, origin, initiator_, |
| 479 route_response_callbacks, timeout, incognito); | 476 route_response_callbacks, timeout, incognito); |
| 480 return true; | 477 return true; |
| 481 } | 478 } |
| 482 | 479 |
| 483 void MediaRouterUI::CloseRoute(const MediaRoute::Id& route_id) { | 480 void MediaRouterUI::CloseRoute(const MediaRoute::Id& route_id) { |
| 484 router_->TerminateRoute(route_id); | 481 router_->TerminateRoute(route_id); |
| 485 } | 482 } |
| 486 | 483 |
| 487 void MediaRouterUI::AddIssue(const Issue& issue) { router_->AddIssue(issue); } | 484 void MediaRouterUI::AddIssue(const IssueInfo& issue) { |
| 485 router_->AddIssue(issue); |
| 486 } |
| 488 | 487 |
| 489 void MediaRouterUI::ClearIssue(const std::string& issue_id) { | 488 void MediaRouterUI::ClearIssue(const Issue::Id& issue_id) { |
| 490 router_->ClearIssue(issue_id); | 489 router_->ClearIssue(issue_id); |
| 491 } | 490 } |
| 492 | 491 |
| 493 void MediaRouterUI::SearchSinksAndCreateRoute( | 492 void MediaRouterUI::SearchSinksAndCreateRoute( |
| 494 const MediaSink::Id& sink_id, | 493 const MediaSink::Id& sink_id, |
| 495 const std::string& search_criteria, | 494 const std::string& search_criteria, |
| 496 const std::string& domain, | 495 const std::string& domain, |
| 497 MediaCastMode cast_mode) { | 496 MediaCastMode cast_mode) { |
| 498 std::unique_ptr<MediaSource> source = | 497 std::unique_ptr<MediaSource> source = |
| 499 query_result_manager_->GetSourceForCastModeAndSink(cast_mode, sink_id); | 498 query_result_manager_->GetSourceForCastModeAndSink(cast_mode, sink_id); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); | 616 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); |
| 618 break; | 617 break; |
| 619 case DESKTOP_MIRROR: | 618 case DESKTOP_MIRROR: |
| 620 issue_title = l10n_util::GetStringUTF8( | 619 issue_title = l10n_util::GetStringUTF8( |
| 621 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_DESKTOP); | 620 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_DESKTOP); |
| 622 break; | 621 break; |
| 623 default: | 622 default: |
| 624 NOTREACHED(); | 623 NOTREACHED(); |
| 625 } | 624 } |
| 626 | 625 |
| 627 Issue issue(issue_title, std::string(), | 626 AddIssue(IssueInfo(issue_title, IssueInfo::Action::DISMISS, |
| 628 IssueAction(IssueAction::TYPE_DISMISS), | 627 IssueInfo::Severity::NOTIFICATION)); |
| 629 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION, | |
| 630 false, -1); | |
| 631 AddIssue(issue); | |
| 632 } | 628 } |
| 633 | 629 |
| 634 void MediaRouterUI::SendIssueForUnableToCast(MediaCastMode cast_mode) { | 630 void MediaRouterUI::SendIssueForUnableToCast(MediaCastMode cast_mode) { |
| 635 // For a generic error, claim a tab error unless it was specifically desktop | 631 // For a generic error, claim a tab error unless it was specifically desktop |
| 636 // mirroring. | 632 // mirroring. |
| 637 std::string issue_title = | 633 std::string issue_title = |
| 638 (cast_mode == MediaCastMode::DESKTOP_MIRROR) | 634 (cast_mode == MediaCastMode::DESKTOP_MIRROR) |
| 639 ? l10n_util::GetStringUTF8( | 635 ? l10n_util::GetStringUTF8( |
| 640 IDS_MEDIA_ROUTER_ISSUE_UNABLE_TO_CAST_DESKTOP) | 636 IDS_MEDIA_ROUTER_ISSUE_UNABLE_TO_CAST_DESKTOP) |
| 641 : l10n_util::GetStringUTF8( | 637 : l10n_util::GetStringUTF8( |
| 642 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); | 638 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); |
| 643 AddIssue(Issue(issue_title, std::string(), | 639 AddIssue(IssueInfo(issue_title, IssueInfo::Action::DISMISS, |
| 644 IssueAction(IssueAction::TYPE_DISMISS), | 640 IssueInfo::Severity::WARNING)); |
| 645 std::vector<IssueAction>(), std::string(), Issue::WARNING, | |
| 646 false, -1)); | |
| 647 } | 641 } |
| 648 | 642 |
| 649 GURL MediaRouterUI::GetFrameURL() const { | 643 GURL MediaRouterUI::GetFrameURL() const { |
| 650 return presentation_request_ ? presentation_request_->frame_url() : GURL(); | 644 return presentation_request_ ? presentation_request_->frame_url() : GURL(); |
| 651 } | 645 } |
| 652 | 646 |
| 653 std::string MediaRouterUI::GetPresentationRequestSourceName() const { | 647 std::string MediaRouterUI::GetPresentationRequestSourceName() const { |
| 654 GURL gurl = GetFrameURL(); | 648 GURL gurl = GetFrameURL(); |
| 655 return gurl.SchemeIs(extensions::kExtensionScheme) | 649 return gurl.SchemeIs(extensions::kExtensionScheme) |
| 656 ? GetExtensionName(gurl, extensions::ExtensionRegistry::Get( | 650 ? GetExtensionName(gurl, extensions::ExtensionRegistry::Get( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 base::Time::Now() - start_time_); | 684 base::Time::Now() - start_time_); |
| 691 start_time_ = base::Time(); | 685 start_time_ = base::Time(); |
| 692 } | 686 } |
| 693 } | 687 } |
| 694 | 688 |
| 695 void MediaRouterUI::UpdateMaxDialogHeight(int height) { | 689 void MediaRouterUI::UpdateMaxDialogHeight(int height) { |
| 696 handler_->UpdateMaxDialogHeight(height); | 690 handler_->UpdateMaxDialogHeight(height); |
| 697 } | 691 } |
| 698 | 692 |
| 699 } // namespace media_router | 693 } // namespace media_router |
| OLD | NEW |