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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/app/chrome_command_ids.h" | |
10 #include "chrome/browser/ui/media_stream_infobar_delegate.h" | 11 #include "chrome/browser/ui/media_stream_infobar_delegate.h" |
11 #include "content/public/common/media_stream_request.h" | 12 #include "content/public/common/media_stream_request.h" |
12 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
13 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
14 | 15 |
15 MediaStreamDevicesMenuModel::MediaStreamDevicesMenuModel( | 16 MediaStreamDevicesMenuModel::MediaStreamDevicesMenuModel( |
16 const MediaStreamInfoBarDelegate* delegate) | 17 const MediaStreamInfoBarDelegate* delegate) |
17 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | 18 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), |
18 selected_command_id_audio_(-1), | 19 selected_command_id_audio_(-1), |
19 selected_command_id_video_(-1) { | 20 selected_command_id_video_(-1), |
20 const bool nonempty_audio_section = | 21 always_allow_(false) { |
21 delegate->has_audio() && !delegate->GetAudioDevices().empty(); | 22 bool audio = delegate->has_audio() && !delegate->GetAudioDevices().empty(); |
22 if (delegate->has_video() && !delegate->GetVideoDevices().empty()) { | 23 bool video = delegate->has_video() && !delegate->GetVideoDevices().empty(); |
24 if (video) { | |
23 // The default command ID is the first element that will be inserted. | 25 // The default command ID is the first element that will be inserted. |
24 selected_command_id_video_ = commands_.size(); | 26 selected_command_id_video_ = commands_.size(); |
25 AddDevices(delegate->GetVideoDevices()); | 27 AddDevices(delegate->GetVideoDevices()); |
26 if (nonempty_audio_section) | 28 if (audio) |
27 AddSeparator(); | 29 AddSeparator(); |
28 } | 30 } |
29 if (nonempty_audio_section) { | 31 if (audio) { |
30 // The default command ID is the first element that will be inserted. | 32 // The default command ID is the first element that will be inserted. |
31 selected_command_id_audio_ = commands_.size(); | 33 selected_command_id_audio_ = commands_.size(); |
32 AddDevices(delegate->GetAudioDevices()); | 34 AddDevices(delegate->GetAudioDevices()); |
33 } | 35 } |
36 | |
37 AddAlwaysAllowOption(audio, video); | |
38 | |
34 } | 39 } |
35 | 40 |
36 MediaStreamDevicesMenuModel::~MediaStreamDevicesMenuModel() { | 41 MediaStreamDevicesMenuModel::~MediaStreamDevicesMenuModel() { |
37 } | 42 } |
38 | 43 |
39 bool MediaStreamDevicesMenuModel::GetSelectedDeviceId( | 44 bool MediaStreamDevicesMenuModel::GetSelectedDeviceId( |
40 content::MediaStreamDeviceType type, | 45 content::MediaStreamDeviceType type, |
41 std::string* device_id) const { | 46 std::string* device_id) const { |
42 int command_id = (type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ? | 47 int command_id = (type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ? |
43 selected_command_id_audio_ : selected_command_id_video_; | 48 selected_command_id_audio_ : selected_command_id_video_; |
44 CommandMap::const_iterator it = commands_.find(command_id); | 49 CommandMap::const_iterator it = commands_.find(command_id); |
45 if (it != commands_.end()) | 50 if (it != commands_.end()) |
46 *device_id = it->second.device_id; | 51 *device_id = it->second.device_id; |
47 return (it != commands_.end()); | 52 return (it != commands_.end()); |
48 } | 53 } |
49 | 54 |
50 bool MediaStreamDevicesMenuModel::IsCommandIdChecked(int command_id) const { | 55 bool MediaStreamDevicesMenuModel::IsCommandIdChecked(int command_id) const { |
51 return (selected_command_id_audio_ == command_id || | 56 switch (command_id) { |
52 selected_command_id_video_ == command_id); | 57 case IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW: |
58 return always_allow_; | |
59 default: | |
60 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
| |
61 selected_command_id_video_ == command_id); | |
62 } | |
53 } | 63 } |
54 | 64 |
55 bool MediaStreamDevicesMenuModel::IsCommandIdEnabled(int command_id) const { | 65 bool MediaStreamDevicesMenuModel::IsCommandIdEnabled(int command_id) const { |
56 return true; | 66 return true; |
57 } | 67 } |
58 | 68 |
59 bool MediaStreamDevicesMenuModel::GetAcceleratorForCommandId( | 69 bool MediaStreamDevicesMenuModel::GetAcceleratorForCommandId( |
60 int command_id, | 70 int command_id, |
61 ui::Accelerator* accelerator) { | 71 ui::Accelerator* accelerator) { |
62 return false; | 72 return false; |
63 } | 73 } |
64 | 74 |
65 void MediaStreamDevicesMenuModel::ExecuteCommand(int command_id) { | 75 void MediaStreamDevicesMenuModel::ExecuteCommand(int command_id) { |
66 CommandMap::iterator it = commands_.find(command_id); | 76 switch (command_id) { |
67 DCHECK(it != commands_.end()); | 77 case IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW: |
78 always_allow_ = !always_allow_; | |
79 break; | |
80 default: | |
81 CommandMap::iterator it = commands_.find(command_id); | |
82 DCHECK(it != commands_.end()); | |
68 | 83 |
69 if (it->second.type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) | 84 if (it->second.type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) |
70 selected_command_id_audio_ = command_id; | 85 selected_command_id_audio_ = command_id; |
71 else | 86 else |
72 selected_command_id_video_ = command_id; | 87 selected_command_id_video_ = command_id; |
88 break; | |
89 } | |
73 } | 90 } |
74 | 91 |
75 void MediaStreamDevicesMenuModel::AddDevices( | 92 void MediaStreamDevicesMenuModel::AddDevices( |
76 const content::MediaStreamDevices& devices) { | 93 const content::MediaStreamDevices& devices) { |
77 for (size_t i = 0; i < devices.size(); ++i) { | 94 for (size_t i = 0; i < devices.size(); ++i) { |
78 int command_id = commands_.size(); | 95 int command_id = commands_.size(); |
79 commands_.insert(std::make_pair(command_id, devices[i])); | 96 commands_.insert(std::make_pair(command_id, devices[i])); |
80 int message_id = (devices[i].type == | 97 int message_id = (devices[i].type == |
81 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ? | 98 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ? |
82 IDS_MEDIA_CAPTURE_MIC : IDS_MEDIA_CAPTURE_VIDEO; | 99 IDS_MEDIA_CAPTURE_AUDIO : IDS_MEDIA_CAPTURE_VIDEO; |
83 AddCheckItem(command_id, | 100 AddCheckItem(command_id, |
84 l10n_util::GetStringFUTF16(message_id, | 101 l10n_util::GetStringFUTF16(message_id, |
85 UTF8ToUTF16(devices[i].name))); | 102 UTF8ToUTF16(devices[i].name))); |
86 } | 103 } |
87 } | 104 } |
105 | |
106 void MediaStreamDevicesMenuModel::AddAlwaysAllowOption(bool audio, bool video) { | |
107 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
| |
108 return; | |
109 | |
110 int command_id = IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW; | |
111 int message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_AND_VIDEO; | |
112 if (audio && !video) | |
113 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_ONLY; | |
114 else if (!audio && video) | |
115 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_VIDEO_ONLY; | |
116 | |
117 AddSeparator(); | |
118 AddCheckItem(command_id, l10n_util::GetStringUTF16(message_id)); | |
119 } | |
OLD | NEW |