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_permission.h" | 5 #include "chrome/browser/media/media_permission.h" |
6 | 6 |
7 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 7 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
8 #include "chrome/browser/media/media_stream_device_permissions.h" | 8 #include "chrome/browser/media/media_stream_device_permissions.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
11 #include "components/content_settings/core/browser/host_content_settings_map.h" | 11 #include "content/public/browser/permission_manager.h" |
12 #include "content/public/browser/permission_type.h" | |
12 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
13 #include "extensions/common/constants.h" | 14 #include "extensions/common/constants.h" |
14 | 15 |
16 namespace { | |
raymes
2015/08/31 01:51:45
nit: newline below
guoweis_left_chromium
2015/09/01 07:08:51
Done.
| |
17 ContentSetting PermissionStatusToContentSetting( | |
18 content::PermissionStatus status) { | |
19 switch (status) { | |
20 case content::PERMISSION_STATUS_GRANTED: | |
21 return CONTENT_SETTING_ALLOW; | |
22 case content::PERMISSION_STATUS_DENIED: | |
23 return CONTENT_SETTING_BLOCK; | |
24 case content::PERMISSION_STATUS_ASK: | |
25 return CONTENT_SETTING_ASK; | |
26 } | |
27 | |
28 NOTREACHED(); | |
29 return CONTENT_SETTING_BLOCK; | |
30 } | |
31 | |
32 content::PermissionType ContentSettingsTypeToPermission( | |
33 ContentSettingsType content_setting) { | |
34 switch (content_setting) { | |
35 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: | |
36 return content::PermissionType::AUDIO_RECORDING; | |
37 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: | |
38 return content::PermissionType::VIDEO_RECORDING; | |
39 default: | |
40 // This will hit the NOTREACHED below. | |
41 break; | |
42 } | |
43 | |
44 NOTREACHED() << "Unexpected content setting for permission " | |
45 << static_cast<int>(content_setting); | |
46 return content::PermissionType::NUM; | |
47 } | |
48 | |
49 } // namespace | |
50 | |
15 MediaPermission::MediaPermission(ContentSettingsType content_type, | 51 MediaPermission::MediaPermission(ContentSettingsType content_type, |
16 content::MediaStreamRequestType request_type, | 52 content::MediaStreamRequestType request_type, |
17 const GURL& origin, | 53 const GURL& origin, |
18 Profile* profile) | 54 Profile* profile) |
19 : content_type_(content_type), | 55 : content_type_(content_type), |
20 request_type_(request_type), | 56 request_type_(request_type), |
21 origin_(origin), | 57 origin_(origin), |
22 profile_(profile) { | 58 profile_(profile) { |
23 } | 59 } |
24 | 60 |
(...skipping 20 matching lines...) Expand all Loading... | |
45 // Deny the request if there is no device attached to the OS of the requested | 81 // Deny the request if there is no device attached to the OS of the requested |
46 // type. | 82 // type. |
47 if (!HasAvailableDevices(device_id)) { | 83 if (!HasAvailableDevices(device_id)) { |
48 *denial_reason = content::MEDIA_DEVICE_NO_HARDWARE; | 84 *denial_reason = content::MEDIA_DEVICE_NO_HARDWARE; |
49 return CONTENT_SETTING_BLOCK; | 85 return CONTENT_SETTING_BLOCK; |
50 } | 86 } |
51 | 87 |
52 return GetPermissionStatus(denial_reason); | 88 return GetPermissionStatus(denial_reason); |
53 } | 89 } |
54 | 90 |
55 ContentSetting MediaPermission::GetStoredContentSetting() const { | 91 ContentSetting MediaPermission::GetStoredContentSetting() const { |
mlamouri (slow - plz ping)
2015/08/28 10:51:35
Could you change MediaPermission::GetStoredContent
raymes
2015/08/29 00:09:02
This unfortunately comes as a result of doing a pa
raymes
2015/08/31 01:51:45
It's probably possible to do some refactoring in M
mlamouri (slow - plz ping)
2015/08/31 13:09:58
Hmmm, my comment was only applying to GetStoredCon
| |
56 // TODO(raymes): Merge this policy check into content settings | 92 ContentSetting setting = CONTENT_SETTING_BLOCK; |
57 // crbug.com/244389. | 93 if (profile_) { |
mlamouri (slow - plz ping)
2015/08/28 10:51:35
Why are you checking for |profile_| while the prev
guoweis_left_chromium
2015/09/01 07:08:51
Done.
| |
58 const char* policy_name = nullptr; | 94 content::PermissionManager* permission_manager = |
59 const char* urls_policy_name = nullptr; | 95 profile_->GetPermissionManager(); |
60 if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | 96 if (permission_manager) { |
mlamouri (slow - plz ping)
2015/08/28 10:51:35
Maybe:
if (!permission_manager)
return CONTENT_S
guoweis_left_chromium
2015/09/01 07:08:51
Done.
| |
61 policy_name = prefs::kAudioCaptureAllowed; | 97 setting = PermissionStatusToContentSetting( |
62 urls_policy_name = prefs::kAudioCaptureAllowedUrls; | 98 permission_manager->GetPermissionStatus( |
63 } else if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | 99 ContentSettingsTypeToPermission(content_type_), origin_, |
64 policy_name = prefs::kVideoCaptureAllowed; | 100 origin_)); |
mlamouri (slow - plz ping)
2015/08/28 10:51:35
Shouldn't you take into account the embedder?
raymes
2015/08/29 00:09:02
Mounir, you should read my replies :) As I mention
mlamouri (slow - plz ping)
2015/08/31 13:09:58
I remember your comment. Though, I would prefer th
raymes
2015/08/31 23:32:49
Ahh, sorry, that makes sense and I agree with you.
guoweis_left_chromium
2015/09/01 07:08:51
Done.
| |
65 urls_policy_name = prefs::kVideoCaptureAllowedUrls; | 101 } |
66 } else { | |
67 NOTREACHED(); | |
68 } | 102 } |
69 | 103 |
70 MediaStreamDevicePolicy policy = | |
71 GetDevicePolicy(profile_, origin_, policy_name, urls_policy_name); | |
72 | |
73 if (policy == ALWAYS_DENY) | |
74 return CONTENT_SETTING_BLOCK; | |
75 | |
76 if (policy == ALWAYS_ALLOW) | |
77 return CONTENT_SETTING_ALLOW; | |
78 | |
79 DCHECK(policy == POLICY_NOT_SET); | |
80 // Check the content setting. | |
81 ContentSetting setting = | |
82 profile_->GetHostContentSettingsMap()->GetContentSetting( | |
83 origin_, origin_, content_type_, | |
84 content_settings::ResourceIdentifier()); | |
85 | |
86 if (setting == CONTENT_SETTING_DEFAULT) | |
87 return CONTENT_SETTING_ASK; | |
88 | |
89 // TODO(raymes): This is here for safety to ensure that we always ask the user | 104 // TODO(raymes): This is here for safety to ensure that we always ask the user |
90 // even if a content setting is set to "allow" if the origin is insecure. In | 105 // even if a content setting is set to "allow" if the origin is insecure. In |
91 // reality we shouldn't really need to check this here as we should respect | 106 // reality we shouldn't really need to check this here as we should respect |
92 // the user's content setting. The problem is that pepper requests allow | 107 // the user's content setting. The problem is that pepper requests allow |
93 // insecure origins to be persisted. We should stop allowing this, do some | 108 // insecure origins to be persisted. We should stop allowing this, do some |
94 // sort of migration and remove this check. See crbug.com/512301. | 109 // sort of migration and remove this check. See crbug.com/512301. |
95 if (!ShouldPersistContentSetting(setting, origin_, request_type_) && | 110 if (!ShouldPersistContentSetting(setting, origin_, request_type_) && |
96 !origin_.SchemeIs(extensions::kExtensionScheme) && | 111 !origin_.SchemeIs(extensions::kExtensionScheme) && |
97 !origin_.SchemeIs(content::kChromeUIScheme) && | 112 !origin_.SchemeIs(content::kChromeUIScheme) && |
98 !origin_.SchemeIs(content::kChromeDevToolsScheme)) { | 113 !origin_.SchemeIs(content::kChromeDevToolsScheme)) { |
99 return CONTENT_SETTING_ASK; | 114 return CONTENT_SETTING_ASK; |
100 } | 115 } |
raymes
2015/08/31 01:51:45
I think this should be moved into the PermissionCo
guoweis_left_chromium
2015/09/01 07:08:51
We can't use PermissionManager for this. Instead,
| |
101 | 116 |
102 return setting; | 117 return setting; |
103 } | 118 } |
104 | 119 |
105 bool MediaPermission::HasAvailableDevices(const std::string& device_id) const { | 120 bool MediaPermission::HasAvailableDevices(const std::string& device_id) const { |
106 const content::MediaStreamDevices* devices = nullptr; | 121 const content::MediaStreamDevices* devices = nullptr; |
107 if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | 122 if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
108 devices = | 123 devices = |
109 &MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices(); | 124 &MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices(); |
110 } else if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | 125 } else if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
(...skipping 12 matching lines...) Expand all Loading... | |
123 return false; | 138 return false; |
124 | 139 |
125 // Note: we check device_id before dereferencing devices. If the requested | 140 // Note: we check device_id before dereferencing devices. If the requested |
126 // device id is non-empty, then the corresponding device list must not be | 141 // device id is non-empty, then the corresponding device list must not be |
127 // NULL. | 142 // NULL. |
128 if (!device_id.empty() && !devices->FindById(device_id)) | 143 if (!device_id.empty() && !devices->FindById(device_id)) |
129 return false; | 144 return false; |
130 | 145 |
131 return true; | 146 return true; |
132 } | 147 } |
OLD | NEW |