| 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/media/media_stream_devices_menu_model.h" | 5 #include "chrome/browser/media/media_stream_devices_menu_model.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" |
| 9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
| 11 #include "chrome/browser/ui/media_stream_infobar_delegate.h" | 12 #include "chrome/browser/ui/media_stream_infobar_delegate.h" |
| 12 #include "content/public/common/media_stream_request.h" | 13 #include "content/public/common/media_stream_request.h" |
| 13 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 15 | 16 |
| 16 MediaStreamDevicesMenuModel::MediaStreamDevicesMenuModel( | 17 MediaStreamDevicesMenuModel::MediaStreamDevicesMenuModel( |
| 17 MediaStreamInfoBarDelegate* delegate) | 18 MediaStreamInfoBarDelegate* delegate) |
| 18 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | 19 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), |
| 19 media_stream_delegate_(delegate) { | 20 media_stream_delegate_(delegate) { |
| 20 bool audio = delegate->HasAudio() && !delegate->GetAudioDevices().empty(); | 21 if (delegate->HasVideo()) { |
| 21 bool video = delegate->HasVideo() && !delegate->GetVideoDevices().empty(); | |
| 22 if (video) { | |
| 23 AddDevices(delegate->GetVideoDevices()); | 22 AddDevices(delegate->GetVideoDevices()); |
| 24 if (audio) | 23 if (delegate->HasAudio()) |
| 25 AddSeparator(ui::NORMAL_SEPARATOR); | 24 AddSeparator(ui::NORMAL_SEPARATOR); |
| 26 } | 25 } |
| 27 if (audio) { | 26 if (delegate->HasAudio()) { |
| 28 AddDevices(delegate->GetAudioDevices()); | 27 AddDevices(delegate->GetAudioDevices()); |
| 29 } | 28 } |
| 30 | 29 |
| 31 // Show "always allow" option only for the secure connection. | 30 // Show "always allow" option when auto-accepting would be safe in the future. |
| 32 if (delegate->GetSecurityOrigin().SchemeIsSecure()) | 31 AddAlwaysAllowOption( |
| 33 AddAlwaysAllowOption(audio, video); | 32 delegate->HasAudio() && delegate->IsSafeToAlwaysAllowAudio(), |
| 33 delegate->HasVideo() && delegate->IsSafeToAlwaysAllowVideo()); |
| 34 } | 34 } |
| 35 | 35 |
| 36 MediaStreamDevicesMenuModel::~MediaStreamDevicesMenuModel() { | 36 MediaStreamDevicesMenuModel::~MediaStreamDevicesMenuModel() { |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool MediaStreamDevicesMenuModel::IsCommandIdChecked(int command_id) const { | 39 bool MediaStreamDevicesMenuModel::IsCommandIdChecked(int command_id) const { |
| 40 if (command_id == IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW) | 40 if (command_id == IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW) |
| 41 return media_stream_delegate_->always_allow(); | 41 return media_stream_delegate_->always_allow(); |
| 42 | 42 |
| 43 CommandMap::const_iterator it = commands_.find(command_id); | 43 CommandMap::const_iterator it = commands_.find(command_id); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 59 } | 59 } |
| 60 | 60 |
| 61 void MediaStreamDevicesMenuModel::ExecuteCommand(int command_id) { | 61 void MediaStreamDevicesMenuModel::ExecuteCommand(int command_id) { |
| 62 if (command_id == IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW) { | 62 if (command_id == IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW) { |
| 63 media_stream_delegate_->toggle_always_allow(); | 63 media_stream_delegate_->toggle_always_allow(); |
| 64 return; | 64 return; |
| 65 } | 65 } |
| 66 | 66 |
| 67 CommandMap::const_iterator it = commands_.find(command_id); | 67 CommandMap::const_iterator it = commands_.find(command_id); |
| 68 DCHECK(it != commands_.end()); | 68 DCHECK(it != commands_.end()); |
| 69 if (it->second.type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) | 69 if (content::IsAudioMediaType(it->second.type)) { |
| 70 media_stream_delegate_->set_selected_audio_device(it->second.device_id); | 70 media_stream_delegate_->set_selected_audio_device(it->second.device_id); |
| 71 else | 71 } else if (content::IsVideoMediaType(it->second.type)) { |
| 72 media_stream_delegate_->set_selected_video_device(it->second.device_id); | 72 media_stream_delegate_->set_selected_video_device(it->second.device_id); |
| 73 } else { |
| 74 NOTREACHED(); |
| 75 } |
| 73 } | 76 } |
| 74 | 77 |
| 75 void MediaStreamDevicesMenuModel::AddDevices( | 78 void MediaStreamDevicesMenuModel::AddDevices( |
| 76 const content::MediaStreamDevices& devices) { | 79 const content::MediaStreamDevices& devices) { |
| 77 for (size_t i = 0; i < devices.size(); ++i) { | 80 for (size_t i = 0; i < devices.size(); ++i) { |
| 78 int command_id = commands_.size(); | 81 int command_id = commands_.size(); |
| 79 commands_.insert(std::make_pair(command_id, devices[i])); | 82 commands_.insert(std::make_pair(command_id, devices[i])); |
| 80 int message_id = (devices[i].type == | 83 int message_id; |
| 81 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ? | 84 if (content::IsAudioMediaType(devices[i].type)) { |
| 82 IDS_MEDIA_CAPTURE_AUDIO : IDS_MEDIA_CAPTURE_VIDEO; | 85 message_id = IDS_MEDIA_CAPTURE_AUDIO; |
| 86 } else if (content::IsVideoMediaType(devices[i].type)) { |
| 87 message_id = IDS_MEDIA_CAPTURE_VIDEO; |
| 88 } else { |
| 89 NOTIMPLEMENTED(); |
| 90 continue; |
| 91 } |
| 83 AddCheckItem(command_id, | 92 AddCheckItem(command_id, |
| 84 l10n_util::GetStringFUTF16(message_id, | 93 l10n_util::GetStringFUTF16(message_id, |
| 85 UTF8ToUTF16(devices[i].name))); | 94 UTF8ToUTF16(devices[i].name))); |
| 86 } | 95 } |
| 87 } | 96 } |
| 88 | 97 |
| 89 void MediaStreamDevicesMenuModel::AddAlwaysAllowOption(bool audio, bool video) { | 98 void MediaStreamDevicesMenuModel::AddAlwaysAllowOption(bool audio, bool video) { |
| 99 if (!audio && !video) |
| 100 return; |
| 101 |
| 90 int command_id = IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW; | 102 int command_id = IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW; |
| 91 int message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_AND_VIDEO; | 103 int message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_AND_VIDEO; |
| 92 if (audio && !video) | 104 if (audio && !video) |
| 93 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_ONLY; | 105 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_ONLY; |
| 94 else if (!audio && video) | 106 else if (!audio && video) |
| 95 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_VIDEO_ONLY; | 107 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_VIDEO_ONLY; |
| 96 | 108 |
| 97 AddSeparator(ui::NORMAL_SEPARATOR); | 109 AddSeparator(ui::NORMAL_SEPARATOR); |
| 98 AddCheckItem(command_id, l10n_util::GetStringUTF16(message_id)); | 110 AddCheckItem(command_id, l10n_util::GetStringUTF16(message_id)); |
| 99 } | 111 } |
| OLD | NEW |