| 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/media_stream_device_permission_context.h" | 5 #include "chrome/browser/media/media_stream_device_permission_context.h" |
| 6 #include "chrome/browser/media/media_stream_device_permissions.h" | 6 #include "chrome/browser/media/media_stream_device_permissions.h" |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/common/pref_names.h" | 8 #include "chrome/common/pref_names.h" |
| 9 #include "components/content_settings/core/browser/host_content_settings_map.h" | 9 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 10 #include "components/content_settings/core/common/content_settings.h" | 10 #include "components/content_settings/core/common/content_settings.h" |
| 11 #include "content/public/common/url_constants.h" | 11 #include "content/public/common/url_constants.h" |
| 12 #include "extensions/common/constants.h" | 12 #include "extensions/common/constants.h" |
| 13 | 13 |
| 14 MediaStreamDevicePermissionContext::MediaStreamDevicePermissionContext( | 14 MediaStreamDevicePermissionContext::MediaStreamDevicePermissionContext( |
| 15 Profile* profile, | 15 Profile* profile, |
| 16 const content::PermissionType permission_type, | 16 const content::PermissionType permission_type, |
| 17 const ContentSettingsType content_settings_type) | 17 const ContentSettingsType content_settings_type) |
| 18 : PermissionContextBase(profile, permission_type, content_settings_type), | 18 : PermissionContextBase(profile, permission_type, content_settings_type), |
| 19 content_settings_type_(content_settings_type) { | 19 content_settings_type_(content_settings_type) { |
| 20 DCHECK(content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | 20 DCHECK(content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
| 21 content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 21 content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 22 } | 22 } |
| 23 | 23 |
| 24 MediaStreamDevicePermissionContext::~MediaStreamDevicePermissionContext() {} | 24 MediaStreamDevicePermissionContext::~MediaStreamDevicePermissionContext() {} |
| 25 | 25 |
| 26 void MediaStreamDevicePermissionContext::RequestPermission( | 26 void MediaStreamDevicePermissionContext::RequestPermission( |
| 27 content::WebContents* web_contents, | 27 content::WebContents* web_contents, |
| 28 const PermissionRequestID& id, | 28 const PermissionRequestID& id, |
| 29 const GURL& requesting_frame, | 29 const url::Origin& requesting_frame, |
| 30 const BrowserPermissionCallback& callback) { | 30 const BrowserPermissionCallback& callback) { |
| 31 NOTREACHED() << "RequestPermission is not implemented"; | 31 NOTREACHED() << "RequestPermission is not implemented"; |
| 32 callback.Run(CONTENT_SETTING_BLOCK); | 32 callback.Run(CONTENT_SETTING_BLOCK); |
| 33 } | 33 } |
| 34 | 34 |
| 35 ContentSetting MediaStreamDevicePermissionContext::GetPermissionStatus( | 35 ContentSetting MediaStreamDevicePermissionContext::GetPermissionStatus( |
| 36 const GURL& requesting_origin, | 36 const url::Origin& requesting_origin, |
| 37 const GURL& embedding_origin) const { | 37 const url::Origin& embedding_origin) const { |
| 38 return GetPermissionStatusInternal(requesting_origin, embedding_origin, | 38 return GetPermissionStatusInternal(requesting_origin, embedding_origin, |
| 39 false); | 39 false); |
| 40 } | 40 } |
| 41 | 41 |
| 42 ContentSetting MediaStreamDevicePermissionContext:: | 42 ContentSetting MediaStreamDevicePermissionContext:: |
| 43 GetPermissionStatusAllowingInsecureForPepper( | 43 GetPermissionStatusAllowingInsecureForPepper( |
| 44 const GURL& requesting_origin, | 44 const url::Origin& requesting_origin, |
| 45 const GURL& embedding_origin) const { | 45 const url::Origin& embedding_origin) const { |
| 46 return GetPermissionStatusInternal(requesting_origin, embedding_origin, true); | 46 return GetPermissionStatusInternal(requesting_origin, embedding_origin, true); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void MediaStreamDevicePermissionContext::ResetPermission( | 49 void MediaStreamDevicePermissionContext::ResetPermission( |
| 50 const GURL& requesting_origin, | 50 const url::Origin& requesting_origin, |
| 51 const GURL& embedding_origin) { | 51 const url::Origin& embedding_origin) { |
| 52 NOTREACHED() << "ResetPermission is not implemented"; | 52 NOTREACHED() << "ResetPermission is not implemented"; |
| 53 } | 53 } |
| 54 | 54 |
| 55 void MediaStreamDevicePermissionContext::CancelPermissionRequest( | 55 void MediaStreamDevicePermissionContext::CancelPermissionRequest( |
| 56 content::WebContents* web_contents, | 56 content::WebContents* web_contents, |
| 57 const PermissionRequestID& id) { | 57 const PermissionRequestID& id) { |
| 58 NOTREACHED() << "CancelPermissionRequest is not implemented"; | 58 NOTREACHED() << "CancelPermissionRequest is not implemented"; |
| 59 } | 59 } |
| 60 | 60 |
| 61 ContentSetting MediaStreamDevicePermissionContext::GetPermissionStatusInternal( | 61 ContentSetting MediaStreamDevicePermissionContext::GetPermissionStatusInternal( |
| 62 const GURL& requesting_origin, | 62 const url::Origin& requesting_origin, |
| 63 const GURL& embedding_origin, | 63 const url::Origin& embedding_origin, |
| 64 bool is_pepper_request) const { | 64 bool is_pepper_request) const { |
| 65 // TODO(raymes): Merge this policy check into content settings | 65 // TODO(raymes): Merge this policy check into content settings |
| 66 // crbug.com/244389. | 66 // crbug.com/244389. |
| 67 const char* policy_name = nullptr; | 67 const char* policy_name = nullptr; |
| 68 const char* urls_policy_name = nullptr; | 68 const char* urls_policy_name = nullptr; |
| 69 if (content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | 69 if (content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
| 70 policy_name = prefs::kAudioCaptureAllowed; | 70 policy_name = prefs::kAudioCaptureAllowed; |
| 71 urls_policy_name = prefs::kAudioCaptureAllowedUrls; | 71 urls_policy_name = prefs::kAudioCaptureAllowedUrls; |
| 72 } else { | 72 } else { |
| 73 DCHECK(content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 73 DCHECK(content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 74 policy_name = prefs::kVideoCaptureAllowed; | 74 policy_name = prefs::kVideoCaptureAllowed; |
| 75 urls_policy_name = prefs::kVideoCaptureAllowedUrls; | 75 urls_policy_name = prefs::kVideoCaptureAllowedUrls; |
| 76 } | 76 } |
| 77 | 77 |
| 78 MediaStreamDevicePolicy policy = GetDevicePolicy( | 78 const GURL requesting_url(requesting_origin.Serialize()); |
| 79 profile(), requesting_origin, policy_name, urls_policy_name); | 79 MediaStreamDevicePolicy policy = |
| 80 GetDevicePolicy(profile(), requesting_url, policy_name, urls_policy_name); |
| 80 | 81 |
| 81 switch (policy) { | 82 switch (policy) { |
| 82 case ALWAYS_DENY: | 83 case ALWAYS_DENY: |
| 83 return CONTENT_SETTING_BLOCK; | 84 return CONTENT_SETTING_BLOCK; |
| 84 case ALWAYS_ALLOW: | 85 case ALWAYS_ALLOW: |
| 85 return CONTENT_SETTING_ALLOW; | 86 return CONTENT_SETTING_ALLOW; |
| 86 default: | 87 default: |
| 87 DCHECK_EQ(POLICY_NOT_SET, policy); | 88 DCHECK_EQ(POLICY_NOT_SET, policy); |
| 88 } | 89 } |
| 89 | 90 |
| 90 // Check the content setting. TODO(raymes): currently mic/camera permission | 91 // Check the content setting. TODO(raymes): currently mic/camera permission |
| 91 // doesn't consider the embedder. | 92 // doesn't consider the embedder. |
| 92 ContentSetting setting = PermissionContextBase::GetPermissionStatus( | 93 ContentSetting setting = PermissionContextBase::GetPermissionStatus( |
| 93 requesting_origin, requesting_origin); | 94 requesting_origin, requesting_origin); |
| 94 | 95 |
| 95 if (setting == CONTENT_SETTING_DEFAULT) | 96 if (setting == CONTENT_SETTING_DEFAULT) |
| 96 setting = CONTENT_SETTING_ASK; | 97 setting = CONTENT_SETTING_ASK; |
| 97 | 98 |
| 98 // TODO(raymes): This is here for safety to ensure that we always ask the user | 99 // TODO(raymes): This is here for safety to ensure that we always ask the user |
| 99 // even if a content setting is set to "allow" if the origin is insecure. In | 100 // even if a content setting is set to "allow" if the origin is insecure. In |
| 100 // reality we shouldn't really need to check this here as we should respect | 101 // reality we shouldn't really need to check this here as we should respect |
| 101 // the user's content setting. The problem is that pepper requests allow | 102 // the user's content setting. The problem is that pepper requests allow |
| 102 // insecure origins to be persisted. We should remove this after | 103 // insecure origins to be persisted. We should remove this after |
| 103 // crbug.com/526324 is fixed. | 104 // crbug.com/526324 is fixed. |
| 104 if (!ShouldPersistContentSetting(setting, requesting_origin, | 105 if (!ShouldPersistContentSetting(setting, requesting_url, |
| 105 is_pepper_request) && | 106 is_pepper_request) && |
| 106 !requesting_origin.SchemeIs(extensions::kExtensionScheme) && | 107 !requesting_url.SchemeIs(extensions::kExtensionScheme) && |
| 107 !requesting_origin.SchemeIs(content::kChromeUIScheme) && | 108 !requesting_url.SchemeIs(content::kChromeUIScheme) && |
| 108 !requesting_origin.SchemeIs(content::kChromeDevToolsScheme)) { | 109 !requesting_url.SchemeIs(content::kChromeDevToolsScheme)) { |
| 109 return CONTENT_SETTING_ASK; | 110 return CONTENT_SETTING_ASK; |
| 110 } | 111 } |
| 111 | 112 |
| 112 return setting; | 113 return setting; |
| 113 } | 114 } |
| 114 | 115 |
| 115 bool MediaStreamDevicePermissionContext::IsRestrictedToSecureOrigins() const { | 116 bool MediaStreamDevicePermissionContext::IsRestrictedToSecureOrigins() const { |
| 116 // Flash currently doesn't require secure origin to use mic/camera. If we | 117 // Flash currently doesn't require secure origin to use mic/camera. If we |
| 117 // return true here, it'll break the use case like http://tinychat.com. | 118 // return true here, it'll break the use case like http://tinychat.com. |
| 118 // TODO(raymes): Change this to true after crbug.com/526324 is fixed. | 119 // TODO(raymes): Change this to true after crbug.com/526324 is fixed. |
| 119 return false; | 120 return false; |
| 120 } | 121 } |
| OLD | NEW |