Index: chrome/browser/media/media_stream_devices_menu_model.cc |
diff --git a/chrome/browser/media/media_stream_devices_menu_model.cc b/chrome/browser/media/media_stream_devices_menu_model.cc |
index ca322bd74c4671d83f40f4eb373efa3761fb37e4..ecd5c33dcc1286c62a9609e6b373da621532a49c 100644 |
--- a/chrome/browser/media/media_stream_devices_menu_model.cc |
+++ b/chrome/browser/media/media_stream_devices_menu_model.cc |
@@ -6,6 +6,7 @@ |
#include <utility> |
+#include "base/logging.h" |
#include "base/utf_string_conversions.h" |
#include "chrome/app/chrome_command_ids.h" |
#include "chrome/browser/ui/media_stream_infobar_delegate.h" |
@@ -19,38 +20,53 @@ MediaStreamDevicesMenuModel::MediaStreamDevicesMenuModel( |
selected_command_id_audio_(-1), |
selected_command_id_video_(-1), |
always_allow_(false) { |
- bool audio = delegate->HasAudio() && !delegate->GetAudioDevices().empty(); |
- bool video = delegate->HasVideo() && !delegate->GetVideoDevices().empty(); |
+ const content::MediaStreamDevices& audio_devices = |
+ delegate->GetAudioDevices(); |
+ const content::MediaStreamDevices& video_devices = |
+ delegate->GetVideoDevices(); |
+ const bool audio = delegate->HasAudio() && !audio_devices.empty(); |
+ const bool video = delegate->HasVideo() && !video_devices.empty(); |
if (video) { |
// The default command ID is the first element that will be inserted. |
selected_command_id_video_ = commands_.size(); |
- AddDevices(delegate->GetVideoDevices()); |
+ AddDevices(video_devices); |
if (audio) |
AddSeparator(ui::NORMAL_SEPARATOR); |
} |
if (audio) { |
// The default command ID is the first element that will be inserted. |
selected_command_id_audio_ = commands_.size(); |
- AddDevices(delegate->GetAudioDevices()); |
+ AddDevices(audio_devices); |
} |
- // Show "always allow" option only for the secure connection. |
- if (delegate->GetSecurityOrigin().SchemeIsSecure()) |
- AddAlwaysAllowOption(audio, video); |
+ // Show "always allow" option when auto-accepting would be safe in the future. |
+ AddAlwaysAllowOption(delegate->IsSafeToAlwaysAllowAudio(), |
+ delegate->IsSafeToAlwaysAllowVideo()); |
} |
MediaStreamDevicesMenuModel::~MediaStreamDevicesMenuModel() { |
} |
-bool MediaStreamDevicesMenuModel::GetSelectedDeviceId( |
- content::MediaStreamDeviceType type, |
+bool MediaStreamDevicesMenuModel::GetSelectedAudioDeviceId( |
std::string* device_id) const { |
- int command_id = (type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ? |
- selected_command_id_audio_ : selected_command_id_video_; |
- CommandMap::const_iterator it = commands_.find(command_id); |
- if (it != commands_.end()) |
+ CommandMap::const_iterator it = commands_.find(selected_command_id_audio_); |
+ if (it != commands_.end()) { |
*device_id = it->second.device_id; |
- return (it != commands_.end()); |
+ return true; |
+ } else { |
+ return false; |
+ } |
+} |
+ |
+bool MediaStreamDevicesMenuModel::GetSelectedVideoDeviceId( |
+ std::string* device_id) const { |
+ CommandMap::const_iterator it = commands_.find(selected_command_id_video_); |
+ if (it != commands_.end()) { |
+ *device_id = it->second.device_id; |
+ return true; |
+ } else { |
+ return false; |
+ } |
} |
bool MediaStreamDevicesMenuModel::IsCommandIdChecked(int command_id) const { |
@@ -82,10 +98,13 @@ void MediaStreamDevicesMenuModel::ExecuteCommand(int command_id) { |
CommandMap::iterator it = commands_.find(command_id); |
DCHECK(it != commands_.end()); |
- if (it->second.type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) |
+ if (content::IsAudioMediaStreamDeviceType(it->second.type)) { |
selected_command_id_audio_ = command_id; |
- else |
+ } else if (content::IsVideoMediaStreamDeviceType(it->second.type)) { |
selected_command_id_video_ = command_id; |
+ } else { |
+ NOTREACHED(); |
+ } |
break; |
} |
} |
@@ -95,9 +114,15 @@ void MediaStreamDevicesMenuModel::AddDevices( |
for (size_t i = 0; i < devices.size(); ++i) { |
int command_id = commands_.size(); |
commands_.insert(std::make_pair(command_id, devices[i])); |
- int message_id = (devices[i].type == |
- content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ? |
- IDS_MEDIA_CAPTURE_AUDIO : IDS_MEDIA_CAPTURE_VIDEO; |
+ int message_id; |
+ if (content::IsAudioMediaStreamDeviceType(devices[i].type)) { |
+ message_id = IDS_MEDIA_CAPTURE_AUDIO; |
+ } else if (content::IsVideoMediaStreamDeviceType(devices[i].type)) { |
+ message_id = IDS_MEDIA_CAPTURE_VIDEO; |
+ } else { |
+ NOTIMPLEMENTED(); |
+ continue; |
+ } |
AddCheckItem(command_id, |
l10n_util::GetStringFUTF16(message_id, |
UTF8ToUTF16(devices[i].name))); |
@@ -105,6 +130,10 @@ void MediaStreamDevicesMenuModel::AddDevices( |
} |
void MediaStreamDevicesMenuModel::AddAlwaysAllowOption(bool audio, bool video) { |
+ if (!audio && !video) { |
+ return; |
+ } |
+ |
int command_id = IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW; |
int message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_AND_VIDEO; |
if (audio && !video) |