Commit b8085fb4 authored by Ehimare Okoyomon's avatar Ehimare Okoyomon Committed by Commit Bot

[Android] Change the AddExceptionPreference defaults for cookie settings

For cookie settings specifically, change whether the result of
AddExceptionPreference is an allow or block exception, depending on the
user's current cookie settings state.

Bug: 1060118
Change-Id: If1440909ac649015bd8c97c632e5e4f571a41841
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2139663Reviewed-by: default avatarFinnur Thorarinsson <finnur@chromium.org>
Commit-Queue: Ehimare Okoyomon <eokoyomon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759670}
parent 2dd72b16
......@@ -539,6 +539,7 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment
getInfoForOrigins();
} else if (FOUR_STATE_COOKIE_TOGGLE_KEY.equals(preference.getKey())) {
setCookieSettingsPreference((CookieSettingsState) newValue);
getInfoForOrigins();
} else if (THIRD_PARTY_COOKIES_TOGGLE_KEY.equals(preference.getKey())) {
PrefServiceBridge.getInstance().setBoolean(
Pref.BLOCK_THIRD_PARTY_COOKIES, ((boolean) newValue));
......@@ -589,13 +590,13 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment
PrefServiceBridge.getInstance().setInteger(Pref.COOKIE_CONTROLS_MODE, mode);
PrefServiceBridge.getInstance().setBoolean(
Pref.BLOCK_THIRD_PARTY_COOKIES, mode == CookieControlsMode.ON);
}
// Re-configure the FourStateCookieToggle in order to avoid having stale state variables
// within the FourStateCookieSettingsPreference. These variables determine the checked and
// enabled states of each of the buttons.
configureFourStateCookieToggle(
private boolean cookieSettingsExceptionShouldBlock() {
FourStateCookieSettingsPreference fourStateCookieToggle =
(FourStateCookieSettingsPreference) getPreferenceScreen().findPreference(
FOUR_STATE_COOKIE_TOGGLE_KEY));
FOUR_STATE_COOKIE_TOGGLE_KEY);
return fourStateCookieToggle.getState() == CookieSettingsState.ALLOW;
}
private String getAddExceptionDialogMessage() {
......@@ -613,9 +614,15 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment
? R.string.website_settings_add_site_description_sound_block
: R.string.website_settings_add_site_description_sound_allow;
} else if (mCategory.showSites(SiteSettingsCategory.Type.COOKIES)) {
resource = WebsitePreferenceBridge.isCategoryEnabled(ContentSettingsType.COOKIES)
? R.string.website_settings_add_site_description_cookies_block
: R.string.website_settings_add_site_description_cookies_allow;
if (mRequiresFourStateSetting) {
resource = cookieSettingsExceptionShouldBlock()
? R.string.website_settings_add_site_description_cookies_block
: R.string.website_settings_add_site_description_cookies_allow;
} else {
resource = WebsitePreferenceBridge.isCategoryEnabled(ContentSettingsType.COOKIES)
? R.string.website_settings_add_site_description_cookies_block
: R.string.website_settings_add_site_description_cookies_allow;
}
}
assert resource > 0;
return getString(resource);
......@@ -650,10 +657,16 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment
// AddExceptionPreference.SiteAddedCallback:
@Override
public void onAddSite(String primaryPattern, String secondaryPattern) {
int setting =
(WebsitePreferenceBridge.isCategoryEnabled(mCategory.getContentSettingsType()))
? ContentSettingValues.BLOCK
: ContentSettingValues.ALLOW;
int setting;
if (mCategory.showSites(SiteSettingsCategory.Type.COOKIES) && mRequiresFourStateSetting) {
setting = cookieSettingsExceptionShouldBlock() ? ContentSettingValues.BLOCK
: ContentSettingValues.ALLOW;
} else {
setting =
(WebsitePreferenceBridge.isCategoryEnabled(mCategory.getContentSettingsType()))
? ContentSettingValues.BLOCK
: ContentSettingValues.ALLOW;
}
WebsitePreferenceBridge.setContentSettingForPattern(
mCategory.getContentSettingsType(), primaryPattern, secondaryPattern, setting);
......
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