Commit 56db9426 authored by Huanzhong Huang's avatar Huanzhong Huang Committed by Commit Bot

Add improved cookie controls toggle to privacy settings

Surface the cookie controls toggle in privacy settings. Implemented
behind the ImprovedCookieControls flag.

Bug: 967668
Change-Id: I0ed43b7ac7f3022c1678261a372aa8aa0e1964f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1677170
Commit-Queue: Huanzhong Huang <huanzhong@chromium.org>
Reviewed-by: default avatarDan Beam <dbeam@chromium.org>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691124}
parent 28044a4d
...@@ -3000,6 +3000,12 @@ ...@@ -3000,6 +3000,12 @@
<message name="IDS_SETTINGS_SYNC_AND_GOOGLE_SERVICES_PRIVACY_DESC_UNIFIED_CONSENT" desc="The description of the 'Sync and Google services' row in the privacy section"> <message name="IDS_SETTINGS_SYNC_AND_GOOGLE_SERVICES_PRIVACY_DESC_UNIFIED_CONSENT" desc="The description of the 'Sync and Google services' row in the privacy section">
More settings that relate to privacy, security, and data collection More settings that relate to privacy, security, and data collection
</message> </message>
<message name="IDS_SETTINGS_COOKIE_CONTROLS" desc="Text for cookie control button in Privacy options">
Tracking protection
</message>
<message name="IDS_SETTINGS_COOKIE_CONTROLS_DESCRIPTION" desc="The description of the 'Cookie control' row in the privacy section">
Blocks cookies that are used for cross-site tracking in Incognito. Some sites may stop working.
</message>
<!-- Reset Settings Page --> <!-- Reset Settings Page -->
<message name="IDS_SETTINGS_RESET" desc="Title for an item in the 'Reset and clean up' section of Chrome Settings. If the user clicks this option, browser settings will be returned to their default values, after a confirmation by the user." meaning="Chrome Cleanup feature. Try to use the same translation for 'Reset' in 'Reset and cleanup' string."> <message name="IDS_SETTINGS_RESET" desc="Title for an item in the 'Reset and clean up' section of Chrome Settings. If the user clicks this option, browser settings will be returned to their default values, after a confirmation by the user." meaning="Chrome Cleanup feature. Try to use the same translation for 'Reset' in 'Reset and cleanup' string.">
......
...@@ -238,6 +238,8 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() { ...@@ -238,6 +238,8 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() {
// Privacy page // Privacy page
(*s_whitelist)[::prefs::kSigninAllowedOnNextStartup] = (*s_whitelist)[::prefs::kSigninAllowedOnNextStartup] =
settings_api::PrefType::PREF_TYPE_BOOLEAN; settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_whitelist)[::prefs::kCookieControlsMode] =
settings_api::PrefType::PREF_TYPE_NUMBER;
// Sync and personalization page. // Sync and personalization page.
(*s_whitelist)[::prefs::kSafeBrowsingEnabled] = (*s_whitelist)[::prefs::kSafeBrowsingEnabled] =
......
...@@ -64,6 +64,15 @@ const SettingsBooleanControlBehaviorImpl = { ...@@ -64,6 +64,15 @@ const SettingsBooleanControlBehaviorImpl = {
numericUncheckedValue: { numericUncheckedValue: {
type: Number, type: Number,
value: 0, value: 0,
},
/**
* For numeric prefs only. The integer value sent to prefs when the user
* checks the control.
*/
numericCheckedValue: {
type: Number,
value: 1,
} }
}, },
...@@ -91,7 +100,9 @@ const SettingsBooleanControlBehaviorImpl = { ...@@ -91,7 +100,9 @@ const SettingsBooleanControlBehaviorImpl = {
// a boolean or a number. // a boolean or a number.
if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) { if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) {
assert(!this.inverted); assert(!this.inverted);
this.set('pref.value', this.checked ? 1 : this.numericUncheckedValue); this.set(
'pref.value',
this.checked ? this.numericCheckedValue : this.numericUncheckedValue);
return; return;
} }
this.set('pref.value', this.inverted ? !this.checked : this.checked); this.set('pref.value', this.inverted ? !this.checked : this.checked);
......
...@@ -109,6 +109,14 @@ ...@@ -109,6 +109,14 @@
unified-consent-enabled="[[unifiedConsentEnabled_]]"> unified-consent-enabled="[[unifiedConsentEnabled_]]">
</settings-personalization-options> </settings-personalization-options>
</template> </template>
<template is="dom-if" if="[[improvedCookieControlsEnabled_]]">
<settings-toggle-button id="cookieControls"
pref="{{prefs.profile.cookie_controls_mode}}"
label="$i18n{cookieControls}"
sub-label="$i18n{cookieControlsDescription}"
numeric-checked-value="2">
</settings-toggle-button>
</template>
<settings-toggle-button id="doNotTrack" <settings-toggle-button id="doNotTrack"
pref="{{prefs.enable_do_not_track}}" label="$i18n{doNotTrack}" pref="{{prefs.enable_do_not_track}}" label="$i18n{doNotTrack}"
on-settings-boolean-control-change="onDoNotTrackChange_" on-settings-boolean-control-change="onDoNotTrackChange_"
......
...@@ -206,6 +206,19 @@ Polymer({ ...@@ -206,6 +206,19 @@ Polymer({
}, },
}, },
/**
* Whether the ImprovedCookieControls flag is enabled.
* Controls whether or not to expose the cookie controls toggle in the
* privacy settings page.
* @private
*/
improvedCookieControlsEnabled_: {
type: Boolean,
value: function() {
return loadTimeData.getBoolean('improvedCookieControlsEnabled');
},
},
// <if expr="not chromeos"> // <if expr="not chromeos">
/** @private */ /** @private */
showRestart_: Boolean, showRestart_: Boolean,
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "components/autofill/core/common/autofill_constants.h" #include "components/autofill/core/common/autofill_constants.h"
#include "components/autofill/core/common/autofill_features.h" #include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_payments_features.h" #include "components/autofill/core/common/autofill_payments_features.h"
#include "components/content_settings/core/common/features.h"
#include "components/google/core/common/google_util.h" #include "components/google/core/common/google_util.h"
#include "components/omnibox/common/omnibox_features.h" #include "components/omnibox/common/omnibox_features.h"
#include "components/password_manager/core/browser/manage_passwords_referrer.h" #include "components/password_manager/core/browser/manage_passwords_referrer.h"
...@@ -2413,6 +2414,8 @@ void AddPrivacyStrings(content::WebUIDataSource* html_source, ...@@ -2413,6 +2414,8 @@ void AddPrivacyStrings(content::WebUIDataSource* html_source,
{"privacyPageTitle", IDS_SETTINGS_PRIVACY}, {"privacyPageTitle", IDS_SETTINGS_PRIVACY},
{"signinAllowedTitle", IDS_SETTINGS_SIGNIN_ALLOWED}, {"signinAllowedTitle", IDS_SETTINGS_SIGNIN_ALLOWED},
{"signinAllowedDescription", IDS_SETTINGS_SIGNIN_ALLOWED_DESC}, {"signinAllowedDescription", IDS_SETTINGS_SIGNIN_ALLOWED_DESC},
{"cookieControls", IDS_SETTINGS_COOKIE_CONTROLS},
{"cookieControlsDescription", IDS_SETTINGS_COOKIE_CONTROLS_DESCRIPTION},
{"doNotTrack", IDS_SETTINGS_ENABLE_DO_NOT_TRACK}, {"doNotTrack", IDS_SETTINGS_ENABLE_DO_NOT_TRACK},
{"doNotTrackDialogTitle", IDS_SETTINGS_ENABLE_DO_NOT_TRACK_DIALOG_TITLE}, {"doNotTrackDialogTitle", IDS_SETTINGS_ENABLE_DO_NOT_TRACK_DIALOG_TITLE},
{"enableContentProtectionAttestation", {"enableContentProtectionAttestation",
...@@ -2446,6 +2449,10 @@ void AddPrivacyStrings(content::WebUIDataSource* html_source, ...@@ -2446,6 +2449,10 @@ void AddPrivacyStrings(content::WebUIDataSource* html_source,
AddLocalizedStringsBulk(html_source, kLocalizedStrings, AddLocalizedStringsBulk(html_source, kLocalizedStrings,
base::size(kLocalizedStrings)); base::size(kLocalizedStrings));
html_source->AddBoolean(
"improvedCookieControlsEnabled",
base::FeatureList::IsEnabled(content_settings::kImprovedCookieControls));
// Select strings depending on unified-consent enabledness. // Select strings depending on unified-consent enabledness.
bool is_unified_consent_enabled = bool is_unified_consent_enabled =
unified_consent::IsUnifiedConsentFeatureEnabled(); unified_consent::IsUnifiedConsentFeatureEnabled();
......
...@@ -15,6 +15,7 @@ GEN('#endif // defined(OS_CHROMEOS)'); ...@@ -15,6 +15,7 @@ GEN('#endif // defined(OS_CHROMEOS)');
GEN('#include "chrome/common/chrome_features.h"'); GEN('#include "chrome/common/chrome_features.h"');
GEN('#include "chromeos/constants/chromeos_features.h"'); GEN('#include "chromeos/constants/chromeos_features.h"');
GEN('#include "components/autofill/core/common/autofill_features.h"'); GEN('#include "components/autofill/core/common/autofill_features.h"');
GEN('#include "components/content_settings/core/common/features.h"');
GEN('#include "components/omnibox/common/omnibox_features.h"'); GEN('#include "components/omnibox/common/omnibox_features.h"');
/** /**
...@@ -1155,6 +1156,8 @@ CrSettingsPrivacyPageTest.prototype = { ...@@ -1155,6 +1156,8 @@ CrSettingsPrivacyPageTest.prototype = {
/** @override */ /** @override */
browsePreload: 'chrome://settings/privacy_page/privacy_page.html', browsePreload: 'chrome://settings/privacy_page/privacy_page.html',
featureList: {enabled: ['content_settings::kImprovedCookieControls']},
/** @override */ /** @override */
extraLibraries: CrSettingsBrowserTest.prototype.extraLibraries.concat([ extraLibraries: CrSettingsBrowserTest.prototype.extraLibraries.concat([
'//ui/webui/resources/js/promise_resolver.js', '//ui/webui/resources/js/promise_resolver.js',
......
...@@ -130,6 +130,10 @@ cr.define('settings_privacy_page', function() { ...@@ -130,6 +130,10 @@ cr.define('settings_privacy_page', function() {
allowed_on_next_startup: allowed_on_next_startup:
{type: chrome.settingsPrivate.PrefType.BOOLEAN, value: true}, {type: chrome.settingsPrivate.PrefType.BOOLEAN, value: true},
}, },
profile: {
cookie_controls_mode:
{type: chrome.settingsPrivate.PrefType.NUMBER, value: 2}
},
}; };
document.body.appendChild(page); document.body.appendChild(page);
}); });
...@@ -153,6 +157,22 @@ cr.define('settings_privacy_page', function() { ...@@ -153,6 +157,22 @@ cr.define('settings_privacy_page', function() {
dialog.$$('#clearBrowsingDataDialog'), 'open', ''); dialog.$$('#clearBrowsingDataDialog'), 'open', '');
}); });
test('cookieControlsToggle', function() {
assertTrue(loadTimeData.getBoolean('improvedCookieControlsEnabled'));
Polymer.dom.flush();
const toggle = page.$$('#cookieControls');
assertTrue(toggle.checked);
assertEquals(2, page.prefs.profile.cookie_controls_mode.value);
toggle.click();
assertFalse(toggle.checked);
assertEquals(0, page.prefs.profile.cookie_controls_mode.value);
toggle.click();
assertTrue(toggle.checked);
assertEquals(2, page.prefs.profile.cookie_controls_mode.value);
});
if (!cr.isChromeOS) { if (!cr.isChromeOS) {
test('signinAllowedToggle', function() { test('signinAllowedToggle', function() {
const toggle = page.$.signinAllowedToggle; const toggle = page.$.signinAllowedToggle;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment