Chromium Code Reviews| 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/webrtc/media_stream_devices_controller.h" | 5 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 17 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" | 17 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
| 18 #include "chrome/browser/media/webrtc/media_permission.h" | |
| 19 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" | 18 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" |
| 20 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" | 19 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" |
| 20 #include "chrome/browser/permissions/permission_manager.h" | |
| 21 #include "chrome/browser/permissions/permission_result.h" | |
| 21 #include "chrome/browser/permissions/permission_uma_util.h" | 22 #include "chrome/browser/permissions/permission_uma_util.h" |
| 22 #include "chrome/browser/permissions/permission_util.h" | 23 #include "chrome/browser/permissions/permission_util.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
| 28 #include "components/content_settings/core/browser/host_content_settings_map.h" | 29 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 29 #include "components/content_settings/core/common/content_settings_pattern.h" | 30 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 30 #include "components/pref_registry/pref_registry_syncable.h" | 31 #include "components/pref_registry/pref_registry_syncable.h" |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 } | 710 } |
| 710 | 711 |
| 711 ContentSetting MediaStreamDevicesController::GetContentSetting( | 712 ContentSetting MediaStreamDevicesController::GetContentSetting( |
| 712 ContentSettingsType content_type, | 713 ContentSettingsType content_type, |
| 713 const content::MediaStreamRequest& request, | 714 const content::MediaStreamRequest& request, |
| 714 bool was_requested, | 715 bool was_requested, |
| 715 bool was_initially_blocked, | 716 bool was_initially_blocked, |
| 716 content::MediaStreamRequestResult* denial_reason) const { | 717 content::MediaStreamRequestResult* denial_reason) const { |
| 717 DCHECK(content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | 718 DCHECK(content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
| 718 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 719 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 720 DCHECK(!request_.security_origin.is_empty()); | |
| 719 DCHECK(content::IsOriginSecure(request_.security_origin) || | 721 DCHECK(content::IsOriginSecure(request_.security_origin) || |
| 720 request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY); | 722 request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY); |
| 721 if (!was_requested) { | 723 if (!was_requested) { |
| 722 // No denial reason set as it will have been previously set. | 724 // No denial reason set as it will have been previously set. |
| 723 return CONTENT_SETTING_DEFAULT; | 725 return CONTENT_SETTING_DEFAULT; |
| 724 } | 726 } |
| 725 | 727 |
| 726 if (was_initially_blocked) { | 728 if (was_initially_blocked) { |
| 727 // No denial reason set as it will have been previously set. | 729 // No denial reason set as it will have been previously set. |
| 728 return CONTENT_SETTING_BLOCK; | 730 return CONTENT_SETTING_BLOCK; |
| 729 } | 731 } |
| 730 | 732 |
| 731 if (!IsUserAcceptAllowed(content_type)) { | 733 if (!IsUserAcceptAllowed(content_type)) { |
| 732 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; | 734 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; |
| 733 return CONTENT_SETTING_BLOCK; | 735 return CONTENT_SETTING_BLOCK; |
| 734 } | 736 } |
| 735 | 737 |
| 736 MediaPermission permission(content_type, request.security_origin, | 738 PermissionResult result = |
| 737 web_contents_->GetLastCommittedURL().GetOrigin(), | 739 PermissionManager::Get(profile_)->GetPermissionStatus( |
| 738 profile_, web_contents_); | 740 content_type, request.security_origin, |
| 739 return permission.GetPermissionStatus(denial_reason); | 741 web_contents_->GetLastCommittedURL().GetOrigin()); |
| 742 if (result.content_setting == CONTENT_SETTING_BLOCK) { | |
| 743 if (result.source == PermissionStatusSource::KILL_SWITCH) | |
| 744 *denial_reason = content::MEDIA_DEVICE_KILL_SWITCH_ON; | |
|
Sergey Ulanov
2017/04/05 19:28:48
*denial_reason = (result.source == PermissionStatu
raymes
2017/04/09 23:55:05
Done.
| |
| 745 else | |
| 746 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; | |
| 747 } | |
| 748 | |
| 749 return result.content_setting; | |
| 740 } | 750 } |
| 741 | 751 |
| 742 ContentSetting MediaStreamDevicesController::GetNewSetting( | 752 ContentSetting MediaStreamDevicesController::GetNewSetting( |
| 743 ContentSettingsType content_type, | 753 ContentSettingsType content_type, |
| 744 ContentSetting old_setting, | 754 ContentSetting old_setting, |
| 745 ContentSetting user_decision) const { | 755 ContentSetting user_decision) const { |
| 746 DCHECK(user_decision == CONTENT_SETTING_ALLOW || | 756 DCHECK(user_decision == CONTENT_SETTING_ALLOW || |
| 747 user_decision == CONTENT_SETTING_BLOCK); | 757 user_decision == CONTENT_SETTING_BLOCK); |
| 748 ContentSetting result = old_setting; | 758 ContentSetting result = old_setting; |
| 749 if (old_setting == CONTENT_SETTING_ASK) { | 759 if (old_setting == CONTENT_SETTING_ASK) { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 779 } | 789 } |
| 780 } | 790 } |
| 781 | 791 |
| 782 // Don't approve device requests if the tab was hidden. | 792 // Don't approve device requests if the tab was hidden. |
| 783 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 793 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
| 784 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 794 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
| 785 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 795 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
| 786 #endif | 796 #endif |
| 787 return true; | 797 return true; |
| 788 } | 798 } |
| OLD | NEW |