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

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

Issue 10912004: Begin adding support for tab mirroring via the MediaStream audio/video capturing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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/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 const MediaStreamInfoBarDelegate* delegate) 18 const MediaStreamInfoBarDelegate* delegate)
18 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), 19 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
19 selected_command_id_audio_(-1), 20 selected_command_id_audio_(-1),
20 selected_command_id_video_(-1), 21 selected_command_id_video_(-1),
21 always_allow_(false) { 22 always_allow_(false) {
22 bool audio = delegate->HasAudio() && !delegate->GetAudioDevices().empty(); 23 const content::MediaStreamDevices& audio_devices =
23 bool video = delegate->HasVideo() && !delegate->GetVideoDevices().empty(); 24 delegate->GetAudioDevices();
25 const content::MediaStreamDevices& video_devices =
26 delegate->GetVideoDevices();
27 const bool audio = delegate->HasAudio() && !audio_devices.empty();
28 const bool video = delegate->HasVideo() && !video_devices.empty();
24 if (video) { 29 if (video) {
25 // The default command ID is the first element that will be inserted. 30 // The default command ID is the first element that will be inserted.
26 selected_command_id_video_ = commands_.size(); 31 selected_command_id_video_ = commands_.size();
27 AddDevices(delegate->GetVideoDevices()); 32 AddDevices(video_devices);
28 if (audio) 33 if (audio)
29 AddSeparator(ui::NORMAL_SEPARATOR); 34 AddSeparator(ui::NORMAL_SEPARATOR);
30 } 35 }
31 if (audio) { 36 if (audio) {
32 // The default command ID is the first element that will be inserted. 37 // The default command ID is the first element that will be inserted.
33 selected_command_id_audio_ = commands_.size(); 38 selected_command_id_audio_ = commands_.size();
34 AddDevices(delegate->GetAudioDevices()); 39 AddDevices(audio_devices);
35 } 40 }
36 41
37 // Show "always allow" option only for the secure connection. 42 // Show "always allow" option when auto-accepting would be safe in the future.
38 if (delegate->GetSecurityOrigin().SchemeIsSecure()) 43 AddAlwaysAllowOption(delegate->IsSafeToAlwaysAllowAudio(),
39 AddAlwaysAllowOption(audio, video); 44 delegate->IsSafeToAlwaysAllowVideo());
40 } 45 }
41 46
42 MediaStreamDevicesMenuModel::~MediaStreamDevicesMenuModel() { 47 MediaStreamDevicesMenuModel::~MediaStreamDevicesMenuModel() {
43 } 48 }
44 49
45 bool MediaStreamDevicesMenuModel::GetSelectedDeviceId( 50 bool MediaStreamDevicesMenuModel::GetSelectedAudioDeviceId(
46 content::MediaStreamDeviceType type,
47 std::string* device_id) const { 51 std::string* device_id) const {
48 int command_id = (type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ? 52 CommandMap::const_iterator it = commands_.find(selected_command_id_audio_);
49 selected_command_id_audio_ : selected_command_id_video_; 53 if (it != commands_.end()) {
50 CommandMap::const_iterator it = commands_.find(command_id);
51 if (it != commands_.end())
52 *device_id = it->second.device_id; 54 *device_id = it->second.device_id;
53 return (it != commands_.end()); 55 return true;
56 } else {
57 return false;
58 }
59 }
60
61 bool MediaStreamDevicesMenuModel::GetSelectedVideoDeviceId(
62 std::string* device_id) const {
63 CommandMap::const_iterator it = commands_.find(selected_command_id_video_);
64 if (it != commands_.end()) {
65 *device_id = it->second.device_id;
66 return true;
67 } else {
68 return false;
69 }
54 } 70 }
55 71
56 bool MediaStreamDevicesMenuModel::IsCommandIdChecked(int command_id) const { 72 bool MediaStreamDevicesMenuModel::IsCommandIdChecked(int command_id) const {
57 switch (command_id) { 73 switch (command_id) {
58 case IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW: 74 case IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW:
59 return always_allow_; 75 return always_allow_;
60 default: 76 default:
61 return (selected_command_id_audio_ == command_id || 77 return (selected_command_id_audio_ == command_id ||
62 selected_command_id_video_ == command_id); 78 selected_command_id_video_ == command_id);
63 } 79 }
(...skipping 11 matching lines...) Expand all
75 91
76 void MediaStreamDevicesMenuModel::ExecuteCommand(int command_id) { 92 void MediaStreamDevicesMenuModel::ExecuteCommand(int command_id) {
77 switch (command_id) { 93 switch (command_id) {
78 case IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW: 94 case IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW:
79 always_allow_ = !always_allow_; 95 always_allow_ = !always_allow_;
80 break; 96 break;
81 default: 97 default:
82 CommandMap::iterator it = commands_.find(command_id); 98 CommandMap::iterator it = commands_.find(command_id);
83 DCHECK(it != commands_.end()); 99 DCHECK(it != commands_.end());
84 100
85 if (it->second.type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) 101 if (content::IsAudioMediaStreamDeviceType(it->second.type)) {
86 selected_command_id_audio_ = command_id; 102 selected_command_id_audio_ = command_id;
87 else 103 } else if (content::IsVideoMediaStreamDeviceType(it->second.type)) {
88 selected_command_id_video_ = command_id; 104 selected_command_id_video_ = command_id;
105 } else {
106 NOTREACHED();
107 }
89 break; 108 break;
90 } 109 }
91 } 110 }
92 111
93 void MediaStreamDevicesMenuModel::AddDevices( 112 void MediaStreamDevicesMenuModel::AddDevices(
94 const content::MediaStreamDevices& devices) { 113 const content::MediaStreamDevices& devices) {
95 for (size_t i = 0; i < devices.size(); ++i) { 114 for (size_t i = 0; i < devices.size(); ++i) {
96 int command_id = commands_.size(); 115 int command_id = commands_.size();
97 commands_.insert(std::make_pair(command_id, devices[i])); 116 commands_.insert(std::make_pair(command_id, devices[i]));
98 int message_id = (devices[i].type == 117 int message_id;
99 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) ? 118 if (content::IsAudioMediaStreamDeviceType(devices[i].type)) {
100 IDS_MEDIA_CAPTURE_AUDIO : IDS_MEDIA_CAPTURE_VIDEO; 119 message_id = IDS_MEDIA_CAPTURE_AUDIO;
120 } else if (content::IsVideoMediaStreamDeviceType(devices[i].type)) {
121 message_id = IDS_MEDIA_CAPTURE_VIDEO;
122 } else {
123 NOTIMPLEMENTED();
124 continue;
125 }
101 AddCheckItem(command_id, 126 AddCheckItem(command_id,
102 l10n_util::GetStringFUTF16(message_id, 127 l10n_util::GetStringFUTF16(message_id,
103 UTF8ToUTF16(devices[i].name))); 128 UTF8ToUTF16(devices[i].name)));
104 } 129 }
105 } 130 }
106 131
107 void MediaStreamDevicesMenuModel::AddAlwaysAllowOption(bool audio, bool video) { 132 void MediaStreamDevicesMenuModel::AddAlwaysAllowOption(bool audio, bool video) {
133 if (!audio && !video) {
134 return;
135 }
136
108 int command_id = IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW; 137 int command_id = IDC_MEDIA_STREAM_DEVICE_ALWAYS_ALLOW;
109 int message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_AND_VIDEO; 138 int message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_AND_VIDEO;
110 if (audio && !video) 139 if (audio && !video)
111 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_ONLY; 140 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_AUDIO_ONLY;
112 else if (!audio && video) 141 else if (!audio && video)
113 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_VIDEO_ONLY; 142 message_id = IDS_MEDIA_CAPTURE_ALWAYS_ALLOW_VIDEO_ONLY;
114 143
115 AddSeparator(ui::NORMAL_SEPARATOR); 144 AddSeparator(ui::NORMAL_SEPARATOR);
116 AddCheckItem(command_id, l10n_util::GetStringUTF16(message_id)); 145 AddCheckItem(command_id, l10n_util::GetStringUTF16(message_id));
117 } 146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698