Chromium Code Reviews| 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 0355767cede5c682a331c38f6e5fff68efac8dc5..190889457ace9d6dfe4973edaacab0e0eb27a408 100644 |
| --- a/chrome/browser/media/media_stream_devices_menu_model.cc |
| +++ b/chrome/browser/media/media_stream_devices_menu_model.cc |
| @@ -7,6 +7,7 @@ |
| #include <utility> |
| #include "base/utf_string_conversions.h" |
| +#include "chrome/app/chrome_command_ids.h" |
| #include "chrome/browser/ui/media_stream_infobar_delegate.h" |
| #include "content/public/common/media_stream_request.h" |
| #include "grit/generated_resources.h" |
| @@ -16,21 +17,25 @@ MediaStreamDevicesMenuModel::MediaStreamDevicesMenuModel( |
| const MediaStreamInfoBarDelegate* delegate) |
| : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), |
| selected_command_id_audio_(-1), |
| - selected_command_id_video_(-1) { |
| - const bool nonempty_audio_section = |
| - delegate->has_audio() && !delegate->GetAudioDevices().empty(); |
| - if (delegate->has_video() && !delegate->GetVideoDevices().empty()) { |
| + selected_command_id_video_(-1), |
| + always_allow_(false) { |
| + bool audio = delegate->has_audio() && !delegate->GetAudioDevices().empty(); |
| + bool video = delegate->has_video() && !delegate->GetVideoDevices().empty(); |
| + if (video) { |
| // The default command ID is the first element that will be inserted. |
| selected_command_id_video_ = commands_.size(); |
| AddDevices(delegate->GetVideoDevices()); |
| - if (nonempty_audio_section) |
| + if (audio) |
| AddSeparator(); |
| } |
| - if (nonempty_audio_section) { |
| + if (audio) { |
| // The default command ID is the first element that will be inserted. |
| selected_command_id_audio_ = commands_.size(); |
| AddDevices(delegate->GetAudioDevices()); |
| } |
| + |
| + AddAlwaysAllowOption(audio, video); |
| + |
| } |
| MediaStreamDevicesMenuModel::~MediaStreamDevicesMenuModel() { |
| @@ -48,8 +53,13 @@ bool MediaStreamDevicesMenuModel::GetSelectedDeviceId( |
| } |
| bool MediaStreamDevicesMenuModel::IsCommandIdChecked(int command_id) const { |
| - return (selected_command_id_audio_ == command_id || |
| - selected_command_id_video_ == command_id); |
| + switch (command_id) { |
| + case IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW: |
| + return always_allow_; |
| + default: |
| + return (selected_command_id_audio_ == command_id || |
|
Ivan Korotkov
2012/06/14 17:14:12
No need in parens.
no longer working on chromium
2012/06/15 16:52:07
I tried, but it looks pretty odd since it does not
|
| + selected_command_id_video_ == command_id); |
| + } |
| } |
| bool MediaStreamDevicesMenuModel::IsCommandIdEnabled(int command_id) const { |
| @@ -63,13 +73,20 @@ bool MediaStreamDevicesMenuModel::GetAcceleratorForCommandId( |
| } |
| void MediaStreamDevicesMenuModel::ExecuteCommand(int command_id) { |
| - CommandMap::iterator it = commands_.find(command_id); |
| - DCHECK(it != commands_.end()); |
| + switch (command_id) { |
| + case IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW: |
| + always_allow_ = !always_allow_; |
| + break; |
| + default: |
| + CommandMap::iterator it = commands_.find(command_id); |
| + DCHECK(it != commands_.end()); |
| - if (it->second.type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) |
| - selected_command_id_audio_ = command_id; |
| - else |
| - selected_command_id_video_ = command_id; |
| + if (it->second.type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) |
| + selected_command_id_audio_ = command_id; |
| + else |
| + selected_command_id_video_ = command_id; |
| + break; |
| + } |
| } |
| void MediaStreamDevicesMenuModel::AddDevices( |
| @@ -79,9 +96,24 @@ void MediaStreamDevicesMenuModel::AddDevices( |
| 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_MIC : IDS_MEDIA_CAPTURE_VIDEO; |
| + IDS_MEDIA_CAPTURE_AUDIO : IDS_MEDIA_CAPTURE_VIDEO; |
| AddCheckItem(command_id, |
| l10n_util::GetStringFUTF16(message_id, |
| UTF8ToUTF16(devices[i].name))); |
| } |
| } |
| + |
| +void MediaStreamDevicesMenuModel::AddAlwaysAllowOption(bool audio, bool video) { |
| + if (!audio && !video) |
|
Ivan Korotkov
2012/06/14 17:14:12
Can that ever happen?
no longer working on chromium
2012/06/15 16:52:07
Good question, we just had our lately UI discussio
|
| + return; |
| + |
| + int command_id = IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW; |
| + int message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_AND_VIDEO; |
| + if (audio && !video) |
| + message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_ONLY; |
| + else if (!audio && video) |
| + message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_VIDEO_ONLY; |
| + |
| + AddSeparator(); |
| + AddCheckItem(command_id, l10n_util::GetStringUTF16(message_id)); |
| +} |