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

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: Rebase 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 }
213 bool needs_audio_device = audio_allowed; 215 case content::MEDIA_GENERATE_STREAM: {
214 bool needs_video_device = video_allowed; 216 bool get_default_audio_device = audio_allowed;
217 bool get_default_video_device = video_allowed;
215 218
216 // Get the exact audio or video device if an id is specified. 219 // Get the exact audio or video device if an id is specified.
217 if (!request_.requested_audio_device_id.empty()) { 220 if (audio_allowed && !request_.requested_audio_device_id.empty()) {
218 const content::MediaStreamDevice* audio_device = 221 const content::MediaStreamDevice* audio_device =
219 MediaCaptureDevicesDispatcher::GetInstance()-> 222 MediaCaptureDevicesDispatcher::GetInstance()->
220 GetRequestedAudioDevice(request_.requested_audio_device_id); 223 GetRequestedAudioDevice(request_.requested_audio_device_id);
221 if (audio_device) { 224 if (audio_device) {
222 devices.push_back(*audio_device); 225 devices.push_back(*audio_device);
223 needs_audio_device = false; 226 get_default_audio_device = false;
224 } 227 }
225 } 228 }
226 if (!request_.requested_video_device_id.empty()) { 229 if (video_allowed && !request_.requested_video_device_id.empty()) {
227 const content::MediaStreamDevice* video_device = 230 const content::MediaStreamDevice* video_device =
228 MediaCaptureDevicesDispatcher::GetInstance()-> 231 MediaCaptureDevicesDispatcher::GetInstance()->
229 GetRequestedVideoDevice(request_.requested_video_device_id); 232 GetRequestedVideoDevice(request_.requested_video_device_id);
230 if (video_device) { 233 if (video_device) {
231 devices.push_back(*video_device); 234 devices.push_back(*video_device);
232 needs_video_device = false; 235 get_default_video_device = false;
233 } 236 }
234 } 237 }
235 238
236 // If either or both audio and video devices were requested but not 239 // If either or both audio and video devices were requested but not
237 // specified by id, get the default devices. 240 // specified by id, get the default devices.
238 if (needs_audio_device || needs_video_device) { 241 if (get_default_audio_device || get_default_video_device) {
239 MediaCaptureDevicesDispatcher::GetInstance()-> 242 MediaCaptureDevicesDispatcher::GetInstance()->
240 GetDefaultDevicesForProfile(profile_, 243 GetDefaultDevicesForProfile(profile_,
241 needs_audio_device, 244 get_default_audio_device,
242 needs_video_device, 245 get_default_video_device,
243 &devices); 246 &devices);
244 } 247 }
245 break; 248 break;
246 } case content::MEDIA_DEVICE_ACCESS: 249 }
250 case content::MEDIA_DEVICE_ACCESS: {
247 // Get the default devices for the request. 251 // Get the default devices for the request.
248 MediaCaptureDevicesDispatcher::GetInstance()-> 252 MediaCaptureDevicesDispatcher::GetInstance()->
249 GetDefaultDevicesForProfile(profile_, 253 GetDefaultDevicesForProfile(profile_,
250 audio_allowed, 254 audio_allowed,
251 video_allowed, 255 video_allowed,
252 &devices); 256 &devices);
253 break; 257 break;
254 case content::MEDIA_ENUMERATE_DEVICES: 258 }
259 case content::MEDIA_ENUMERATE_DEVICES: {
255 // Do nothing. 260 // Do nothing.
256 NOTREACHED(); 261 NOTREACHED();
257 break; 262 break;
258 } 263 }
264 } // switch
259 265
260 // TODO(raymes): We currently set the content permission for non-https 266 // TODO(raymes): We currently set the content permission for non-https
261 // websites for Pepper requests as well. This is temporary and should be 267 // websites for Pepper requests as well. This is temporary and should be
262 // removed. 268 // removed.
263 if (update_content_setting) { 269 if (update_content_setting) {
264 if ((IsSchemeSecure() && !devices.empty()) || 270 if ((IsSchemeSecure() && !devices.empty()) ||
265 request_.request_type == content::MEDIA_OPEN_DEVICE) { 271 request_.request_type == content::MEDIA_OPEN_DEVICE) {
266 SetPermission(true); 272 SetPermission(true);
267 } 273 }
268 } 274 }
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 request_permissions_.find(content::MEDIA_DEVICE_AUDIO_CAPTURE); 510 request_permissions_.find(content::MEDIA_DEVICE_AUDIO_CAPTURE);
505 return it != request_permissions_.end() && it->second == MEDIA_ALLOWED; 511 return it != request_permissions_.end() && it->second == MEDIA_ALLOWED;
506 } 512 }
507 513
508 bool MediaStreamDevicesController::IsDeviceVideoCaptureRequestedAndAllowed() 514 bool MediaStreamDevicesController::IsDeviceVideoCaptureRequestedAndAllowed()
509 const { 515 const {
510 MediaStreamTypePermissionMap::const_iterator it = 516 MediaStreamTypePermissionMap::const_iterator it =
511 request_permissions_.find(content::MEDIA_DEVICE_VIDEO_CAPTURE); 517 request_permissions_.find(content::MEDIA_DEVICE_VIDEO_CAPTURE);
512 return it != request_permissions_.end() && it->second == MEDIA_ALLOWED; 518 return it != request_permissions_.end() && it->second == MEDIA_ALLOWED;
513 } 519 }
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