| 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/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/prefs/scoped_user_pref_update.h" | 8 #include "base/prefs/scoped_user_pref_update.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 cb.Run(devices, request_result, ui.Pass()); | 332 cb.Run(devices, request_result, ui.Pass()); |
| 333 } | 333 } |
| 334 | 334 |
| 335 void MediaStreamDevicesController::StorePermission( | 335 void MediaStreamDevicesController::StorePermission( |
| 336 ContentSetting new_audio_setting, | 336 ContentSetting new_audio_setting, |
| 337 ContentSetting new_video_setting) const { | 337 ContentSetting new_video_setting) const { |
| 338 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 338 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 339 ContentSettingsPattern primary_pattern = | 339 ContentSettingsPattern primary_pattern = |
| 340 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin); | 340 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin); |
| 341 | 341 |
| 342 bool is_pepper_request = request_.request_type == content::MEDIA_OPEN_DEVICE; |
| 343 |
| 342 if (IsAskingForAudio() && new_audio_setting != CONTENT_SETTING_ASK) { | 344 if (IsAskingForAudio() && new_audio_setting != CONTENT_SETTING_ASK) { |
| 343 if (ShouldPersistContentSetting(new_audio_setting, request_.security_origin, | 345 if (ShouldPersistContentSetting(new_audio_setting, request_.security_origin, |
| 344 request_.request_type)) { | 346 is_pepper_request)) { |
| 345 profile_->GetHostContentSettingsMap()->SetContentSetting( | 347 profile_->GetHostContentSettingsMap()->SetContentSetting( |
| 346 primary_pattern, ContentSettingsPattern::Wildcard(), | 348 primary_pattern, ContentSettingsPattern::Wildcard(), |
| 347 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), | 349 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), |
| 348 new_audio_setting); | 350 new_audio_setting); |
| 349 } | 351 } |
| 350 } | 352 } |
| 351 if (IsAskingForVideo() && new_video_setting != CONTENT_SETTING_ASK) { | 353 if (IsAskingForVideo() && new_video_setting != CONTENT_SETTING_ASK) { |
| 352 if (ShouldPersistContentSetting(new_video_setting, request_.security_origin, | 354 if (ShouldPersistContentSetting(new_video_setting, request_.security_origin, |
| 353 request_.request_type)) { | 355 is_pepper_request)) { |
| 354 profile_->GetHostContentSettingsMap()->SetContentSetting( | 356 profile_->GetHostContentSettingsMap()->SetContentSetting( |
| 355 primary_pattern, ContentSettingsPattern::Wildcard(), | 357 primary_pattern, ContentSettingsPattern::Wildcard(), |
| 356 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), | 358 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), |
| 357 new_video_setting); | 359 new_video_setting); |
| 358 } | 360 } |
| 359 } | 361 } |
| 360 } | 362 } |
| 361 | 363 |
| 362 void MediaStreamDevicesController::UpdateTabSpecificContentSettings( | 364 void MediaStreamDevicesController::UpdateTabSpecificContentSettings( |
| 363 ContentSetting audio_setting, | 365 ContentSetting audio_setting, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 requested_device_id = request.requested_audio_device_id; | 419 requested_device_id = request.requested_audio_device_id; |
| 418 else if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) | 420 else if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) |
| 419 requested_device_id = request.requested_video_device_id; | 421 requested_device_id = request.requested_video_device_id; |
| 420 | 422 |
| 421 if (!IsUserAcceptAllowed(content_type)) { | 423 if (!IsUserAcceptAllowed(content_type)) { |
| 422 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; | 424 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; |
| 423 return CONTENT_SETTING_BLOCK; | 425 return CONTENT_SETTING_BLOCK; |
| 424 } | 426 } |
| 425 | 427 |
| 426 if (ContentTypeIsRequested(content_type, request)) { | 428 if (ContentTypeIsRequested(content_type, request)) { |
| 427 MediaPermission permission(content_type, request.request_type, | 429 MediaPermission permission( |
| 428 request.security_origin, profile_); | 430 content_type, request.request_type, request.security_origin, |
| 431 web_contents_->GetLastCommittedURL().GetOrigin(), profile_); |
| 429 return permission.GetPermissionStatusWithDeviceRequired(requested_device_id, | 432 return permission.GetPermissionStatusWithDeviceRequired(requested_device_id, |
| 430 denial_reason); | 433 denial_reason); |
| 431 } | 434 } |
| 432 // Return the default content setting if the device is not requested. | 435 // Return the default content setting if the device is not requested. |
| 433 return CONTENT_SETTING_DEFAULT; | 436 return CONTENT_SETTING_DEFAULT; |
| 434 } | 437 } |
| 435 | 438 |
| 436 ContentSetting MediaStreamDevicesController::GetNewSetting( | 439 ContentSetting MediaStreamDevicesController::GetNewSetting( |
| 437 ContentSettingsType content_type, | 440 ContentSettingsType content_type, |
| 438 ContentSetting old_setting, | 441 ContentSetting old_setting, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 if (android_permission_blocked) | 477 if (android_permission_blocked) |
| 475 return false; | 478 return false; |
| 476 | 479 |
| 477 // Don't approve device requests if the tab was hidden. | 480 // Don't approve device requests if the tab was hidden. |
| 478 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 481 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
| 479 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 482 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
| 480 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 483 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
| 481 #endif | 484 #endif |
| 482 return true; | 485 return true; |
| 483 } | 486 } |
| OLD | NEW |