| 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_stream_devices_controller.h" | 5 #include "chrome/browser/media/media_stream_devices_controller.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 ->GetMediaStreamCaptureIndicator() | 456 ->GetMediaStreamCaptureIndicator() |
| 457 ->RegisterMediaStream(web_contents_, devices); | 457 ->RegisterMediaStream(web_contents_, devices); |
| 458 } | 458 } |
| 459 base::ResetAndReturn(&callback_).Run(devices, request_result, std::move(ui)); | 459 base::ResetAndReturn(&callback_).Run(devices, request_result, std::move(ui)); |
| 460 } | 460 } |
| 461 | 461 |
| 462 void MediaStreamDevicesController::StorePermission( | 462 void MediaStreamDevicesController::StorePermission( |
| 463 ContentSetting new_audio_setting, | 463 ContentSetting new_audio_setting, |
| 464 ContentSetting new_video_setting) const { | 464 ContentSetting new_video_setting) const { |
| 465 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 465 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 466 | 466 DCHECK(content::IsOriginSecure(request_.security_origin) || |
| 467 bool is_pepper_request = | 467 request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY); |
| 468 request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY; | |
| 469 | 468 |
| 470 if (IsAskingForAudio() && new_audio_setting != CONTENT_SETTING_ASK) { | 469 if (IsAskingForAudio() && new_audio_setting != CONTENT_SETTING_ASK) { |
| 471 if (ShouldPersistContentSetting(new_audio_setting, request_.security_origin, | 470 HostContentSettingsMapFactory::GetForProfile(profile_) |
| 472 is_pepper_request)) { | 471 ->SetContentSettingDefaultScope(request_.security_origin, GURL(), |
| 473 HostContentSettingsMapFactory::GetForProfile(profile_) | 472 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| 474 ->SetContentSettingDefaultScope(request_.security_origin, GURL(), | 473 std::string(), new_audio_setting); |
| 475 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | |
| 476 std::string(), new_audio_setting); | |
| 477 } | |
| 478 } | 474 } |
| 479 if (IsAskingForVideo() && new_video_setting != CONTENT_SETTING_ASK) { | 475 if (IsAskingForVideo() && new_video_setting != CONTENT_SETTING_ASK) { |
| 480 if (ShouldPersistContentSetting(new_video_setting, request_.security_origin, | 476 HostContentSettingsMapFactory::GetForProfile(profile_) |
| 481 is_pepper_request)) { | 477 ->SetContentSettingDefaultScope( |
| 482 HostContentSettingsMapFactory::GetForProfile(profile_) | 478 request_.security_origin, GURL(), |
| 483 ->SetContentSettingDefaultScope( | 479 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), |
| 484 request_.security_origin, GURL(), | 480 new_video_setting); |
| 485 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), | |
| 486 new_video_setting); | |
| 487 } | |
| 488 } | 481 } |
| 489 } | 482 } |
| 490 | 483 |
| 491 void MediaStreamDevicesController::UpdateTabSpecificContentSettings( | 484 void MediaStreamDevicesController::UpdateTabSpecificContentSettings( |
| 492 ContentSetting audio_setting, | 485 ContentSetting audio_setting, |
| 493 ContentSetting video_setting) const { | 486 ContentSetting video_setting) const { |
| 494 if (!content_settings_) | 487 if (!content_settings_) |
| 495 return; | 488 return; |
| 496 | 489 |
| 497 TabSpecificContentSettings::MicrophoneCameraState microphone_camera_state = | 490 TabSpecificContentSettings::MicrophoneCameraState microphone_camera_state = |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 | 547 |
| 555 content::PermissionType permission_type; | 548 content::PermissionType permission_type; |
| 556 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | 549 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
| 557 permission_type = content::PermissionType::AUDIO_CAPTURE; | 550 permission_type = content::PermissionType::AUDIO_CAPTURE; |
| 558 } else { | 551 } else { |
| 559 DCHECK(content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 552 DCHECK(content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 560 permission_type = content::PermissionType::VIDEO_CAPTURE; | 553 permission_type = content::PermissionType::VIDEO_CAPTURE; |
| 561 } | 554 } |
| 562 | 555 |
| 563 if (ContentTypeIsRequested(permission_type, request)) { | 556 if (ContentTypeIsRequested(permission_type, request)) { |
| 564 bool is_insecure_pepper_request = | 557 DCHECK(content::IsOriginSecure(request_.security_origin) || |
| 565 request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY && | 558 request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY); |
| 566 request.security_origin.SchemeIs(url::kHttpScheme); | 559 MediaPermission permission(content_type, request.security_origin, |
| 567 MediaPermission permission( | |
| 568 content_type, is_insecure_pepper_request, request.security_origin, | |
| 569 web_contents_->GetLastCommittedURL().GetOrigin(), profile_); | 560 web_contents_->GetLastCommittedURL().GetOrigin(), profile_); |
| 570 return permission.GetPermissionStatusWithDeviceRequired(requested_device_id, | 561 return permission.GetPermissionStatusWithDeviceRequired(requested_device_id, |
| 571 denial_reason); | 562 denial_reason); |
| 572 } | 563 } |
| 573 // Return the default content setting if the device is not requested. | 564 // Return the default content setting if the device is not requested. |
| 574 return CONTENT_SETTING_DEFAULT; | 565 return CONTENT_SETTING_DEFAULT; |
| 575 } | 566 } |
| 576 | 567 |
| 577 ContentSetting MediaStreamDevicesController::GetNewSetting( | 568 ContentSetting MediaStreamDevicesController::GetNewSetting( |
| 578 ContentSettingsType content_type, | 569 ContentSettingsType content_type, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 if (android_permission_blocked) | 606 if (android_permission_blocked) |
| 616 return false; | 607 return false; |
| 617 | 608 |
| 618 // Don't approve device requests if the tab was hidden. | 609 // Don't approve device requests if the tab was hidden. |
| 619 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 610 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
| 620 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 611 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
| 621 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 612 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
| 622 #endif | 613 #endif |
| 623 return true; | 614 return true; |
| 624 } | 615 } |
| OLD | NEW |