| 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 18 matching lines...) Expand all Loading... |
| 29 #include "chrome/browser/media/router/media_source.h" | 29 #include "chrome/browser/media/router/media_source.h" |
| 30 #include "chrome/browser/media/router/media_source_helper.h" | 30 #include "chrome/browser/media/router/media_source_helper.h" |
| 31 #include "chrome/browser/media/router/mojo/media_router_mojo_impl.h" | 31 #include "chrome/browser/media/router/mojo/media_router_mojo_impl.h" |
| 32 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" | 32 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" |
| 33 #include "chrome/browser/media/router/route_request_result.h" | 33 #include "chrome/browser/media/router/route_request_result.h" |
| 34 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
| 35 #include "chrome/browser/sessions/session_tab_helper.h" | 35 #include "chrome/browser/sessions/session_tab_helper.h" |
| 36 #include "chrome/browser/ui/webui/media_router/media_router_localized_strings_pr
ovider.h" | 36 #include "chrome/browser/ui/webui/media_router/media_router_localized_strings_pr
ovider.h" |
| 37 #include "chrome/browser/ui/webui/media_router/media_router_resources_provider.h
" | 37 #include "chrome/browser/ui/webui/media_router/media_router_resources_provider.h
" |
| 38 #include "chrome/browser/ui/webui/media_router/media_router_webui_message_handle
r.h" | 38 #include "chrome/browser/ui/webui/media_router/media_router_webui_message_handle
r.h" |
| 39 #include "chrome/common/pref_names.h" |
| 39 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
| 40 #include "chrome/grit/generated_resources.h" | 41 #include "chrome/grit/generated_resources.h" |
| 42 #include "components/prefs/pref_service.h" |
| 43 #include "components/prefs/scoped_user_pref_update.h" |
| 41 #include "content/public/browser/web_contents.h" | 44 #include "content/public/browser/web_contents.h" |
| 42 #include "content/public/browser/web_ui.h" | 45 #include "content/public/browser/web_ui.h" |
| 43 #include "content/public/browser/web_ui_data_source.h" | 46 #include "content/public/browser/web_ui_data_source.h" |
| 44 #include "extensions/browser/extension_registry.h" | 47 #include "extensions/browser/extension_registry.h" |
| 45 #include "extensions/common/constants.h" | 48 #include "extensions/common/constants.h" |
| 46 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 49 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 47 #include "third_party/icu/source/i18n/unicode/coll.h" | 50 #include "third_party/icu/source/i18n/unicode/coll.h" |
| 48 #include "ui/base/l10n/l10n_util.h" | 51 #include "ui/base/l10n/l10n_util.h" |
| 49 #include "ui/web_dialogs/web_dialog_delegate.h" | 52 #include "ui/web_dialogs/web_dialog_delegate.h" |
| 53 #include "url/origin.h" |
| 50 | 54 |
| 51 namespace media_router { | 55 namespace media_router { |
| 52 | 56 |
| 53 namespace { | 57 namespace { |
| 54 | 58 |
| 55 // The amount of time to wait for a response when creating a new route. | 59 // The amount of time to wait for a response when creating a new route. |
| 56 const int kCreateRouteTimeoutSeconds = 20; | 60 const int kCreateRouteTimeoutSeconds = 20; |
| 57 const int kCreateRouteTimeoutSecondsForTab = 60; | 61 const int kCreateRouteTimeoutSecondsForTab = 60; |
| 58 const int kCreateRouteTimeoutSecondsForDesktop = 120; | 62 const int kCreateRouteTimeoutSecondsForDesktop = 120; |
| 59 | 63 |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 const std::string source_id = source ? source->id() : ""; | 504 const std::string source_id = source ? source->id() : ""; |
| 501 | 505 |
| 502 // The CreateRoute() part of the function is accomplished in the callback | 506 // The CreateRoute() part of the function is accomplished in the callback |
| 503 // OnSearchSinkResponseReceived(). | 507 // OnSearchSinkResponseReceived(). |
| 504 router_->SearchSinks( | 508 router_->SearchSinks( |
| 505 sink_id, source_id, search_criteria, domain, | 509 sink_id, source_id, search_criteria, domain, |
| 506 base::Bind(&MediaRouterUI::OnSearchSinkResponseReceived, | 510 base::Bind(&MediaRouterUI::OnSearchSinkResponseReceived, |
| 507 weak_factory_.GetWeakPtr(), cast_mode)); | 511 weak_factory_.GetWeakPtr(), cast_mode)); |
| 508 } | 512 } |
| 509 | 513 |
| 514 bool MediaRouterUI::UserSelectedTabMirroringForCurrentOrigin() const { |
| 515 const base::ListValue* origins = |
| 516 Profile::FromWebUI(web_ui())->GetPrefs()->GetList( |
| 517 prefs::kMediaRouterTabMirroringSources); |
| 518 return origins->Find(base::StringValue(GetSerializedInitiatorOrigin())) != |
| 519 origins->end(); |
| 520 } |
| 521 |
| 522 void MediaRouterUI::RecordCastModeSelection(MediaCastMode cast_mode) { |
| 523 ListPrefUpdate update(Profile::FromWebUI(web_ui())->GetPrefs(), |
| 524 prefs::kMediaRouterTabMirroringSources); |
| 525 |
| 526 switch (cast_mode) { |
| 527 case MediaCastMode::DEFAULT: |
| 528 update->Remove(base::StringValue(GetSerializedInitiatorOrigin()), |
| 529 nullptr); |
| 530 break; |
| 531 case MediaCastMode::TAB_MIRROR: |
| 532 update->AppendIfNotPresent( |
| 533 base::MakeUnique<base::StringValue>(GetSerializedInitiatorOrigin())); |
| 534 break; |
| 535 case MediaCastMode::DESKTOP_MIRROR: |
| 536 // Desktop mirroring isn't domain-specific, so we don't record the |
| 537 // selection. |
| 538 break; |
| 539 default: |
| 540 NOTREACHED(); |
| 541 break; |
| 542 } |
| 543 } |
| 544 |
| 510 void MediaRouterUI::OnResultsUpdated( | 545 void MediaRouterUI::OnResultsUpdated( |
| 511 const std::vector<MediaSinkWithCastModes>& sinks) { | 546 const std::vector<MediaSinkWithCastModes>& sinks) { |
| 512 sinks_ = sinks; | 547 sinks_ = sinks; |
| 513 | 548 |
| 514 const icu::Collator* collator_ptr = collator_.get(); | 549 const icu::Collator* collator_ptr = collator_.get(); |
| 515 std::sort(sinks_.begin(), sinks_.end(), | 550 std::sort(sinks_.begin(), sinks_.end(), |
| 516 [collator_ptr](const MediaSinkWithCastModes& sink1, | 551 [collator_ptr](const MediaSinkWithCastModes& sink1, |
| 517 const MediaSinkWithCastModes& sink2) { | 552 const MediaSinkWithCastModes& sink2) { |
| 518 return sink1.sink.CompareUsingCollator(sink2.sink, collator_ptr); | 553 return sink1.sink.CompareUsingCollator(sink2.sink, collator_ptr); |
| 519 }); | 554 }); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 MediaRouterMetrics::RecordMediaRouterDialogLoaded( | 724 MediaRouterMetrics::RecordMediaRouterDialogLoaded( |
| 690 base::Time::Now() - start_time_); | 725 base::Time::Now() - start_time_); |
| 691 start_time_ = base::Time(); | 726 start_time_ = base::Time(); |
| 692 } | 727 } |
| 693 } | 728 } |
| 694 | 729 |
| 695 void MediaRouterUI::UpdateMaxDialogHeight(int height) { | 730 void MediaRouterUI::UpdateMaxDialogHeight(int height) { |
| 696 handler_->UpdateMaxDialogHeight(height); | 731 handler_->UpdateMaxDialogHeight(height); |
| 697 } | 732 } |
| 698 | 733 |
| 734 std::string MediaRouterUI::GetSerializedInitiatorOrigin() const { |
| 735 url::Origin origin = initiator_ |
| 736 ? url::Origin(initiator_->GetLastCommittedURL()) |
| 737 : url::Origin(); |
| 738 return origin.Serialize(); |
| 739 } |
| 740 |
| 699 } // namespace media_router | 741 } // namespace media_router |
| OLD | NEW |