OLD | NEW |
---|---|
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 | |
25 static const char kApiFieldStudy[] = "ApiKillSwitch"; | |
26 static const char kApiFieldParamEnabledValue[] = "enabled"; | |
raymes
2015/10/11 22:11:22
Are these not defined as constants somewhere else?
kcarattini
2015/10/12 03:58:06
No. From looking at other examples, these constant
| |
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 if (IsApiKillSwitchOn()) { | |
52 // The kill switch is enabled for this API; Block all requests. | |
53 NotifyPermissionSet(id, requesting_frame.GetOrigin(), | |
54 web_contents->GetLastCommittedURL().GetOrigin(), callback, | |
55 false /* persist */, CONTENT_SETTING_BLOCK); | |
56 return; | |
57 } | |
58 | |
45 DecidePermission(web_contents, | 59 DecidePermission(web_contents, |
46 id, | 60 id, |
47 requesting_frame.GetOrigin(), | 61 requesting_frame.GetOrigin(), |
48 web_contents->GetLastCommittedURL().GetOrigin(), | 62 web_contents->GetLastCommittedURL().GetOrigin(), |
49 user_gesture, | 63 user_gesture, |
50 callback); | 64 callback); |
51 } | 65 } |
52 | 66 |
53 ContentSetting PermissionContextBase::GetPermissionStatus( | 67 ContentSetting PermissionContextBase::GetPermissionStatus( |
54 const GURL& requesting_origin, | 68 const GURL& requesting_origin, |
55 const GURL& embedding_origin) const { | 69 const GURL& embedding_origin) const { |
70 | |
71 // If the API has been disabled through Finch, block all requests. | |
72 if (IsApiKillSwitchOn()) | |
73 return CONTENT_SETTING_BLOCK; | |
74 | |
56 if (IsRestrictedToSecureOrigins() && | 75 if (IsRestrictedToSecureOrigins() && |
57 !content::IsOriginSecure(requesting_origin)) { | 76 !content::IsOriginSecure(requesting_origin)) { |
58 return CONTENT_SETTING_BLOCK; | 77 return CONTENT_SETTING_BLOCK; |
59 } | 78 } |
60 | 79 |
61 return HostContentSettingsMapFactory::GetForProfile(profile_) | 80 return HostContentSettingsMapFactory::GetForProfile(profile_) |
62 ->GetContentSetting(requesting_origin, | 81 ->GetContentSetting(requesting_origin, |
63 embedding_origin, | 82 embedding_origin, |
64 permission_type_, | 83 permission_type_, |
65 std::string()); | 84 std::string()); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); | 268 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); |
250 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin()); | 269 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin()); |
251 DCHECK(content_setting == CONTENT_SETTING_ALLOW || | 270 DCHECK(content_setting == CONTENT_SETTING_ALLOW || |
252 content_setting == CONTENT_SETTING_BLOCK); | 271 content_setting == CONTENT_SETTING_BLOCK); |
253 | 272 |
254 HostContentSettingsMapFactory::GetForProfile(profile_)->SetContentSetting( | 273 HostContentSettingsMapFactory::GetForProfile(profile_)->SetContentSetting( |
255 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), | 274 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), |
256 ContentSettingsPattern::FromURLNoWildcard(embedding_origin), | 275 ContentSettingsPattern::FromURLNoWildcard(embedding_origin), |
257 permission_type_, std::string(), content_setting); | 276 permission_type_, std::string(), content_setting); |
258 } | 277 } |
278 | |
279 bool PermissionContextBase::IsApiKillSwitchOn() const { | |
raymes
2015/10/11 22:11:22
Should we add an about:flag to gate this behavior
kcarattini
2015/10/12 03:58:06
There is a way to force the field trial already wi
| |
280 const std::string param = | |
281 variations::GetVariationParamValue(kApiFieldStudy, | |
282 PermissionContextUmaUtil::GetPermissionString(permission_type_)); | |
283 | |
284 return param == kApiFieldParamEnabledValue; | |
285 } | |
OLD | NEW |