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

Unified 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: Change 'enabled' to 'blocked' 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 side-by-side diff with in-line comments
Download patch
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..1f2726f255ce6b8230150d5ea01be98888b145c6 100644
--- a/chrome/browser/permissions/permission_context_base.cc
+++ b/chrome/browser/permissions/permission_context_base.cc
@@ -16,10 +16,17 @@
#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"
+// static
+const char PermissionContextBase::kApiKillSwitchFieldStudy[] = "ApiKillSwitch";
mlamouri (slow - plz ping) 2015/10/20 13:35:45 I would prefer if the name of the switch was more
kcarattini 2015/10/21 03:39:37 I switched to "Permission" from "Api" since that's
+// static
+const char PermissionContextBase::kApiKillSwitchFieldParamBlockedValue[] =
+ "blocked";
mlamouri (slow - plz ping) 2015/10/20 13:35:45 I think we should just try to match the string "en
kcarattini 2015/10/21 03:39:37 I actually moved from "enabled" to "blocked" becau
+
PermissionContextBase::PermissionContextBase(
Profile* profile,
const ContentSettingsType permission_type)
@@ -42,6 +49,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()) {
mlamouri (slow - plz ping) 2015/10/20 13:35:45 In order to make sure this is always called, I thi
Bernhard Bauer 2015/10/20 14:27:17 I don't think that works, as this method is overri
mlamouri (slow - plz ping) 2015/10/20 14:32:28 The logic in GeolocationPermissionContext::Request
kcarattini 2015/10/21 03:39:37 GeolocationPermissionContext calls the base class
kcarattini 2015/10/21 03:39:37 I'm happy to do that in a followup cl, and then I
+ // 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 +69,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 +277,11 @@ void PermissionContextBase::UpdateContentSetting(
ContentSettingsPattern::FromURLNoWildcard(embedding_origin),
permission_type_, std::string(), content_setting);
}
+
+bool PermissionContextBase::IsApiKillSwitchOn() const {
mlamouri (slow - plz ping) 2015/10/20 13:35:45 nit: maybe rename: ShouldAutoDeny()?
kcarattini 2015/10/21 03:39:37 Changed from Api to Permission.
+ const std::string param =
+ variations::GetVariationParamValue(kApiKillSwitchFieldStudy,
+ PermissionContextUmaUtil::GetPermissionString(permission_type_));
+
+ return param == kApiKillSwitchFieldParamBlockedValue;
+}

Powered by Google App Engine
This is Rietveld 408576698