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

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

Issue 23453012: Make sure we don't open audio or video device if blocked by policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_controller.h" 5 #include "chrome/browser/media/media_stream_devices_controller.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/content_settings/content_settings_provider.h" 10 #include "chrome/browser/content_settings/content_settings_provider.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // Get the default devices for the request. 181 // Get the default devices for the request.
182 content::MediaStreamDevices devices; 182 content::MediaStreamDevices devices;
183 bool audio_allowed = IsDeviceAudioCaptureRequestedAndAllowed(); 183 bool audio_allowed = IsDeviceAudioCaptureRequestedAndAllowed();
184 bool video_allowed = IsDeviceVideoCaptureRequestedAndAllowed(); 184 bool video_allowed = IsDeviceVideoCaptureRequestedAndAllowed();
185 if (audio_allowed || video_allowed) { 185 if (audio_allowed || video_allowed) {
186 switch (request_.request_type) { 186 switch (request_.request_type) {
187 case content::MEDIA_OPEN_DEVICE: { 187 case content::MEDIA_OPEN_DEVICE: {
188 const content::MediaStreamDevice* device = NULL; 188 const content::MediaStreamDevice* device = NULL;
189 // For open device request pick the desired device or fall back to the 189 // For open device request pick the desired device or fall back to the
190 // first available of the given type. 190 // first available of the given type.
191 if (request_.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { 191 if (audio_allowed &&
192 request_.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) {
192 device = MediaCaptureDevicesDispatcher::GetInstance()-> 193 device = MediaCaptureDevicesDispatcher::GetInstance()->
193 GetRequestedAudioDevice(request_.requested_audio_device_id); 194 GetRequestedAudioDevice(request_.requested_audio_device_id);
194 // TODO(wjia): Confirm this is the intended behavior. 195 // TODO(wjia): Confirm this is the intended behavior.
195 if (!device) { 196 if (!device) {
196 device = MediaCaptureDevicesDispatcher::GetInstance()-> 197 device = MediaCaptureDevicesDispatcher::GetInstance()->
197 GetFirstAvailableAudioDevice(); 198 GetFirstAvailableAudioDevice();
198 } 199 }
199 } else if (request_.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) { 200 } else if (video_allowed &&
201 request_.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) {
200 // Pepper API opens only one device at a time. 202 // Pepper API opens only one device at a time.
201 device = MediaCaptureDevicesDispatcher::GetInstance()-> 203 device = MediaCaptureDevicesDispatcher::GetInstance()->
202 GetRequestedVideoDevice(request_.requested_video_device_id); 204 GetRequestedVideoDevice(request_.requested_video_device_id);
203 // TODO(wjia): Confirm this is the intended behavior. 205 // TODO(wjia): Confirm this is the intended behavior.
204 if (!device) { 206 if (!device) {
205 device = MediaCaptureDevicesDispatcher::GetInstance()-> 207 device = MediaCaptureDevicesDispatcher::GetInstance()->
206 GetFirstAvailableVideoDevice(); 208 GetFirstAvailableVideoDevice();
207 } 209 }
208 } 210 }
209 if (device) 211 if (device)
210 devices.push_back(*device); 212 devices.push_back(*device);
211 break; 213 break;
212 } case content::MEDIA_GENERATE_STREAM: { 214 } case content::MEDIA_GENERATE_STREAM: {
wjia(left Chromium) 2013/08/28 16:57:35 nit: drop the case to a new line. Somehow, this sl
Henrik Grunell 2013/08/29 08:19:51 Done. Also added {} to the other case blocks to be
213 bool needs_audio_device = audio_allowed; 215 bool needs_audio_device = audio_allowed;
214 bool needs_video_device = video_allowed; 216 bool needs_video_device = video_allowed;
wjia(left Chromium) 2013/08/28 16:57:35 Should these be the following? needs_*_device =
Henrik Grunell 2013/08/29 08:19:51 For request_.request_type == content::MEDIA_GENERA
215 217
216 // Get the exact audio or video device if an id is specified. 218 // Get the exact audio or video device if an id is specified.
217 if (!request_.requested_audio_device_id.empty()) { 219 if (needs_audio_device && !request_.requested_audio_device_id.empty()) {
218 const content::MediaStreamDevice* audio_device = 220 const content::MediaStreamDevice* audio_device =
219 MediaCaptureDevicesDispatcher::GetInstance()-> 221 MediaCaptureDevicesDispatcher::GetInstance()->
220 GetRequestedAudioDevice(request_.requested_audio_device_id); 222 GetRequestedAudioDevice(request_.requested_audio_device_id);
221 if (audio_device) { 223 if (audio_device) {
222 devices.push_back(*audio_device); 224 devices.push_back(*audio_device);
223 needs_audio_device = false; 225 needs_audio_device = false;
224 } 226 }
225 } 227 }
226 if (!request_.requested_video_device_id.empty()) { 228 if (needs_video_device && !request_.requested_video_device_id.empty()) {
227 const content::MediaStreamDevice* video_device = 229 const content::MediaStreamDevice* video_device =
tommi (sloooow) - chröme 2013/08/28 16:13:47 Wouldn't it make more sense to check the allowed b
Henrik Grunell 2013/08/29 08:19:51 Agree. Then I also renamed the needs_* bools to ge
228 MediaCaptureDevicesDispatcher::GetInstance()-> 230 MediaCaptureDevicesDispatcher::GetInstance()->
229 GetRequestedVideoDevice(request_.requested_video_device_id); 231 GetRequestedVideoDevice(request_.requested_video_device_id);
230 if (video_device) { 232 if (video_device) {
231 devices.push_back(*video_device); 233 devices.push_back(*video_device);
232 needs_video_device = false; 234 needs_video_device = false;
233 } 235 }
234 } 236 }
235 237
236 // If either or both audio and video devices were requested but not 238 // If either or both audio and video devices were requested but not
237 // specified by id, get the default devices. 239 // specified by id, get the default devices.
238 if (needs_audio_device || needs_video_device) { 240 if (needs_audio_device || needs_video_device) {
239 MediaCaptureDevicesDispatcher::GetInstance()-> 241 MediaCaptureDevicesDispatcher::GetInstance()->
240 GetDefaultDevicesForProfile(profile_, 242 GetDefaultDevicesForProfile(profile_,
241 needs_audio_device, 243 needs_audio_device,
242 needs_video_device, 244 needs_video_device,
243 &devices); 245 &devices);
244 } 246 }
245 break; 247 break;
246 } case content::MEDIA_DEVICE_ACCESS: 248 } case content::MEDIA_DEVICE_ACCESS:
wjia(left Chromium) 2013/08/28 16:57:35 ditto.
Henrik Grunell 2013/08/29 08:19:51 Done.
247 // Get the default devices for the request. 249 // Get the default devices for the request.
248 MediaCaptureDevicesDispatcher::GetInstance()-> 250 MediaCaptureDevicesDispatcher::GetInstance()->
249 GetDefaultDevicesForProfile(profile_, 251 GetDefaultDevicesForProfile(profile_,
250 audio_allowed, 252 audio_allowed,
251 video_allowed, 253 video_allowed,
252 &devices); 254 &devices);
253 break; 255 break;
254 case content::MEDIA_ENUMERATE_DEVICES: 256 case content::MEDIA_ENUMERATE_DEVICES:
255 // Do nothing. 257 // Do nothing.
256 NOTREACHED(); 258 NOTREACHED();
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 request_permissions_.find(content::MEDIA_DEVICE_AUDIO_CAPTURE); 506 request_permissions_.find(content::MEDIA_DEVICE_AUDIO_CAPTURE);
505 return it != request_permissions_.end() && it->second == MEDIA_ALLOWED; 507 return it != request_permissions_.end() && it->second == MEDIA_ALLOWED;
506 } 508 }
507 509
508 bool MediaStreamDevicesController::IsDeviceVideoCaptureRequestedAndAllowed() 510 bool MediaStreamDevicesController::IsDeviceVideoCaptureRequestedAndAllowed()
509 const { 511 const {
510 MediaStreamTypePermissionMap::const_iterator it = 512 MediaStreamTypePermissionMap::const_iterator it =
511 request_permissions_.find(content::MEDIA_DEVICE_VIDEO_CAPTURE); 513 request_permissions_.find(content::MEDIA_DEVICE_VIDEO_CAPTURE);
512 return it != request_permissions_.end() && it->second == MEDIA_ALLOWED; 514 return it != request_permissions_.end() && it->second == MEDIA_ALLOWED;
513 } 515 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698