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 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 type == content::MEDIA_DEVICE_AUDIO_CAPTURE | 396 type == content::MEDIA_DEVICE_AUDIO_CAPTURE |
397 ? CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC | 397 ? CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC |
398 : CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 398 : CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
399 NO_RESOURCE_IDENTIFIER) == CONTENT_SETTING_ALLOW) { | 399 NO_RESOURCE_IDENTIFIER) == CONTENT_SETTING_ALLOW) { |
400 return true; | 400 return true; |
401 } | 401 } |
402 | 402 |
403 return false; | 403 return false; |
404 } | 404 } |
405 | 405 |
| 406 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( |
| 407 content::WebContents* web_contents, |
| 408 const GURL& security_origin, |
| 409 content::MediaStreamType type) { |
| 410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 411 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || |
| 412 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); |
| 413 |
| 414 Profile* profile = |
| 415 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 416 |
| 417 if (CheckAllowAllMediaStreamContentForOrigin(profile, security_origin)) |
| 418 return true; |
| 419 |
| 420 const char* policy_name = type == content::MEDIA_DEVICE_AUDIO_CAPTURE |
| 421 ? prefs::kAudioCaptureAllowed |
| 422 : prefs::kVideoCaptureAllowed; |
| 423 const char* list_policy_name = type == content::MEDIA_DEVICE_AUDIO_CAPTURE |
| 424 ? prefs::kAudioCaptureAllowedUrls |
| 425 : prefs::kVideoCaptureAllowedUrls; |
| 426 if (GetDevicePolicy( |
| 427 profile, security_origin, policy_name, list_policy_name) == |
| 428 ALWAYS_ALLOW) { |
| 429 return true; |
| 430 } |
| 431 |
| 432 // There's no secondary URL for these content types, hence duplicating |
| 433 // |security_origin|. |
| 434 if (profile->GetHostContentSettingsMap()->GetContentSetting( |
| 435 security_origin, |
| 436 security_origin, |
| 437 type == content::MEDIA_DEVICE_AUDIO_CAPTURE |
| 438 ? CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC |
| 439 : CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 440 NO_RESOURCE_IDENTIFIER) == CONTENT_SETTING_ALLOW) { |
| 441 return true; |
| 442 } |
| 443 |
| 444 return false; |
| 445 } |
| 446 |
| 447 #if defined(ENABLE_EXTENSIONS) |
| 448 bool MediaCaptureDevicesDispatcher::CheckMediaAccessPermission( |
| 449 content::WebContents* web_contents, |
| 450 const GURL& security_origin, |
| 451 content::MediaStreamType type, |
| 452 const extensions::Extension* extension) { |
| 453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 454 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || |
| 455 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); |
| 456 |
| 457 if (extension->is_platform_app() || |
| 458 IsMediaRequestWhitelistedForExtension(extension)) { |
| 459 return extension->permissions_data()->HasAPIPermission( |
| 460 type == content::MEDIA_DEVICE_AUDIO_CAPTURE |
| 461 ? extensions::APIPermission::kAudioCapture |
| 462 : extensions::APIPermission::kVideoCapture); |
| 463 } |
| 464 |
| 465 return CheckMediaAccessPermission(web_contents, security_origin, type); |
| 466 } |
| 467 #endif |
| 468 |
406 void MediaCaptureDevicesDispatcher::ProcessDesktopCaptureAccessRequest( | 469 void MediaCaptureDevicesDispatcher::ProcessDesktopCaptureAccessRequest( |
407 content::WebContents* web_contents, | 470 content::WebContents* web_contents, |
408 const content::MediaStreamRequest& request, | 471 const content::MediaStreamRequest& request, |
409 const content::MediaResponseCallback& callback, | 472 const content::MediaResponseCallback& callback, |
410 const extensions::Extension* extension) { | 473 const extensions::Extension* extension) { |
411 content::MediaStreamDevices devices; | 474 content::MediaStreamDevices devices; |
412 scoped_ptr<content::MediaStreamUI> ui; | 475 scoped_ptr<content::MediaStreamUI> ui; |
413 | 476 |
414 if (request.video_type != content::MEDIA_DESKTOP_VIDEO_CAPTURE) { | 477 if (request.video_type != content::MEDIA_DESKTOP_VIDEO_CAPTURE) { |
415 callback.Run(devices, content::MEDIA_DEVICE_INVALID_STATE, ui.Pass()); | 478 callback.Run(devices, content::MEDIA_DEVICE_INVALID_STATE, ui.Pass()); |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 | 1064 |
1002 void MediaCaptureDevicesDispatcher::SetTestAudioCaptureDevices( | 1065 void MediaCaptureDevicesDispatcher::SetTestAudioCaptureDevices( |
1003 const MediaStreamDevices& devices) { | 1066 const MediaStreamDevices& devices) { |
1004 test_audio_devices_ = devices; | 1067 test_audio_devices_ = devices; |
1005 } | 1068 } |
1006 | 1069 |
1007 void MediaCaptureDevicesDispatcher::SetTestVideoCaptureDevices( | 1070 void MediaCaptureDevicesDispatcher::SetTestVideoCaptureDevices( |
1008 const MediaStreamDevices& devices) { | 1071 const MediaStreamDevices& devices) { |
1009 test_video_devices_ = devices; | 1072 test_video_devices_ = devices; |
1010 } | 1073 } |
OLD | NEW |