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

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: Rebase Created 5 years, 1 month 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_context_uma_util.h" 10 #include "chrome/browser/permissions/permission_context_uma_util.h"
11 #include "chrome/browser/permissions/permission_request_id.h" 11 #include "chrome/browser/permissions/permission_request_id.h"
12 #include "chrome/browser/permissions/permission_util.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
14 #include "components/content_settings/core/browser/host_content_settings_map.h" 15 #include "components/content_settings/core/browser/host_content_settings_map.h"
15 #include "components/content_settings/core/browser/website_settings_registry.h" 16 #include "components/content_settings/core/browser/website_settings_registry.h"
17 #include "components/variations/variations_associated_data.h"
16 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
18 #include "content/public/common/origin_util.h" 20 #include "content/public/common/origin_util.h"
19 21
20 #if defined(OS_ANDROID) 22 #if defined(OS_ANDROID)
21 #include "chrome/browser/permissions/permission_queue_controller.h" 23 #include "chrome/browser/permissions/permission_queue_controller.h"
22 #else 24 #else
23 #include "chrome/browser/permissions/permission_bubble_request_impl.h" 25 #include "chrome/browser/permissions/permission_bubble_request_impl.h"
24 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 26 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
25 #endif 27 #endif
26 28
29 // static
30 const char PermissionContextBase::kPermissionsKillSwitchFieldStudy[] =
31 "PermissionsKillSwitch";
32 // static
33 const char PermissionContextBase::kPermissionsKillSwitchBlockedValue[] =
34 "blocked";
35
27 PermissionContextBase::PermissionContextBase( 36 PermissionContextBase::PermissionContextBase(
28 Profile* profile, 37 Profile* profile,
29 const ContentSettingsType permission_type) 38 const ContentSettingsType permission_type)
30 : profile_(profile), 39 : profile_(profile),
31 permission_type_(permission_type), 40 permission_type_(permission_type),
32 weak_factory_(this) { 41 weak_factory_(this) {
33 #if defined(OS_ANDROID) 42 #if defined(OS_ANDROID)
34 permission_queue_controller_.reset( 43 permission_queue_controller_.reset(
35 new PermissionQueueController(profile_, permission_type_)); 44 new PermissionQueueController(profile_, permission_type_));
36 #endif 45 #endif
37 } 46 }
38 47
39 PermissionContextBase::~PermissionContextBase() { 48 PermissionContextBase::~PermissionContextBase() {
40 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 49 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
41 } 50 }
42 51
43 void PermissionContextBase::RequestPermission( 52 void PermissionContextBase::RequestPermission(
44 content::WebContents* web_contents, 53 content::WebContents* web_contents,
45 const PermissionRequestID& id, 54 const PermissionRequestID& id,
46 const GURL& requesting_frame, 55 const GURL& requesting_frame,
47 bool user_gesture, 56 bool user_gesture,
48 const BrowserPermissionCallback& callback) { 57 const BrowserPermissionCallback& callback) {
49 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 58 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
50 59
60 // First check if this permission has been disabled.
61 if (IsPermissionKillSwitchOn()) {
62 // The kill switch is enabled for this permission; Block all requests.
63 NotifyPermissionSet(id, requesting_frame.GetOrigin(),
64 web_contents->GetLastCommittedURL().GetOrigin(), callback,
65 false /* persist */, CONTENT_SETTING_BLOCK);
66 return;
67 }
68
51 DecidePermission(web_contents, 69 DecidePermission(web_contents,
52 id, 70 id,
53 requesting_frame.GetOrigin(), 71 requesting_frame.GetOrigin(),
54 web_contents->GetLastCommittedURL().GetOrigin(), 72 web_contents->GetLastCommittedURL().GetOrigin(),
55 user_gesture, 73 user_gesture,
56 callback); 74 callback);
57 } 75 }
58 76
59 ContentSetting PermissionContextBase::GetPermissionStatus( 77 ContentSetting PermissionContextBase::GetPermissionStatus(
60 const GURL& requesting_origin, 78 const GURL& requesting_origin,
61 const GURL& embedding_origin) const { 79 const GURL& embedding_origin) const {
80
81 // If the permission has been disabled through Finch, block all requests.
82 if (IsPermissionKillSwitchOn())
83 return CONTENT_SETTING_BLOCK;
84
62 if (IsRestrictedToSecureOrigins() && 85 if (IsRestrictedToSecureOrigins() &&
63 !content::IsOriginSecure(requesting_origin)) { 86 !content::IsOriginSecure(requesting_origin)) {
64 return CONTENT_SETTING_BLOCK; 87 return CONTENT_SETTING_BLOCK;
65 } 88 }
66 89
67 return HostContentSettingsMapFactory::GetForProfile(profile_) 90 return HostContentSettingsMapFactory::GetForProfile(profile_)
68 ->GetContentSetting(requesting_origin, 91 ->GetContentSetting(requesting_origin,
69 embedding_origin, 92 embedding_origin,
70 permission_type_, 93 permission_type_,
71 std::string()); 94 std::string());
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); 278 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin());
256 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin()); 279 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin());
257 DCHECK(content_setting == CONTENT_SETTING_ALLOW || 280 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
258 content_setting == CONTENT_SETTING_BLOCK); 281 content_setting == CONTENT_SETTING_BLOCK);
259 282
260 HostContentSettingsMapFactory::GetForProfile(profile_)->SetContentSetting( 283 HostContentSettingsMapFactory::GetForProfile(profile_)->SetContentSetting(
261 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), 284 ContentSettingsPattern::FromURLNoWildcard(requesting_origin),
262 ContentSettingsPattern::FromURLNoWildcard(embedding_origin), 285 ContentSettingsPattern::FromURLNoWildcard(embedding_origin),
263 permission_type_, std::string(), content_setting); 286 permission_type_, std::string(), content_setting);
264 } 287 }
288
289 bool PermissionContextBase::IsPermissionKillSwitchOn() const {
290 const std::string param =
291 variations::GetVariationParamValue(kPermissionsKillSwitchFieldStudy,
292 PermissionUtil::GetPermissionString(permission_type_));
293
294 return param == kPermissionsKillSwitchBlockedValue;
295 }
OLDNEW
« no previous file with comments | « chrome/browser/permissions/permission_context_base.h ('k') | chrome/browser/permissions/permission_context_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698