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

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: addressed sky's comment and replaced "Do not allow any site to" with "Do not allow sites to" 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 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->HasAudio() && !delegate->GetAudioDevices().empty();
22 if (delegate->has_video() && !delegate->GetVideoDevices().empty()) { 23 bool video = delegate->HasVideo() && !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);
34 } 38 }
35 39
36 MediaStreamDevicesMenuModel::~MediaStreamDevicesMenuModel() { 40 MediaStreamDevicesMenuModel::~MediaStreamDevicesMenuModel() {
37 } 41 }
38 42
39 bool MediaStreamDevicesMenuModel::GetSelectedDeviceId( 43 bool MediaStreamDevicesMenuModel::GetSelectedDeviceId(
40 content::MediaStreamDeviceType type, 44 content::MediaStreamDeviceType type,
41 std::string* device_id) const { 45 std::string* device_id) const {
42 int command_id = (type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ? 46 int command_id = (type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ?
43 selected_command_id_audio_ : selected_command_id_video_; 47 selected_command_id_audio_ : selected_command_id_video_;
44 CommandMap::const_iterator it = commands_.find(command_id); 48 CommandMap::const_iterator it = commands_.find(command_id);
45 if (it != commands_.end()) 49 if (it != commands_.end())
46 *device_id = it->second.device_id; 50 *device_id = it->second.device_id;
47 return (it != commands_.end()); 51 return (it != commands_.end());
48 } 52 }
49 53
50 bool MediaStreamDevicesMenuModel::IsCommandIdChecked(int command_id) const { 54 bool MediaStreamDevicesMenuModel::IsCommandIdChecked(int command_id) const {
51 return (selected_command_id_audio_ == command_id || 55 switch (command_id) {
52 selected_command_id_video_ == command_id); 56 case IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW:
57 return always_allow_;
58 default:
59 return (selected_command_id_audio_ == command_id ||
60 selected_command_id_video_ == command_id);
61 }
53 } 62 }
54 63
55 bool MediaStreamDevicesMenuModel::IsCommandIdEnabled(int command_id) const { 64 bool MediaStreamDevicesMenuModel::IsCommandIdEnabled(int command_id) const {
56 return true; 65 return true;
57 } 66 }
58 67
59 bool MediaStreamDevicesMenuModel::GetAcceleratorForCommandId( 68 bool MediaStreamDevicesMenuModel::GetAcceleratorForCommandId(
60 int command_id, 69 int command_id,
61 ui::Accelerator* accelerator) { 70 ui::Accelerator* accelerator) {
62 return false; 71 return false;
63 } 72 }
64 73
65 void MediaStreamDevicesMenuModel::ExecuteCommand(int command_id) { 74 void MediaStreamDevicesMenuModel::ExecuteCommand(int command_id) {
66 CommandMap::iterator it = commands_.find(command_id); 75 switch (command_id) {
67 DCHECK(it != commands_.end()); 76 case IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW:
77 always_allow_ = !always_allow_;
78 break;
79 default:
80 CommandMap::iterator it = commands_.find(command_id);
81 DCHECK(it != commands_.end());
68 82
69 if (it->second.type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) 83 if (it->second.type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE)
70 selected_command_id_audio_ = command_id; 84 selected_command_id_audio_ = command_id;
71 else 85 else
72 selected_command_id_video_ = command_id; 86 selected_command_id_video_ = command_id;
87 break;
88 }
73 } 89 }
74 90
75 void MediaStreamDevicesMenuModel::AddDevices( 91 void MediaStreamDevicesMenuModel::AddDevices(
76 const content::MediaStreamDevices& devices) { 92 const content::MediaStreamDevices& devices) {
77 for (size_t i = 0; i < devices.size(); ++i) { 93 for (size_t i = 0; i < devices.size(); ++i) {
78 int command_id = commands_.size(); 94 int command_id = commands_.size();
79 commands_.insert(std::make_pair(command_id, devices[i])); 95 commands_.insert(std::make_pair(command_id, devices[i]));
80 int message_id = (devices[i].type == 96 int message_id = (devices[i].type ==
81 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ? 97 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ?
82 IDS_MEDIA_CAPTURE_MIC : IDS_MEDIA_CAPTURE_VIDEO; 98 IDS_MEDIA_CAPTURE_AUDIO : IDS_MEDIA_CAPTURE_VIDEO;
83 AddCheckItem(command_id, 99 AddCheckItem(command_id,
84 l10n_util::GetStringFUTF16(message_id, 100 l10n_util::GetStringFUTF16(message_id,
85 UTF8ToUTF16(devices[i].name))); 101 UTF8ToUTF16(devices[i].name)));
86 } 102 }
87 } 103 }
104
105 void MediaStreamDevicesMenuModel::AddAlwaysAllowOption(bool audio, bool video) {
106 int command_id = IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW;
107 int message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_AND_VIDEO;
108 if (audio && !video)
109 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_ONLY;
110 else if (!audio && video)
111 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_VIDEO_ONLY;
112
113 AddSeparator();
114 AddCheckItem(command_id, l10n_util::GetStringUTF16(message_id));
115 }
OLDNEW
« no previous file with comments | « chrome/browser/media/media_stream_devices_menu_model.h ('k') | chrome/browser/policy/configuration_policy_handler_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698