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

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: Address nhiroki's comment. Created 5 years, 8 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/origin_util.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
20 #include "components/content_settings/core/browser/host_content_settings_map.h" 21 #include "components/content_settings/core/browser/host_content_settings_map.h"
21 #include "components/content_settings/core/common/content_settings.h" 22 #include "components/content_settings/core/common/content_settings.h"
22 #include "components/content_settings/core/common/content_settings_pattern.h" 23 #include "components/content_settings/core/common/content_settings_pattern.h"
23 #include "components/pref_registry/pref_registry_syncable.h" 24 #include "components/pref_registry/pref_registry_syncable.h"
24 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/render_widget_host_view.h" 26 #include "content/public/browser/render_widget_host_view.h"
26 #include "content/public/common/media_stream_request.h" 27 #include "content/public/common/media_stream_request.h"
27 #include "extensions/common/constants.h" 28 #include "extensions/common/constants.h"
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 // Do nothing. 376 // Do nothing.
376 NOTREACHED(); 377 NOTREACHED();
377 break; 378 break;
378 } 379 }
379 } // switch 380 } // switch
380 381
381 // TODO(raymes): We currently set the content permission for non-https 382 // TODO(raymes): We currently set the content permission for non-https
382 // 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
383 // removed. 384 // removed.
384 if (update_content_setting) { 385 if (update_content_setting) {
385 if ((IsSchemeSecure() && !devices.empty()) || 386 if ((IsOriginSecure(request_.security_origin) && !devices.empty()) ||
386 request_.request_type == content::MEDIA_OPEN_DEVICE) { 387 request_.request_type == content::MEDIA_OPEN_DEVICE) {
387 StorePermission(true); 388 StorePermission(true);
388 } 389 }
389 } 390 }
390 391
391 if (audio_allowed) { 392 if (audio_allowed) {
392 profile_->GetHostContentSettingsMap()->UpdateLastUsageByPattern( 393 profile_->GetHostContentSettingsMap()->UpdateLastUsageByPattern(
393 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin), 394 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin),
394 ContentSettingsPattern::Wildcard(), 395 ContentSettingsPattern::Wildcard(),
395 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); 396 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 bool MediaStreamDevicesController::HasUserGesture() const { 465 bool MediaStreamDevicesController::HasUserGesture() const {
465 return request_.user_gesture; 466 return request_.user_gesture;
466 } 467 }
467 468
468 GURL MediaStreamDevicesController::GetRequestingHostname() const { 469 GURL MediaStreamDevicesController::GetRequestingHostname() const {
469 return request_.security_origin; 470 return request_.security_origin;
470 } 471 }
471 472
472 void MediaStreamDevicesController::PermissionGranted() { 473 void MediaStreamDevicesController::PermissionGranted() {
473 GURL origin(GetSecurityOriginSpec()); 474 GURL origin(GetSecurityOriginSpec());
474 if (origin.SchemeIsSecure()) { 475 if (IsOriginSecure(origin)) {
475 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", 476 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions",
476 kAllowHttps, kPermissionActionsMax); 477 kAllowHttps, kPermissionActionsMax);
477 } else { 478 } else {
478 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", 479 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions",
479 kAllowHttp, kPermissionActionsMax); 480 kAllowHttp, kPermissionActionsMax);
480 } 481 }
481 Accept(true); 482 Accept(true);
482 } 483 }
483 484
484 void MediaStreamDevicesController::PermissionDenied() { 485 void MediaStreamDevicesController::PermissionDenied() {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 request_.security_origin, 531 request_.security_origin,
531 device_checks[i].policy_name, 532 device_checks[i].policy_name,
532 device_checks[i].list_policy_name); 533 device_checks[i].list_policy_name);
533 534
534 if (policy == ALWAYS_DENY) 535 if (policy == ALWAYS_DENY)
535 return false; 536 return false;
536 537
537 if (policy == POLICY_NOT_SET) { 538 if (policy == POLICY_NOT_SET) {
538 // Only load content settings from secure origins unless it is a 539 // Only load content settings from secure origins unless it is a
539 // content::MEDIA_OPEN_DEVICE (Pepper) request. 540 // content::MEDIA_OPEN_DEVICE (Pepper) request.
540 if (!IsSchemeSecure() && 541 if (!IsOriginSecure(request_.security_origin) &&
541 request_.request_type != content::MEDIA_OPEN_DEVICE) { 542 request_.request_type != content::MEDIA_OPEN_DEVICE) {
542 return false; 543 return false;
543 } 544 }
544 if (profile_->GetHostContentSettingsMap()->GetContentSetting( 545 if (profile_->GetHostContentSettingsMap()->GetContentSetting(
545 request_.security_origin, 546 request_.security_origin,
546 request_.security_origin, 547 request_.security_origin,
547 device_checks[i].settings_type, 548 device_checks[i].settings_type,
548 content_settings::ResourceIdentifier()) != 549 content_settings::ResourceIdentifier()) !=
549 CONTENT_SETTING_ALLOW) { 550 CONTENT_SETTING_ALLOW) {
550 return false; 551 return false;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 bool MediaStreamDevicesController::IsDefaultMediaAccessBlocked() const { 595 bool MediaStreamDevicesController::IsDefaultMediaAccessBlocked() const {
595 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 596 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
596 return (profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( 597 return (profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
597 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, NULL) 598 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, NULL)
598 == CONTENT_SETTING_BLOCK && 599 == CONTENT_SETTING_BLOCK &&
599 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( 600 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
600 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, NULL) 601 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, NULL)
601 == CONTENT_SETTING_BLOCK); 602 == CONTENT_SETTING_BLOCK);
602 } 603 }
603 604
604 bool MediaStreamDevicesController::IsSchemeSecure() const {
605 return request_.security_origin.SchemeIsSecure() ||
606 request_.security_origin.SchemeIs(extensions::kExtensionScheme);
607 }
608
609 void MediaStreamDevicesController::StorePermission(bool allowed) const { 605 void MediaStreamDevicesController::StorePermission(bool allowed) const {
610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 606 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
611 ContentSettingsPattern primary_pattern = 607 ContentSettingsPattern primary_pattern =
612 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin); 608 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin);
613 // Check the pattern is valid or not. When the request is from a file access, 609 // Check the pattern is valid or not. When the request is from a file access,
614 // no exception will be made. 610 // no exception will be made.
615 if (!primary_pattern.IsValid()) 611 if (!primary_pattern.IsValid())
616 return; 612 return;
617 613
618 ContentSetting content_setting = allowed ? 614 ContentSetting content_setting = allowed ?
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 } 679 }
684 680
685 bool MediaStreamDevicesController::IsCaptureDeviceRequestAllowed() const { 681 bool MediaStreamDevicesController::IsCaptureDeviceRequestAllowed() const {
686 #if defined(OS_ANDROID) 682 #if defined(OS_ANDROID)
687 // Don't approve device requests if the tab was hidden. 683 // Don't approve device requests if the tab was hidden.
688 // TODO(qinmin): Add a test for this. http://crbug.com/396869. 684 // TODO(qinmin): Add a test for this. http://crbug.com/396869.
689 return web_contents_->GetRenderWidgetHostView()->IsShowing(); 685 return web_contents_->GetRenderWidgetHostView()->IsShowing();
690 #endif 686 #endif
691 return true; 687 return true;
692 } 688 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698