Index: chrome/browser/permissions/permission_context_base.cc |
diff --git a/chrome/browser/permissions/permission_context_base.cc b/chrome/browser/permissions/permission_context_base.cc |
index f329b2bbb640a9b6826ee85bac39ff266dbc7528..c3b8257e219134321a14a246d39077efba66acf2 100644 |
--- a/chrome/browser/permissions/permission_context_base.cc |
+++ b/chrome/browser/permissions/permission_context_base.cc |
@@ -16,10 +16,15 @@ |
#include "chrome/common/pref_names.h" |
#include "components/content_settings/core/browser/host_content_settings_map.h" |
#include "components/content_settings/core/browser/website_settings_registry.h" |
+#include "components/variations/variations_associated_data.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/common/origin_util.h" |
+// API kill switch Finch Trials |
+static const char kApiFieldStudy[] = "ApiKillSwitch"; |
+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
|
+ |
PermissionContextBase::PermissionContextBase( |
Profile* profile, |
const ContentSettingsType permission_type) |
@@ -42,6 +47,15 @@ void PermissionContextBase::RequestPermission( |
const BrowserPermissionCallback& callback) { |
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ // First check if this API has been disabled through Finch. |
+ if (IsApiKillSwitchOn()) { |
+ // The kill switch is enabled for this API; Block all requests. |
+ NotifyPermissionSet(id, requesting_frame.GetOrigin(), |
+ web_contents->GetLastCommittedURL().GetOrigin(), callback, |
+ false /* persist */, CONTENT_SETTING_BLOCK); |
+ return; |
+ } |
+ |
DecidePermission(web_contents, |
id, |
requesting_frame.GetOrigin(), |
@@ -53,6 +67,11 @@ void PermissionContextBase::RequestPermission( |
ContentSetting PermissionContextBase::GetPermissionStatus( |
const GURL& requesting_origin, |
const GURL& embedding_origin) const { |
+ |
+ // If the API has been disabled through Finch, block all requests. |
+ if (IsApiKillSwitchOn()) |
+ return CONTENT_SETTING_BLOCK; |
+ |
if (IsRestrictedToSecureOrigins() && |
!content::IsOriginSecure(requesting_origin)) { |
return CONTENT_SETTING_BLOCK; |
@@ -256,3 +275,11 @@ void PermissionContextBase::UpdateContentSetting( |
ContentSettingsPattern::FromURLNoWildcard(embedding_origin), |
permission_type_, std::string(), content_setting); |
} |
+ |
+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
|
+ const std::string param = |
+ variations::GetVariationParamValue(kApiFieldStudy, |
+ PermissionContextUmaUtil::GetPermissionString(permission_type_)); |
+ |
+ return param == kApiFieldParamEnabledValue; |
+} |