| 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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 break; | 378 break; |
| 379 } | 379 } |
| 380 } // switch | 380 } // switch |
| 381 | 381 |
| 382 // TODO(raymes): We currently set the content permission for non-https | 382 // TODO(raymes): We currently set the content permission for non-https |
| 383 // websites for Pepper requests as well. This is temporary and should be | 383 // websites for Pepper requests as well. This is temporary and should be |
| 384 // removed. | 384 // removed. |
| 385 if (update_content_setting) { | 385 if (update_content_setting) { |
| 386 if ((IsSchemeSecure() && !devices.empty()) || | 386 if ((IsSchemeSecure() && !devices.empty()) || |
| 387 request_.request_type == content::MEDIA_OPEN_DEVICE) { | 387 request_.request_type == content::MEDIA_OPEN_DEVICE) { |
| 388 SetPermission(true); | 388 StorePermission(true); |
| 389 } | 389 } |
| 390 } | 390 } |
| 391 | 391 |
| 392 if (audio_allowed) { | 392 if (audio_allowed) { |
| 393 profile_->GetHostContentSettingsMap()->UpdateLastUsageByPattern( | 393 profile_->GetHostContentSettingsMap()->UpdateLastUsageByPattern( |
| 394 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin), | 394 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin), |
| 395 ContentSettingsPattern::Wildcard(), | 395 ContentSettingsPattern::Wildcard(), |
| 396 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 396 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| 397 } | 397 } |
| 398 if (video_allowed) { | 398 if (video_allowed) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 416 content::MEDIA_DEVICE_NO_HARDWARE : content::MEDIA_DEVICE_OK, | 416 content::MEDIA_DEVICE_NO_HARDWARE : content::MEDIA_DEVICE_OK, |
| 417 ui.Pass()); | 417 ui.Pass()); |
| 418 } | 418 } |
| 419 | 419 |
| 420 void MediaStreamDevicesController::Deny( | 420 void MediaStreamDevicesController::Deny( |
| 421 bool update_content_setting, | 421 bool update_content_setting, |
| 422 content::MediaStreamRequestResult result) { | 422 content::MediaStreamRequestResult result) { |
| 423 DLOG(WARNING) << "MediaStreamDevicesController::Deny: " << result; | 423 DLOG(WARNING) << "MediaStreamDevicesController::Deny: " << result; |
| 424 NotifyUIRequestDenied(); | 424 NotifyUIRequestDenied(); |
| 425 | 425 |
| 426 if (update_content_setting) { | 426 if (update_content_setting && request_.all_ancestors_have_same_origin) { |
| 427 // Store sticky permissions if |update_content_setting| and the request |
| 428 // is not done from an iframe where the ancestor has a different origin. |
| 427 CHECK_EQ(content::MEDIA_DEVICE_PERMISSION_DENIED, result); | 429 CHECK_EQ(content::MEDIA_DEVICE_PERMISSION_DENIED, result); |
| 428 SetPermission(false); | 430 StorePermission(false); |
| 429 } | 431 } |
| 430 | 432 |
| 431 content::MediaResponseCallback cb = callback_; | 433 content::MediaResponseCallback cb = callback_; |
| 432 callback_.Reset(); | 434 callback_.Reset(); |
| 433 cb.Run(content::MediaStreamDevices(), | 435 cb.Run(content::MediaStreamDevices(), |
| 434 result, | 436 result, |
| 435 scoped_ptr<content::MediaStreamUI>()); | 437 scoped_ptr<content::MediaStreamUI>()); |
| 436 } | 438 } |
| 437 | 439 |
| 438 int MediaStreamDevicesController::GetIconID() const { | 440 int MediaStreamDevicesController::GetIconID() const { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( | 599 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( |
| 598 CONTENT_SETTINGS_TYPE_MEDIASTREAM, NULL); | 600 CONTENT_SETTINGS_TYPE_MEDIASTREAM, NULL); |
| 599 return (current_setting == CONTENT_SETTING_BLOCK); | 601 return (current_setting == CONTENT_SETTING_BLOCK); |
| 600 } | 602 } |
| 601 | 603 |
| 602 bool MediaStreamDevicesController::IsSchemeSecure() const { | 604 bool MediaStreamDevicesController::IsSchemeSecure() const { |
| 603 return request_.security_origin.SchemeIsSecure() || | 605 return request_.security_origin.SchemeIsSecure() || |
| 604 request_.security_origin.SchemeIs(extensions::kExtensionScheme); | 606 request_.security_origin.SchemeIs(extensions::kExtensionScheme); |
| 605 } | 607 } |
| 606 | 608 |
| 607 void MediaStreamDevicesController::SetPermission(bool allowed) const { | 609 void MediaStreamDevicesController::StorePermission(bool allowed) const { |
| 608 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 609 ContentSettingsPattern primary_pattern = | 611 ContentSettingsPattern primary_pattern = |
| 610 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin); | 612 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin); |
| 611 // Check the pattern is valid or not. When the request is from a file access, | 613 // Check the pattern is valid or not. When the request is from a file access, |
| 612 // no exception will be made. | 614 // no exception will be made. |
| 613 if (!primary_pattern.IsValid()) | 615 if (!primary_pattern.IsValid()) |
| 614 return; | 616 return; |
| 615 | 617 |
| 616 ContentSetting content_setting = allowed ? | 618 ContentSetting content_setting = allowed ? |
| 617 CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 619 CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 } | 683 } |
| 682 | 684 |
| 683 bool MediaStreamDevicesController::IsCaptureDeviceRequestAllowed() const { | 685 bool MediaStreamDevicesController::IsCaptureDeviceRequestAllowed() const { |
| 684 #if defined(OS_ANDROID) | 686 #if defined(OS_ANDROID) |
| 685 // Don't approve device requests if the tab was hidden. | 687 // Don't approve device requests if the tab was hidden. |
| 686 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 688 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
| 687 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 689 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
| 688 #endif | 690 #endif |
| 689 return true; | 691 return true; |
| 690 } | 692 } |
| OLD | NEW |