Index: chrome/browser/ui/content_settings/content_setting_bubble_model.cc |
diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc |
index 52f19686d9d0220d3c83043d95b4d6974f4f01d9..2c219c9625fca64ae79989f4e72896d7d9b612b5 100644 |
--- a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc |
+++ b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc |
@@ -12,6 +12,7 @@ |
#include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
#include "chrome/browser/favicon/favicon_tab_helper.h" |
+#include "chrome/browser/media/media_capture_devices_dispatcher.h" |
#include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
#include "chrome/browser/prefs/pref_service.h" |
#include "chrome/browser/profiles/profile.h" |
@@ -56,6 +57,20 @@ int GetIdForContentType(const ContentSettingsTypeIdEntry* entries, |
return 0; |
} |
+const content::MediaStreamDevice& GetMediaDeviceById( |
+ const std::string& device_id, const content::MediaStreamDevices& devices) { |
+ DCHECK(devices.size()); |
+ for (content::MediaStreamDevices::const_iterator it = devices.begin(); |
+ it != devices.end(); ++it) { |
+ if (it->id == device_id) |
+ return *(it); |
+ } |
+ |
+ // Could not find any device with |device_id|, likely the device has been |
markusheintz_
2013/02/06 11:03:26
Nit; changing this is up to you:
A device with the
no longer working on chromium
2013/02/06 13:31:52
Done.
|
+ // unplugged from the OS. Return the first device as the default device. |
+ return *devices.begin(); |
+} |
+ |
} // namespace |
ContentSettingTitleAndLinkModel::ContentSettingTitleAndLinkModel( |
@@ -505,11 +520,19 @@ class ContentSettingMediaStreamBubbleModel |
void SetTitle(); |
// Sets the data for the radio buttons of the bubble. |
void SetRadioGroup(); |
+ // Sets the data for the media menus of the bubble. |
+ void SetMediaMenus(); |
// Updates the camera and microphone setting with the passed |setting|. |
void UpdateSettings(ContentSetting setting); |
+ // Updates the camera and microphone default device with the passed |type| |
+ // and device. |
+ void UpdateDefaultDeviceForType(content::MediaStreamType type, |
+ const std::string& device); |
// ContentSettingBubbleModel implementation. |
virtual void OnRadioClicked(int radio_index) OVERRIDE; |
+ virtual void OnMeiaMenuClicked(content::MediaStreamType type, |
+ const std::string& selected_device) OVERRIDE; |
// The index of the selected radio item. |
int selected_item_; |
@@ -525,6 +548,7 @@ ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel( |
: ContentSettingTitleAndLinkModel( |
delegate, web_contents, profile, CONTENT_SETTINGS_TYPE_MEDIASTREAM), |
selected_item_(0) { |
+ DCHECK(profile); |
// Initialize the content settings associated with the individual radio |
// buttons. |
radio_item_setting_[0] = CONTENT_SETTING_ASK; |
@@ -532,12 +556,20 @@ ContentSettingMediaStreamBubbleModel::ContentSettingMediaStreamBubbleModel( |
SetTitle(); |
SetRadioGroup(); |
+ SetMediaMenus(); |
} |
ContentSettingMediaStreamBubbleModel::~ContentSettingMediaStreamBubbleModel() { |
// Update the media settings if the radio button selection was changed. |
if (selected_item_ != bubble_content().radio_group.default_item) |
UpdateSettings(radio_item_setting_[selected_item_]); |
+ |
+ for (MediaMenuMap::const_iterator it = bubble_content().media_menus.begin(); |
+ it != bubble_content().media_menus.end(); ++it) { |
+ if (it->second.selected_device.id != it->second.default_device.id) { |
+ UpdateDefaultDeviceForType(it->first, it->second.selected_device.id); |
+ } |
+ } |
} |
void ContentSettingMediaStreamBubbleModel::SetTitle() { |
@@ -617,10 +649,77 @@ void ContentSettingMediaStreamBubbleModel::UpdateSettings( |
} |
} |
+void ContentSettingMediaStreamBubbleModel::UpdateDefaultDeviceForType( |
+ content::MediaStreamType type, const std::string& device) { |
+ PrefService* prefs = profile()->GetPrefs(); |
+ switch (type) { |
+ case content::MEDIA_DEVICE_AUDIO_CAPTURE: |
+ prefs->SetString(prefs::kDefaultAudioCaptureDevice, device); |
+ break; |
+ case content::MEDIA_DEVICE_VIDEO_CAPTURE: |
+ prefs->SetString(prefs::kDefaultVideoCaptureDevice, device); |
+ break; |
+ default: |
+ NOTREACHED(); |
+ } |
+} |
+ |
+void ContentSettingMediaStreamBubbleModel::SetMediaMenus() { |
+ // Add microphone menu. |
+ PrefService* prefs = profile()->GetPrefs(); |
+ MediaCaptureDevicesDispatcher* dispatcher = |
+ MediaCaptureDevicesDispatcher::GetInstance(); |
+ const content::MediaStreamDevices& micophones = |
markusheintz_
2013/02/06 11:03:26
typo: please s/micophones/microphones/g
no longer working on chromium
2013/02/06 13:31:52
Done.
|
+ dispatcher->GetAudioCaptureDevices(); |
+ MediaMenu mic_menu; |
+ mic_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_MIC_LABEL); |
+ if (micophones.size()) { |
+ std::string preferred_mic = |
+ prefs->GetString(prefs::kDefaultAudioCaptureDevice); |
+ mic_menu.default_device = GetMediaDeviceById(preferred_mic, micophones); |
+ mic_menu.selected_device = mic_menu.default_device; |
+ } |
+ add_media_menu(content::MEDIA_DEVICE_AUDIO_CAPTURE, mic_menu); |
+ |
+ // Add camera menu. |
+ const content::MediaStreamDevices& cameras = |
+ dispatcher->GetVideoCaptureDevices(); |
+ MediaMenu camera_menu; |
+ camera_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_CAMERA_LABEL); |
+ if (cameras.size()) { |
+ std::string preferred_camera = |
+ prefs->GetString(prefs::kDefaultVideoCaptureDevice); |
+ camera_menu.default_device = GetMediaDeviceById(preferred_camera, |
+ cameras); |
+ camera_menu.selected_device = camera_menu.default_device; |
+ } |
+ add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, camera_menu); |
+} |
+ |
void ContentSettingMediaStreamBubbleModel::OnRadioClicked(int radio_index) { |
selected_item_ = radio_index; |
} |
+void ContentSettingMediaStreamBubbleModel::OnMeiaMenuClicked( |
+ content::MediaStreamType type, const std::string& selected_device_id) { |
+ DCHECK(bubble_content().media_menus.find(type) != |
+ bubble_content().media_menus.end()); |
+ MediaCaptureDevicesDispatcher* dispatcher = |
+ MediaCaptureDevicesDispatcher::GetInstance(); |
+ content::MediaStreamDevices devices; |
+ switch (type) { |
+ case content::MEDIA_DEVICE_AUDIO_CAPTURE: |
+ devices = dispatcher->GetAudioCaptureDevices(); |
+ break; |
+ case content::MEDIA_DEVICE_VIDEO_CAPTURE: |
+ devices = dispatcher->GetVideoCaptureDevices(); |
+ break; |
+ default: |
+ NOTREACHED(); |
+ } |
+ set_selected_device(GetMediaDeviceById(selected_device_id, devices)); |
+} |
+ |
class ContentSettingDomainListBubbleModel |
: public ContentSettingTitleAndLinkModel { |
public: |