Index: chrome/browser/ui/views/desktop_media_picker_views.cc |
diff --git a/chrome/browser/ui/views/desktop_media_picker_views.cc b/chrome/browser/ui/views/desktop_media_picker_views.cc |
index 2614f56088103a2849e8d0ee12042d020ab0c801..b8ab07751a649e1fa8fc31be3abb5b3f2d13e7ef 100644 |
--- a/chrome/browser/ui/views/desktop_media_picker_views.cc |
+++ b/chrome/browser/ui/views/desktop_media_picker_views.cc |
@@ -11,14 +11,19 @@ |
#include "base/command_line.h" |
#include "base/strings/utf_string_conversions.h" |
#include "build/build_config.h" |
+#include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
#include "chrome/browser/media/desktop_media_list.h" |
+#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/ui/ash/ash_util.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/grit/generated_resources.h" |
#include "components/constrained_window/constrained_window_views.h" |
+#include "components/content_settings/core/browser/host_content_settings_map.h" |
+#include "components/content_settings/core/common/content_settings.h" |
#include "components/web_modal/web_contents_modal_dialog_manager.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/web_contents_delegate.h" |
+#include "content/public/common/content_switches.h" |
#include "grit/components_strings.h" |
#include "ui/aura/window_tree_host.h" |
#include "ui/base/l10n/l10n_util.h" |
@@ -28,6 +33,7 @@ |
#include "ui/native_theme/native_theme.h" |
#include "ui/views/background.h" |
#include "ui/views/bubble/bubble_frame_view.h" |
+#include "ui/views/controls/button/checkbox.h" |
#include "ui/views/controls/image_view.h" |
#include "ui/views/controls/label.h" |
#include "ui/views/controls/scroll_view.h" |
@@ -390,10 +396,13 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( |
const base::string16& target_name, |
scoped_ptr<DesktopMediaList> media_list) |
: parent_(parent), |
+ web_contents_(parent_web_contents), |
GeorgeZ
2016/01/15 16:37:55
parent_web_contents_(parent_web_contents) probably
qiangchen
2016/01/15 18:19:40
Done.
|
app_name_(app_name), |
label_(new views::Label()), |
scroll_view_(views::ScrollView::CreateScrollViewWithBorder()), |
- list_view_(new DesktopMediaListView(this, std::move(media_list))) { |
+ list_view_(new DesktopMediaListView(this, std::move(media_list))), |
+ checkbox_(new views::Checkbox( |
+ l10n_util::GetStringUTF16(IDS_DESTOP_MEDIA_PICKER_ALLOW_AUDIO))) { |
GeorgeZ
2016/01/15 16:37:55
Spell error. Change to IDS_DESKTOP_MEDIA_PICKER_AL
qiangchen
2016/01/15 18:19:40
Done.
|
if (app_name == target_name) { |
label_->SetText( |
l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name)); |
@@ -405,6 +414,28 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( |
label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
AddChildView(label_); |
+ audio_support_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kEnableAudioSupportForDesktopShare); |
+ |
+ if (audio_support_) { |
+ checkbox_->SetElideBehavior(gfx::ELIDE_MIDDLE); |
+ AddChildView(checkbox_); |
+ |
+ Profile* profile = |
+ Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
+ |
+ GURL origin(parent_web_contents->GetLastCommittedURL().GetOrigin()); |
GeorgeZ
2016/01/15 16:37:55
Is it possible change to const GURL?
qiangchen
2016/01/15 18:19:40
Done.
|
+ |
+ ContentSetting result = |
+ HostContentSettingsMapFactory::GetForProfile(profile) |
+ ->GetContentSetting( |
+ origin, origin, |
+ ContentSettingsType::CONTENT_SETTINGS_TYPE_DESKTOP_AUDIO_SHARE, |
+ std::string()); |
+ |
+ checkbox_->SetChecked(result == ContentSetting::CONTENT_SETTING_ALLOW); |
+ } |
+ |
scroll_view_->SetContents(list_view_); |
scroll_view_->ClipHeightTo( |
GetMediaListViewHeightForRows(1), GetMediaListViewHeightForRows(2)); |
@@ -461,9 +492,12 @@ gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const { |
size_t label_height = |
label_->GetHeightForWidth(kDialogViewWidth - title_insets.height() * 2); |
+ size_t checkbox_height = |
+ audio_support_ ? checkbox_->GetPreferredSize().height() : 0; |
+ |
return gfx::Size(kDialogViewWidth, |
views::kPanelVertMargin * 2 + label_height + |
- views::kPanelVerticalSpacing + |
+ checkbox_height + views::kPanelVerticalSpacing + |
scroll_view_->GetPreferredSize().height()); |
} |
@@ -478,6 +512,14 @@ void DesktopMediaPickerDialogView::Layout() { |
label_->GetHeightForWidth(rect.width())); |
label_->SetBoundsRect(label_rect); |
+ if (audio_support_) { |
+ gfx::Rect checkbox_rect(rect.x(), |
+ label_rect.bottom() + views::kPanelVertMargin, |
+ checkbox_->GetPreferredSize().width(), |
+ checkbox_->GetPreferredSize().height()); |
+ checkbox_->SetBoundsRect(checkbox_rect); |
+ } |
+ |
int scroll_view_top = label_rect.bottom() + views::kPanelVerticalSpacing; |
scroll_view_->SetBounds( |
rect.x(), scroll_view_top, |
@@ -519,6 +561,25 @@ bool DesktopMediaPickerDialogView::Accept() { |
if (selection) |
source = selection->source_id(); |
+ if (audio_support_) { |
+ Profile* profile = |
+ Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
+ |
+ GURL origin(web_contents_->GetLastCommittedURL().GetOrigin()); |
+ |
+ ContentSettingsPattern pattern = |
+ ContentSettingsPattern::FromURLNoWildcard(origin); |
+ |
+ ContentSetting result = checkbox_->checked() |
+ ? ContentSetting::CONTENT_SETTING_ALLOW |
+ : ContentSetting::CONTENT_SETTING_BLOCK; |
+ |
+ HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting( |
+ pattern, pattern, |
+ ContentSettingsType::CONTENT_SETTINGS_TYPE_DESKTOP_AUDIO_SHARE, |
+ std::string(), result); |
+ } |
+ |
if (parent_) |
parent_->NotifyDialogResult(source); |