Commit ecf7c9ee authored by Christian Dullweber's avatar Christian Dullweber Committed by Commit Bot

Show confirmation dialog when clearing cookies

Show confirmation for cookie deletion before deleting cookies.

Screenshot: https://crbug.com/1077766#c50
Bug: 1077766
Change-Id: I916cdde882dcaf31b9313661a8f734c9112b2640
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2426424Reviewed-by: default avatarEhimare Okoyomon <eokoyomon@chromium.org>
Commit-Queue: Christian Dullweber <dullweber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810170}
parent 81f5dd1a
......@@ -362,6 +362,7 @@ public class PageInfoViewTest {
onViewWaiting(allOf(withText(containsString("stored data")), isDisplayed()));
// Clear cookies in page info.
onView(withText("Clear cookies")).perform(click());
onView(withText("Clear")).perform(click());
// Wait until the UI navigates back and check cookies are deleted.
onViewWaiting(allOf(withId(R.id.page_info_cookies_row), isDisplayed()));
expectHasCookies(false);
......
......@@ -489,6 +489,12 @@
<message name="IDS_PAGE_INFO_COOKIES_CLEAR" desc="Text on the button to clear cookies for a site.">
Clear cookies
</message>
<message name="IDS_PAGE_INFO_COOKIES_CLEAR_CONFIRMATION" desc="Description of the confirmation dialog when the user clicked 'Clear cookies'.">
Are you sure you want to clear cookies and other site data for this website?
</message>
<message name="IDS_PAGE_INFO_COOKIES_CLEAR_CONFIRMATION_BUTTON" desc="Button in the confirmation dialog when the user clicked 'Clear cookies'.">
Clear
</message>
<message name="IDS_PAGE_INFO_COOKIES_DESCRIPTION" desc="Description in the Page Info UI explaining cookies.">
Cookies and other site data are used to remember you, for example to sign you in or to personalize ads. To manage cookies for all sites, see <ph name="BEGIN_LINK">&lt;link&gt;</ph>Settings<ph name="END_LINK">&lt;/link&gt;</ph>.
</message>
......
......@@ -6,6 +6,7 @@ package org.chromium.components.page_info;
import android.os.Bundle;
import android.text.format.Formatter;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
......@@ -29,6 +30,7 @@ public class PageInfoCookiesPreference extends PreferenceFragmentCompat {
private ChromeSwitchPreference mCookieSwitch;
private ChromeBasePreference mCookieInUse;
private Runnable mOnClearCallback;
/** Parameters to configure the cookie controls view. */
public static class PageInfoCookiesViewParams {
......@@ -65,9 +67,10 @@ public class PageInfoCookiesPreference extends PreferenceFragmentCompat {
mCookieInUse.setIcon(
SettingsUtils.getTintedIcon(getContext(), R.drawable.permission_cookie));
mOnClearCallback = params.onClearCallback;
ButtonPreference clearButton = findPreference(CLEAR_BUTTON_PREFERENCE);
clearButton.setOnPreferenceClickListener(preference -> {
params.onClearCallback.run();
showClearCookiesConfirmation();
return true;
});
if (params.disableCookieDeletion) {
......@@ -75,6 +78,16 @@ public class PageInfoCookiesPreference extends PreferenceFragmentCompat {
}
}
private void showClearCookiesConfirmation() {
new AlertDialog.Builder(getActivity(), R.style.Theme_Chromium_AlertDialog)
.setTitle(R.string.page_info_cookies_clear)
.setMessage(R.string.page_info_cookies_clear_confirmation)
.setPositiveButton(R.string.page_info_cookies_clear_confirmation_button,
(dialog, which) -> mOnClearCallback.run())
.setNegativeButton(R.string.cancel, null)
.show();
}
public void setCookieBlockingStatus(@CookieControlsStatus int status, boolean isEnforced) {
boolean visible = status != CookieControlsStatus.DISABLED;
boolean enabled = status == CookieControlsStatus.ENABLED;
......
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