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 // TODO(tommi): Remove the kiosk mode check when the whitelist below | |
| 208 // is visible in the media exceptions UI. | |
| 209 // See discussion here: https://codereview.chromium.org/15738004/ | |
| 210 bool kiosk_mode = | |
| 211 CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode); | |
|
markusheintz_
2013/05/27 14:37:24
What about CROS ?
The Kiosk mode on CROS is a bit
| |
| 212 | |
| 213 // If the security origin policy matches a value in the whitelist, allow it. | |
| 214 // Otherwise, check the |policy_name| master switch for the default behavior. | |
| 215 | |
| 198 PrefService* prefs = profile_->GetPrefs(); | 216 PrefService* prefs = profile_->GetPrefs(); |
| 199 if (!prefs->IsManagedPreference(policy_name)) | 217 if (kiosk_mode && prefs->IsManagedPreference(whitelist_policy_name)) { |
| 200 return POLICY_NOT_SET; | 218 const base::ListValue* list = prefs->GetList(whitelist_policy_name); |
| 219 std::string value; | |
| 220 for (size_t i = 0; i < list->GetSize(); ++i) { | |
| 221 if (list->GetString(i, &value)) { | |
| 222 ContentSettingsPattern pattern = | |
| 223 ContentSettingsPattern::FromString(value); | |
| 224 if (pattern == ContentSettingsPattern::Wildcard()) { | |
| 225 DLOG(WARNING) << "Ignoring wildcard URL pattern: " << value; | |
| 226 continue; | |
| 227 } | |
| 228 DLOG_IF(ERROR, !pattern.IsValid()) << "Invalid URL pattern: " << value; | |
| 229 if (pattern.IsValid() && pattern.Matches(request_.security_origin)) | |
| 230 return ALWAYS_ALLOW; | |
| 231 } | |
| 232 } | |
| 233 } | |
| 201 | 234 |
| 202 return prefs->GetBoolean(policy_name) ? ALWAYS_ALLOW : ALWAYS_DENY; | 235 // If a match was not found, check if audio capture is otherwise disallowed |
| 236 // or if the user should be prompted. Setting the policy value to "true" | |
| 237 // is equal to not setting it at all, so from hereon out, we will return | |
| 238 // either POLICY_NOT_SET (prompt) or ALWAYS_DENY (no prompt, no access). | |
| 239 if (prefs->IsManagedPreference(policy_name) && | |
| 240 !prefs->GetBoolean(policy_name)) { | |
| 241 return ALWAYS_DENY; | |
| 242 } | |
| 243 | |
| 244 return POLICY_NOT_SET; | |
| 203 } | 245 } |
| 204 | 246 |
| 205 bool MediaStreamDevicesController::IsRequestAllowedByDefault() const { | 247 bool MediaStreamDevicesController::IsRequestAllowedByDefault() const { |
| 206 // The request from internal objects like chrome://URLs is always allowed. | 248 // The request from internal objects like chrome://URLs is always allowed. |
| 207 if (ShouldAlwaysAllowOrigin()) | 249 if (ShouldAlwaysAllowOrigin()) |
| 208 return true; | 250 return true; |
| 209 | 251 |
| 210 struct { | 252 struct { |
| 211 bool has_capability; | 253 bool has_capability; |
| 212 const char* policy_name; | 254 const char* policy_name; |
| 255 const char* list_policy_name; | |
| 213 ContentSettingsType settings_type; | 256 ContentSettingsType settings_type; |
| 214 } device_checks[] = { | 257 } device_checks[] = { |
| 215 { microphone_requested_, prefs::kAudioCaptureAllowed, | 258 { microphone_requested_, prefs::kAudioCaptureAllowed, |
| 216 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC }, | 259 prefs::kAudioCaptureAllowedUrls, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC }, |
| 217 { webcam_requested_, prefs::kVideoCaptureAllowed, | 260 { webcam_requested_, prefs::kVideoCaptureAllowed, |
| 261 prefs::kVideoCaptureAllowedUrls, | |
| 218 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA }, | 262 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA }, |
| 219 }; | 263 }; |
| 220 | 264 |
| 221 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(device_checks); ++i) { | 265 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(device_checks); ++i) { |
| 222 if (!device_checks[i].has_capability) | 266 if (!device_checks[i].has_capability) |
| 223 continue; | 267 continue; |
| 224 | 268 |
| 225 DevicePolicy policy = GetDevicePolicy(device_checks[i].policy_name); | 269 DevicePolicy policy = GetDevicePolicy(device_checks[i].policy_name, |
| 270 device_checks[i].list_policy_name); | |
| 226 if (policy == ALWAYS_DENY || | 271 if (policy == ALWAYS_DENY || |
| 227 (policy == POLICY_NOT_SET && | 272 (policy == POLICY_NOT_SET && |
| 228 profile_->GetHostContentSettingsMap()->GetContentSetting( | 273 profile_->GetHostContentSettingsMap()->GetContentSetting( |
| 229 request_.security_origin, request_.security_origin, | 274 request_.security_origin, request_.security_origin, |
| 230 device_checks[i].settings_type, NO_RESOURCE_IDENTIFIER) != | 275 device_checks[i].settings_type, NO_RESOURCE_IDENTIFIER) != |
| 231 CONTENT_SETTING_ALLOW)) { | 276 CONTENT_SETTING_ALLOW)) { |
| 232 return false; | 277 return false; |
| 233 } | 278 } |
| 234 // If we get here, then either policy is set to ALWAYS_ALLOW or the content | 279 // If we get here, then either policy is set to ALWAYS_ALLOW or the content |
| 235 // settings allow the request by default. | 280 // settings allow the request by default. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 } | 354 } |
| 310 if (webcam_requested_) { | 355 if (webcam_requested_) { |
| 311 profile_->GetHostContentSettingsMap()->SetContentSetting( | 356 profile_->GetHostContentSettingsMap()->SetContentSetting( |
| 312 primary_pattern, | 357 primary_pattern, |
| 313 ContentSettingsPattern::Wildcard(), | 358 ContentSettingsPattern::Wildcard(), |
| 314 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 359 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 315 std::string(), | 360 std::string(), |
| 316 content_setting); | 361 content_setting); |
| 317 } | 362 } |
| 318 } | 363 } |
| OLD | NEW |