Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(738)

Side by Side Diff: chrome/browser/ui/views/desktop_media_picker_views.cc

Issue 1576073003: Support Audio for Desktop Capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/views/desktop_media_picker_views.h" 5 #include "chrome/browser/ui/views/desktop_media_picker_views.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
14 #include "chrome/browser/media/desktop_media_list.h" 15 #include "chrome/browser/media/desktop_media_list.h"
16 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/ash/ash_util.h" 17 #include "chrome/browser/ui/ash/ash_util.h"
16 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
17 #include "chrome/grit/generated_resources.h" 19 #include "chrome/grit/generated_resources.h"
18 #include "components/constrained_window/constrained_window_views.h" 20 #include "components/constrained_window/constrained_window_views.h"
21 #include "components/content_settings/core/browser/host_content_settings_map.h"
22 #include "components/content_settings/core/common/content_settings.h"
19 #include "components/web_modal/web_contents_modal_dialog_manager.h" 23 #include "components/web_modal/web_contents_modal_dialog_manager.h"
20 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/web_contents_delegate.h" 25 #include "content/public/browser/web_contents_delegate.h"
26 #include "content/public/common/content_switches.h"
22 #include "grit/components_strings.h" 27 #include "grit/components_strings.h"
23 #include "ui/aura/window_tree_host.h" 28 #include "ui/aura/window_tree_host.h"
24 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/events/event_constants.h" 30 #include "ui/events/event_constants.h"
26 #include "ui/events/keycodes/keyboard_codes.h" 31 #include "ui/events/keycodes/keyboard_codes.h"
27 #include "ui/gfx/canvas.h" 32 #include "ui/gfx/canvas.h"
28 #include "ui/native_theme/native_theme.h" 33 #include "ui/native_theme/native_theme.h"
29 #include "ui/views/background.h" 34 #include "ui/views/background.h"
30 #include "ui/views/bubble/bubble_frame_view.h" 35 #include "ui/views/bubble/bubble_frame_view.h"
36 #include "ui/views/controls/button/checkbox.h"
31 #include "ui/views/controls/image_view.h" 37 #include "ui/views/controls/image_view.h"
32 #include "ui/views/controls/label.h" 38 #include "ui/views/controls/label.h"
33 #include "ui/views/controls/scroll_view.h" 39 #include "ui/views/controls/scroll_view.h"
34 #include "ui/views/layout/layout_constants.h" 40 #include "ui/views/layout/layout_constants.h"
35 #include "ui/views/widget/widget.h" 41 #include "ui/views/widget/widget.h"
36 #include "ui/views/window/dialog_client_view.h" 42 #include "ui/views/window/dialog_client_view.h"
37 #include "ui/wm/core/shadow_types.h" 43 #include "ui/wm/core/shadow_types.h"
38 44
39 using content::DesktopMediaID; 45 using content::DesktopMediaID;
40 46
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 } 389 }
384 390
385 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( 391 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
386 content::WebContents* parent_web_contents, 392 content::WebContents* parent_web_contents,
387 gfx::NativeWindow context, 393 gfx::NativeWindow context,
388 DesktopMediaPickerViews* parent, 394 DesktopMediaPickerViews* parent,
389 const base::string16& app_name, 395 const base::string16& app_name,
390 const base::string16& target_name, 396 const base::string16& target_name,
391 scoped_ptr<DesktopMediaList> media_list) 397 scoped_ptr<DesktopMediaList> media_list)
392 : parent_(parent), 398 : parent_(parent),
399 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.
393 app_name_(app_name), 400 app_name_(app_name),
394 label_(new views::Label()), 401 label_(new views::Label()),
395 scroll_view_(views::ScrollView::CreateScrollViewWithBorder()), 402 scroll_view_(views::ScrollView::CreateScrollViewWithBorder()),
396 list_view_(new DesktopMediaListView(this, std::move(media_list))) { 403 list_view_(new DesktopMediaListView(this, std::move(media_list))),
404 checkbox_(new views::Checkbox(
405 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.
397 if (app_name == target_name) { 406 if (app_name == target_name) {
398 label_->SetText( 407 label_->SetText(
399 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name)); 408 l10n_util::GetStringFUTF16(IDS_DESKTOP_MEDIA_PICKER_TEXT, app_name));
400 } else { 409 } else {
401 label_->SetText(l10n_util::GetStringFUTF16( 410 label_->SetText(l10n_util::GetStringFUTF16(
402 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name)); 411 IDS_DESKTOP_MEDIA_PICKER_TEXT_DELEGATED, app_name, target_name));
403 } 412 }
404 label_->SetMultiLine(true); 413 label_->SetMultiLine(true);
405 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 414 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
406 AddChildView(label_); 415 AddChildView(label_);
407 416
417 audio_support_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
418 switches::kEnableAudioSupportForDesktopShare);
419
420 if (audio_support_) {
421 checkbox_->SetElideBehavior(gfx::ELIDE_MIDDLE);
422 AddChildView(checkbox_);
423
424 Profile* profile =
425 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
426
427 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.
428
429 ContentSetting result =
430 HostContentSettingsMapFactory::GetForProfile(profile)
431 ->GetContentSetting(
432 origin, origin,
433 ContentSettingsType::CONTENT_SETTINGS_TYPE_DESKTOP_AUDIO_SHARE,
434 std::string());
435
436 checkbox_->SetChecked(result == ContentSetting::CONTENT_SETTING_ALLOW);
437 }
438
408 scroll_view_->SetContents(list_view_); 439 scroll_view_->SetContents(list_view_);
409 scroll_view_->ClipHeightTo( 440 scroll_view_->ClipHeightTo(
410 GetMediaListViewHeightForRows(1), GetMediaListViewHeightForRows(2)); 441 GetMediaListViewHeightForRows(1), GetMediaListViewHeightForRows(2));
411 AddChildView(scroll_view_); 442 AddChildView(scroll_view_);
412 443
413 // If |parent_web_contents| is set and it's not a background page then the 444 // If |parent_web_contents| is set and it's not a background page then the
414 // picker will be shown modal to the web contents. Otherwise the picker is 445 // picker will be shown modal to the web contents. Otherwise the picker is
415 // shown in a separate window. 446 // shown in a separate window.
416 views::Widget* widget = NULL; 447 views::Widget* widget = NULL;
417 bool modal_dialog = 448 bool modal_dialog =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 void DesktopMediaPickerDialogView::DetachParent() { 485 void DesktopMediaPickerDialogView::DetachParent() {
455 parent_ = NULL; 486 parent_ = NULL;
456 } 487 }
457 488
458 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const { 489 gfx::Size DesktopMediaPickerDialogView::GetPreferredSize() const {
459 static const size_t kDialogViewWidth = 600; 490 static const size_t kDialogViewWidth = 600;
460 const gfx::Insets title_insets = views::BubbleFrameView::GetTitleInsets(); 491 const gfx::Insets title_insets = views::BubbleFrameView::GetTitleInsets();
461 size_t label_height = 492 size_t label_height =
462 label_->GetHeightForWidth(kDialogViewWidth - title_insets.height() * 2); 493 label_->GetHeightForWidth(kDialogViewWidth - title_insets.height() * 2);
463 494
495 size_t checkbox_height =
496 audio_support_ ? checkbox_->GetPreferredSize().height() : 0;
497
464 return gfx::Size(kDialogViewWidth, 498 return gfx::Size(kDialogViewWidth,
465 views::kPanelVertMargin * 2 + label_height + 499 views::kPanelVertMargin * 2 + label_height +
466 views::kPanelVerticalSpacing + 500 checkbox_height + views::kPanelVerticalSpacing +
467 scroll_view_->GetPreferredSize().height()); 501 scroll_view_->GetPreferredSize().height());
468 } 502 }
469 503
470 void DesktopMediaPickerDialogView::Layout() { 504 void DesktopMediaPickerDialogView::Layout() {
471 // DialogDelegate uses the bubble style frame. 505 // DialogDelegate uses the bubble style frame.
472 const gfx::Insets title_insets = views::BubbleFrameView::GetTitleInsets(); 506 const gfx::Insets title_insets = views::BubbleFrameView::GetTitleInsets();
473 gfx::Rect rect = GetLocalBounds(); 507 gfx::Rect rect = GetLocalBounds();
474 508
475 rect.Inset(title_insets.left(), views::kPanelVertMargin); 509 rect.Inset(title_insets.left(), views::kPanelVertMargin);
476 510
477 gfx::Rect label_rect(rect.x(), rect.y(), rect.width(), 511 gfx::Rect label_rect(rect.x(), rect.y(), rect.width(),
478 label_->GetHeightForWidth(rect.width())); 512 label_->GetHeightForWidth(rect.width()));
479 label_->SetBoundsRect(label_rect); 513 label_->SetBoundsRect(label_rect);
480 514
515 if (audio_support_) {
516 gfx::Rect checkbox_rect(rect.x(),
517 label_rect.bottom() + views::kPanelVertMargin,
518 checkbox_->GetPreferredSize().width(),
519 checkbox_->GetPreferredSize().height());
520 checkbox_->SetBoundsRect(checkbox_rect);
521 }
522
481 int scroll_view_top = label_rect.bottom() + views::kPanelVerticalSpacing; 523 int scroll_view_top = label_rect.bottom() + views::kPanelVerticalSpacing;
482 scroll_view_->SetBounds( 524 scroll_view_->SetBounds(
483 rect.x(), scroll_view_top, 525 rect.x(), scroll_view_top,
484 rect.width(), rect.height() - scroll_view_top); 526 rect.width(), rect.height() - scroll_view_top);
485 } 527 }
486 528
487 ui::ModalType DesktopMediaPickerDialogView::GetModalType() const { 529 ui::ModalType DesktopMediaPickerDialogView::GetModalType() const {
488 return ui::MODAL_TYPE_CHILD; 530 return ui::MODAL_TYPE_CHILD;
489 } 531 }
490 532
(...skipping 21 matching lines...) Expand all
512 bool DesktopMediaPickerDialogView::Accept() { 554 bool DesktopMediaPickerDialogView::Accept() {
513 DesktopMediaSourceView* selection = list_view_->GetSelection(); 555 DesktopMediaSourceView* selection = list_view_->GetSelection();
514 556
515 // Ok button should only be enabled when a source is selected. 557 // Ok button should only be enabled when a source is selected.
516 DCHECK(selection); 558 DCHECK(selection);
517 559
518 DesktopMediaID source; 560 DesktopMediaID source;
519 if (selection) 561 if (selection)
520 source = selection->source_id(); 562 source = selection->source_id();
521 563
564 if (audio_support_) {
565 Profile* profile =
566 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
567
568 GURL origin(web_contents_->GetLastCommittedURL().GetOrigin());
569
570 ContentSettingsPattern pattern =
571 ContentSettingsPattern::FromURLNoWildcard(origin);
572
573 ContentSetting result = checkbox_->checked()
574 ? ContentSetting::CONTENT_SETTING_ALLOW
575 : ContentSetting::CONTENT_SETTING_BLOCK;
576
577 HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting(
578 pattern, pattern,
579 ContentSettingsType::CONTENT_SETTINGS_TYPE_DESKTOP_AUDIO_SHARE,
580 std::string(), result);
581 }
582
522 if (parent_) 583 if (parent_)
523 parent_->NotifyDialogResult(source); 584 parent_->NotifyDialogResult(source);
524 585
525 // Return true to close the window. 586 // Return true to close the window.
526 return true; 587 return true;
527 } 588 }
528 589
529 void DesktopMediaPickerDialogView::DeleteDelegate() { 590 void DesktopMediaPickerDialogView::DeleteDelegate() {
530 // If the dialog is being closed then notify the parent about it. 591 // If the dialog is being closed then notify the parent about it.
531 if (parent_) 592 if (parent_)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 content::BrowserThread::PostTask( 660 content::BrowserThread::PostTask(
600 content::BrowserThread::UI, FROM_HERE, 661 content::BrowserThread::UI, FROM_HERE,
601 base::Bind(callback_, source)); 662 base::Bind(callback_, source));
602 callback_.Reset(); 663 callback_.Reset();
603 } 664 }
604 665
605 // static 666 // static
606 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { 667 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() {
607 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); 668 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews());
608 } 669 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698