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