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

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: Fix comment 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
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
24 // API kill switch Finch Trials
raymes 2015/10/13 01:30:18 nit: don't really need this comment now that comme
kcarattini 2015/10/13 03:06:22 Done.
25 // static
26 const char PermissionContextBase::kApiKillSwitchFieldStudy[] = "ApiKillSwitch";
27 // static
28 const char PermissionContextBase::kApiKillSwitchFieldParamEnabledValue[] =
29 "enabled";
30
23 PermissionContextBase::PermissionContextBase( 31 PermissionContextBase::PermissionContextBase(
24 Profile* profile, 32 Profile* profile,
25 const ContentSettingsType permission_type) 33 const ContentSettingsType permission_type)
26 : profile_(profile), 34 : profile_(profile),
27 permission_type_(permission_type), 35 permission_type_(permission_type),
28 weak_factory_(this) { 36 weak_factory_(this) {
29 permission_queue_controller_.reset( 37 permission_queue_controller_.reset(
30 new PermissionQueueController(profile_, permission_type_)); 38 new PermissionQueueController(profile_, permission_type_));
31 } 39 }
32 40
33 PermissionContextBase::~PermissionContextBase() { 41 PermissionContextBase::~PermissionContextBase() {
34 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 42 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
35 } 43 }
36 44
37 void PermissionContextBase::RequestPermission( 45 void PermissionContextBase::RequestPermission(
38 content::WebContents* web_contents, 46 content::WebContents* web_contents,
39 const PermissionRequestID& id, 47 const PermissionRequestID& id,
40 const GURL& requesting_frame, 48 const GURL& requesting_frame,
41 bool user_gesture, 49 bool user_gesture,
42 const BrowserPermissionCallback& callback) { 50 const BrowserPermissionCallback& callback) {
43 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 51 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
44 52
53 // First check if this API has been disabled through Finch.
54 if (IsApiKillSwitchOn()) {
55 // The kill switch is enabled for this API; Block all requests.
56 NotifyPermissionSet(id, requesting_frame.GetOrigin(),
57 web_contents->GetLastCommittedURL().GetOrigin(), callback,
58 false /* persist */, CONTENT_SETTING_BLOCK);
59 return;
60 }
61
45 DecidePermission(web_contents, 62 DecidePermission(web_contents,
46 id, 63 id,
47 requesting_frame.GetOrigin(), 64 requesting_frame.GetOrigin(),
48 web_contents->GetLastCommittedURL().GetOrigin(), 65 web_contents->GetLastCommittedURL().GetOrigin(),
49 user_gesture, 66 user_gesture,
50 callback); 67 callback);
51 } 68 }
52 69
53 ContentSetting PermissionContextBase::GetPermissionStatus( 70 ContentSetting PermissionContextBase::GetPermissionStatus(
54 const GURL& requesting_origin, 71 const GURL& requesting_origin,
55 const GURL& embedding_origin) const { 72 const GURL& embedding_origin) const {
73
74 // If the API has been disabled through Finch, block all requests.
75 if (IsApiKillSwitchOn())
76 return CONTENT_SETTING_BLOCK;
77
56 if (IsRestrictedToSecureOrigins() && 78 if (IsRestrictedToSecureOrigins() &&
57 !content::IsOriginSecure(requesting_origin)) { 79 !content::IsOriginSecure(requesting_origin)) {
58 return CONTENT_SETTING_BLOCK; 80 return CONTENT_SETTING_BLOCK;
59 } 81 }
60 82
61 return HostContentSettingsMapFactory::GetForProfile(profile_) 83 return HostContentSettingsMapFactory::GetForProfile(profile_)
62 ->GetContentSetting(requesting_origin, 84 ->GetContentSetting(requesting_origin,
63 embedding_origin, 85 embedding_origin,
64 permission_type_, 86 permission_type_,
65 std::string()); 87 std::string());
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); 271 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin());
250 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin()); 272 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin());
251 DCHECK(content_setting == CONTENT_SETTING_ALLOW || 273 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
252 content_setting == CONTENT_SETTING_BLOCK); 274 content_setting == CONTENT_SETTING_BLOCK);
253 275
254 HostContentSettingsMapFactory::GetForProfile(profile_)->SetContentSetting( 276 HostContentSettingsMapFactory::GetForProfile(profile_)->SetContentSetting(
255 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), 277 ContentSettingsPattern::FromURLNoWildcard(requesting_origin),
256 ContentSettingsPattern::FromURLNoWildcard(embedding_origin), 278 ContentSettingsPattern::FromURLNoWildcard(embedding_origin),
257 permission_type_, std::string(), content_setting); 279 permission_type_, std::string(), content_setting);
258 } 280 }
281
282 bool PermissionContextBase::IsApiKillSwitchOn() const {
283 const std::string param =
284 variations::GetVariationParamValue(kApiKillSwitchFieldStudy,
285 PermissionContextUmaUtil::GetPermissionString(permission_type_));
286
287 return param == kApiKillSwitchFieldParamEnabledValue;
288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698