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/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/api/infobars/infobar_service.h" | 9 #include "chrome/browser/api/infobars/infobar_service.h" |
10 #include "chrome/browser/content_settings/content_settings_utils.h" | 10 #include "chrome/browser/content_settings/content_settings_utils.h" |
11 #include "chrome/browser/content_settings/cookie_settings.h" | 11 #include "chrome/browser/content_settings/cookie_settings.h" |
12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 12 #include "chrome/browser/content_settings/tab_specific_content_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/media/media_capture_devices_dispatcher.h" |
16 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 17 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 19 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
19 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate.
h" | 20 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate.
h" |
20 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" | 21 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" |
21 #include "chrome/browser/ui/content_settings/content_setting_bubble_model_delega
te.h" | 22 #include "chrome/browser/ui/content_settings/content_setting_bubble_model_delega
te.h" |
22 #include "chrome/browser/ui/content_settings/content_setting_changed_infobar_del
egate.h" | 23 #include "chrome/browser/ui/content_settings/content_setting_changed_infobar_del
egate.h" |
23 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
24 #include "chrome/common/content_settings.h" | 25 #include "chrome/common/content_settings.h" |
25 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
(...skipping 25 matching lines...) Expand all Loading... |
51 int GetIdForContentType(const ContentSettingsTypeIdEntry* entries, | 52 int GetIdForContentType(const ContentSettingsTypeIdEntry* entries, |
52 size_t num_entries, | 53 size_t num_entries, |
53 ContentSettingsType type) { | 54 ContentSettingsType type) { |
54 for (size_t i = 0; i < num_entries; ++i) { | 55 for (size_t i = 0; i < num_entries; ++i) { |
55 if (entries[i].type == type) | 56 if (entries[i].type == type) |
56 return entries[i].id; | 57 return entries[i].id; |
57 } | 58 } |
58 return 0; | 59 return 0; |
59 } | 60 } |
60 | 61 |
| 62 const content::MediaStreamDevice& GetMediaDeviceById( |
| 63 const std::string& device_id, |
| 64 const content::MediaStreamDevices& devices) { |
| 65 DCHECK(!devices.empty()); |
| 66 for (content::MediaStreamDevices::const_iterator it = devices.begin(); |
| 67 it != devices.end(); ++it) { |
| 68 if (it->id == device_id) |
| 69 return *(it); |
| 70 } |
| 71 |
| 72 // A device with the |device_id| was not found. It is likely that the device |
| 73 // has been unplugged from the OS. Return the first device as the default |
| 74 // device. |
| 75 return *devices.begin(); |
| 76 } |
| 77 |
61 } // namespace | 78 } // namespace |
62 | 79 |
63 ContentSettingTitleAndLinkModel::ContentSettingTitleAndLinkModel( | 80 ContentSettingTitleAndLinkModel::ContentSettingTitleAndLinkModel( |
64 Delegate* delegate, | 81 Delegate* delegate, |
65 WebContents* web_contents, | 82 WebContents* web_contents, |
66 Profile* profile, | 83 Profile* profile, |
67 ContentSettingsType content_type) | 84 ContentSettingsType content_type) |
68 : ContentSettingBubbleModel(web_contents, profile, content_type), | 85 : ContentSettingBubbleModel(web_contents, profile, content_type), |
69 delegate_(delegate) { | 86 delegate_(delegate) { |
70 // Notifications do not have a bubble. | 87 // Notifications do not have a bubble. |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 WebContents* web_contents, | 554 WebContents* web_contents, |
538 Profile* profile); | 555 Profile* profile); |
539 | 556 |
540 virtual ~ContentSettingMediaStreamBubbleModel(); | 557 virtual ~ContentSettingMediaStreamBubbleModel(); |
541 | 558 |
542 private: | 559 private: |
543 // Sets the title of the bubble. | 560 // Sets the title of the bubble. |
544 void SetTitle(); | 561 void SetTitle(); |
545 // Sets the data for the radio buttons of the bubble. | 562 // Sets the data for the radio buttons of the bubble. |
546 void SetRadioGroup(); | 563 void SetRadioGroup(); |
| 564 // Sets the data for the media menus of the bubble. |
| 565 void SetMediaMenus(); |
547 // Updates the camera and microphone setting with the passed |setting|. | 566 // Updates the camera and microphone setting with the passed |setting|. |
548 void UpdateSettings(ContentSetting setting); | 567 void UpdateSettings(ContentSetting setting); |
| 568 // Updates the camera and microphone default device with the passed |type| |
| 569 // and device. |
| 570 void UpdateDefaultDeviceForType(content::MediaStreamType type, |
| 571 const std::string& device); |
549 | 572 |
550 // ContentSettingBubbleModel implementation. | 573 // ContentSettingBubbleModel implementation. |
551 virtual void OnRadioClicked(int radio_index) OVERRIDE; | 574 virtual void OnRadioClicked(int radio_index) OVERRIDE; |
| 575 virtual void OnMediaMenuClicked(content::MediaStreamType type, |
| 576 const std::string& selected_device) OVERRIDE; |
552 | 577 |
553 // The index of the selected radio item. | 578 // The index of the selected radio item. |
554 int selected_item_; | 579 int selected_item_; |
555 // The content settings that are associated with the individual radio | 580 // The content settings that are associated with the individual radio |
556 // buttons. | 581 // buttons. |
557 ContentSetting radio_item_setting_[2]; | 582 ContentSetting radio_item_setting_[2]; |
558 }; | 583 }; |
559 | 584 |
560 ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel( | 585 ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel( |
561 Delegate* delegate, | 586 Delegate* delegate, |
562 WebContents* web_contents, | 587 WebContents* web_contents, |
563 Profile* profile) | 588 Profile* profile) |
564 : ContentSettingTitleAndLinkModel( | 589 : ContentSettingTitleAndLinkModel( |
565 delegate, web_contents, profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM), | 590 delegate, web_contents, profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM), |
566 selected_item_(0) { | 591 selected_item_(0) { |
| 592 DCHECK(profile); |
567 // Initialize the content settings associated with the individual radio | 593 // Initialize the content settings associated with the individual radio |
568 // buttons. | 594 // buttons. |
569 radio_item_setting_[0] = CONTENT_SETTING_ASK; | 595 radio_item_setting_[0] = CONTENT_SETTING_ASK; |
570 radio_item_setting_[1] = CONTENT_SETTING_BLOCK; | 596 radio_item_setting_[1] = CONTENT_SETTING_BLOCK; |
571 | 597 |
572 SetTitle(); | 598 SetTitle(); |
573 SetRadioGroup(); | 599 SetRadioGroup(); |
| 600 SetMediaMenus(); |
574 } | 601 } |
575 | 602 |
576 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() { | 603 ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() { |
| 604 bool media_setting_changed = false; |
| 605 for (MediaMenuMap::const_iterator it = bubble_content().media_menus.begin(); |
| 606 it != bubble_content().media_menus.end(); ++it) { |
| 607 if (it->second.selected_device.id != it->second.default_device.id) { |
| 608 UpdateDefaultDeviceForType(it->first, it->second.selected_device.id); |
| 609 media_setting_changed = true; |
| 610 } |
| 611 } |
| 612 |
577 // Update the media settings if the radio button selection was changed. | 613 // Update the media settings if the radio button selection was changed. |
578 if (selected_item_ != bubble_content().radio_group.default_item) { | 614 if (selected_item_ != bubble_content().radio_group.default_item) { |
579 UpdateSettings(radio_item_setting_[selected_item_]); | 615 UpdateSettings(radio_item_setting_[selected_item_]); |
| 616 media_setting_changed = true; |
| 617 } |
| 618 |
| 619 // Trigger the reload infobar if the media setting has been changed. |
| 620 if (media_setting_changed) { |
580 ContentSettingChangedInfoBarDelegate::Create( | 621 ContentSettingChangedInfoBarDelegate::Create( |
581 InfoBarService::FromWebContents(web_contents()), | 622 InfoBarService::FromWebContents(web_contents()), |
582 IDR_INFOBAR_MEDIA_STREAM_CAMERA, | 623 IDR_INFOBAR_MEDIA_STREAM_CAMERA, |
583 IDS_MEDIASTREAM_SETTING_CHANGED_INFOBAR_MESSAGE); | 624 IDS_MEDIASTREAM_SETTING_CHANGED_INFOBAR_MESSAGE); |
584 } | 625 } |
585 } | 626 } |
586 | 627 |
587 void ContentSettingMediaStreamBubbleModel::SetTitle() { | 628 void ContentSettingMediaStreamBubbleModel::SetTitle() { |
588 TabSpecificContentSettings* content_settings = | 629 TabSpecificContentSettings* content_settings = |
589 TabSpecificContentSettings::FromWebContents(web_contents()); | 630 TabSpecificContentSettings::FromWebContents(web_contents()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 ContentSettingsPattern::Wildcard(); | 695 ContentSettingsPattern::Wildcard(); |
655 content_settings->SetContentSetting( | 696 content_settings->SetContentSetting( |
656 primary_pattern, secondary_pattern, | 697 primary_pattern, secondary_pattern, |
657 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting); | 698 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), setting); |
658 content_settings->SetContentSetting( | 699 content_settings->SetContentSetting( |
659 primary_pattern, secondary_pattern, | 700 primary_pattern, secondary_pattern, |
660 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting); | 701 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), setting); |
661 } | 702 } |
662 } | 703 } |
663 | 704 |
| 705 void ContentSettingMediaStreamBubbleModel::UpdateDefaultDeviceForType( |
| 706 content::MediaStreamType type, |
| 707 const std::string& device) { |
| 708 PrefService* prefs = profile()->GetPrefs(); |
| 709 if (type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { |
| 710 prefs->SetString(prefs::kDefaultAudioCaptureDevice, device); |
| 711 } else { |
| 712 DCHECK_EQ(content::MEDIA_DEVICE_VIDEO_CAPTURE, type); |
| 713 prefs->SetString(prefs::kDefaultVideoCaptureDevice, device); |
| 714 } |
| 715 } |
| 716 |
| 717 void ContentSettingMediaStreamBubbleModel::SetMediaMenus() { |
| 718 // Add microphone menu. |
| 719 PrefService* prefs = profile()->GetPrefs(); |
| 720 MediaCaptureDevicesDispatcher* dispatcher = |
| 721 MediaCaptureDevicesDispatcher::GetInstance(); |
| 722 const content::MediaStreamDevices& microphones = |
| 723 dispatcher->GetAudioCaptureDevices(); |
| 724 MediaMenu mic_menu; |
| 725 mic_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_MIC_LABEL); |
| 726 if (!microphones.empty()) { |
| 727 std::string preferred_mic = |
| 728 prefs->GetString(prefs::kDefaultAudioCaptureDevice); |
| 729 mic_menu.default_device = GetMediaDeviceById(preferred_mic, microphones); |
| 730 mic_menu.selected_device = mic_menu.default_device; |
| 731 } |
| 732 add_media_menu(content::MEDIA_DEVICE_AUDIO_CAPTURE, mic_menu); |
| 733 |
| 734 // Add camera menu. |
| 735 const content::MediaStreamDevices& cameras = |
| 736 dispatcher->GetVideoCaptureDevices(); |
| 737 MediaMenu camera_menu; |
| 738 camera_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_CAMERA_LABEL); |
| 739 if (!cameras.empty()) { |
| 740 std::string preferred_camera = |
| 741 prefs->GetString(prefs::kDefaultVideoCaptureDevice); |
| 742 camera_menu.default_device = |
| 743 GetMediaDeviceById(preferred_camera, cameras); |
| 744 camera_menu.selected_device = camera_menu.default_device; |
| 745 } |
| 746 add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, camera_menu); |
| 747 } |
| 748 |
664 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) { | 749 void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) { |
665 selected_item_ = radio_index; | 750 selected_item_ = radio_index; |
666 } | 751 } |
667 | 752 |
| 753 void ContentSettingMediaStreamBubbleModel::OnMediaMenuClicked( |
| 754 content::MediaStreamType type, |
| 755 const std::string& selected_device_id) { |
| 756 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || |
| 757 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); |
| 758 DCHECK_EQ(1U, bubble_content().media_menus.count(type)); |
| 759 MediaCaptureDevicesDispatcher* dispatcher = |
| 760 MediaCaptureDevicesDispatcher::GetInstance(); |
| 761 const content::MediaStreamDevices& devices = |
| 762 (type == content::MEDIA_DEVICE_AUDIO_CAPTURE) ? |
| 763 dispatcher->GetAudioCaptureDevices() : |
| 764 dispatcher->GetVideoCaptureDevices(); |
| 765 set_selected_device(GetMediaDeviceById(selected_device_id, devices)); |
| 766 } |
| 767 |
668 class ContentSettingDomainListBubbleModel | 768 class ContentSettingDomainListBubbleModel |
669 : public ContentSettingTitleAndLinkModel { | 769 : public ContentSettingTitleAndLinkModel { |
670 public: | 770 public: |
671 ContentSettingDomainListBubbleModel(Delegate* delegate, | 771 ContentSettingDomainListBubbleModel(Delegate* delegate, |
672 WebContents* web_contents, | 772 WebContents* web_contents, |
673 Profile* profile, | 773 Profile* profile, |
674 ContentSettingsType content_type); | 774 ContentSettingsType content_type); |
675 virtual ~ContentSettingDomainListBubbleModel() {} | 775 virtual ~ContentSettingDomainListBubbleModel() {} |
676 | 776 |
677 private: | 777 private: |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 1102 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
1003 DCHECK_EQ(web_contents_, | 1103 DCHECK_EQ(web_contents_, |
1004 content::Source<WebContents>(source).ptr()); | 1104 content::Source<WebContents>(source).ptr()); |
1005 web_contents_ = NULL; | 1105 web_contents_ = NULL; |
1006 } else { | 1106 } else { |
1007 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 1107 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
1008 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 1108 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
1009 profile_ = NULL; | 1109 profile_ = NULL; |
1010 } | 1110 } |
1011 } | 1111 } |
OLD | NEW |