Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: chrome/browser/media/media_stream_devices_menu_model.cc

Issue 10537099: add "always allow" option to the mediastream infobar and allow user to allow/not allow acces to devi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 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) {
22 const bool audio =
21 delegate->has_audio() && !delegate->GetAudioDevices().empty(); 23 delegate->has_audio() && !delegate->GetAudioDevices().empty();
22 if (delegate->has_video() && !delegate->GetVideoDevices().empty()) { 24 const bool video =
25 delegate->has_video() && !delegate->GetVideoDevices().empty();
26 if (video) {
23 // The default command ID is the first element that will be inserted. 27 // The default command ID is the first element that will be inserted.
24 selected_command_id_video_ = commands_.size(); 28 selected_command_id_video_ = commands_.size();
25 AddDevices(delegate->GetVideoDevices()); 29 AddDevices(delegate->GetVideoDevices());
26 if (nonempty_audio_section) 30 if (audio)
27 AddSeparator(); 31 AddSeparator();
28 } 32 }
29 if (nonempty_audio_section) { 33 if (audio) {
30 // The default command ID is the first element that will be inserted. 34 // The default command ID is the first element that will be inserted.
31 selected_command_id_audio_ = commands_.size(); 35 selected_command_id_audio_ = commands_.size();
32 AddDevices(delegate->GetAudioDevices()); 36 AddDevices(delegate->GetAudioDevices());
33 } 37 }
38
39 AddAlwaysAndNeverOptions(audio, video);
40
34 } 41 }
35 42
36 MediaStreamDevicesMenuModel::~MediaStreamDevicesMenuModel() { 43 MediaStreamDevicesMenuModel::~MediaStreamDevicesMenuModel() {
37 } 44 }
38 45
39 bool MediaStreamDevicesMenuModel::GetSelectedDeviceId( 46 bool MediaStreamDevicesMenuModel::GetSelectedDeviceId(
40 content::MediaStreamDeviceType type, 47 content::MediaStreamDeviceType type,
41 std::string* device_id) const { 48 std::string* device_id) const {
42 int command_id = (type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ? 49 int command_id = (type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ?
43 selected_command_id_audio_ : selected_command_id_video_; 50 selected_command_id_audio_ : selected_command_id_video_;
44 CommandMap::const_iterator it = commands_.find(command_id); 51 CommandMap::const_iterator it = commands_.find(command_id);
45 if (it != commands_.end()) 52 if (it != commands_.end())
46 *device_id = it->second.device_id; 53 *device_id = it->second.device_id;
47 return (it != commands_.end()); 54 return (it != commands_.end());
48 } 55 }
49 56
50 bool MediaStreamDevicesMenuModel::IsCommandIdChecked(int command_id) const { 57 bool MediaStreamDevicesMenuModel::IsCommandIdChecked(int command_id) const {
51 return (selected_command_id_audio_ == command_id || 58 switch (command_id) {
52 selected_command_id_video_ == command_id); 59 case IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW:
60 return always_allow_;
61 default:
62 return (selected_command_id_audio_ == command_id ||
63 selected_command_id_video_ == command_id);
64 }
53 } 65 }
54 66
55 bool MediaStreamDevicesMenuModel::IsCommandIdEnabled(int command_id) const { 67 bool MediaStreamDevicesMenuModel::IsCommandIdEnabled(int command_id) const {
56 return true; 68 return true;
57 } 69 }
58 70
59 bool MediaStreamDevicesMenuModel::GetAcceleratorForCommandId( 71 bool MediaStreamDevicesMenuModel::GetAcceleratorForCommandId(
60 int command_id, 72 int command_id,
61 ui::Accelerator* accelerator) { 73 ui::Accelerator* accelerator) {
62 return false; 74 return false;
63 } 75 }
64 76
65 void MediaStreamDevicesMenuModel::ExecuteCommand(int command_id) { 77 void MediaStreamDevicesMenuModel::ExecuteCommand(int command_id) {
66 CommandMap::iterator it = commands_.find(command_id); 78 switch (command_id) {
67 DCHECK(it != commands_.end()); 79 case IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW:
80 always_allow_ = !always_allow_;
81 break;
82 default:
83 CommandMap::iterator it = commands_.find(command_id);
84 DCHECK(it != commands_.end());
68 85
69 if (it->second.type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) 86 if (it->second.type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE)
70 selected_command_id_audio_ = command_id; 87 selected_command_id_audio_ = command_id;
71 else 88 else
72 selected_command_id_video_ = command_id; 89 selected_command_id_video_ = command_id;
90 break;
91 }
73 } 92 }
74 93
75 void MediaStreamDevicesMenuModel::AddDevices( 94 void MediaStreamDevicesMenuModel::AddDevices(
76 const content::MediaStreamDevices& devices) { 95 const content::MediaStreamDevices& devices) {
77 for (size_t i = 0; i < devices.size(); ++i) { 96 for (size_t i = 0; i < devices.size(); ++i) {
78 int command_id = commands_.size(); 97 int command_id = commands_.size();
79 commands_.insert(std::make_pair(command_id, devices[i])); 98 commands_.insert(std::make_pair(command_id, devices[i]));
80 int message_id = (devices[i].type == 99 int message_id = (devices[i].type ==
81 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ? 100 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ?
82 IDS_MEDIA_CAPTURE_MIC : IDS_MEDIA_CAPTURE_VIDEO; 101 IDS_MEDIA_CAPTURE_AUDIO : IDS_MEDIA_CAPTURE_VIDEO;
83 AddCheckItem(command_id, 102 AddCheckItem(command_id,
84 l10n_util::GetStringFUTF16(message_id, 103 l10n_util::GetStringFUTF16(message_id,
85 UTF8ToUTF16(devices[i].name))); 104 UTF8ToUTF16(devices[i].name)));
86 } 105 }
87 } 106 }
107
108 void MediaStreamDevicesMenuModel::AddAlwaysAndNeverOptions(
109 bool audio, bool video) {
110 if (!audio && !video)
111 return;
112
113 AddSeparator();
114
115 // Add "always allow" item.
116 int command_id = IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW;
117 int message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_AND_VIDEO;
118 if (audio && !video)
119 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_ONLY;
120 else if (!audio && video)
121 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_VIDEO_ONLY;
122
123 AddCheckItem(command_id, l10n_util::GetStringUTF16(message_id));
124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698