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, |
579 const std::string& selected_device) OVERRIDE; | 579 const std::string& selected_device) OVERRIDE; |
580 | 580 |
581 // The index of the selected radio item. | 581 // The index of the selected radio item. |
582 int selected_item_; | 582 int selected_item_; |
583 // The content settings that are associated with the individual radio | 583 // The content settings that are associated with the individual radio |
584 // buttons. | 584 // buttons. |
585 ContentSetting radio_item_setting_[2]; | 585 ContentSetting radio_item_setting_[2]; |
586 // The state of the microphone and camera access. | 586 // The state of the microphone and camera access. |
587 TabSpecificContentSettings::MicrophoneCameraState state_; | 587 unsigned state_; |
588 }; | 588 }; |
589 | 589 |
590 ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel( | 590 ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel( |
591 Delegate* delegate, | 591 Delegate* delegate, |
592 WebContents* web_contents, | 592 WebContents* web_contents, |
593 Profile* profile) | 593 Profile* profile) |
594 : ContentSettingTitleAndLinkModel( | 594 : ContentSettingTitleAndLinkModel( |
595 delegate, web_contents, profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM), | 595 delegate, web_contents, profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM), |
596 selected_item_(0), | 596 selected_item_(0), |
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() { |
642 int title_id = 0; | 636 int title_id = 0; |
643 switch (state_) { | 637 if (state_ & TabSpecificContentSettings::MICROPHONE_BLOCKED) { |
644 case TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED: | 638 title_id = (state_ & TabSpecificContentSettings::CAMERA_BLOCKED) ? |
645 // If neither microphone nor camera stream was accessed, then there is no | 639 IDS_MICROPHONE_CAMERA_BLOCKED : IDS_MICROPHONE_BLOCKED; |
646 // icon didplayed in the omnibox and no settings bubble availbale. Hence | 640 } else if (state_ & TabSpecificContentSettings::CAMERA_BLOCKED) { |
647 // there is no title. | 641 title_id = IDS_CAMERA_BLOCKED; |
648 NOTREACHED(); | 642 } else if (state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) { |
649 return; | 643 title_id = (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) ? |
650 case TabSpecificContentSettings::MICROPHONE_ACCESSED: | 644 IDS_MICROPHONE_CAMERA_ALLOWED : IDS_MICROPHONE_ACCESSED; |
651 title_id = IDS_MICROPHONE_ACCESSED; | 645 } else if (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) { |
652 break; | 646 title_id = IDS_CAMERA_ACCESSED; |
653 case TabSpecificContentSettings::CAMERA_ACCESSED: | 647 } else { |
654 title_id = IDS_CAMERA_ACCESSED; | 648 NOTREACHED(); |
Peter Kasting
2014/09/24 01:33:00
Nit: Better than this NOTREACHED() would be to eli
robwu
2014/09/24 23:38:44
Done.
| |
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 } | 649 } |
669 set_title(l10n_util::GetStringUTF8(title_id)); | 650 set_title(l10n_util::GetStringUTF8(title_id)); |
670 } | 651 } |
671 | 652 |
672 void ContentSettingMediaStreamBubbleModel::SetRadioGroup() { | 653 void ContentSettingMediaStreamBubbleModel::SetRadioGroup() { |
673 TabSpecificContentSettings* content_settings = | 654 TabSpecificContentSettings* content_settings = |
674 TabSpecificContentSettings::FromWebContents(web_contents()); | 655 TabSpecificContentSettings::FromWebContents(web_contents()); |
675 GURL url = content_settings->media_stream_access_origin(); | 656 GURL url = content_settings->media_stream_access_origin(); |
676 RadioGroup radio_group; | 657 RadioGroup radio_group; |
677 radio_group.url = url; | 658 radio_group.url = url; |
678 | 659 |
679 base::string16 display_host_utf16; | 660 base::string16 display_host_utf16; |
680 net::AppendFormattedHost( | 661 net::AppendFormattedHost( |
681 url, | 662 url, |
682 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages), | 663 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages), |
683 &display_host_utf16); | 664 &display_host_utf16); |
684 std::string display_host(base::UTF16ToUTF8(display_host_utf16)); | 665 std::string display_host(base::UTF16ToUTF8(display_host_utf16)); |
685 if (display_host.empty()) | 666 if (display_host.empty()) |
686 display_host = url.spec(); | 667 display_host = url.spec(); |
687 | 668 |
669 const bool is_mic = state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED; | |
670 const bool is_cam = state_ & TabSpecificContentSettings::CAMERA_ACCESSED; | |
671 DCHECK(is_mic || is_cam); | |
672 const bool is_blocked = | |
673 (is_mic && content_settings->IsContentBlocked( | |
674 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) || | |
675 (is_cam && content_settings->IsContentBlocked( | |
676 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | |
688 int radio_allow_label_id = 0; | 677 int radio_allow_label_id = 0; |
689 int radio_block_label_id = 0; | 678 int radio_block_label_id = 0; |
690 switch (state_) { | 679 if (state_ & (TabSpecificContentSettings::MICROPHONE_BLOCKED | |
691 case TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED: | 680 TabSpecificContentSettings::CAMERA_BLOCKED)) { |
692 NOTREACHED(); | 681 if (url.SchemeIsSecure()) { |
693 return; | 682 radio_item_setting_[0] = CONTENT_SETTING_ALLOW; |
694 case TabSpecificContentSettings::MICROPHONE_ACCESSED: | 683 if (is_mic && is_cam) |
684 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ALLOW; | |
685 else if (is_mic) | |
686 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_ALLOW; | |
687 else if (is_cam) | |
Peter Kasting
2014/09/24 01:33:00
Nit: This conditional is always true, remove it.
Peter Kasting
2014/09/25 00:53:25
Still would be good to do this.
robwu
2014/09/25 08:57:57
Was already done.
Peter Kasting
2014/09/25 09:00:06
Eh? It's still not done even in your latest patch
robwu
2014/09/25 09:12:18
Apologies, I confused this one with your other com
| |
688 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ALLOW; | |
689 } else { | |
690 if (is_mic && is_cam) | |
691 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_AND_CAMERA_ASK; | |
692 else if (is_mic) | |
693 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_MIC_ASK; | |
694 else if (is_cam) | |
695 radio_allow_label_id = IDS_BLOCKED_MEDIASTREAM_CAMERA_ASK; | |
696 } | |
697 } else { | |
698 if (is_mic && is_cam) { | |
699 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_NO_ACTION; | |
700 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_BLOCK; | |
701 } else if (is_mic) { | |
695 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_NO_ACTION; | 702 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_NO_ACTION; |
696 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_BLOCK; | 703 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_MIC_BLOCK; |
697 selected_item_ = 0; | 704 } else if (is_cam) { |
698 break; | |
699 case TabSpecificContentSettings::CAMERA_ACCESSED: | |
700 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_CAMERA_NO_ACTION; | 705 radio_allow_label_id = IDS_ALLOWED_MEDIASTREAM_CAMERA_NO_ACTION; |
701 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_CAMERA_BLOCK; | 706 radio_block_label_id = IDS_ALLOWED_MEDIASTREAM_CAMERA_BLOCK; |
702 selected_item_ = 0; | 707 } |
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 } | 708 } |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 } |
OLD | NEW |