1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
|
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/desktop_capture/desktop_media_picker_views.h"
#include <algorithm>
#include <string>
#include <utility>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/user_metrics.h"
#include "base/types/expected.h"
#include "build/build_config.h"
#include "chrome/browser/media/webrtc/desktop_media_list.h"
#include "chrome/browser/media/webrtc/desktop_media_picker_controller.h"
#include "chrome/browser/media/webrtc/desktop_media_picker_manager.h"
#include "chrome/browser/media/webrtc/desktop_media_picker_utils.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/extensions/extensions_container.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/desktop_capture/desktop_media_source_view.h"
#include "chrome/browser/ui/views/desktop_capture/screen_capture_permission_checker.h"
#include "chrome/browser/ui/views/desktop_capture/share_this_tab_dialog_views.h"
#include "chrome/browser/ui/views/extensions/security_dialog_tracker.h"
#include "chrome/browser/ui/views/media_picker_utils.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/grit/branded_strings.h"
#include "chrome/grit/generated_resources.h"
#include "components/constrained_window/constrained_window_views.h"
#include "components/strings/grit/components_strings.h"
#include "components/vector_icons/vector_icons.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/desktop_media_id.h"
#include "content/public/browser/media_stream_request.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/mojom/dialog_button.mojom.h"
#include "ui/base/mojom/ui_base_types.mojom-shared.h"
#include "ui/base/ui_base_features.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/tabbed_pane/tabbed_pane.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/style/typography.h"
#include "ui/views/widget/widget.h"
#if defined(USE_AURA)
#include "ui/aura/window_tree_host.h"
#endif
#if BUILDFLAG(ENABLE_GLIC)
#include "chrome/browser/glic/resources/grit/glic_browser_resources.h"
#endif
using ::blink::mojom::MediaStreamRequestResult;
using ::content::DesktopMediaID;
using ::content::RenderFrameHost;
using ::content::WebContents;
using ::content::WebContentsMediaCaptureId;
using RequestSource = ::DesktopMediaPicker::Params::RequestSource;
const DesktopMediaSourceViewStyle& GetGenericScreenStyle() {
static const DesktopMediaSourceViewStyle style(
/*columns=*/2,
/*item_size=*/gfx::Size(266, 224),
/*icon_rect=*/gfx::Rect(),
/*label_rect=*/gfx::Rect(8, 196, 250, 36),
/*text_alignment=*/gfx::HorizontalAlignment::ALIGN_CENTER,
/*image_rect=*/gfx::Rect(8, 8, 250, 180));
return style;
}
const DesktopMediaSourceViewStyle& GetSingleScreenStyle() {
static const DesktopMediaSourceViewStyle style(GetGenericScreenStyle());
return style;
}
namespace {
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class AudioToggleStatus {
kAudioNotRequested = 0,
kAudioRequestedButNotSupported = 1,
kAudioRequestedButUserDidNotApprove = 2,
kAudioRequestedAndUserApproved = 3,
kMaxValue = kAudioRequestedAndUserApproved
};
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class SelectedTabDiscardStatus {
kNonDiscarded = 0,
kDiscarded = 1,
kMaxValue = kDiscarded
};
#if !BUILDFLAG(IS_CHROMEOS) && defined(USE_AURA)
DesktopMediaID::Id AcceleratedWidgetToDesktopMediaId(
gfx::AcceleratedWidget accelerated_widget) {
#if BUILDFLAG(IS_WIN)
return reinterpret_cast<DesktopMediaID::Id>(accelerated_widget);
#else
return static_cast<DesktopMediaID::Id>(accelerated_widget);
#endif
}
#endif
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class GDMResult {
kDialogDismissed = 0, // Tab/window closed, navigation, etc.
kUserCancelled = 1, // User explicitly cancelled.
kUserSelectedScreen = 2, // Screen selected.
kUserSelectedWindow = 3, // Window selected.
kUserSelectedOtherTab = 4, // Other tab selected from tab-list.
kUserSelectedThisTab = 5, // Current tab selected from tab-list.
kMaxValue = kUserSelectedThisTab
};
void RecordUma(GDMResult result, base::TimeTicks dialog_open_time) {
base::UmaHistogramEnumeration(
"Media.Ui.GetDisplayMedia.BasicFlow.UserInteraction", result);
const base::TimeDelta elapsed = base::TimeTicks::Now() - dialog_open_time;
base::HistogramBase* histogram = base::LinearHistogram::FactoryTimeGet(
"Media.Ui.GetDisplayMedia.BasicFlow.DialogDuration",
/*minimum=*/base::Milliseconds(500), /*maximum=*/base::Seconds(45),
/*bucket_count=*/91, base::HistogramBase::kUmaTargetedHistogramFlag);
histogram->AddTime(elapsed);
}
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class PermissionInteraction {
kNotShown = 0,
kShown = 1,
kClicked = 2,
kMaxValue = kClicked
};
void RecordUmaCancellation(base::TimeTicks dialog_open_time) {
RecordAction(base::UserMetricsAction("GetDisplayMedia.Cancel"));
RecordUma(GDMResult::kUserCancelled, dialog_open_time);
}
// Convenience function for recording UMA.
void RecordUmaSelection(content::GlobalRenderFrameHostId capturer_global_id,
const DesktopMediaID& selected_media,
DesktopMediaList::Type source_type,
base::TimeTicks dialog_open_time) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
switch (source_type) {
case DesktopMediaList::Type::kNone:
case DesktopMediaList::Type::kCurrentTab:
NOTREACHED();
case DesktopMediaList::Type::kScreen:
RecordAction(base::UserMetricsAction("GetDisplayMedia.SelectScreen"));
RecordUma(GDMResult::kUserSelectedScreen, dialog_open_time);
return;
case DesktopMediaList::Type::kWindow:
RecordAction(base::UserMetricsAction("GetDisplayMedia.SelectWindow"));
RecordUma(GDMResult::kUserSelectedWindow, dialog_open_time);
return;
case DesktopMediaList::Type::kWebContents: {
RecordAction(
base::UserMetricsAction("GetDisplayMedia.SelectWebContents"));
// Whether the current tab was selected. Note that this can happen
// through a non-explicit selection of the current tab through the
// list of all available tabs.
const bool current_tab_selected =
capturer_global_id.child_id ==
selected_media.web_contents_id.render_process_id &&
capturer_global_id.frame_routing_id ==
selected_media.web_contents_id.main_render_frame_id;
RecordUma(current_tab_selected ? GDMResult::kUserSelectedThisTab
: GDMResult::kUserSelectedOtherTab,
dialog_open_time);
return;
}
}
NOTREACHED();
}
#if BUILDFLAG(IS_MAC)
void RecordUma(PermissionInteraction permission_interaction) {
base::UmaHistogramEnumeration(
"Media.Ui.GetDisplayMedia.PermissionInteractionMac",
permission_interaction);
}
void RecordPermissionButtonOpenedAction(DesktopMediaList::Type type) {
switch (type) {
case DesktopMediaList::Type::kScreen:
RecordAction(base::UserMetricsAction(
"GetDisplayMedia.PermissionPane.Screen.Opened"));
return;
case DesktopMediaList::Type::kWindow:
RecordAction(base::UserMetricsAction(
"GetDisplayMedia.PermissionPane.Window.Opened"));
return;
case DesktopMediaList::Type::kWebContents:
case DesktopMediaList::Type::kCurrentTab:
case DesktopMediaList::Type::kNone:
break;
}
NOTREACHED();
}
#endif // BUILDFLAG(IS_MAC)
std::u16string GetLabelForReselectButton(DesktopMediaList::Type type) {
switch (type) {
case DesktopMediaList::Type::kScreen:
return l10n_util::GetStringUTF16(
IDS_DESKTOP_MEDIA_PICKER_RESELECT_SCREEN);
case DesktopMediaList::Type::kWindow:
return l10n_util::GetStringUTF16(
IDS_DESKTOP_MEDIA_PICKER_RESELECT_WINDOW);
case DesktopMediaList::Type::kWebContents:
case DesktopMediaList::Type::kCurrentTab:
case DesktopMediaList::Type::kNone:
break;
}
NOTREACHED();
}
// Helper to generate the view containing the enterprise icon and a message that
// the picker choices may have been restricted.
std::unique_ptr<views::View> CreatePolicyRestrictedView() {
auto icon = std::make_unique<views::ImageView>();
icon->SetImage(ui::ImageModel::FromVectorIcon(vector_icons::kBusinessIcon,
ui::kColorIcon, 18));
auto policy_label = std::make_unique<views::Label>();
policy_label->SetMultiLine(true);
policy_label->SetText(
l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_MANAGED));
policy_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
auto policy_view = std::make_unique<views::View>();
views::BoxLayout* layout =
policy_view->SetLayoutManager(std::make_unique<views::BoxLayout>());
int text_padding = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_TEXTFIELD_HORIZONTAL_TEXT_PADDING);
layout->set_between_child_spacing(text_padding);
policy_view->AddChildView(std::move(icon));
policy_view->AddChildView(std::move(policy_label));
return policy_view;
}
bool ShouldSelectTab(DesktopMediaList::Type type,
blink::mojom::PreferredDisplaySurface display_surface) {
switch (type) {
case DesktopMediaList::Type::kNone:
case DesktopMediaList::Type::kCurrentTab:
break;
case DesktopMediaList::Type::kScreen:
return display_surface == blink::mojom::PreferredDisplaySurface::MONITOR;
case DesktopMediaList::Type::kWindow:
return display_surface == blink::mojom::PreferredDisplaySurface::WINDOW;
case DesktopMediaList::Type::kWebContents:
return display_surface == blink::mojom::PreferredDisplaySurface::BROWSER;
}
NOTREACHED();
}
std::unique_ptr<views::ScrollView> CreateScrollView(bool audio_requested) {
auto scroll_view = std::make_unique<views::ScrollView>();
scroll_view->SetBackgroundColor(ui::kColorSysSurface4);
// The overflow indicator is disabled to reduce clutter next to the
// separator to the audio control when audio is requested or the bottom of
// the dialog when audio is not requested.
scroll_view->SetDrawOverflowIndicator(false);
return scroll_view;
}
} // namespace
bool DesktopMediaPickerDialogView::AudioSupported(
DesktopMediaList::Type type) const {
switch (type) {
case DesktopMediaList::Type::kScreen:
return DesktopMediaPickerController::IsSystemAudioCaptureSupported(
request_source_);
case DesktopMediaList::Type::kWindow:
return false;
case DesktopMediaList::Type::kWebContents:
return true;
case DesktopMediaList::Type::kNone:
case DesktopMediaList::Type::kCurrentTab:
break;
}
NOTREACHED();
}
bool DesktopMediaPickerDialogView::AudioRequestedForType(
DesktopMediaList::Type type) const {
// TODO(crbug.com/397167331): Instead of special-casing kScreen, iterate
// over the `categories_`, find the one with the relevant `type` and
// return `category.audio_offered`.
if (type == DesktopMediaList::Type::kScreen) {
return audio_requested_ && !exclude_system_audio_requested_;
} else {
return audio_requested_;
}
}
DesktopMediaPickerDialogView::DisplaySurfaceCategory::DisplaySurfaceCategory(
DesktopMediaList::Type type,
std::unique_ptr<DesktopMediaListController> controller,
bool audio_offered,
bool audio_checked,
bool supports_reselect_button)
: type(type),
controller(std::move(controller)),
audio_offered(audio_offered),
audio_checked(audio_checked),
supports_reselect_button(supports_reselect_button) {}
DesktopMediaPickerDialogView::DisplaySurfaceCategory::DisplaySurfaceCategory(
DesktopMediaPickerDialogView::DisplaySurfaceCategory&& other)
: type(other.type),
controller(std::move(other.controller)),
audio_offered(other.audio_offered),
audio_checked(other.audio_checked),
supports_reselect_button(other.supports_reselect_button),
pane(other.pane) {}
DesktopMediaPickerDialogView::DisplaySurfaceCategory::
~DisplaySurfaceCategory() = default;
DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
const DesktopMediaPicker::Params& params,
DesktopMediaPickerImpl* parent,
std::vector<std::unique_ptr<DesktopMediaList>> source_lists)
: web_contents_(params.web_contents),
request_source_(params.request_source),
app_name_(params.app_name),
audio_requested_(params.request_audio),
exclude_system_audio_requested_(params.exclude_system_audio),
is_system_audio_offered_(audio_requested_ &&
!params.exclude_system_audio &&
AudioSupported(DesktopMediaList::Type::kScreen)),
suppress_local_audio_playback_(params.suppress_local_audio_playback),
restrict_own_audio_(params.restrict_own_audio),
capturer_global_id_(
params.web_contents
? params.web_contents->GetPrimaryMainFrame()->GetGlobalId()
: content::GlobalRenderFrameHostId()),
parent_(parent),
dialog_open_time_(base::TimeTicks::Now()) {
CHECK(!params.force_audio_checkboxes_to_default_checked ||
!params.exclude_system_audio);
RecordAction(base::UserMetricsAction("GetDisplayMedia.ShowDialog"));
#if BUILDFLAG(IS_MAC)
screen_capture_permission_checker_ =
ScreenCapturePermissionChecker::MaybeCreate(
base::BindRepeating(&DesktopMediaPickerDialogView::OnPermissionUpdate,
weak_factory_.GetWeakPtr()));
#endif
SetModalType(params.modality);
int message_id = IDS_DESKTOP_MEDIA_PICKER_SHARE;
#if BUILDFLAG(ENABLE_GLIC)
if (request_source_ == RequestSource::kGlic) {
message_id = IDS_GLIC_SCREEN_PICKER_CTA;
}
#endif
SetButtonLabel(ui::mojom::DialogButton::kOk,
l10n_util::GetStringUTF16(message_id));
SetButtonStyle(ui::mojom::DialogButton::kCancel, ui::ButtonStyle::kTonal);
RegisterDeleteDelegateCallback(
RegisterDeleteCallbackPassKey(),
base::BindOnce(
[](DesktopMediaPickerDialogView* dialog) {
// If the dialog is being closed then notify the parent about it.
// That the parent has not yet been detached indicates that there
// has been no result yet. We can infer that the user rejected.
if (dialog->parent_) {
dialog->parent_->NotifyDialogResult(base::unexpected(
MediaStreamRequestResult::PERMISSION_DENIED_BY_USER));
}
},
this));
const ChromeLayoutProvider* const provider = ChromeLayoutProvider::Get();
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
provider->GetDialogInsetsForContentType(
views::DialogContentType::kText, views::DialogContentType::kControl),
provider->GetDistanceMetric(DISTANCE_RELATED_CONTROL_VERTICAL_SMALL)));
auto description_label = std::make_unique<views::Label>();
description_label->SetMultiLine(true);
description_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
description_label->SetTextStyle(views::style::STYLE_BODY_3);
description_label->SetEnabledColor(kColorDesktopMediaPickerDescriptionLabel);
description_label_ = AddChildView(std::move(description_label));
std::vector<std::pair<std::u16string, std::unique_ptr<View>>> panes;
// This command-line switch takes precedence over
// params.force_audio_checkboxes_to_default_checked.
const bool screen_capture_audio_default_unchecked =
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kScreenCaptureAudioDefaultUnchecked);
for (auto& source_list : source_lists) {
switch (source_list->GetMediaListType()) {
case DesktopMediaList::Type::kNone:
case DesktopMediaList::Type::kCurrentTab:
NOTREACHED();
case DesktopMediaList::Type::kScreen: {
std::unique_ptr<views::ScrollView> screen_scroll_view =
CreateScrollView(audio_requested_);
screen_scroll_view->SetID(VIEW_ID_MEDIA_PICKER_SCREEN_SCROLL_VIEW);
std::u16string screen_title_text = l10n_util::GetStringUTF16(
IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_SCREEN);
auto list_controller = std::make_unique<DesktopMediaListController>(
this, std::move(source_list));
const bool supports_reselect_button =
list_controller->SupportsReselectButton();
screen_scroll_view->SetContents(list_controller->CreateView(
GetGenericScreenStyle(), GetSingleScreenStyle(), screen_title_text,
DesktopMediaList::Type::kScreen));
// Allow space for the audio-toggle controller.
screen_scroll_view->ClipHeightTo(
GetGenericScreenStyle().item_size.height() +
GetGenericScreenStyle().label_rect.height(),
GetGenericScreenStyle().item_size.height() * 3 / 2);
screen_scroll_view->SetHorizontalScrollBarMode(
views::ScrollView::ScrollBarMode::kDisabled);
std::unique_ptr<views::View> pane = SetupPane(
DesktopMediaList::Type::kScreen, std::move(list_controller),
/*audio_offered=*/is_system_audio_offered_,
/*audio_checked=*/
params.force_audio_checkboxes_to_default_checked &&
!screen_capture_audio_default_unchecked,
supports_reselect_button, std::move(screen_scroll_view));
panes.emplace_back(screen_title_text, std::move(pane));
break;
}
case DesktopMediaList::Type::kWindow: {
const DesktopMediaSourceViewStyle kWindowStyle =
DesktopMediaSourceViewStyle(
/*columns=*/3,
/*item_size=*/gfx::Size(176, 164),
/*icon_rect=*/gfx::Rect(8, 136, 16, 16),
/*label_rect=*/gfx::Rect(32, 136, 136, 20),
/*text_alignment=*/gfx::HorizontalAlignment::ALIGN_LEFT,
/*image_rect=*/gfx::Rect(8, 8, 160, 120));
std::unique_ptr<views::ScrollView> window_scroll_view =
CreateScrollView(audio_requested_);
std::u16string window_title_text = l10n_util::GetStringUTF16(
IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_WINDOW);
auto list_controller = std::make_unique<DesktopMediaListController>(
this, std::move(source_list));
const bool supports_reselect_button =
list_controller->SupportsReselectButton();
window_scroll_view->SetContents(list_controller->CreateView(
kWindowStyle, kWindowStyle, window_title_text,
DesktopMediaList::Type::kWindow));
window_scroll_view->ClipHeightTo(kWindowStyle.item_size.height(),
kWindowStyle.item_size.height() * 2);
window_scroll_view->SetHorizontalScrollBarMode(
views::ScrollView::ScrollBarMode::kDisabled);
std::unique_ptr<views::View> pane = SetupPane(
DesktopMediaList::Type::kWindow, std::move(list_controller),
/*audio_offered=*/
AudioSupported(DesktopMediaList::Type::kWindow),
/*audio_checked=*/
params.force_audio_checkboxes_to_default_checked &&
!screen_capture_audio_default_unchecked,
supports_reselect_button, std::move(window_scroll_view));
panes.emplace_back(window_title_text, std::move(pane));
break;
}
case DesktopMediaList::Type::kWebContents: {
// Note that "other tab" is inaccurate - we actually allow any tab
// to be selected in either case.
const std::u16string title =
l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_TAB);
auto list_controller = std::make_unique<DesktopMediaListController>(
this, std::move(source_list));
const bool supports_reselect_button =
list_controller->SupportsReselectButton();
std::unique_ptr<views::View> list_view =
list_controller->CreateTabListView(title);
std::unique_ptr<views::View> pane = SetupPane(
DesktopMediaList::Type::kWebContents, std::move(list_controller),
/*audio_offered=*/
AudioSupported(DesktopMediaList::Type::kWebContents),
/*audio_checked=*/!screen_capture_audio_default_unchecked,
supports_reselect_button, std::move(list_view));
panes.emplace_back(title, std::move(pane));
break;
}
}
}
if (panes.size() > 1) {
auto tabbed_pane = std::make_unique<views::TabbedPane>();
for (auto& pane : panes) {
tabbed_pane->AddTab(pane.first, std::move(pane.second));
}
for (size_t i = 0; i < categories_.size(); i++) {
if (ShouldSelectTab(categories_[i].type,
params.preferred_display_surface)) {
tabbed_pane->SelectTabAt(i, /*animate=*/false);
break;
}
}
tabbed_pane->SetListener(this);
tabbed_pane->SetFocusBehavior(views::View::FocusBehavior::NEVER);
tabbed_pane_ = AddChildView(std::move(tabbed_pane));
} else {
AddChildView(std::move(panes.front().second));
}
if (request_source_ == RequestSource::kGetDisplayMedia) {
description_label_->SetText(
l10n_util::GetStringUTF16(IDS_DISPLAY_MEDIA_PICKER_TEXT));
} else {
if (params.app_name == params.target_name) {
description_label_->SetText(l10n_util::GetStringFUTF16(
IDS_DESKTOP_MEDIA_PICKER_TEXT, params.app_name));
} else {
description_label_->SetText(
l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED,
params.app_name, params.target_name));
}
}
#if BUILDFLAG(ENABLE_GLIC)
if (request_source_ == RequestSource::kGlic) {
description_label_->SetText(
l10n_util::GetStringUTF16(IDS_GLIC_SCREEN_PICKER_DESCRIPTION));
}
#endif
DCHECK(!categories_.empty());
if (params.restricted_by_policy) {
AddChildView(CreatePolicyRestrictedView());
}
previously_selected_category_ = GetSelectedTabIndex();
ConfigureUIForNewPane(previously_selected_category_);
bool modal_dialog = MediaPickerCanShowAsWebModal(params.web_contents);
views::Widget* widget = CreateMediaPickerDialogWidget(
modal_dialog ? chrome::FindBrowserWithTab(params.web_contents) : nullptr,
params.web_contents,
/*delegate=*/this, params.context, /*parent=*/gfx::NativeView());
extensions::SecurityDialogTracker::GetInstance()->AddSecurityDialog(widget);
#if BUILDFLAG(IS_MAC)
// On Mac, even modals are shown using separate native windows.
bool is_separate_native_window = true;
#else
bool is_separate_native_window = !modal_dialog;
#endif
// If the picker is a separate native window, it should not be shown in the
// source list, so its id is passed into NativeDesktopMediaList to be ignored.
DesktopMediaID dialog_window_id;
if (is_separate_native_window) {
dialog_window_id = DesktopMediaID::RegisterNativeWindow(
DesktopMediaID::TYPE_WINDOW, widget->GetNativeWindow());
#if !BUILDFLAG(IS_CHROMEOS) && defined(USE_AURA)
// Set native window ID if the windows is outside Ash.
dialog_window_id.id = AcceleratedWidgetToDesktopMediaId(
widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget());
#elif BUILDFLAG(IS_MAC)
// On Mac, the window_id in DesktopMediaID is the same as the actual native
// window ID. Note that assuming this is a bit of a layering violation; the
// fact that this code makes that assumption is documented at the code that
// causes it to hold, so hopefully nobody changes that :)
dialog_window_id.id = dialog_window_id.window_id;
#endif
}
for (auto& category : categories_) {
category.controller->StartUpdating(dialog_window_id);
}
GetSelectedController()->FocusView();
}
DesktopMediaPickerDialogView::~DesktopMediaPickerDialogView() {
#if BUILDFLAG(IS_MAC)
RecordPermissionInteractionUma();
#endif
}
void DesktopMediaPickerDialogView::RecordUmaDismissal() const {
RecordUma(GDMResult::kDialogDismissed, dialog_open_time_);
}
void DesktopMediaPickerDialogView::TabSelectedAt(int index) {
if (previously_selected_category_ == index) {
return;
}
ConfigureUIForNewPane(index);
categories_[previously_selected_category_].controller->HideView();
categories_[index].controller->FocusView();
DialogModelChanged();
previously_selected_category_ = index;
}
void DesktopMediaPickerDialogView::ConfigureUIForNewPane(int index) {
// Process any potential audio_checked state updates.
StoreAudioCheckboxState();
RemoveCurrentPaneUI();
const DisplaySurfaceCategory& category = categories_[index];
MaybeCreateReselectButtonForPane(category);
if (!category.pane) {
return;
}
if (audio_requested_ && category.audio_offered) {
category.pane->SetAudioSharingApprovedByUser(category.audio_checked);
}
#if BUILDFLAG(IS_MAC)
if (category.pane->IsPermissionPaneVisible()) {
permission_pane_was_shown_ = true;
RecordPermissionButtonOpenedAction(category.type);
}
#endif
}
void DesktopMediaPickerDialogView::StoreAudioCheckboxState() {
const DisplaySurfaceCategory& prev_category =
categories_[previously_selected_category_];
const bool has_audio_control =
prev_category.pane && prev_category.pane->AudioOffered();
if (!has_audio_control || !prev_category.audio_offered) {
return;
}
// Store pre-change audio control state.
const bool checked =
prev_category.pane && prev_category.pane->IsAudioSharingApprovedByUser();
for (auto& category : categories_) {
if (category.type == prev_category.type) {
category.audio_checked = checked;
}
}
}
void DesktopMediaPickerDialogView::RemoveCurrentPaneUI() {
// We cannot remove the Views from the "ExtraView" slot where they are added.
// They will be re-created for the given category that is visible, but in the
// mean time (and in case they aren't needed), we set them invisible and drop
// our pointer to them. Once they are replaced by a new "SetExtraView" call
// they will be destroyed.
if (reselect_button_) {
reselect_button_->SetVisible(false);
reselect_button_ = nullptr;
}
}
void DesktopMediaPickerDialogView::MaybeCreateReselectButtonForPane(
const DisplaySurfaceCategory& category) {
if (!category.supports_reselect_button) {
return;
}
auto reselect_button = std::make_unique<views::MdTextButton>(
base::BindRepeating(&DesktopMediaListController::OnReselectRequested,
category.controller->GetWeakPtr()),
GetLabelForReselectButton(category.type));
reselect_button->SetVisible(true);
reselect_button->SetEnabled(category.controller->can_reselect());
reselect_button_ = SetExtraView(std::move(reselect_button));
}
std::u16string DesktopMediaPickerDialogView::GetLabelForAudioToggle(
const DisplaySurfaceCategory& category) const {
if (!category.audio_offered) {
return l10n_util::GetStringUTF16(
is_system_audio_offered_
? IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_HINT_TAB_OR_SCREEN
: IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_HINT_TAB);
}
switch (category.type) {
case DesktopMediaList::Type::kScreen: {
return l10n_util::GetStringUTF16(
suppress_local_audio_playback_
? IDS_DESKTOP_MEDIA_PICKER_AUDIO_SHARE_SCREEN_WITH_MUTE_WARNING
: IDS_DESKTOP_MEDIA_PICKER_ALSO_SHARE_SYSTEM_AUDIO);
}
case DesktopMediaList::Type::kWindow:
NOTREACHED();
case DesktopMediaList::Type::kWebContents:
return l10n_util::GetStringUTF16(
IDS_DESKTOP_MEDIA_PICKER_ALSO_SHARE_TAB_AUDIO);
case DesktopMediaList::Type::kNone:
case DesktopMediaList::Type::kCurrentTab:
break;
}
NOTREACHED();
}
std::unique_ptr<views::View> DesktopMediaPickerDialogView::SetupPane(
DesktopMediaList::Type type,
std::unique_ptr<DesktopMediaListController> controller,
bool audio_offered,
bool audio_checked,
bool supports_reselect_button,
std::unique_ptr<views::View> content_view) {
DisplaySurfaceCategory& category =
categories_.emplace_back(type, std::move(controller), audio_offered,
audio_checked, supports_reselect_button);
auto share_audio_view =
audio_requested_
? std::make_unique<ShareAudioView>(GetLabelForAudioToggle(category),
category.audio_offered)
: nullptr;
auto pane = std::make_unique<DesktopMediaPaneView>(
category.type, std::move(content_view), std::move(share_audio_view));
if (audio_requested_ && audio_offered) {
pane->SetAudioSharingApprovedByUser(audio_checked);
}
category.pane = pane.get();
return pane;
}
int DesktopMediaPickerDialogView::GetSelectedTabIndex() const {
return tabbed_pane_ ? tabbed_pane_->GetSelectedTabIndex() : 0;
}
const DesktopMediaListController*
DesktopMediaPickerDialogView::GetSelectedController() const {
return categories_[GetSelectedTabIndex()].controller.get();
}
DesktopMediaListController*
DesktopMediaPickerDialogView::GetSelectedController() {
return categories_[GetSelectedTabIndex()].controller.get();
}
DesktopMediaList::Type DesktopMediaPickerDialogView::GetSelectedSourceListType()
const {
const int index = GetSelectedTabIndex();
DCHECK_GE(index, 0);
DCHECK_LT(static_cast<size_t>(index), categories_.size());
return categories_[index].type;
}
bool DesktopMediaPickerDialogView::IsAudioSharingApprovedByUser() const {
const int index = GetSelectedTabIndex();
CHECK_GE(index, 0);
CHECK_LT(static_cast<size_t>(index), categories_.size());
return categories_[index].pane &&
categories_[index].pane->IsAudioSharingApprovedByUser();
}
void DesktopMediaPickerDialogView::RecordSourceCountsUma() {
// Note that tabs are counted up to 1000, and windows/screens up to 100.
const std::optional<int> tab_count =
CountSourcesOfType(DesktopMediaList::Type::kWebContents);
if (tab_count.has_value()) {
base::UmaHistogramCounts1000(
"Media.Ui.GetDisplayMedia.BasicFlow.SourceCount.Tabs",
tab_count.value());
}
const std::optional<int> window_count =
CountSourcesOfType(DesktopMediaList::Type::kWindow);
if (window_count.has_value()) {
base::UmaHistogramCounts100(
"Media.Ui.GetDisplayMedia.BasicFlow.SourceCount.Windows",
window_count.value());
}
const std::optional<int> screen_count =
CountSourcesOfType(DesktopMediaList::Type::kScreen);
if (screen_count.has_value()) {
base::UmaHistogramCounts100(
"Media.Ui.GetDisplayMedia.BasicFlow.SourceCount.Screens",
screen_count.value());
}
}
void DesktopMediaPickerDialogView::RecordAudioToggleUma(
const content::DesktopMediaID& source) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (request_source_ != RequestSource::kGetDisplayMedia) {
return;
}
const char* display_surface = nullptr;
switch (source.type) {
case DesktopMediaID::Type::TYPE_WEB_CONTENTS:
display_surface = "Tabs";
break;
case DesktopMediaID::Type::TYPE_WINDOW:
display_surface = "Windows";
break;
case DesktopMediaID::Type::TYPE_SCREEN:
display_surface = "Screens";
break;
case DesktopMediaID::Type::TYPE_NONE:
break; // Should not happen - subsequent CHECK failure.
}
CHECK_NE(display_surface, nullptr);
const std::string name =
base::StrCat({"Media.Ui.GetDisplayMedia.BasicFlow.AudioToggleState.",
display_surface});
const DesktopMediaList::Type type = AsDesktopMediaListType(source.type);
AudioToggleStatus status;
if (!AudioRequestedForType(type)) {
status = AudioToggleStatus::kAudioNotRequested;
} else if (!AudioSupported(type)) {
status = AudioToggleStatus::kAudioRequestedButNotSupported;
} else {
status = source.audio_share
? AudioToggleStatus::kAudioRequestedAndUserApproved
: AudioToggleStatus::kAudioRequestedButUserDidNotApprove;
}
base::UmaHistogramEnumeration(name, status);
}
void DesktopMediaPickerDialogView::RecordTabDiscardedStatusUma(
const DesktopMediaID& source) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (source.type != DesktopMediaID::Type::TYPE_WEB_CONTENTS) {
return;
}
const WebContentsMediaCaptureId& web_contents_id = source.web_contents_id;
RenderFrameHost* const rfh = RenderFrameHost::FromID(
web_contents_id.render_process_id, web_contents_id.main_render_frame_id);
WebContents* const wc = WebContents::FromRenderFrameHost(rfh);
if (!wc) {
return;
}
const SelectedTabDiscardStatus status =
wc->WasDiscarded() ? SelectedTabDiscardStatus::kDiscarded
: SelectedTabDiscardStatus::kNonDiscarded;
// Note: For simplicty's sake, we count all invocations of the picker,
// regardless of whether getDisplayMedia() or extension-based.
base::UmaHistogramEnumeration(
"Media.Ui.GetDisplayMedia.BasicFlow.SelectedTabDiscardStatus", status);
}
std::optional<int> DesktopMediaPickerDialogView::CountSourcesOfType(
DesktopMediaList::Type type) {
std::optional<int> count;
for (const DisplaySurfaceCategory& category : categories_) {
if (category.type != type) {
continue;
}
if (!count.has_value()) {
count = 0;
}
*count += static_cast<int>(category.controller->GetSourceCount());
}
return count;
}
void DesktopMediaPickerDialogView::DetachParent() {
parent_ = nullptr;
}
gfx::Size DesktopMediaPickerDialogView::CalculatePreferredSize(
const views::SizeBounds& /*available_size*/) const {
static constexpr size_t kDialogViewWidth = 600;
return gfx::Size(
kDialogViewWidth,
GetLayoutManager()->GetPreferredHeightForWidth(this, kDialogViewWidth));
}
std::u16string DesktopMediaPickerDialogView::GetWindowTitle() const {
if (request_source_ == RequestSource::kGetDisplayMedia) {
return l10n_util::GetStringFUTF16(IDS_DISPLAY_MEDIA_PICKER_TITLE,
app_name_);
}
#if BUILDFLAG(ENABLE_GLIC)
if (request_source_ == RequestSource::kGlic) {
return l10n_util::GetStringUTF16(IDS_GLIC_SCREEN_PICKER_HEADLINE);
}
#endif
int title_id = IDS_DESKTOP_MEDIA_PICKER_TITLE;
if (!tabbed_pane_) {
switch (categories_.front().type) {
case DesktopMediaList::Type::kScreen:
title_id = IDS_DESKTOP_MEDIA_PICKER_TITLE_SCREEN_ONLY;
break;
case DesktopMediaList::Type::kWindow:
title_id = IDS_DESKTOP_MEDIA_PICKER_TITLE_WINDOW_ONLY;
break;
case DesktopMediaList::Type::kWebContents:
title_id = IDS_DESKTOP_MEDIA_PICKER_TITLE_WEB_CONTENTS_ONLY;
break;
default:
break;
}
}
return l10n_util::GetStringUTF16(title_id);
}
bool DesktopMediaPickerDialogView::IsDialogButtonEnabled(
ui::mojom::DialogButton button) const {
return button != ui::mojom::DialogButton::kOk ||
GetSelectedController()->GetSelection().has_value() ||
accepted_source_.has_value();
}
views::View* DesktopMediaPickerDialogView::GetInitiallyFocusedView() {
return GetCancelButton();
}
bool DesktopMediaPickerDialogView::Accept() {
CHECK(IsDialogButtonEnabled(ui::mojom::DialogButton::kOk));
// Accept() can only be called if IsDialogButtonEnabled() for the OK button,
// which implies that at least one of these two options has_value().
DesktopMediaID source = accepted_source_.has_value()
? accepted_source_.value()
: GetSelectedController()->GetSelection().value();
source.audio_share = IsAudioSharingApprovedByUser();
if (request_source_ == RequestSource::kGetDisplayMedia) {
RecordUmaSelection(capturer_global_id_, source, GetSelectedSourceListType(),
dialog_open_time_);
}
RecordSourceCountsUma();
RecordAudioToggleUma(source);
RecordTabDiscardedStatusUma(source);
if (parent_) {
parent_->NotifyDialogResult(source);
}
// Return true to close the window.
return true;
}
bool DesktopMediaPickerDialogView::Cancel() {
if (request_source_ == RequestSource::kGetDisplayMedia) {
RecordUmaCancellation(dialog_open_time_);
}
RecordSourceCountsUma();
return views::DialogDelegateView::Cancel();
}
bool DesktopMediaPickerDialogView::ShouldShowCloseButton() const {
return false;
}
void DesktopMediaPickerDialogView::OnWidgetInitialized() {
views::DialogDelegateView::OnWidgetInitialized();
}
void DesktopMediaPickerDialogView::OnSelectionChanged() {
DialogModelChanged();
}
void DesktopMediaPickerDialogView::AcceptSource() {
// This will call Accept() and close the dialog.
AcceptDialog();
}
void DesktopMediaPickerDialogView::AcceptSpecificSource(
const DesktopMediaID& source) {
VLOG(1) << "DMPDV::AcceptSpecificSource: source_id = " << source.id;
if (tabbed_pane_) {
for (size_t i = 0; i < categories_.size(); i++) {
if (AsDesktopMediaIdType(categories_[i].type) == source.type) {
tabbed_pane_->SelectTabAt(i, /*animate=*/false);
break;
}
}
}
accepted_source_ = std::optional<DesktopMediaID>(source);
AcceptSource();
}
void DesktopMediaPickerDialogView::Reject() {
RecordSourceCountsUma();
CancelDialog();
}
void DesktopMediaPickerDialogView::OnSourceListLayoutChanged() {
PreferredSizeChanged();
}
void DesktopMediaPickerDialogView::OnDelegatedSourceListDismissed() {
#if BUILDFLAG(IS_MAC)
// This function is called when the native picker has been cancelled or has
// experienced an error. In both these cases for MacOS, we should reject the
// dialog and close it.
Reject();
return;
#else
if (!tabbed_pane_) {
Reject();
return;
}
size_t fallback_pane_index = std::distance(
categories_.begin(),
std::ranges::find(categories_, DesktopMediaList::Type::kWebContents,
&DisplaySurfaceCategory::type));
if (fallback_pane_index >= categories_.size()) {
Reject();
return;
}
categories_[fallback_pane_index].controller->ClearSelection();
tabbed_pane_->SelectTabAt(fallback_pane_index);
GetCancelButton()->RequestFocus();
#endif
}
void DesktopMediaPickerDialogView::OnCanReselectChanged(
const DesktopMediaListController* controller) {
// DelegatedSourceLists (currently just PipeWire and currently the only
// controllers that support a reselect button), aren't necessarily running on
// the UI thread; so there is a very slight chance that we could have an event
// working it's way back to us after we've switched controllers. If that's the
// case, then the state will be updated the next time that controller is
// active, but we shouldn't update it just now.
if (controller != GetSelectedController() || !reselect_button_) {
return;
}
reselect_button_->SetEnabled(controller->can_reselect());
}
#if BUILDFLAG(IS_MAC)
void DesktopMediaPickerDialogView::OnPermissionUpdate(bool has_permission) {
CHECK(screen_capture_permission_checker_);
if (!initial_permission_state_.has_value()) {
initial_permission_state_ = has_permission;
}
if (has_permission) {
// Avoid needless polling.
// (A user who revokes permission while the media-picker is visible,
// likely knows what they are doing, and can recover by themselves.)
screen_capture_permission_checker_->Stop();
}
for (auto& category : categories_) {
category.pane->OnScreenCapturePermissionUpdate(has_permission);
}
}
void DesktopMediaPickerDialogView::RecordPermissionInteractionUma() const {
if (initial_permission_state_.value_or(true)) {
return;
}
bool permission_button_was_clicked = false;
for (auto& category : categories_) {
if (category.pane->WasPermissionButtonClicked()) {
permission_button_was_clicked = true;
break;
}
}
const PermissionInteraction permission_interaction =
permission_button_was_clicked ? PermissionInteraction::kClicked
: permission_pane_was_shown_ ? PermissionInteraction::kShown
: PermissionInteraction::kNotShown;
RecordUma(permission_interaction);
}
#endif
BEGIN_METADATA(DesktopMediaPickerDialogView)
END_METADATA
DesktopMediaPickerImpl::DesktopMediaPickerImpl() : dialog_(nullptr) {}
DesktopMediaPickerImpl::~DesktopMediaPickerImpl() {
if (dialog_) {
if (request_source_ == RequestSource::kGetDisplayMedia) {
dialog_->RecordUmaDismissal();
}
dialog_->DetachParent();
dialog_->GetWidget()->Close();
}
}
void DesktopMediaPickerImpl::Show(
const DesktopMediaPicker::Params& params,
std::vector<std::unique_ptr<DesktopMediaList>> source_lists,
DoneCallback done_callback) {
DesktopMediaPickerManager::Get()->OnShowDialog(params);
request_source_ = params.request_source;
callback_ = std::move(done_callback);
dialog_ =
new DesktopMediaPickerDialogView(params, this, std::move(source_lists));
}
void DesktopMediaPickerImpl::NotifyDialogResult(
base::expected<DesktopMediaID, MediaStreamRequestResult> result) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Once this method is called the |dialog_| will close and destroy itself.
dialog_->DetachParent();
dialog_ = nullptr;
DesktopMediaPickerManager::Get()->OnHideDialog();
if (callback_.is_null()) {
return;
}
// Notify the |callback_| asynchronously because it may need to destroy
// DesktopMediaPicker.
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(std::move(callback_), result));
}
// static
std::unique_ptr<DesktopMediaPicker> DesktopMediaPicker::Create(
const content::MediaStreamRequest* request) {
if (request &&
request->video_type ==
blink::mojom::MediaStreamType::DISPLAY_VIDEO_CAPTURE_THIS_TAB) {
return std::make_unique<ShareThisTabMediaPicker>();
} else {
return std::make_unique<DesktopMediaPickerImpl>();
}
}
|