Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: chrome/browser/media/media_stream_devices_controller.cc

Issue 1099453005: Switch web API/permission code to use IsOriginSecure() instead of SchemeIsSecure(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change WalletServiceUrl::IsSignInContinueUrl to use SchemeIsCryptographic. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 11 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
12 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 12 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
13 #include "chrome/browser/media/media_stream_capture_indicator.h" 13 #include "chrome/browser/media/media_stream_capture_indicator.h"
14 #include "chrome/browser/media/media_stream_device_permissions.h" 14 #include "chrome/browser/media/media_stream_device_permissions.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "chrome/grit/generated_resources.h" 19 #include "chrome/grit/generated_resources.h"
20 #include "components/content_settings/core/browser/host_content_settings_map.h" 20 #include "components/content_settings/core/browser/host_content_settings_map.h"
21 #include "components/content_settings/core/common/content_settings.h" 21 #include "components/content_settings/core/common/content_settings.h"
22 #include "components/content_settings/core/common/content_settings_pattern.h" 22 #include "components/content_settings/core/common/content_settings_pattern.h"
23 #include "components/pref_registry/pref_registry_syncable.h" 23 #include "components/pref_registry/pref_registry_syncable.h"
24 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/render_widget_host_view.h" 25 #include "content/public/browser/render_widget_host_view.h"
26 #include "content/public/common/media_stream_request.h" 26 #include "content/public/common/media_stream_request.h"
27 #include "content/public/common/origin_util.h"
27 #include "extensions/common/constants.h" 28 #include "extensions/common/constants.h"
28 #include "grit/theme_resources.h" 29 #include "grit/theme_resources.h"
29 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
30 31
31 using content::BrowserThread; 32 using content::BrowserThread;
32 33
33 namespace { 34 namespace {
34 35
35 bool HasAvailableDevicesForRequest(const content::MediaStreamRequest& request) { 36 bool HasAvailableDevicesForRequest(const content::MediaStreamRequest& request) {
36 const content::MediaStreamDevices* audio_devices = 37 const content::MediaStreamDevices* audio_devices =
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 // Do nothing. 370 // Do nothing.
370 NOTREACHED(); 371 NOTREACHED();
371 break; 372 break;
372 } 373 }
373 } // switch 374 } // switch
374 375
375 // TODO(raymes): We currently set the content permission for non-https 376 // TODO(raymes): We currently set the content permission for non-https
376 // websites for Pepper requests as well. This is temporary and should be 377 // websites for Pepper requests as well. This is temporary and should be
377 // removed. 378 // removed.
378 if (update_content_setting) { 379 if (update_content_setting) {
379 if ((IsSchemeSecure() && !devices.empty()) || 380 if ((IsOriginSecure(request_.security_origin) && !devices.empty()) ||
380 request_.request_type == content::MEDIA_OPEN_DEVICE) { 381 request_.request_type == content::MEDIA_OPEN_DEVICE) {
381 StorePermission(true); 382 StorePermission(true);
382 } 383 }
383 } 384 }
384 385
385 if (audio_allowed) { 386 if (audio_allowed) {
386 profile_->GetHostContentSettingsMap()->UpdateLastUsageByPattern( 387 profile_->GetHostContentSettingsMap()->UpdateLastUsageByPattern(
387 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin), 388 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin),
388 ContentSettingsPattern::Wildcard(), 389 ContentSettingsPattern::Wildcard(),
389 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); 390 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 bool MediaStreamDevicesController::HasUserGesture() const { 459 bool MediaStreamDevicesController::HasUserGesture() const {
459 return request_.user_gesture; 460 return request_.user_gesture;
460 } 461 }
461 462
462 GURL MediaStreamDevicesController::GetRequestingHostname() const { 463 GURL MediaStreamDevicesController::GetRequestingHostname() const {
463 return request_.security_origin; 464 return request_.security_origin;
464 } 465 }
465 466
466 void MediaStreamDevicesController::PermissionGranted() { 467 void MediaStreamDevicesController::PermissionGranted() {
467 GURL origin(GetSecurityOriginSpec()); 468 GURL origin(GetSecurityOriginSpec());
468 if (origin.SchemeIsSecure()) { 469 if (IsOriginSecure(origin)) {
469 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", 470 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions",
470 kAllowHttps, kPermissionActionsMax); 471 kAllowHttps, kPermissionActionsMax);
471 } else { 472 } else {
472 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", 473 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions",
473 kAllowHttp, kPermissionActionsMax); 474 kAllowHttp, kPermissionActionsMax);
474 } 475 }
475 Accept(true); 476 Accept(true);
476 } 477 }
477 478
478 void MediaStreamDevicesController::PermissionDenied() { 479 void MediaStreamDevicesController::PermissionDenied() {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 request_.security_origin, 525 request_.security_origin,
525 device_checks[i].policy_name, 526 device_checks[i].policy_name,
526 device_checks[i].list_policy_name); 527 device_checks[i].list_policy_name);
527 528
528 if (policy == ALWAYS_DENY) 529 if (policy == ALWAYS_DENY)
529 return false; 530 return false;
530 531
531 if (policy == POLICY_NOT_SET) { 532 if (policy == POLICY_NOT_SET) {
532 // Only load content settings from secure origins unless it is a 533 // Only load content settings from secure origins unless it is a
533 // content::MEDIA_OPEN_DEVICE (Pepper) request. 534 // content::MEDIA_OPEN_DEVICE (Pepper) request.
534 if (!IsSchemeSecure() && 535 if (!IsOriginSecure(request_.security_origin) &&
535 request_.request_type != content::MEDIA_OPEN_DEVICE) { 536 request_.request_type != content::MEDIA_OPEN_DEVICE) {
536 return false; 537 return false;
537 } 538 }
538 if (profile_->GetHostContentSettingsMap()->GetContentSetting( 539 if (profile_->GetHostContentSettingsMap()->GetContentSetting(
539 request_.security_origin, 540 request_.security_origin,
540 request_.security_origin, 541 request_.security_origin,
541 device_checks[i].settings_type, 542 device_checks[i].settings_type,
542 content_settings::ResourceIdentifier()) != 543 content_settings::ResourceIdentifier()) !=
543 CONTENT_SETTING_ALLOW) { 544 CONTENT_SETTING_ALLOW) {
544 return false; 545 return false;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 bool MediaStreamDevicesController::IsDefaultMediaAccessBlocked() const { 589 bool MediaStreamDevicesController::IsDefaultMediaAccessBlocked() const {
589 DCHECK_CURRENTLY_ON(BrowserThread::UI); 590 DCHECK_CURRENTLY_ON(BrowserThread::UI);
590 return (profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( 591 return (profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
591 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, NULL) 592 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, NULL)
592 == CONTENT_SETTING_BLOCK && 593 == CONTENT_SETTING_BLOCK &&
593 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( 594 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
594 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, NULL) 595 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, NULL)
595 == CONTENT_SETTING_BLOCK); 596 == CONTENT_SETTING_BLOCK);
596 } 597 }
597 598
598 bool MediaStreamDevicesController::IsSchemeSecure() const {
599 return request_.security_origin.SchemeIsSecure() ||
600 request_.security_origin.SchemeIs(extensions::kExtensionScheme);
601 }
602
603 void MediaStreamDevicesController::StorePermission(bool allowed) const { 599 void MediaStreamDevicesController::StorePermission(bool allowed) const {
604 DCHECK_CURRENTLY_ON(BrowserThread::UI); 600 DCHECK_CURRENTLY_ON(BrowserThread::UI);
605 ContentSettingsPattern primary_pattern = 601 ContentSettingsPattern primary_pattern =
606 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin); 602 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin);
607 // Check the pattern is valid or not. When the request is from a file access, 603 // Check the pattern is valid or not. When the request is from a file access,
608 // no exception will be made. 604 // no exception will be made.
609 if (!primary_pattern.IsValid()) 605 if (!primary_pattern.IsValid())
610 return; 606 return;
611 607
612 ContentSetting content_setting = allowed ? 608 ContentSetting content_setting = allowed ?
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 } 673 }
678 674
679 bool MediaStreamDevicesController::IsCaptureDeviceRequestAllowed() const { 675 bool MediaStreamDevicesController::IsCaptureDeviceRequestAllowed() const {
680 #if defined(OS_ANDROID) 676 #if defined(OS_ANDROID)
681 // Don't approve device requests if the tab was hidden. 677 // Don't approve device requests if the tab was hidden.
682 // TODO(qinmin): Add a test for this. http://crbug.com/396869. 678 // TODO(qinmin): Add a test for this. http://crbug.com/396869.
683 return web_contents_->GetRenderWidgetHostView()->IsShowing(); 679 return web_contents_->GetRenderWidgetHostView()->IsShowing();
684 #endif 680 #endif
685 return true; 681 return true;
686 } 682 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698