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/media_stream_devices_controller.h" | 5 #include "chrome/browser/media/media_stream_devices_controller.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/content_settings/content_settings_provider.h" | 10 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 11 #include "chrome/browser/content_settings/host_content_settings_map.h" | 11 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 13 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 13 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 14 #include "chrome/browser/media/media_stream_capture_indicator.h" | 14 #include "chrome/browser/media/media_stream_capture_indicator.h" |
| 15 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 15 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/content_settings.h" | 19 #include "chrome/common/content_settings.h" |
| 20 #include "chrome/common/content_settings_pattern.h" | |
| 20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 21 #include "components/user_prefs/pref_registry_syncable.h" | 22 #include "components/user_prefs/pref_registry_syncable.h" |
| 22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/common/media_stream_request.h" | 24 #include "content/public/common/media_stream_request.h" |
| 24 | 25 |
| 25 using content::BrowserThread; | 26 using content::BrowserThread; |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 bool HasAnyAvailableDevice() { | 30 bool HasAnyAvailableDevice() { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 47 microphone_requested_( | 48 microphone_requested_( |
| 48 request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE), | 49 request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE), |
| 49 webcam_requested_( | 50 webcam_requested_( |
| 50 request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) { | 51 request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) { |
| 51 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 52 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 52 content_settings_ = TabSpecificContentSettings::FromWebContents(web_contents); | 53 content_settings_ = TabSpecificContentSettings::FromWebContents(web_contents); |
| 53 | 54 |
| 54 // Don't call GetDevicePolicy from the initializer list since the | 55 // Don't call GetDevicePolicy from the initializer list since the |
| 55 // implementation depends on member variables. | 56 // implementation depends on member variables. |
| 56 if (microphone_requested_ && | 57 if (microphone_requested_ && |
| 57 GetDevicePolicy(prefs::kAudioCaptureAllowed) == ALWAYS_DENY) { | 58 GetDevicePolicy(prefs::kAudioCaptureAllowed, |
| 59 prefs::kAudioCaptureAllowedUrls) == ALWAYS_DENY) { | |
| 58 microphone_requested_ = false; | 60 microphone_requested_ = false; |
| 59 } | 61 } |
| 60 | 62 |
| 61 if (webcam_requested_ && | 63 if (webcam_requested_ && |
| 62 GetDevicePolicy(prefs::kVideoCaptureAllowed) == ALWAYS_DENY) { | 64 GetDevicePolicy(prefs::kVideoCaptureAllowed, |
| 65 prefs::kVideoCaptureAllowedUrls) == ALWAYS_DENY) { | |
| 63 webcam_requested_ = false; | 66 webcam_requested_ = false; |
| 64 } | 67 } |
| 65 } | 68 } |
| 66 | 69 |
| 67 MediaStreamDevicesController::~MediaStreamDevicesController() {} | 70 MediaStreamDevicesController::~MediaStreamDevicesController() {} |
| 68 | 71 |
| 69 // static | 72 // static |
| 70 void MediaStreamDevicesController::RegisterUserPrefs( | 73 void MediaStreamDevicesController::RegisterUserPrefs( |
| 71 user_prefs::PrefRegistrySyncable* prefs) { | 74 user_prefs::PrefRegistrySyncable* prefs) { |
| 72 prefs->RegisterBooleanPref(prefs::kVideoCaptureAllowed, | 75 prefs->RegisterBooleanPref(prefs::kVideoCaptureAllowed, |
| 73 true, | 76 true, |
| 74 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 77 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 75 prefs->RegisterBooleanPref(prefs::kAudioCaptureAllowed, | 78 prefs->RegisterBooleanPref(prefs::kAudioCaptureAllowed, |
| 76 true, | 79 true, |
| 77 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 80 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 81 prefs->RegisterListPref(prefs::kVideoCaptureAllowedUrls, | |
| 82 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 83 prefs->RegisterListPref(prefs::kAudioCaptureAllowedUrls, | |
| 84 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 78 } | 85 } |
| 79 | 86 |
| 80 | 87 |
| 81 bool MediaStreamDevicesController::DismissInfoBarAndTakeActionOnSettings() { | 88 bool MediaStreamDevicesController::DismissInfoBarAndTakeActionOnSettings() { |
| 82 // If this is a no UI check for policies only go straight to accept - policy | 89 // If this is a no UI check for policies only go straight to accept - policy |
| 83 // check will be done automatically on the way. | 90 // check will be done automatically on the way. |
| 84 if (request_.request_type == content::MEDIA_OPEN_DEVICE) { | 91 if (request_.request_type == content::MEDIA_OPEN_DEVICE) { |
| 85 Accept(false); | 92 Accept(false); |
| 86 return true; | 93 return true; |
| 87 } | 94 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 } | 192 } |
| 186 | 193 |
| 187 if (update_content_setting) | 194 if (update_content_setting) |
| 188 SetPermission(false); | 195 SetPermission(false); |
| 189 | 196 |
| 190 callback_.Run(content::MediaStreamDevices(), | 197 callback_.Run(content::MediaStreamDevices(), |
| 191 scoped_ptr<content::MediaStreamUI>()); | 198 scoped_ptr<content::MediaStreamUI>()); |
| 192 } | 199 } |
| 193 | 200 |
| 194 MediaStreamDevicesController::DevicePolicy | 201 MediaStreamDevicesController::DevicePolicy |
| 195 MediaStreamDevicesController::GetDevicePolicy(const char* policy_name) const { | 202 MediaStreamDevicesController::GetDevicePolicy( |
| 203 const char* policy_name, | |
| 204 const char* whitelist_policy_name) const { | |
| 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 197 | 206 |
| 207 // If the security origin policy matches a value in the whitelist, allow it. | |
| 208 // Otherwise, check the |policy_name| master switch for the default behavior. | |
| 209 | |
| 198 PrefService* prefs = profile_->GetPrefs(); | 210 PrefService* prefs = profile_->GetPrefs(); |
| 199 if (!prefs->IsManagedPreference(policy_name)) | 211 if (prefs->IsManagedPreference(whitelist_policy_name)) { |
|
markusheintz_
2013/05/24 10:55:35
Is there a particular reason why you don't integra
tommi (sloooow) - chröme
2013/05/24 13:08:31
Yes - ignorance! 8)
markusheintz_
2013/05/24 13:18:18
:) Please file a bug for integrating the policies
| |
| 212 const base::ListValue* list = prefs->GetList(whitelist_policy_name); | |
| 213 std::string value; | |
| 214 for (size_t i = 0; i < list->GetSize(); ++i) { | |
| 215 if (list->GetString(i, &value)) { | |
| 216 ContentSettingsPattern pattern = | |
| 217 ContentSettingsPattern::FromString(value); | |
|
markusheintz_
2013/05/24 13:18:18
If an admin could use the Wildcard pattern "*" in
| |
| 218 DLOG_IF(ERROR, !pattern.IsValid()) << "Invalid URL pattern: " << value; | |
| 219 if (pattern.IsValid() && pattern.Matches(request_.security_origin)) | |
| 220 return ALWAYS_ALLOW; | |
| 221 } | |
| 222 } | |
| 223 } | |
| 224 | |
| 225 // If a match was not found, check if audio capture is otherwise disallowed | |
| 226 // or if the user should be prompted. Setting the policy value to "true" | |
| 227 // is equal to not setting it at all, so from hereon out, we will return | |
| 228 // either POLICY_NOT_SET (prompt) or ALWAYS_DENY (no prompt, no access). | |
| 229 if (!prefs->IsManagedPreference(policy_name) || | |
| 230 prefs->GetBoolean(policy_name)) { | |
|
markusheintz_
2013/05/24 13:01:54
Will this not re-introduce the same issue as befor
tommi (sloooow) - chröme
2013/05/24 13:08:31
In this case the function returns POLICY_NOT_SET,
markusheintz_
2013/05/24 13:18:18
True. Sorry I missed that.
| |
| 200 return POLICY_NOT_SET; | 231 return POLICY_NOT_SET; |
| 232 } | |
| 201 | 233 |
| 202 return prefs->GetBoolean(policy_name) ? ALWAYS_ALLOW : ALWAYS_DENY; | 234 return ALWAYS_DENY; |
|
Joao da Silva
2013/05/24 12:48:01
Suggestion: I think the logic here would be cleare
tommi (sloooow) - chröme
2013/05/24 13:08:31
Done.
| |
| 203 } | 235 } |
| 204 | 236 |
| 205 bool MediaStreamDevicesController::IsRequestAllowedByDefault() const { | 237 bool MediaStreamDevicesController::IsRequestAllowedByDefault() const { |
| 206 // The request from internal objects like chrome://URLs is always allowed. | 238 // The request from internal objects like chrome://URLs is always allowed. |
| 207 if (ShouldAlwaysAllowOrigin()) | 239 if (ShouldAlwaysAllowOrigin()) |
| 208 return true; | 240 return true; |
| 209 | 241 |
| 210 struct { | 242 struct { |
| 211 bool has_capability; | 243 bool has_capability; |
| 212 const char* policy_name; | 244 const char* policy_name; |
| 245 const char* list_policy_name; | |
| 213 ContentSettingsType settings_type; | 246 ContentSettingsType settings_type; |
| 214 } device_checks[] = { | 247 } device_checks[] = { |
| 215 { microphone_requested_, prefs::kAudioCaptureAllowed, | 248 { microphone_requested_, prefs::kAudioCaptureAllowed, |
| 216 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC }, | 249 prefs::kAudioCaptureAllowedUrls, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC }, |
| 217 { webcam_requested_, prefs::kVideoCaptureAllowed, | 250 { webcam_requested_, prefs::kVideoCaptureAllowed, |
| 251 prefs::kVideoCaptureAllowedUrls, | |
| 218 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA }, | 252 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA }, |
| 219 }; | 253 }; |
| 220 | 254 |
| 221 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(device_checks); ++i) { | 255 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(device_checks); ++i) { |
| 222 if (!device_checks[i].has_capability) | 256 if (!device_checks[i].has_capability) |
| 223 continue; | 257 continue; |
| 224 | 258 |
| 225 DevicePolicy policy = GetDevicePolicy(device_checks[i].policy_name); | 259 DevicePolicy policy = GetDevicePolicy(device_checks[i].policy_name, |
| 260 device_checks[i].list_policy_name); | |
| 226 if (policy == ALWAYS_DENY || | 261 if (policy == ALWAYS_DENY || |
| 227 (policy == POLICY_NOT_SET && | 262 (policy == POLICY_NOT_SET && |
| 228 profile_->GetHostContentSettingsMap()->GetContentSetting( | 263 profile_->GetHostContentSettingsMap()->GetContentSetting( |
| 229 request_.security_origin, request_.security_origin, | 264 request_.security_origin, request_.security_origin, |
| 230 device_checks[i].settings_type, NO_RESOURCE_IDENTIFIER) != | 265 device_checks[i].settings_type, NO_RESOURCE_IDENTIFIER) != |
| 231 CONTENT_SETTING_ALLOW)) { | 266 CONTENT_SETTING_ALLOW)) { |
| 232 return false; | 267 return false; |
| 233 } | 268 } |
| 234 // If we get here, then either policy is set to ALWAYS_ALLOW or the content | 269 // If we get here, then either policy is set to ALWAYS_ALLOW or the content |
| 235 // settings allow the request by default. | 270 // settings allow the request by default. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 } | 344 } |
| 310 if (webcam_requested_) { | 345 if (webcam_requested_) { |
| 311 profile_->GetHostContentSettingsMap()->SetContentSetting( | 346 profile_->GetHostContentSettingsMap()->SetContentSetting( |
| 312 primary_pattern, | 347 primary_pattern, |
| 313 ContentSettingsPattern::Wildcard(), | 348 ContentSettingsPattern::Wildcard(), |
| 314 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 349 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 315 std::string(), | 350 std::string(), |
| 316 content_setting); | 351 content_setting); |
| 317 } | 352 } |
| 318 } | 353 } |
| OLD | NEW |