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

Side by Side Diff: chrome/browser/permissions/permission_context_base.cc

Issue 1388343003: Adds a field trial to control Web API kill switches. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add MediaStream Created 5 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/permissions/permission_context_uma_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/permissions/permission_context_base.h" 5 #include "chrome/browser/permissions/permission_context_base.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
10 #include "chrome/browser/permissions/permission_bubble_request_impl.h" 10 #include "chrome/browser/permissions/permission_bubble_request_impl.h"
11 #include "chrome/browser/permissions/permission_context_uma_util.h" 11 #include "chrome/browser/permissions/permission_context_uma_util.h"
12 #include "chrome/browser/permissions/permission_queue_controller.h" 12 #include "chrome/browser/permissions/permission_queue_controller.h"
13 #include "chrome/browser/permissions/permission_request_id.h" 13 #include "chrome/browser/permissions/permission_request_id.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 15 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "components/content_settings/core/browser/host_content_settings_map.h" 17 #include "components/content_settings/core/browser/host_content_settings_map.h"
18 #include "components/content_settings/core/browser/website_settings_registry.h" 18 #include "components/content_settings/core/browser/website_settings_registry.h"
19 #include "components/variations/variations_associated_data.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
21 #include "content/public/common/origin_util.h" 22 #include "content/public/common/origin_util.h"
22 23
Nathan Parker 2015/10/09 00:38:37 Put in an anonymous namespace, or make static
kcarattini 2015/10/09 01:35:52 Done.
24 // API kill switch Finch Trials
25 const char kApiFieldStudy[] = "ApiKillSwitch";
26 const char kApiFieldParamEnabledValue[] = "enabled";
27
23 PermissionContextBase::PermissionContextBase( 28 PermissionContextBase::PermissionContextBase(
24 Profile* profile, 29 Profile* profile,
25 const ContentSettingsType permission_type) 30 const ContentSettingsType permission_type)
26 : profile_(profile), 31 : profile_(profile),
27 permission_type_(permission_type), 32 permission_type_(permission_type),
28 weak_factory_(this) { 33 weak_factory_(this) {
29 permission_queue_controller_.reset( 34 permission_queue_controller_.reset(
30 new PermissionQueueController(profile_, permission_type_)); 35 new PermissionQueueController(profile_, permission_type_));
31 } 36 }
32 37
33 PermissionContextBase::~PermissionContextBase() { 38 PermissionContextBase::~PermissionContextBase() {
34 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 39 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
35 } 40 }
36 41
37 void PermissionContextBase::RequestPermission( 42 void PermissionContextBase::RequestPermission(
38 content::WebContents* web_contents, 43 content::WebContents* web_contents,
39 const PermissionRequestID& id, 44 const PermissionRequestID& id,
40 const GURL& requesting_frame, 45 const GURL& requesting_frame,
41 bool user_gesture, 46 bool user_gesture,
42 const BrowserPermissionCallback& callback) { 47 const BrowserPermissionCallback& callback) {
43 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
44 49
50 // First check if this API has been disabled through Finch.
51 const std::string param =
52 variations::GetVariationParamValue(kApiFieldStudy,
Nathan Parker 2015/10/09 00:38:37 Meta: We should document how to use this kill swit
Nathan Parker 2015/10/09 00:38:37 Since you use this twice, I'd make a helper func (
kcarattini 2015/10/09 01:35:52 Acknowledged.
kcarattini 2015/10/09 01:35:52 Done.
53 PermissionContextUmaUtil::GetPermissionString(permission_type_));
54
55 if (param == kApiFieldParamEnabledValue) {
56 // This kill switch is enabled for this API; Block all requests.
57 NotifyPermissionSet(id, requesting_frame.GetOrigin(),
58 web_contents->GetLastCommittedURL().GetOrigin(), callback,
59 false /* persist */, CONTENT_SETTING_BLOCK);
60 return;
61 }
62
45 DecidePermission(web_contents, 63 DecidePermission(web_contents,
46 id, 64 id,
47 requesting_frame.GetOrigin(), 65 requesting_frame.GetOrigin(),
48 web_contents->GetLastCommittedURL().GetOrigin(), 66 web_contents->GetLastCommittedURL().GetOrigin(),
49 user_gesture, 67 user_gesture,
50 callback); 68 callback);
51 } 69 }
52 70
53 ContentSetting PermissionContextBase::GetPermissionStatus( 71 ContentSetting PermissionContextBase::GetPermissionStatus(
54 const GURL& requesting_origin, 72 const GURL& requesting_origin,
55 const GURL& embedding_origin) const { 73 const GURL& embedding_origin) const {
74
75 // First check if this API has been disabled through Finch.
76 const std::string param =
77 variations::GetVariationParamValue(kApiFieldStudy,
78 PermissionContextUmaUtil::GetPermissionString(permission_type_));
79
80 if (param == kApiFieldParamEnabledValue) {
81 // This kill switch is enabled for this API; Block all requests.
82 return CONTENT_SETTING_BLOCK;
83 }
84
56 if (IsRestrictedToSecureOrigins() && 85 if (IsRestrictedToSecureOrigins() &&
57 !content::IsOriginSecure(requesting_origin)) { 86 !content::IsOriginSecure(requesting_origin)) {
58 return CONTENT_SETTING_BLOCK; 87 return CONTENT_SETTING_BLOCK;
59 } 88 }
60 89
61 return HostContentSettingsMapFactory::GetForProfile(profile_) 90 return HostContentSettingsMapFactory::GetForProfile(profile_)
62 ->GetContentSetting(requesting_origin, 91 ->GetContentSetting(requesting_origin,
63 embedding_origin, 92 embedding_origin,
64 permission_type_, 93 permission_type_,
65 std::string()); 94 std::string());
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); 278 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin());
250 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin()); 279 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin());
251 DCHECK(content_setting == CONTENT_SETTING_ALLOW || 280 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
252 content_setting == CONTENT_SETTING_BLOCK); 281 content_setting == CONTENT_SETTING_BLOCK);
253 282
254 HostContentSettingsMapFactory::GetForProfile(profile_)->SetContentSetting( 283 HostContentSettingsMapFactory::GetForProfile(profile_)->SetContentSetting(
255 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), 284 ContentSettingsPattern::FromURLNoWildcard(requesting_origin),
256 ContentSettingsPattern::FromURLNoWildcard(embedding_origin), 285 ContentSettingsPattern::FromURLNoWildcard(embedding_origin),
257 permission_type_, std::string(), content_setting); 286 permission_type_, std::string(), content_setting);
258 } 287 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/permissions/permission_context_uma_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698