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); |
25 } | |
26 } | 26 } |
27 if (audio) { | 27 if (delegate->HasAudio()) { |
28 AddDevices(delegate->GetAudioDevices()); | 28 AddDevices(delegate->GetAudioDevices()); |
29 } | 29 } |
30 | 30 |
31 // Show "always allow" option only for the secure connection. | 31 // Show "always allow" option when auto-accepting would be safe in the future. |
32 if (delegate->GetSecurityOrigin().SchemeIsSecure()) | 32 AddAlwaysAllowOption( |
33 AddAlwaysAllowOption(audio, video); | 33 delegate->HasAudio() && delegate->IsSafeToAlwaysAllowAudio(), |
34 delegate->HasVideo() && delegate->IsSafeToAlwaysAllowVideo()); | |
34 } | 35 } |
35 | 36 |
36 MediaStreamDevicesMenuModel::~MediaStreamDevicesMenuModel() { | 37 MediaStreamDevicesMenuModel::~MediaStreamDevicesMenuModel() { |
37 } | 38 } |
38 | 39 |
39 bool MediaStreamDevicesMenuModel::IsCommandIdChecked(int command_id) const { | 40 bool MediaStreamDevicesMenuModel::IsCommandIdChecked(int command_id) const { |
40 if (command_id == IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW) | 41 if (command_id == IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW) |
41 return media_stream_delegate_->always_allow(); | 42 return media_stream_delegate_->always_allow(); |
42 | 43 |
43 CommandMap::const_iterator it = commands_.find(command_id); | 44 CommandMap::const_iterator it = commands_.find(command_id); |
(...skipping 15 matching lines...) Expand all Loading... | |
59 } | 60 } |
60 | 61 |
61 void MediaStreamDevicesMenuModel::ExecuteCommand(int command_id) { | 62 void MediaStreamDevicesMenuModel::ExecuteCommand(int command_id) { |
62 if (command_id == IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW) { | 63 if (command_id == IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW) { |
63 media_stream_delegate_->toggle_always_allow(); | 64 media_stream_delegate_->toggle_always_allow(); |
64 return; | 65 return; |
65 } | 66 } |
66 | 67 |
67 CommandMap::const_iterator it = commands_.find(command_id); | 68 CommandMap::const_iterator it = commands_.find(command_id); |
68 DCHECK(it != commands_.end()); | 69 DCHECK(it != commands_.end()); |
69 if (it->second.type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) | 70 if (content::IsAudioMediaType(it->second.type)) { |
70 media_stream_delegate_->set_selected_audio_device(it->second.device_id); | 71 media_stream_delegate_->set_selected_audio_device(it->second.device_id); |
71 else | 72 } else if (content::IsVideoMediaType(it->second.type)) { |
72 media_stream_delegate_->set_selected_video_device(it->second.device_id); | 73 media_stream_delegate_->set_selected_video_device(it->second.device_id); |
74 } else { | |
75 NOTREACHED(); | |
76 } | |
73 } | 77 } |
74 | 78 |
75 void MediaStreamDevicesMenuModel::AddDevices( | 79 void MediaStreamDevicesMenuModel::AddDevices( |
76 const content::MediaStreamDevices& devices) { | 80 const content::MediaStreamDevices& devices) { |
77 for (size_t i = 0; i < devices.size(); ++i) { | 81 for (size_t i = 0; i < devices.size(); ++i) { |
78 int command_id = commands_.size(); | 82 int command_id = commands_.size(); |
79 commands_.insert(std::make_pair(command_id, devices[i])); | 83 commands_.insert(std::make_pair(command_id, devices[i])); |
80 int message_id = (devices[i].type == | 84 int message_id; |
81 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ? | 85 if (content::IsAudioMediaType(devices[i].type)) { |
82 IDS_MEDIA_CAPTURE_AUDIO : IDS_MEDIA_CAPTURE_VIDEO; | 86 message_id = IDS_MEDIA_CAPTURE_AUDIO; |
87 } else if (content::IsVideoMediaType(devices[i].type)) { | |
88 message_id = IDS_MEDIA_CAPTURE_VIDEO; | |
89 } else { | |
90 NOTIMPLEMENTED(); | |
91 continue; | |
92 } | |
83 AddCheckItem(command_id, | 93 AddCheckItem(command_id, |
84 l10n_util::GetStringFUTF16(message_id, | 94 l10n_util::GetStringFUTF16(message_id, |
85 UTF8ToUTF16(devices[i].name))); | 95 UTF8ToUTF16(devices[i].name))); |
86 } | 96 } |
87 } | 97 } |
88 | 98 |
89 void MediaStreamDevicesMenuModel::AddAlwaysAllowOption(bool audio, bool video) { | 99 void MediaStreamDevicesMenuModel::AddAlwaysAllowOption(bool audio, bool video) { |
100 if (!audio && !video) { | |
tommi (sloooow) - chröme
2012/09/10 09:17:25
no {}
miu
2012/09/10 21:24:38
Done.
| |
101 return; | |
102 } | |
103 | |
90 int command_id = IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW; | 104 int command_id = IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW; |
91 int message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_AND_VIDEO; | 105 int message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_AND_VIDEO; |
92 if (audio && !video) | 106 if (audio && !video) |
93 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_ONLY; | 107 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_ONLY; |
94 else if (!audio && video) | 108 else if (!audio && video) |
95 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_VIDEO_ONLY; | 109 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_VIDEO_ONLY; |
96 | 110 |
97 AddSeparator(ui::NORMAL_SEPARATOR); | 111 AddSeparator(ui::NORMAL_SEPARATOR); |
98 AddCheckItem(command_id, l10n_util::GetStringUTF16(message_id)); | 112 AddCheckItem(command_id, l10n_util::GetStringUTF16(message_id)); |
99 } | 113 } |
OLD | NEW |