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

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: Review Comments 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/permissions/permission_util.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 16 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
17 #include "components/content_settings/core/browser/host_content_settings_map.h" 18 #include "components/content_settings/core/browser/host_content_settings_map.h"
18 #include "components/content_settings/core/browser/website_settings_registry.h" 19 #include "components/content_settings/core/browser/website_settings_registry.h"
20 #include "components/variations/variations_associated_data.h"
19 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
21 #include "content/public/common/origin_util.h" 23 #include "content/public/common/origin_util.h"
22 24
25 // static
26 const char PermissionContextBase::kPermissionsKillSwitchFieldStudy[] =
27 "PermissionsKillSwitch";
28 // static
29 const char PermissionContextBase::kPermissionsKillSwitchBlockedValue[] =
30 "blocked";
31
23 PermissionContextBase::PermissionContextBase( 32 PermissionContextBase::PermissionContextBase(
24 Profile* profile, 33 Profile* profile,
25 const ContentSettingsType permission_type) 34 const ContentSettingsType permission_type)
26 : profile_(profile), 35 : profile_(profile),
27 permission_type_(permission_type), 36 permission_type_(permission_type),
28 weak_factory_(this) { 37 weak_factory_(this) {
29 permission_queue_controller_.reset( 38 permission_queue_controller_.reset(
30 new PermissionQueueController(profile_, permission_type_)); 39 new PermissionQueueController(profile_, permission_type_));
31 } 40 }
32 41
33 PermissionContextBase::~PermissionContextBase() { 42 PermissionContextBase::~PermissionContextBase() {
34 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 43 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
35 } 44 }
36 45
37 void PermissionContextBase::RequestPermission( 46 void PermissionContextBase::RequestPermission(
38 content::WebContents* web_contents, 47 content::WebContents* web_contents,
39 const PermissionRequestID& id, 48 const PermissionRequestID& id,
40 const GURL& requesting_frame, 49 const GURL& requesting_frame,
41 bool user_gesture, 50 bool user_gesture,
42 const BrowserPermissionCallback& callback) { 51 const BrowserPermissionCallback& callback) {
43 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 52 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
44 53
54 // First check if this permission has been disabled through Finch.
Bernhard Bauer 2015/10/21 10:29:03 s/ through Finch/ if you plan on controlling this
kcarattini 2015/10/26 00:30:59 Done.
55 if (IsPermissionKillSwitchOn()) {
56 // The kill switch is enabled for this permission; 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 // If the permission has been disabled through Finch, block all requests.
76 if (IsPermissionKillSwitchOn())
77 return CONTENT_SETTING_BLOCK;
78
56 if (IsRestrictedToSecureOrigins() && 79 if (IsRestrictedToSecureOrigins() &&
57 !content::IsOriginSecure(requesting_origin)) { 80 !content::IsOriginSecure(requesting_origin)) {
58 return CONTENT_SETTING_BLOCK; 81 return CONTENT_SETTING_BLOCK;
59 } 82 }
60 83
61 return HostContentSettingsMapFactory::GetForProfile(profile_) 84 return HostContentSettingsMapFactory::GetForProfile(profile_)
62 ->GetContentSetting(requesting_origin, 85 ->GetContentSetting(requesting_origin,
63 embedding_origin, 86 embedding_origin,
64 permission_type_, 87 permission_type_,
65 std::string()); 88 std::string());
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); 272 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin());
250 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin()); 273 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin());
251 DCHECK(content_setting == CONTENT_SETTING_ALLOW || 274 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
252 content_setting == CONTENT_SETTING_BLOCK); 275 content_setting == CONTENT_SETTING_BLOCK);
253 276
254 HostContentSettingsMapFactory::GetForProfile(profile_)->SetContentSetting( 277 HostContentSettingsMapFactory::GetForProfile(profile_)->SetContentSetting(
255 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), 278 ContentSettingsPattern::FromURLNoWildcard(requesting_origin),
256 ContentSettingsPattern::FromURLNoWildcard(embedding_origin), 279 ContentSettingsPattern::FromURLNoWildcard(embedding_origin),
257 permission_type_, std::string(), content_setting); 280 permission_type_, std::string(), content_setting);
258 } 281 }
282
283 bool PermissionContextBase::IsPermissionKillSwitchOn() const {
284 const std::string param =
285 variations::GetVariationParamValue(kPermissionsKillSwitchFieldStudy,
286 PermissionUtil::GetPermissionString(permission_type_));
287
288 return param == kPermissionsKillSwitchBlockedValue;
289 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698