| 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/string_util.h" |
| 9 #include "base/values.h" | 10 #include "base/values.h" |
| 10 #include "chrome/browser/content_settings/content_settings_provider.h" | 11 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 11 #include "chrome/browser/content_settings/host_content_settings_map.h" | 12 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 13 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 14 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 14 #include "chrome/browser/media/media_stream_capture_indicator.h" | 15 #include "chrome/browser/media/media_stream_capture_indicator.h" |
| 15 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| (...skipping 28 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)) { |
| 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 MatchPattern(request_.security_origin.spec(), value)) { |
| 217 return ALWAYS_ALLOW; |
| 218 } |
| 219 } |
| 220 } |
| 221 |
| 222 // If a match was not found, check if audio capture is otherwise disallowed |
| 223 // or if the user should be prompted. Setting the policy value to "true" |
| 224 // is equal to not setting it at all, so from hereon out, we will return |
| 225 // either POLICY_NOT_SET (prompt) or ALWAYS_DENY (no prompt, no access). |
| 226 if (!prefs->IsManagedPreference(policy_name) || |
| 227 prefs->GetBoolean(policy_name)) { |
| 200 return POLICY_NOT_SET; | 228 return POLICY_NOT_SET; |
| 229 } |
| 201 | 230 |
| 202 return prefs->GetBoolean(policy_name) ? ALWAYS_ALLOW : ALWAYS_DENY; | 231 return ALWAYS_DENY; |
| 203 } | 232 } |
| 204 | 233 |
| 205 bool MediaStreamDevicesController::IsRequestAllowedByDefault() const { | 234 bool MediaStreamDevicesController::IsRequestAllowedByDefault() const { |
| 206 // The request from internal objects like chrome://URLs is always allowed. | 235 // The request from internal objects like chrome://URLs is always allowed. |
| 207 if (ShouldAlwaysAllowOrigin()) | 236 if (ShouldAlwaysAllowOrigin()) |
| 208 return true; | 237 return true; |
| 209 | 238 |
| 210 struct { | 239 struct { |
| 211 bool has_capability; | 240 bool has_capability; |
| 212 const char* policy_name; | 241 const char* policy_name; |
| 242 const char* list_policy_name; |
| 213 ContentSettingsType settings_type; | 243 ContentSettingsType settings_type; |
| 214 } device_checks[] = { | 244 } device_checks[] = { |
| 215 { microphone_requested_, prefs::kAudioCaptureAllowed, | 245 { microphone_requested_, prefs::kAudioCaptureAllowed, |
| 216 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC }, | 246 prefs::kAudioCaptureAllowedUrls, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC }, |
| 217 { webcam_requested_, prefs::kVideoCaptureAllowed, | 247 { webcam_requested_, prefs::kVideoCaptureAllowed, |
| 248 prefs::kVideoCaptureAllowedUrls, |
| 218 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA }, | 249 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA }, |
| 219 }; | 250 }; |
| 220 | 251 |
| 221 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(device_checks); ++i) { | 252 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(device_checks); ++i) { |
| 222 if (!device_checks[i].has_capability) | 253 if (!device_checks[i].has_capability) |
| 223 continue; | 254 continue; |
| 224 | 255 |
| 225 DevicePolicy policy = GetDevicePolicy(device_checks[i].policy_name); | 256 DevicePolicy policy = GetDevicePolicy(device_checks[i].policy_name, |
| 257 device_checks[i].list_policy_name); |
| 226 if (policy == ALWAYS_DENY || | 258 if (policy == ALWAYS_DENY || |
| 227 (policy == POLICY_NOT_SET && | 259 (policy == POLICY_NOT_SET && |
| 228 profile_->GetHostContentSettingsMap()->GetContentSetting( | 260 profile_->GetHostContentSettingsMap()->GetContentSetting( |
| 229 request_.security_origin, request_.security_origin, | 261 request_.security_origin, request_.security_origin, |
| 230 device_checks[i].settings_type, NO_RESOURCE_IDENTIFIER) != | 262 device_checks[i].settings_type, NO_RESOURCE_IDENTIFIER) != |
| 231 CONTENT_SETTING_ALLOW)) { | 263 CONTENT_SETTING_ALLOW)) { |
| 232 return false; | 264 return false; |
| 233 } | 265 } |
| 234 // If we get here, then either policy is set to ALWAYS_ALLOW or the content | 266 // If we get here, then either policy is set to ALWAYS_ALLOW or the content |
| 235 // settings allow the request by default. | 267 // settings allow the request by default. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 } | 341 } |
| 310 if (webcam_requested_) { | 342 if (webcam_requested_) { |
| 311 profile_->GetHostContentSettingsMap()->SetContentSetting( | 343 profile_->GetHostContentSettingsMap()->SetContentSetting( |
| 312 primary_pattern, | 344 primary_pattern, |
| 313 ContentSettingsPattern::Wildcard(), | 345 ContentSettingsPattern::Wildcard(), |
| 314 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 346 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 315 std::string(), | 347 std::string(), |
| 316 content_setting); | 348 content_setting); |
| 317 } | 349 } |
| 318 } | 350 } |
| OLD | NEW |