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/media/media_stream_capture_indicator.h" | |
18 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 19 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" | 21 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" |
21 #include "chrome/browser/ui/browser_navigator.h" | 22 #include "chrome/browser/ui/browser_navigator.h" |
22 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" | 23 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" |
23 #include "chrome/browser/ui/content_settings/content_setting_bubble_model_delega te.h" | 24 #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" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
27 #include "chrome/common/render_messages.h" | 27 #include "chrome/common/render_messages.h" |
28 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
29 #include "components/content_settings/core/common/content_settings.h" | 29 #include "components/content_settings/core/common/content_settings.h" |
30 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
31 #include "content/public/browser/render_frame_host.h" | 31 #include "content/public/browser/render_frame_host.h" |
32 #include "content/public/browser/render_process_host.h" | 32 #include "content/public/browser/render_process_host.h" |
33 #include "content/public/browser/render_view_host.h" | 33 #include "content/public/browser/render_view_host.h" |
34 #include "content/public/browser/user_metrics.h" | 34 #include "content/public/browser/user_metrics.h" |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 Profile* profile); | 559 Profile* profile); |
560 | 560 |
561 virtual ~ContentSettingMediaStreamBubbleModel(); | 561 virtual ~ContentSettingMediaStreamBubbleModel(); |
562 | 562 |
563 private: | 563 private: |
564 void SetTitle(); | 564 void SetTitle(); |
565 // Sets the data for the radio buttons of the bubble. | 565 // Sets the data for the radio buttons of the bubble. |
566 void SetRadioGroup(); | 566 void SetRadioGroup(); |
567 // Sets the data for the media menus of the bubble. | 567 // Sets the data for the media menus of the bubble. |
568 void SetMediaMenus(); | 568 void SetMediaMenus(); |
569 void SetCustomLink(); | |
569 // Updates the camera and microphone setting with the passed |setting|. | 570 // Updates the camera and microphone setting with the passed |setting|. |
570 void UpdateSettings(ContentSetting setting); | 571 void UpdateSettings(ContentSetting setting); |
571 // Updates the camera and microphone default device with the passed |type| | 572 // Updates the camera and microphone default device with the passed |type| |
572 // and device. | 573 // and device. |
573 void UpdateDefaultDeviceForType(content::MediaStreamType type, | 574 void UpdateDefaultDeviceForType(content::MediaStreamType type, |
574 const std::string& device); | 575 const std::string& device); |
575 | 576 |
576 // ContentSettingBubbleModel implementation. | 577 // ContentSettingBubbleModel implementation. |
577 virtual void OnRadioClicked(int radio_index) OVERRIDE; | 578 virtual void OnRadioClicked(int radio_index) OVERRIDE; |
578 virtual void OnMediaMenuClicked(content::MediaStreamType type, | 579 virtual void OnMediaMenuClicked(content::MediaStreamType type, |
(...skipping 22 matching lines...) Expand all Loading... | |
601 radio_item_setting_[0] = CONTENT_SETTING_ASK; | 602 radio_item_setting_[0] = CONTENT_SETTING_ASK; |
602 radio_item_setting_[1] = CONTENT_SETTING_BLOCK; | 603 radio_item_setting_[1] = CONTENT_SETTING_BLOCK; |
603 | 604 |
604 TabSpecificContentSettings* content_settings = | 605 TabSpecificContentSettings* content_settings = |
605 TabSpecificContentSettings::FromWebContents(web_contents); | 606 TabSpecificContentSettings::FromWebContents(web_contents); |
606 state_ = content_settings->GetMicrophoneCameraState(); | 607 state_ = content_settings->GetMicrophoneCameraState(); |
607 | 608 |
608 SetTitle(); | 609 SetTitle(); |
609 SetRadioGroup(); | 610 SetRadioGroup(); |
610 SetMediaMenus(); | 611 SetMediaMenus(); |
612 SetCustomLink(); | |
611 } | 613 } |
612 | 614 |
613 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() { | 615 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() { |
614 // On some platforms (e.g. MacOS X) it is possible to close a tab while the | 616 // 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. | 617 // media stream bubble is open. This resets the web contents to NULL. |
616 if (!web_contents()) | 618 if (!web_contents()) |
617 return; | 619 return; |
618 | 620 |
619 bool media_setting_changed = false; | |
620 for (MediaMenuMap::const_iterator it = bubble_content().media_menus.begin(); | 621 for (MediaMenuMap::const_iterator it = bubble_content().media_menus.begin(); |
621 it != bubble_content().media_menus.end(); ++it) { | 622 it != bubble_content().media_menus.end(); ++it) { |
622 if (it->second.selected_device.id != it->second.default_device.id) { | 623 if (it->second.selected_device.id != it->second.default_device.id) { |
623 UpdateDefaultDeviceForType(it->first, it->second.selected_device.id); | 624 UpdateDefaultDeviceForType(it->first, it->second.selected_device.id); |
624 media_setting_changed = true; | |
625 } | 625 } |
626 } | 626 } |
627 | 627 |
628 // Update the media settings if the radio button selection was changed. | 628 // Update the media settings if the radio button selection was changed. |
629 if (selected_item_ != bubble_content().radio_group.default_item) { | 629 if (selected_item_ != bubble_content().radio_group.default_item) { |
630 UpdateSettings(radio_item_setting_[selected_item_]); | 630 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 } | 631 } |
639 } | 632 } |
640 | 633 |
641 void ContentSettingMediaStreamBubbleModel::SetTitle() { | 634 void ContentSettingMediaStreamBubbleModel::SetTitle() { |
642 int title_id = 0; | 635 int title_id = 0; |
643 switch (state_) { | 636 switch (state_) { |
644 case TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED: | 637 case TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED: |
645 // If neither microphone nor camera stream was accessed, then there is no | 638 // If neither microphone nor camera stream was accessed, then there is no |
646 // icon didplayed in the omnibox and no settings bubble availbale. Hence | 639 // icon didplayed in the omnibox and no settings bubble availbale. Hence |
647 // there is no title. | 640 // there is no title. |
(...skipping 30 matching lines...) Expand all Loading... | |
678 | 671 |
679 base::string16 display_host_utf16; | 672 base::string16 display_host_utf16; |
680 net::AppendFormattedHost( | 673 net::AppendFormattedHost( |
681 url, | 674 url, |
682 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages), | 675 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages), |
683 &display_host_utf16); | 676 &display_host_utf16); |
684 std::string display_host(base::UTF16ToUTF8(display_host_utf16)); | 677 std::string display_host(base::UTF16ToUTF8(display_host_utf16)); |
685 if (display_host.empty()) | 678 if (display_host.empty()) |
686 display_host = url.spec(); | 679 display_host = url.spec(); |
687 | 680 |
681 const bool is_mic_blocked = content_settings->IsContentBlocked( | |
682 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | |
683 const bool is_cam_blocked = content_settings->IsContentBlocked( | |
684 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | |
688 int radio_allow_label_id = 0; | 685 int radio_allow_label_id = 0; |
689 int radio_block_label_id = 0; | 686 int radio_block_label_id = 0; |
690 switch (state_) { | 687 switch (state_) { |
691 case TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED: | 688 case TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED: |
692 NOTREACHED(); | 689 NOTREACHED(); |
693 return; | 690 return; |
694 case TabSpecificContentSettings::MICROPHONE_ACCESSED: | 691 case TabSpecificContentSettings::MICROPHONE_ACCESSED: |
695 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_NO_ACTION; | 692 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_NO_ACTION; |
696 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_BLOCK; | 693 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_BLOCK; |
697 selected_item_ = 0; | 694 selected_item_ = is_mic_blocked ? 1 : 0; |
698 break; | 695 break; |
699 case TabSpecificContentSettings::CAMERA_ACCESSED: | 696 case TabSpecificContentSettings::CAMERA_ACCESSED: |
700 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_CAMERA_NO_ACTION; | 697 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_CAMERA_NO_ACTION; |
701 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_CAMERA_BLOCK; | 698 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_CAMERA_BLOCK; |
702 selected_item_ = 0; | 699 selected_item_ = is_cam_blocked ? 1 : 0; |
703 break; | 700 break; |
704 case TabSpecificContentSettings::MICROPHONE_CAMERA_ACCESSED: | 701 case TabSpecificContentSettings::MICROPHONE_CAMERA_ACCESSED: |
705 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION; | 702 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION; |
706 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_BLOCK; | 703 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_BLOCK; |
707 selected_item_ = 0; | 704 selected_item_ = is_mic_blocked || is_cam_blocked ? 1 : 0; |
708 break; | 705 break; |
709 case TabSpecificContentSettings::MICROPHONE_BLOCKED: | 706 case TabSpecificContentSettings::MICROPHONE_BLOCKED: |
710 if (url.SchemeIsSecure()) { | 707 if (url.SchemeIsSecure()) { |
711 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_ALLOW; | 708 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_ALLOW; |
712 radio_item_setting_[0] = CONTENT_SETTING_ALLOW; | 709 radio_item_setting_[0] = CONTENT_SETTING_ALLOW; |
713 } else { | 710 } else { |
714 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_ASK; | 711 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_ASK; |
715 } | 712 } |
716 | 713 |
717 radio_block_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_NO_ACTION; | 714 radio_block_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_NO_ACTION; |
718 selected_item_ = 1; | 715 selected_item_ = is_mic_blocked ? 1 : 0; |
719 break; | 716 break; |
720 case TabSpecificContentSettings::CAMERA_BLOCKED: | 717 case TabSpecificContentSettings::CAMERA_BLOCKED: |
721 if (url.SchemeIsSecure()) { | 718 if (url.SchemeIsSecure()) { |
722 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ALLOW; | 719 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ALLOW; |
723 radio_item_setting_[0] = CONTENT_SETTING_ALLOW; | 720 radio_item_setting_[0] = CONTENT_SETTING_ALLOW; |
724 } else { | 721 } else { |
725 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ASK; | 722 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ASK; |
726 } | 723 } |
727 | 724 |
728 radio_block_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_NO_ACTION; | 725 radio_block_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_NO_ACTION; |
729 selected_item_ = 1; | 726 selected_item_ = is_cam_blocked ? 1 : 0; |
730 break; | 727 break; |
731 case TabSpecificContentSettings::MICROPHONE_CAMERA_BLOCKED: | 728 case TabSpecificContentSettings::MICROPHONE_CAMERA_BLOCKED: |
732 if (url.SchemeIsSecure()) { | 729 if (url.SchemeIsSecure()) { |
733 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ALLOW; | 730 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ALLOW; |
734 radio_item_setting_[0] = CONTENT_SETTING_ALLOW; | 731 radio_item_setting_[0] = CONTENT_SETTING_ALLOW; |
735 } else { | 732 } else { |
736 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ASK; | 733 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ASK; |
737 } | 734 } |
738 | 735 |
739 radio_block_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION; | 736 radio_block_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION; |
740 selected_item_ = 1; | 737 selected_item_ = is_mic_blocked || is_cam_blocked ? 1 : 0; |
741 break; | 738 break; |
742 } | 739 } |
743 | 740 |
744 std::string radio_allow_label = l10n_util::GetStringFUTF8( | 741 std::string radio_allow_label = l10n_util::GetStringFUTF8( |
745 radio_allow_label_id, base::UTF8ToUTF16(display_host)); | 742 radio_allow_label_id, base::UTF8ToUTF16(display_host)); |
746 std::string radio_block_label = | 743 std::string radio_block_label = |
747 l10n_util::GetStringUTF8(radio_block_label_id); | 744 l10n_util::GetStringUTF8(radio_block_label_id); |
748 | 745 |
749 radio_group.default_item = selected_item_; | 746 radio_group.default_item = selected_item_; |
750 radio_group.radio_items.push_back(radio_allow_label); | 747 radio_group.radio_items.push_back(radio_allow_label); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
869 } | 866 } |
870 | 867 |
871 camera_menu.default_device = | 868 camera_menu.default_device = |
872 GetMediaDeviceById(preferred_camera, cameras); | 869 GetMediaDeviceById(preferred_camera, cameras); |
873 camera_menu.selected_device = camera_menu.default_device; | 870 camera_menu.selected_device = camera_menu.default_device; |
874 } | 871 } |
875 add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, camera_menu); | 872 add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, camera_menu); |
876 } | 873 } |
877 } | 874 } |
878 | 875 |
876 void ContentSettingMediaStreamBubbleModel::SetCustomLink() { | |
Peter Kasting
2014/09/22 23:11:23
Nit: Instead of having this function set the link
| |
877 TabSpecificContentSettings* content_settings = | |
878 TabSpecificContentSettings::FromWebContents(web_contents()); | |
879 PrefService* prefs = profile()->GetPrefs(); | |
880 | |
881 if (content_settings->IsMicrophoneCameraStateChanged() || | |
882 ((prefs->GetString(prefs::kDefaultAudioCaptureDevice) != | |
883 content_settings->media_stream_selected_audio_device() || | |
884 prefs->GetString(prefs::kDefaultVideoCaptureDevice) != | |
885 content_settings->media_stream_selected_video_device()) && | |
886 MediaCaptureDevicesDispatcher::GetInstance()-> | |
887 GetMediaStreamCaptureIndicator()-> | |
888 IsCapturingUserMedia(web_contents()))) { | |
889 // TODO(robwu): Rename the next resource ID (remove "INFOBAR"). | |
Peter Kasting
2014/09/22 23:11:23
Why not go ahead and do that in this change? It's
robwu
2014/09/24 00:03:04
Done.
| |
890 set_custom_link(l10n_util::GetStringUTF8( | |
891 IDS_MEDIASTREAM_SETTING_CHANGED_INFOBAR_MESSAGE)); | |
Peter Kasting
2014/09/22 23:11:23
Nit: Bizarre indenting (should be 4)
robwu
2014/09/24 00:03:04
Done.
| |
892 } | |
893 } | |
894 | |
879 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) { | 895 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) { |
880 selected_item_ = radio_index; | 896 selected_item_ = radio_index; |
881 } | 897 } |
882 | 898 |
883 void ContentSettingMediaStreamBubbleModel::OnMediaMenuClicked( | 899 void ContentSettingMediaStreamBubbleModel::OnMediaMenuClicked( |
884 content::MediaStreamType type, | 900 content::MediaStreamType type, |
885 const std::string& selected_device_id) { | 901 const std::string& selected_device_id) { |
886 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || | 902 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || |
887 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); | 903 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); |
888 DCHECK_EQ(1U, bubble_content().media_menus.count(type)); | 904 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) { | 1338 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
1323 DCHECK_EQ(web_contents_, | 1339 DCHECK_EQ(web_contents_, |
1324 content::Source<WebContents>(source).ptr()); | 1340 content::Source<WebContents>(source).ptr()); |
1325 web_contents_ = NULL; | 1341 web_contents_ = NULL; |
1326 } else { | 1342 } else { |
1327 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 1343 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
1328 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 1344 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
1329 profile_ = NULL; | 1345 profile_ = NULL; |
1330 } | 1346 } |
1331 } | 1347 } |
OLD | NEW |