OLD | NEW |
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_capture_devices_dispatcher.h" | 5 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 window_list.begin(); | 227 window_list.begin(); |
228 iter != window_list.end(); ++iter) { | 228 iter != window_list.end(); ++iter) { |
229 if ((*iter)->web_contents() == web_contents) | 229 if ((*iter)->web_contents() == web_contents) |
230 return (*iter)->GetNativeWindow(); | 230 return (*iter)->GetNativeWindow(); |
231 } | 231 } |
232 | 232 |
233 return NULL; | 233 return NULL; |
234 } | 234 } |
235 #endif | 235 #endif |
236 | 236 |
237 #if defined(ENABLE_EXTENSIONS) | |
238 const extensions::Extension* GetExtensionForOrigin( | |
239 Profile* profile, | |
240 const GURL& security_origin) { | |
241 if (!security_origin.SchemeIs(extensions::kExtensionScheme)) | |
242 return NULL; | |
243 | |
244 const extensions::Extension* extension = | |
245 extensions::ExtensionRegistry::Get(profile)->enabled_extensions().GetByID( | |
246 security_origin.host()); | |
247 DCHECK(extension); | |
248 return extension; | |
249 } | |
250 #endif | |
251 | |
252 } // namespace | 237 } // namespace |
253 | 238 |
254 MediaCaptureDevicesDispatcher::PendingAccessRequest::PendingAccessRequest( | 239 MediaCaptureDevicesDispatcher::PendingAccessRequest::PendingAccessRequest( |
255 const content::MediaStreamRequest& request, | 240 const content::MediaStreamRequest& request, |
256 const content::MediaResponseCallback& callback) | 241 const content::MediaResponseCallback& callback) |
257 : request(request), | 242 : request(request), |
258 callback(callback) { | 243 callback(callback) { |
259 } | 244 } |
260 | 245 |
261 MediaCaptureDevicesDispatcher::PendingAccessRequest::~PendingAccessRequest() {} | 246 MediaCaptureDevicesDispatcher::PendingAccessRequest::~PendingAccessRequest() {} |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 ProcessMediaAccessRequestFromPlatformAppOrExtension( | 347 ProcessMediaAccessRequestFromPlatformAppOrExtension( |
363 web_contents, request, callback, extension); | 348 web_contents, request, callback, extension); |
364 return; | 349 return; |
365 } | 350 } |
366 #endif | 351 #endif |
367 ProcessRegularMediaAccessRequest(web_contents, request, callback); | 352 ProcessRegularMediaAccessRequest(web_contents, request, callback); |
368 } | 353 } |
369 } | 354 } |
370 | 355 |
371 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( | 356 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( |
372 content::BrowserContext* browser_context, | |
373 const GURL& security_origin, | |
374 content::MediaStreamType type) { | |
375 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
376 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || | |
377 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); | |
378 | |
379 Profile* profile = Profile::FromBrowserContext(browser_context); | |
380 #if defined(ENABLE_EXTENSIONS) | |
381 const extensions::Extension* extension = | |
382 GetExtensionForOrigin(profile, security_origin); | |
383 | |
384 if (extension && (extension->is_platform_app() || | |
385 IsMediaRequestWhitelistedForExtension(extension))) { | |
386 return extension->permissions_data()->HasAPIPermission( | |
387 type == content::MEDIA_DEVICE_AUDIO_CAPTURE | |
388 ? extensions::APIPermission::kAudioCapture | |
389 : extensions::APIPermission::kVideoCapture); | |
390 } | |
391 #endif | |
392 | |
393 ContentSettingsType contentSettingsType = | |
394 type == content::MEDIA_DEVICE_AUDIO_CAPTURE | |
395 ? CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC | |
396 : CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA; | |
397 | |
398 if (CheckAllowAllMediaStreamContentForOrigin( | |
399 profile, security_origin, contentSettingsType)) { | |
400 return true; | |
401 } | |
402 | |
403 const char* policy_name = type == content::MEDIA_DEVICE_AUDIO_CAPTURE | |
404 ? prefs::kAudioCaptureAllowed | |
405 : prefs::kVideoCaptureAllowed; | |
406 const char* list_policy_name = type == content::MEDIA_DEVICE_AUDIO_CAPTURE | |
407 ? prefs::kAudioCaptureAllowedUrls | |
408 : prefs::kVideoCaptureAllowedUrls; | |
409 if (GetDevicePolicy( | |
410 profile, security_origin, policy_name, list_policy_name) == | |
411 ALWAYS_ALLOW) { | |
412 return true; | |
413 } | |
414 | |
415 // There's no secondary URL for these content types, hence duplicating | |
416 // |security_origin|. | |
417 if (profile->GetHostContentSettingsMap()->GetContentSetting( | |
418 security_origin, | |
419 security_origin, | |
420 contentSettingsType, | |
421 content_settings::ResourceIdentifier()) == CONTENT_SETTING_ALLOW) { | |
422 return true; | |
423 } | |
424 | |
425 return false; | |
426 } | |
427 | |
428 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( | |
429 content::WebContents* web_contents, | 357 content::WebContents* web_contents, |
430 const GURL& security_origin, | 358 const GURL& security_origin, |
431 content::MediaStreamType type) { | 359 content::MediaStreamType type) { |
432 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 360 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
433 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || | 361 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || |
434 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); | 362 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); |
435 | 363 |
436 Profile* profile = | 364 Profile* profile = |
437 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 365 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
438 | 366 |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 | 1067 |
1140 void MediaCaptureDevicesDispatcher::SetTestAudioCaptureDevices( | 1068 void MediaCaptureDevicesDispatcher::SetTestAudioCaptureDevices( |
1141 const MediaStreamDevices& devices) { | 1069 const MediaStreamDevices& devices) { |
1142 test_audio_devices_ = devices; | 1070 test_audio_devices_ = devices; |
1143 } | 1071 } |
1144 | 1072 |
1145 void MediaCaptureDevicesDispatcher::SetTestVideoCaptureDevices( | 1073 void MediaCaptureDevicesDispatcher::SetTestVideoCaptureDevices( |
1146 const MediaStreamDevices& devices) { | 1074 const MediaStreamDevices& devices) { |
1147 test_video_devices_ = devices; | 1075 test_video_devices_ = devices; |
1148 } | 1076 } |
OLD | NEW |