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..dada7dc99a2aa59497e7e09fc5b22021e232e12d 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,21 @@ int GetIdForContentType(const ContentSettingsTypeIdEntry* entries, |
return 0; |
} |
+const content::MediaStreamDevice& GetMediaDeviceById( |
+ const std::string& device_id, const content::MediaStreamDevices& devices) { |
Peter Kasting
2013/02/06 22:11:18
Nit: One arg per line
no longer working on chromium
2013/02/07 16:25:19
Done.
|
+ DCHECK(devices.size()); |
Peter Kasting
2013/02/06 22:11:18
Nit: !empty()
no longer working on chromium
2013/02/07 16:25:19
Done.
|
+ for (content::MediaStreamDevices::const_iterator it = devices.begin(); |
+ it != devices.end(); ++it) { |
+ if (it->id == device_id) |
+ return *(it); |
+ } |
+ |
+ // A device with the |device_id| was not found. It is likely that the device |
+ // has been unplugged from the OS. Return the first device as the default |
+ // device. |
+ return *devices.begin(); |
+} |
+ |
} // namespace |
ContentSettingTitleAndLinkModel::ContentSettingTitleAndLinkModel( |
@@ -505,11 +521,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 OnMediaMenuClicked(content::MediaStreamType type, |
+ const std::string& selected_device) OVERRIDE; |
// The index of the selected radio item. |
int selected_item_; |
@@ -525,6 +549,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 +557,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) { |
Peter Kasting
2013/02/06 22:11:18
Nit: {} not necessary
no longer working on chromium
2013/02/07 16:25:19
Done.
|
+ UpdateDefaultDeviceForType(it->first, it->second.selected_device.id); |
+ } |
+ } |
} |
void ContentSettingMediaStreamBubbleModel::SetTitle() { |
@@ -617,10 +650,77 @@ void ContentSettingMediaStreamBubbleModel::UpdateSettings( |
} |
} |
+void ContentSettingMediaStreamBubbleModel::UpdateDefaultDeviceForType( |
+ content::MediaStreamType type, const std::string& device) { |
Peter Kasting
2013/02/06 22:11:18
Nit: One arg per line
no longer working on chromium
2013/02/07 16:25:19
Done.
|
+ PrefService* prefs = profile()->GetPrefs(); |
+ switch (type) { |
Peter Kasting
2013/02/06 22:11:18
Nit: Shorter:
DCHECK((type == content::MEDIA_DE
no longer working on chromium
2013/02/07 16:25:19
Done with using the ifs.
|
+ 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& microphones = |
+ dispatcher->GetAudioCaptureDevices(); |
+ MediaMenu mic_menu; |
+ mic_menu.label = l10n_util::GetStringUTF8(IDS_MEDIA_SELECTED_MIC_LABEL); |
+ if (microphones.size()) { |
Peter Kasting
2013/02/06 22:11:18
Nit: !empty() (2 places)
no longer working on chromium
2013/02/07 16:25:19
Done.
|
+ std::string preferred_mic = |
+ prefs->GetString(prefs::kDefaultAudioCaptureDevice); |
+ mic_menu.default_device = GetMediaDeviceById(preferred_mic, microphones); |
+ 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::OnMediaMenuClicked( |
+ content::MediaStreamType type, const std::string& selected_device_id) { |
+ DCHECK(bubble_content().media_menus.find(type) != |
Peter Kasting
2013/02/06 22:11:18
Nit: Use count() instead of find() (shorter)
no longer working on chromium
2013/02/07 16:25:19
Done.
|
+ bubble_content().media_menus.end()); |
+ MediaCaptureDevicesDispatcher* dispatcher = |
+ MediaCaptureDevicesDispatcher::GetInstance(); |
+ content::MediaStreamDevices devices; |
Peter Kasting
2013/02/06 22:11:18
Nit: I suggest using ?: to initialize this at its
no longer working on chromium
2013/02/07 16:25:19
Done.
|
+ 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: |