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

Side by Side Diff: chrome/browser/ui/content_settings/content_setting_bubble_model.cc

Issue 588153003: Remove MediaSettingChangedInfobar and show latest state in bubble (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove redundant is_cam Created 6 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/content_settings/content_setting_bubble_model.h" 5 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/content_settings/content_settings_utils.h" 11 #include "chrome/browser/content_settings/content_settings_utils.h"
12 #include "chrome/browser/content_settings/cookie_settings.h" 12 #include "chrome/browser/content_settings/cookie_settings.h"
13 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 13 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
14 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" 14 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
15 #include "chrome/browser/favicon/favicon_tab_helper.h" 15 #include "chrome/browser/favicon/favicon_tab_helper.h"
16 #include "chrome/browser/infobars/infobar_service.h" 16 #include "chrome/browser/infobars/infobar_service.h"
17 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 17 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
18 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" 18 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" 20 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
21 #include "chrome/browser/ui/browser_navigator.h" 21 #include "chrome/browser/ui/browser_navigator.h"
22 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" 22 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h"
23 #include "chrome/browser/ui/content_settings/content_setting_bubble_model_delega te.h" 23 #include "chrome/browser/ui/content_settings/content_setting_bubble_model_delega te.h"
24 #include "chrome/browser/ui/content_settings/media_setting_changed_infobar_deleg ate.h"
25 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
27 #include "chrome/common/render_messages.h" 26 #include "chrome/common/render_messages.h"
28 #include "chrome/grit/generated_resources.h" 27 #include "chrome/grit/generated_resources.h"
29 #include "components/content_settings/core/common/content_settings.h" 28 #include "components/content_settings/core/common/content_settings.h"
30 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
31 #include "content/public/browser/render_frame_host.h" 30 #include "content/public/browser/render_frame_host.h"
32 #include "content/public/browser/render_process_host.h" 31 #include "content/public/browser/render_process_host.h"
33 #include "content/public/browser/render_view_host.h" 32 #include "content/public/browser/render_view_host.h"
34 #include "content/public/browser/user_metrics.h" 33 #include "content/public/browser/user_metrics.h"
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 Profile* profile); 558 Profile* profile);
560 559
561 virtual ~ContentSettingMediaStreamBubbleModel(); 560 virtual ~ContentSettingMediaStreamBubbleModel();
562 561
563 private: 562 private:
564 void SetTitle(); 563 void SetTitle();
565 // Sets the data for the radio buttons of the bubble. 564 // Sets the data for the radio buttons of the bubble.
566 void SetRadioGroup(); 565 void SetRadioGroup();
567 // Sets the data for the media menus of the bubble. 566 // Sets the data for the media menus of the bubble.
568 void SetMediaMenus(); 567 void SetMediaMenus();
568 void SetCustomLink();
569 // Updates the camera and microphone setting with the passed |setting|. 569 // Updates the camera and microphone setting with the passed |setting|.
570 void UpdateSettings(ContentSetting setting); 570 void UpdateSettings(ContentSetting setting);
571 // Updates the camera and microphone default device with the passed |type| 571 // Updates the camera and microphone default device with the passed |type|
572 // and device. 572 // and device.
573 void UpdateDefaultDeviceForType(content::MediaStreamType type, 573 void UpdateDefaultDeviceForType(content::MediaStreamType type,
574 const std::string& device); 574 const std::string& device);
575 575
576 // ContentSettingBubbleModel implementation. 576 // ContentSettingBubbleModel implementation.
577 virtual void OnRadioClicked(int radio_index) OVERRIDE; 577 virtual void OnRadioClicked(int radio_index) OVERRIDE;
578 virtual void OnMediaMenuClicked(content::MediaStreamType type, 578 virtual void OnMediaMenuClicked(content::MediaStreamType type,
(...skipping 18 matching lines...) Expand all
597 state_(TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED) { 597 state_(TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED) {
598 DCHECK(profile); 598 DCHECK(profile);
599 // Initialize the content settings associated with the individual radio 599 // Initialize the content settings associated with the individual radio
600 // buttons. 600 // buttons.
601 radio_item_setting_[0] = CONTENT_SETTING_ASK; 601 radio_item_setting_[0] = CONTENT_SETTING_ASK;
602 radio_item_setting_[1] = CONTENT_SETTING_BLOCK; 602 radio_item_setting_[1] = CONTENT_SETTING_BLOCK;
603 603
604 TabSpecificContentSettings* content_settings = 604 TabSpecificContentSettings* content_settings =
605 TabSpecificContentSettings::FromWebContents(web_contents); 605 TabSpecificContentSettings::FromWebContents(web_contents);
606 state_ = content_settings->GetMicrophoneCameraState(); 606 state_ = content_settings->GetMicrophoneCameraState();
607 DCHECK(state_ & (TabSpecificContentSettings::MICROPHONE_ACCESSED |
608 TabSpecificContentSettings::CAMERA_ACCESSED));
607 609
608 SetTitle(); 610 SetTitle();
609 SetRadioGroup(); 611 SetRadioGroup();
610 SetMediaMenus(); 612 SetMediaMenus();
613 SetCustomLink();
611 } 614 }
612 615
613 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() { 616 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() {
614 // On some platforms (e.g. MacOS X) it is possible to close a tab while the 617 // On some platforms (e.g. MacOS X) it is possible to close a tab while the
615 // media stream bubble is open. This resets the web contents to NULL. 618 // media stream bubble is open. This resets the web contents to NULL.
616 if (!web_contents()) 619 if (!web_contents())
617 return; 620 return;
618 621
619 bool media_setting_changed = false;
620 for (MediaMenuMap::const_iterator it = bubble_content().media_menus.begin(); 622 for (MediaMenuMap::const_iterator it = bubble_content().media_menus.begin();
621 it != bubble_content().media_menus.end(); ++it) { 623 it != bubble_content().media_menus.end(); ++it) {
622 if (it->second.selected_device.id != it->second.default_device.id) { 624 if (it->second.selected_device.id != it->second.default_device.id) {
623 UpdateDefaultDeviceForType(it->first, it->second.selected_device.id); 625 UpdateDefaultDeviceForType(it->first, it->second.selected_device.id);
624 media_setting_changed = true;
625 } 626 }
626 } 627 }
627 628
628 // Update the media settings if the radio button selection was changed. 629 // Update the media settings if the radio button selection was changed.
629 if (selected_item_ != bubble_content().radio_group.default_item) { 630 if (selected_item_ != bubble_content().radio_group.default_item) {
630 UpdateSettings(radio_item_setting_[selected_item_]); 631 UpdateSettings(radio_item_setting_[selected_item_]);
631 media_setting_changed = true;
632 }
633
634 // Trigger the reload infobar if the media setting has been changed.
635 if (media_setting_changed) {
636 MediaSettingChangedInfoBarDelegate::Create(
637 InfoBarService::FromWebContents(web_contents()));
638 } 632 }
639 } 633 }
640 634
641 void ContentSettingMediaStreamBubbleModel::SetTitle() { 635 void ContentSettingMediaStreamBubbleModel::SetTitle() {
636 DCHECK_NE(TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED, state_);
642 int title_id = 0; 637 int title_id = 0;
643 switch (state_) { 638 if (state_ & TabSpecificContentSettings::MICROPHONE_BLOCKED) {
644 case TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED: 639 title_id = (state_ & TabSpecificContentSettings::CAMERA_BLOCKED) ?
645 // If neither microphone nor camera stream was accessed, then there is no 640 IDS_MICROPHONE_CAMERA_BLOCKED : IDS_MICROPHONE_BLOCKED;
646 // icon didplayed in the omnibox and no settings bubble availbale. Hence 641 } else if (state_ & TabSpecificContentSettings::CAMERA_BLOCKED) {
647 // there is no title. 642 title_id = IDS_CAMERA_BLOCKED;
648 NOTREACHED(); 643 } else if (state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) {
649 return; 644 title_id = (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) ?
650 case TabSpecificContentSettings::MICROPHONE_ACCESSED: 645 IDS_MICROPHONE_CAMERA_ALLOWED : IDS_MICROPHONE_ACCESSED;
651 title_id = IDS_MICROPHONE_ACCESSED; 646 } else if (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) {
652 break; 647 title_id = IDS_CAMERA_ACCESSED;
653 case TabSpecificContentSettings::CAMERA_ACCESSED:
654 title_id = IDS_CAMERA_ACCESSED;
655 break;
656 case TabSpecificContentSettings::MICROPHONE_CAMERA_ACCESSED:
657 title_id = IDS_MICROPHONE_CAMERA_ALLOWED;
658 break;
659 case TabSpecificContentSettings::MICROPHONE_BLOCKED:
660 title_id = IDS_MICROPHONE_BLOCKED;
661 break;
662 case TabSpecificContentSettings::CAMERA_BLOCKED:
663 title_id = IDS_CAMERA_BLOCKED;
664 break;
665 case TabSpecificContentSettings::MICROPHONE_CAMERA_BLOCKED:
666 title_id = IDS_MICROPHONE_CAMERA_BLOCKED;
667 break;
668 } 648 }
669 set_title(l10n_util::GetStringUTF8(title_id)); 649 set_title(l10n_util::GetStringUTF8(title_id));
670 } 650 }
671 651
672 void ContentSettingMediaStreamBubbleModel::SetRadioGroup() { 652 void ContentSettingMediaStreamBubbleModel::SetRadioGroup() {
673 TabSpecificContentSettings* content_settings = 653 TabSpecificContentSettings* content_settings =
674 TabSpecificContentSettings::FromWebContents(web_contents()); 654 TabSpecificContentSettings::FromWebContents(web_contents());
675 GURL url = content_settings->media_stream_access_origin(); 655 GURL url = content_settings->media_stream_access_origin();
676 RadioGroup radio_group; 656 RadioGroup radio_group;
677 radio_group.url = url; 657 radio_group.url = url;
678 658
679 base::string16 display_host_utf16; 659 base::string16 display_host_utf16;
680 net::AppendFormattedHost( 660 net::AppendFormattedHost(
681 url, 661 url,
682 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages), 662 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages),
683 &display_host_utf16); 663 &display_host_utf16);
684 std::string display_host(base::UTF16ToUTF8(display_host_utf16)); 664 std::string display_host(base::UTF16ToUTF8(display_host_utf16));
685 if (display_host.empty()) 665 if (display_host.empty())
686 display_host = url.spec(); 666 display_host = url.spec();
687 667
668 const bool is_mic = state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED;
669 const bool is_cam = state_ & TabSpecificContentSettings::CAMERA_ACCESSED;
670 DCHECK(is_mic || is_cam);
688 int radio_allow_label_id = 0; 671 int radio_allow_label_id = 0;
689 int radio_block_label_id = 0; 672 int radio_block_label_id = 0;
690 switch (state_) { 673 if (state_ & (TabSpecificContentSettings::MICROPHONE_BLOCKED |
691 case TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED: 674 TabSpecificContentSettings::CAMERA_BLOCKED)) {
692 NOTREACHED(); 675 if (url.SchemeIsSecure()) {
693 return; 676 radio_item_setting_[0] = CONTENT_SETTING_ALLOW;
694 case TabSpecificContentSettings::MICROPHONE_ACCESSED: 677 if (is_mic && is_cam)
678 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ALLOW;
679 else if (is_mic)
680 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_ALLOW;
681 else
682 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ALLOW;
683 } else {
684 if (is_mic && is_cam)
685 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ASK;
686 else if (is_mic)
687 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_ASK;
688 else
689 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ASK;
690 }
691 } else {
692 if (is_mic && is_cam) {
693 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION;
694 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_BLOCK;
695 } else if (is_mic) {
695 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_NO_ACTION; 696 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_NO_ACTION;
696 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_BLOCK; 697 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_BLOCK;
697 selected_item_ = 0; 698 } else {
698 break;
699 case TabSpecificContentSettings::CAMERA_ACCESSED:
700 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_CAMERA_NO_ACTION; 699 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_CAMERA_NO_ACTION;
701 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_CAMERA_BLOCK; 700 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_CAMERA_BLOCK;
702 selected_item_ = 0; 701 }
703 break;
704 case TabSpecificContentSettings::MICROPHONE_CAMERA_ACCESSED:
705 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION;
706 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_BLOCK;
707 selected_item_ = 0;
708 break;
709 case TabSpecificContentSettings::MICROPHONE_BLOCKED:
710 if (url.SchemeIsSecure()) {
711 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_ALLOW;
712 radio_item_setting_[0] = CONTENT_SETTING_ALLOW;
713 } else {
714 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_ASK;
715 }
716
717 radio_block_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_NO_ACTION;
718 selected_item_ = 1;
719 break;
720 case TabSpecificContentSettings::CAMERA_BLOCKED:
721 if (url.SchemeIsSecure()) {
722 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ALLOW;
723 radio_item_setting_[0] = CONTENT_SETTING_ALLOW;
724 } else {
725 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ASK;
726 }
727
728 radio_block_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_NO_ACTION;
729 selected_item_ = 1;
730 break;
731 case TabSpecificContentSettings::MICROPHONE_CAMERA_BLOCKED:
732 if (url.SchemeIsSecure()) {
733 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ALLOW;
734 radio_item_setting_[0] = CONTENT_SETTING_ALLOW;
735 } else {
736 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ASK;
737 }
738
739 radio_block_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION;
740 selected_item_ = 1;
741 break;
742 } 702 }
703 const bool is_blocked =
704 selected_item_ =
Bernhard Bauer 2014/09/25 16:18:27 Indent this four spaces.
robwu 2014/09/25 19:15:53 Fixed.
705 (is_mic && content_settings->IsContentBlocked(
706 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) ||
707 (is_cam && content_settings->IsContentBlocked(
708 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
709 selected_item_ = is_blocked ? 1 : 0;
743 710
744 std::string radio_allow_label = l10n_util::GetStringFUTF8( 711 std::string radio_allow_label = l10n_util::GetStringFUTF8(
745 radio_allow_label_id, base::UTF8ToUTF16(display_host)); 712 radio_allow_label_id, base::UTF8ToUTF16(display_host));
746 std::string radio_block_label = 713 std::string radio_block_label =
747 l10n_util::GetStringUTF8(radio_block_label_id); 714 l10n_util::GetStringUTF8(radio_block_label_id);
748 715
749 radio_group.default_item = selected_item_; 716 radio_group.default_item = selected_item_;
750 radio_group.radio_items.push_back(radio_allow_label); 717 radio_group.radio_items.push_back(radio_allow_label);
751 radio_group.radio_items.push_back(radio_block_label); 718 radio_group.radio_items.push_back(radio_block_label);
752 719
(...skipping 10 matching lines...) Expand all
763 TabSpecificContentSettings::FromWebContents(web_contents()); 730 TabSpecificContentSettings::FromWebContents(web_contents());
764 // The same patterns must be used as in other places (e.g. the infobar) in 731 // The same patterns must be used as in other places (e.g. the infobar) in
765 // order to override the existing rule. Otherwise a new rule is created. 732 // order to override the existing rule. Otherwise a new rule is created.
766 // TODO(markusheintz): Extract to a helper so that there is only a single 733 // TODO(markusheintz): Extract to a helper so that there is only a single
767 // place to touch. 734 // place to touch.
768 ContentSettingsPattern primary_pattern = 735 ContentSettingsPattern primary_pattern =
769 ContentSettingsPattern::FromURLNoWildcard( 736 ContentSettingsPattern::FromURLNoWildcard(
770 tab_content_settings->media_stream_access_origin()); 737 tab_content_settings->media_stream_access_origin());
771 ContentSettingsPattern secondary_pattern = 738 ContentSettingsPattern secondary_pattern =
772 ContentSettingsPattern::Wildcard(); 739 ContentSettingsPattern::Wildcard();
773 if (state_ == TabSpecificContentSettings::MICROPHONE_ACCESSED || 740 if (state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) {
774 state_ == TabSpecificContentSettings::MICROPHONE_CAMERA_ACCESSED ||
775 state_ == TabSpecificContentSettings::MICROPHONE_BLOCKED ||
776 state_ == TabSpecificContentSettings::MICROPHONE_CAMERA_BLOCKED) {
777 content_settings->SetContentSetting( 741 content_settings->SetContentSetting(
778 primary_pattern, secondary_pattern, 742 primary_pattern, secondary_pattern,
779 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting); 743 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting);
780 } 744 }
781 if (state_ == TabSpecificContentSettings::CAMERA_ACCESSED || 745 if (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) {
782 state_ == TabSpecificContentSettings::MICROPHONE_CAMERA_ACCESSED ||
783 state_ == TabSpecificContentSettings::CAMERA_BLOCKED ||
784 state_ == TabSpecificContentSettings::MICROPHONE_CAMERA_BLOCKED) {
785 content_settings->SetContentSetting( 746 content_settings->SetContentSetting(
786 primary_pattern, secondary_pattern, 747 primary_pattern, secondary_pattern,
787 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting); 748 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting);
788 } 749 }
789 } 750 }
790 } 751 }
791 752
792 void ContentSettingMediaStreamBubbleModel::UpdateDefaultDeviceForType( 753 void ContentSettingMediaStreamBubbleModel::UpdateDefaultDeviceForType(
793 content::MediaStreamType type, 754 content::MediaStreamType type,
794 const std::string& device) { 755 const std::string& device) {
(...skipping 14 matching lines...) Expand all
809 const std::string& requested_camera = 770 const std::string& requested_camera =
810 content_settings->media_stream_requested_video_device(); 771 content_settings->media_stream_requested_video_device();
811 772
812 // Add microphone menu. 773 // Add microphone menu.
813 PrefService* prefs = profile()->GetPrefs(); 774 PrefService* prefs = profile()->GetPrefs();
814 MediaCaptureDevicesDispatcher* dispatcher = 775 MediaCaptureDevicesDispatcher* dispatcher =
815 MediaCaptureDevicesDispatcher::GetInstance(); 776 MediaCaptureDevicesDispatcher::GetInstance();
816 const content::MediaStreamDevices& microphones = 777 const content::MediaStreamDevices& microphones =
817 dispatcher->GetAudioCaptureDevices(); 778 dispatcher->GetAudioCaptureDevices();
818 779
819 bool show_mic_menu = 780 if (state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) {
820 (state_ == TabSpecificContentSettings::MICROPHONE_ACCESSED ||
821 state_ == TabSpecificContentSettings::MICROPHONE_CAMERA_ACCESSED ||
822 state_ == TabSpecificContentSettings::MICROPHONE_BLOCKED ||
823 state_ == TabSpecificContentSettings::MICROPHONE_CAMERA_BLOCKED);
824 bool show_camera_menu =
825 (state_ == TabSpecificContentSettings::CAMERA_ACCESSED ||
826 state_ == TabSpecificContentSettings::MICROPHONE_CAMERA_ACCESSED ||
827 state_ == TabSpecificContentSettings::CAMERA_BLOCKED ||
828 state_ == TabSpecificContentSettings::MICROPHONE_CAMERA_BLOCKED);
829 DCHECK(show_mic_menu || show_camera_menu);
830
831 if (show_mic_menu) {
832 MediaMenu mic_menu; 781 MediaMenu mic_menu;
833 mic_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_MIC_LABEL); 782 mic_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_MIC_LABEL);
834 if (!microphones.empty()) { 783 if (!microphones.empty()) {
835 std::string preferred_mic; 784 std::string preferred_mic;
836 if (requested_microphone.empty()) { 785 if (requested_microphone.empty()) {
837 preferred_mic = prefs->GetString(prefs::kDefaultAudioCaptureDevice); 786 preferred_mic = prefs->GetString(prefs::kDefaultAudioCaptureDevice);
838 mic_menu.disabled = false; 787 mic_menu.disabled = false;
839 } else { 788 } else {
840 // Set the |disabled| to true in order to disable the device selection 789 // Set the |disabled| to true in order to disable the device selection
841 // menu on the media settings bubble. This must be done if the website 790 // menu on the media settings bubble. This must be done if the website
842 // manages the microphone devices itself. 791 // manages the microphone devices itself.
843 preferred_mic = requested_microphone; 792 preferred_mic = requested_microphone;
844 mic_menu.disabled = true; 793 mic_menu.disabled = true;
845 } 794 }
846 795
847 mic_menu.default_device = GetMediaDeviceById(preferred_mic, microphones); 796 mic_menu.default_device = GetMediaDeviceById(preferred_mic, microphones);
848 mic_menu.selected_device = mic_menu.default_device; 797 mic_menu.selected_device = mic_menu.default_device;
849 } 798 }
850 add_media_menu(content::MEDIA_DEVICE_AUDIO_CAPTURE, mic_menu); 799 add_media_menu(content::MEDIA_DEVICE_AUDIO_CAPTURE, mic_menu);
851 } 800 }
852 801
853 if (show_camera_menu) { 802 if (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) {
854 const content::MediaStreamDevices& cameras = 803 const content::MediaStreamDevices& cameras =
855 dispatcher->GetVideoCaptureDevices(); 804 dispatcher->GetVideoCaptureDevices();
856 MediaMenu camera_menu; 805 MediaMenu camera_menu;
857 camera_menu.label = 806 camera_menu.label =
858 l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_CAMERA_LABEL); 807 l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_CAMERA_LABEL);
859 if (!cameras.empty()) { 808 if (!cameras.empty()) {
860 std::string preferred_camera; 809 std::string preferred_camera;
861 if (requested_camera.empty()) { 810 if (requested_camera.empty()) {
862 preferred_camera = prefs->GetString(prefs::kDefaultVideoCaptureDevice); 811 preferred_camera = prefs->GetString(prefs::kDefaultVideoCaptureDevice);
863 camera_menu.disabled = false; 812 camera_menu.disabled = false;
864 } else { 813 } else {
865 // Disable the menu since the website is managing the camera devices 814 // Disable the menu since the website is managing the camera devices
866 // itself. 815 // itself.
867 preferred_camera = requested_camera; 816 preferred_camera = requested_camera;
868 camera_menu.disabled = true; 817 camera_menu.disabled = true;
869 } 818 }
870 819
871 camera_menu.default_device = 820 camera_menu.default_device =
872 GetMediaDeviceById(preferred_camera, cameras); 821 GetMediaDeviceById(preferred_camera, cameras);
873 camera_menu.selected_device = camera_menu.default_device; 822 camera_menu.selected_device = camera_menu.default_device;
874 } 823 }
875 add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, camera_menu); 824 add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, camera_menu);
876 } 825 }
877 } 826 }
878 827
828 void ContentSettingMediaStreamBubbleModel::SetCustomLink() {
829 TabSpecificContentSettings* content_settings =
830 TabSpecificContentSettings::FromWebContents(web_contents());
831 if (content_settings->IsMicrophoneCameraStateChanged()) {
832 set_custom_link(l10n_util::GetStringUTF8(
833 IDS_MEDIASTREAM_SETTING_CHANGED_MESSAGE));
834 }
835 }
836
879 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) { 837 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) {
880 selected_item_ = radio_index; 838 selected_item_ = radio_index;
881 } 839 }
882 840
883 void ContentSettingMediaStreamBubbleModel::OnMediaMenuClicked( 841 void ContentSettingMediaStreamBubbleModel::OnMediaMenuClicked(
884 content::MediaStreamType type, 842 content::MediaStreamType type,
885 const std::string& selected_device_id) { 843 const std::string& selected_device_id) {
886 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || 844 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE ||
887 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); 845 type == content::MEDIA_DEVICE_VIDEO_CAPTURE);
888 DCHECK_EQ(1U, bubble_content().media_menus.count(type)); 846 DCHECK_EQ(1U, bubble_content().media_menus.count(type));
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { 1280 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) {
1323 DCHECK_EQ(web_contents_, 1281 DCHECK_EQ(web_contents_,
1324 content::Source<WebContents>(source).ptr()); 1282 content::Source<WebContents>(source).ptr());
1325 web_contents_ = NULL; 1283 web_contents_ = NULL;
1326 } else { 1284 } else {
1327 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); 1285 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
1328 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); 1286 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr());
1329 profile_ = NULL; 1287 profile_ = NULL;
1330 } 1288 }
1331 } 1289 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698