| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_device_permission_context.h" | 5 #include "chrome/browser/media/webrtc/media_stream_device_permission_context.h" |
| 6 #include "base/feature_list.h" | 6 #include "base/feature_list.h" |
| 7 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" | 7 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/common/chrome_features.h" | 9 #include "chrome/common/chrome_features.h" |
| 10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 const GURL& embedding_origin, | 47 const GURL& embedding_origin, |
| 48 bool user_gesture, | 48 bool user_gesture, |
| 49 const BrowserPermissionCallback& callback) { | 49 const BrowserPermissionCallback& callback) { |
| 50 DCHECK(base::FeatureList::IsEnabled( | 50 DCHECK(base::FeatureList::IsEnabled( |
| 51 features::kUsePermissionManagerForMediaRequests)); | 51 features::kUsePermissionManagerForMediaRequests)); |
| 52 PermissionContextBase::DecidePermission(web_contents, id, requesting_origin, | 52 PermissionContextBase::DecidePermission(web_contents, id, requesting_origin, |
| 53 embedding_origin, user_gesture, | 53 embedding_origin, user_gesture, |
| 54 callback); | 54 callback); |
| 55 } | 55 } |
| 56 | 56 |
| 57 ContentSetting MediaStreamDevicePermissionContext::GetPermissionStatusInternal( | 57 PermissionResult |
| 58 MediaStreamDevicePermissionContext::GetPermissionStatusInternal( |
| 58 content::RenderFrameHost* render_frame_host, | 59 content::RenderFrameHost* render_frame_host, |
| 59 const GURL& requesting_origin, | 60 const GURL& requesting_origin, |
| 60 const GURL& embedding_origin) const { | 61 const GURL& embedding_origin) const { |
| 61 // TODO(raymes): Merge this policy check into content settings | 62 // TODO(raymes): Merge this policy check into content settings |
| 62 // crbug.com/244389. | 63 // crbug.com/244389. |
| 63 const char* policy_name = nullptr; | 64 const char* policy_name = nullptr; |
| 64 const char* urls_policy_name = nullptr; | 65 const char* urls_policy_name = nullptr; |
| 65 if (content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | 66 if (content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
| 66 policy_name = prefs::kAudioCaptureAllowed; | 67 policy_name = prefs::kAudioCaptureAllowed; |
| 67 urls_policy_name = prefs::kAudioCaptureAllowedUrls; | 68 urls_policy_name = prefs::kAudioCaptureAllowedUrls; |
| 68 } else { | 69 } else { |
| 69 DCHECK(content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 70 DCHECK(content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 70 policy_name = prefs::kVideoCaptureAllowed; | 71 policy_name = prefs::kVideoCaptureAllowed; |
| 71 urls_policy_name = prefs::kVideoCaptureAllowedUrls; | 72 urls_policy_name = prefs::kVideoCaptureAllowedUrls; |
| 72 } | 73 } |
| 73 | 74 |
| 74 MediaStreamDevicePolicy policy = GetDevicePolicy( | 75 MediaStreamDevicePolicy policy = GetDevicePolicy( |
| 75 profile(), requesting_origin, policy_name, urls_policy_name); | 76 profile(), requesting_origin, policy_name, urls_policy_name); |
| 76 | 77 |
| 77 switch (policy) { | 78 switch (policy) { |
| 78 case ALWAYS_DENY: | 79 case ALWAYS_DENY: |
| 79 return CONTENT_SETTING_BLOCK; | 80 return PermissionResult(CONTENT_SETTING_BLOCK, |
| 81 PermissionStatusSource::ENTERPRISE_POLICY); |
| 80 case ALWAYS_ALLOW: | 82 case ALWAYS_ALLOW: |
| 81 return CONTENT_SETTING_ALLOW; | 83 return PermissionResult(CONTENT_SETTING_ALLOW, |
| 84 PermissionStatusSource::ENTERPRISE_POLICY); |
| 82 default: | 85 default: |
| 83 DCHECK_EQ(POLICY_NOT_SET, policy); | 86 DCHECK_EQ(POLICY_NOT_SET, policy); |
| 84 } | 87 } |
| 85 | 88 |
| 86 // Check the content setting. TODO(raymes): currently mic/camera permission | 89 // Check the content setting. TODO(raymes): currently mic/camera permission |
| 87 // doesn't consider the embedder. | 90 // doesn't consider the embedder. |
| 88 ContentSetting setting = PermissionContextBase::GetPermissionStatusInternal( | 91 PermissionResult result = PermissionContextBase::GetPermissionStatusInternal( |
| 89 render_frame_host, requesting_origin, requesting_origin); | 92 render_frame_host, requesting_origin, requesting_origin); |
| 90 | 93 |
| 91 if (setting == CONTENT_SETTING_DEFAULT) | 94 if (result.content_setting == CONTENT_SETTING_DEFAULT) |
| 92 setting = CONTENT_SETTING_ASK; | 95 result.content_setting = CONTENT_SETTING_ASK; |
| 93 | 96 |
| 94 return setting; | 97 return result; |
| 95 } | 98 } |
| 96 | 99 |
| 97 void MediaStreamDevicePermissionContext::ResetPermission( | 100 void MediaStreamDevicePermissionContext::ResetPermission( |
| 98 const GURL& requesting_origin, | 101 const GURL& requesting_origin, |
| 99 const GURL& embedding_origin) { | 102 const GURL& embedding_origin) { |
| 100 NOTREACHED() << "ResetPermission is not implemented"; | 103 NOTREACHED() << "ResetPermission is not implemented"; |
| 101 } | 104 } |
| 102 | 105 |
| 103 void MediaStreamDevicePermissionContext::CancelPermissionRequest( | 106 void MediaStreamDevicePermissionContext::CancelPermissionRequest( |
| 104 content::WebContents* web_contents, | 107 content::WebContents* web_contents, |
| 105 const PermissionRequestID& id) { | 108 const PermissionRequestID& id) { |
| 106 NOTREACHED() << "CancelPermissionRequest is not implemented"; | 109 NOTREACHED() << "CancelPermissionRequest is not implemented"; |
| 107 } | 110 } |
| 108 | 111 |
| 109 bool MediaStreamDevicePermissionContext::IsRestrictedToSecureOrigins() const { | 112 bool MediaStreamDevicePermissionContext::IsRestrictedToSecureOrigins() const { |
| 110 return base::FeatureList::IsEnabled( | 113 return base::FeatureList::IsEnabled( |
| 111 features::kRequireSecureOriginsForPepperMediaRequests); | 114 features::kRequireSecureOriginsForPepperMediaRequests); |
| 112 } | 115 } |
| OLD | NEW |