OLD | NEW |
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 Loading... |
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 Loading... |
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 bool is_mic = (state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) != 0; |
| 669 bool is_cam = (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) != 0; |
| 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 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ALLOW; |
| 678 if (is_mic) |
| 679 radio_allow_label_id = is_cam ? |
| 680 IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ALLOW : |
| 681 IDS_BLOCKED_MEDIASTREAM_MIC_ALLOW; |
| 682 } else { |
| 683 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ASK; |
| 684 if (is_mic) |
| 685 radio_allow_label_id = is_cam ? |
| 686 IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ASK : |
| 687 IDS_BLOCKED_MEDIASTREAM_MIC_ASK; |
| 688 } |
| 689 radio_block_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_NO_ACTION; |
| 690 if (is_mic) |
| 691 radio_block_label_id = is_cam ? |
| 692 IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION : |
| 693 IDS_BLOCKED_MEDIASTREAM_MIC_NO_ACTION; |
| 694 } else { |
| 695 if (is_mic && is_cam) { |
| 696 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION; |
| 697 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_BLOCK; |
| 698 } else if (is_mic) { |
695 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_NO_ACTION; | 699 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_NO_ACTION; |
696 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_BLOCK; | 700 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_BLOCK; |
697 selected_item_ = 0; | 701 } else { |
698 break; | |
699 case TabSpecificContentSettings::CAMERA_ACCESSED: | |
700 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_CAMERA_NO_ACTION; | 702 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_CAMERA_NO_ACTION; |
701 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_CAMERA_BLOCK; | 703 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_CAMERA_BLOCK; |
702 selected_item_ = 0; | 704 } |
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 } | 705 } |
| 706 selected_item_ = |
| 707 (is_mic && content_settings->IsContentBlocked( |
| 708 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) || |
| 709 (is_cam && content_settings->IsContentBlocked( |
| 710 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) ? 1 : 0; |
743 | 711 |
744 std::string radio_allow_label = l10n_util::GetStringFUTF8( | 712 std::string radio_allow_label = l10n_util::GetStringFUTF8( |
745 radio_allow_label_id, base::UTF8ToUTF16(display_host)); | 713 radio_allow_label_id, base::UTF8ToUTF16(display_host)); |
746 std::string radio_block_label = | 714 std::string radio_block_label = |
747 l10n_util::GetStringUTF8(radio_block_label_id); | 715 l10n_util::GetStringUTF8(radio_block_label_id); |
748 | 716 |
749 radio_group.default_item = selected_item_; | 717 radio_group.default_item = selected_item_; |
750 radio_group.radio_items.push_back(radio_allow_label); | 718 radio_group.radio_items.push_back(radio_allow_label); |
751 radio_group.radio_items.push_back(radio_block_label); | 719 radio_group.radio_items.push_back(radio_block_label); |
752 | 720 |
(...skipping 10 matching lines...) Expand all Loading... |
763 TabSpecificContentSettings::FromWebContents(web_contents()); | 731 TabSpecificContentSettings::FromWebContents(web_contents()); |
764 // The same patterns must be used as in other places (e.g. the infobar) in | 732 // 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. | 733 // 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 | 734 // TODO(markusheintz): Extract to a helper so that there is only a single |
767 // place to touch. | 735 // place to touch. |
768 ContentSettingsPattern primary_pattern = | 736 ContentSettingsPattern primary_pattern = |
769 ContentSettingsPattern::FromURLNoWildcard( | 737 ContentSettingsPattern::FromURLNoWildcard( |
770 tab_content_settings->media_stream_access_origin()); | 738 tab_content_settings->media_stream_access_origin()); |
771 ContentSettingsPattern secondary_pattern = | 739 ContentSettingsPattern secondary_pattern = |
772 ContentSettingsPattern::Wildcard(); | 740 ContentSettingsPattern::Wildcard(); |
773 if (state_ == TabSpecificContentSettings::MICROPHONE_ACCESSED || | 741 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( | 742 content_settings->SetContentSetting( |
778 primary_pattern, secondary_pattern, | 743 primary_pattern, secondary_pattern, |
779 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting); | 744 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting); |
780 } | 745 } |
781 if (state_ == TabSpecificContentSettings::CAMERA_ACCESSED || | 746 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( | 747 content_settings->SetContentSetting( |
786 primary_pattern, secondary_pattern, | 748 primary_pattern, secondary_pattern, |
787 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting); | 749 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting); |
788 } | 750 } |
789 } | 751 } |
790 } | 752 } |
791 | 753 |
792 void ContentSettingMediaStreamBubbleModel::UpdateDefaultDeviceForType( | 754 void ContentSettingMediaStreamBubbleModel::UpdateDefaultDeviceForType( |
793 content::MediaStreamType type, | 755 content::MediaStreamType type, |
794 const std::string& device) { | 756 const std::string& device) { |
(...skipping 14 matching lines...) Expand all Loading... |
809 const std::string& requested_camera = | 771 const std::string& requested_camera = |
810 content_settings->media_stream_requested_video_device(); | 772 content_settings->media_stream_requested_video_device(); |
811 | 773 |
812 // Add microphone menu. | 774 // Add microphone menu. |
813 PrefService* prefs = profile()->GetPrefs(); | 775 PrefService* prefs = profile()->GetPrefs(); |
814 MediaCaptureDevicesDispatcher* dispatcher = | 776 MediaCaptureDevicesDispatcher* dispatcher = |
815 MediaCaptureDevicesDispatcher::GetInstance(); | 777 MediaCaptureDevicesDispatcher::GetInstance(); |
816 const content::MediaStreamDevices& microphones = | 778 const content::MediaStreamDevices& microphones = |
817 dispatcher->GetAudioCaptureDevices(); | 779 dispatcher->GetAudioCaptureDevices(); |
818 | 780 |
819 bool show_mic_menu = | 781 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; | 782 MediaMenu mic_menu; |
833 mic_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_MIC_LABEL); | 783 mic_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_MIC_LABEL); |
834 if (!microphones.empty()) { | 784 if (!microphones.empty()) { |
835 std::string preferred_mic; | 785 std::string preferred_mic; |
836 if (requested_microphone.empty()) { | 786 if (requested_microphone.empty()) { |
837 preferred_mic = prefs->GetString(prefs::kDefaultAudioCaptureDevice); | 787 preferred_mic = prefs->GetString(prefs::kDefaultAudioCaptureDevice); |
838 mic_menu.disabled = false; | 788 mic_menu.disabled = false; |
839 } else { | 789 } else { |
840 // Set the |disabled| to true in order to disable the device selection | 790 // 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 | 791 // menu on the media settings bubble. This must be done if the website |
842 // manages the microphone devices itself. | 792 // manages the microphone devices itself. |
843 preferred_mic = requested_microphone; | 793 preferred_mic = requested_microphone; |
844 mic_menu.disabled = true; | 794 mic_menu.disabled = true; |
845 } | 795 } |
846 | 796 |
847 mic_menu.default_device = GetMediaDeviceById(preferred_mic, microphones); | 797 mic_menu.default_device = GetMediaDeviceById(preferred_mic, microphones); |
848 mic_menu.selected_device = mic_menu.default_device; | 798 mic_menu.selected_device = mic_menu.default_device; |
849 } | 799 } |
850 add_media_menu(content::MEDIA_DEVICE_AUDIO_CAPTURE, mic_menu); | 800 add_media_menu(content::MEDIA_DEVICE_AUDIO_CAPTURE, mic_menu); |
851 } | 801 } |
852 | 802 |
853 if (show_camera_menu) { | 803 if (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) { |
854 const content::MediaStreamDevices& cameras = | 804 const content::MediaStreamDevices& cameras = |
855 dispatcher->GetVideoCaptureDevices(); | 805 dispatcher->GetVideoCaptureDevices(); |
856 MediaMenu camera_menu; | 806 MediaMenu camera_menu; |
857 camera_menu.label = | 807 camera_menu.label = |
858 l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_CAMERA_LABEL); | 808 l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_CAMERA_LABEL); |
859 if (!cameras.empty()) { | 809 if (!cameras.empty()) { |
860 std::string preferred_camera; | 810 std::string preferred_camera; |
861 if (requested_camera.empty()) { | 811 if (requested_camera.empty()) { |
862 preferred_camera = prefs->GetString(prefs::kDefaultVideoCaptureDevice); | 812 preferred_camera = prefs->GetString(prefs::kDefaultVideoCaptureDevice); |
863 camera_menu.disabled = false; | 813 camera_menu.disabled = false; |
864 } else { | 814 } else { |
865 // Disable the menu since the website is managing the camera devices | 815 // Disable the menu since the website is managing the camera devices |
866 // itself. | 816 // itself. |
867 preferred_camera = requested_camera; | 817 preferred_camera = requested_camera; |
868 camera_menu.disabled = true; | 818 camera_menu.disabled = true; |
869 } | 819 } |
870 | 820 |
871 camera_menu.default_device = | 821 camera_menu.default_device = |
872 GetMediaDeviceById(preferred_camera, cameras); | 822 GetMediaDeviceById(preferred_camera, cameras); |
873 camera_menu.selected_device = camera_menu.default_device; | 823 camera_menu.selected_device = camera_menu.default_device; |
874 } | 824 } |
875 add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, camera_menu); | 825 add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, camera_menu); |
876 } | 826 } |
877 } | 827 } |
878 | 828 |
| 829 void ContentSettingMediaStreamBubbleModel::SetCustomLink() { |
| 830 TabSpecificContentSettings* content_settings = |
| 831 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 832 if (content_settings->IsMicrophoneCameraStateChanged()) { |
| 833 set_custom_link(l10n_util::GetStringUTF8( |
| 834 IDS_MEDIASTREAM_SETTING_CHANGED_MESSAGE)); |
| 835 } |
| 836 } |
| 837 |
879 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) { | 838 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) { |
880 selected_item_ = radio_index; | 839 selected_item_ = radio_index; |
881 } | 840 } |
882 | 841 |
883 void ContentSettingMediaStreamBubbleModel::OnMediaMenuClicked( | 842 void ContentSettingMediaStreamBubbleModel::OnMediaMenuClicked( |
884 content::MediaStreamType type, | 843 content::MediaStreamType type, |
885 const std::string& selected_device_id) { | 844 const std::string& selected_device_id) { |
886 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || | 845 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || |
887 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); | 846 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); |
888 DCHECK_EQ(1U, bubble_content().media_menus.count(type)); | 847 DCHECK_EQ(1U, bubble_content().media_menus.count(type)); |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 1281 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
1323 DCHECK_EQ(web_contents_, | 1282 DCHECK_EQ(web_contents_, |
1324 content::Source<WebContents>(source).ptr()); | 1283 content::Source<WebContents>(source).ptr()); |
1325 web_contents_ = NULL; | 1284 web_contents_ = NULL; |
1326 } else { | 1285 } else { |
1327 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 1286 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
1328 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 1287 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
1329 profile_ = NULL; | 1288 profile_ = NULL; |
1330 } | 1289 } |
1331 } | 1290 } |
OLD | NEW |