Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferences.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferences.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferences.java |
| index 54e1914072ed79a96e4142f3bac74d76dee30768..010483e61dfaf6a4f2d6b7ad40c2df9420043f81 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferences.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataPreferences.java |
| @@ -6,10 +6,12 @@ package org.chromium.chrome.browser.preferences.privacy; |
| import android.app.Activity; |
| import android.app.ProgressDialog; |
| +import android.content.DialogInterface; |
| import android.os.Bundle; |
| import android.preference.CheckBoxPreference; |
| import android.preference.Preference; |
| import android.preference.PreferenceFragment; |
| +import android.support.v7.app.AlertDialog; |
| import android.widget.ListView; |
| import org.chromium.base.VisibleForTesting; |
| @@ -19,19 +21,29 @@ import org.chromium.chrome.browser.preferences.ButtonPreference; |
| import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
| import org.chromium.chrome.browser.preferences.SpinnerPreference; |
| import org.chromium.chrome.browser.preferences.privacy.BrowsingDataCounterBridge.BrowsingDataCounterCallback; |
| +import org.chromium.chrome.browser.preferences.privacy.ConfirmImportantSitesDialogFragment.OriginEntry; |
| +import org.chromium.chrome.browser.preferences.website.ImportantOriginInfo; |
| +import org.chromium.chrome.browser.preferences.website.WebsitePreferenceBridge; |
| +import org.chromium.chrome.browser.profiles.Profile; |
| import org.chromium.sync.signin.ChromeSigninController; |
| +import java.util.ArrayList; |
| import java.util.Arrays; |
| import java.util.EnumSet; |
| +import java.util.HashMap; |
| +import java.util.List; |
| +import java.util.Map; |
| /** |
| * Modal dialog with options for selection the type of browsing data |
| * to clear (history, cookies), triggered from a preference. |
| */ |
| public class ClearBrowsingDataPreferences extends PreferenceFragment |
| - implements PrefServiceBridge.OnClearBrowsingDataListener, |
| + implements WebsitePreferenceBridge.ImportantOriginsReadyCallback, |
| + PrefServiceBridge.OnClearBrowsingDataListener, |
| Preference.OnPreferenceClickListener, |
| - Preference.OnPreferenceChangeListener{ |
| + Preference.OnPreferenceChangeListener, |
| + DialogInterface.OnClickListener { |
| /** |
| * Represents a single item in the dialog. |
| */ |
| @@ -171,6 +183,11 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment |
| private boolean mCanDeleteBrowsingHistory; |
| private Item[] mItems; |
| + private boolean mWaitingForOrigins = false; |
|
Finnur
2016/03/03 14:15:43
Probably clearer to add a private function Waiting
dmurph
2016/04/26 21:43:12
I cleaned this up a bit.
|
| + private List<String> mSortedImportantOrigins; |
| + private Map<String, ImportantOriginInfo> mImportantOriginMap; |
|
Finnur
2016/03/03 14:15:43
Unused, right?
Well, I guess you said the CL wasn
dmurph
2016/04/26 21:43:12
REmoved.
|
| + private ConfirmImportantSitesDialogFragment mConfirmImportantSitesDialog; |
| + |
| protected final EnumSet<DialogOption> getSelectedOptions() { |
| EnumSet<DialogOption> selected = EnumSet.noneOf(DialogOption.class); |
| for (Item item : mItems) { |
| @@ -210,11 +227,11 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment |
| */ |
| protected DialogOption[] getDialogOptions() { |
| return new DialogOption[] { |
| - DialogOption.CLEAR_HISTORY, |
| - DialogOption.CLEAR_COOKIES_AND_SITE_DATA, |
| - DialogOption.CLEAR_CACHE, |
| - DialogOption.CLEAR_PASSWORDS, |
| - DialogOption.CLEAR_FORM_DATA}; |
| + DialogOption.CLEAR_HISTORY, |
| + DialogOption.CLEAR_COOKIES_AND_SITE_DATA, |
| + DialogOption.CLEAR_CACHE, |
| + DialogOption.CLEAR_PASSWORDS, |
| + DialogOption.CLEAR_FORM_DATA}; |
| } |
| /** |
| @@ -246,7 +263,7 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment |
| */ |
| protected boolean isOptionSelectedByDefault(DialogOption option) { |
| return PrefServiceBridge.getInstance().getBrowsingDataDeletionPreference( |
| - option.getDataType()); |
| + option.getDataType()); |
| } |
| // Called when "clear browsing data" completes. |
| @@ -308,11 +325,11 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment |
| } |
| mItems[i] = new Item( |
| - this, |
| - options[i], |
| - (CheckBoxPreference) findPreference(options[i].getPreferenceKey()), |
| - isOptionSelectedByDefault(options[i]), |
| - enabled); |
| + this, |
| + options[i], |
| + (CheckBoxPreference) findPreference(options[i].getPreferenceKey()), |
| + isOptionSelectedByDefault(options[i]), |
| + enabled); |
| } |
| // Not all checkboxes defined in the layout are necessarily handled by this class |
| @@ -352,6 +369,7 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment |
| } else { |
| summary.setSummary(R.string.clear_browsing_data_footnote); |
| } |
| + WebsitePreferenceBridge.fetchImportantOriginInfo(this); |
|
Finnur
2016/03/03 14:15:43
nit: Line break above.
dmurph
2016/04/26 21:43:12
Done.
|
| } |
| @Override |
| @@ -378,7 +396,13 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment |
| */ |
| protected void onOptionSelected() { |
| showProgressDialog(); |
| - clearBrowsingData(getSelectedOptions()); |
| + if (mSortedImportantOrigins == null) { |
| + mWaitingForOrigins = true; |
| + return; |
| + } |
| + if (!showImportantOriginsDialog()) { |
| + clearBrowsingData(getSelectedOptions()); |
| + } |
| } |
| protected final void showProgressDialog() { |
| @@ -391,8 +415,58 @@ public class ClearBrowsingDataPreferences extends PreferenceFragment |
| false); |
| } |
| + /** |
| + * @return if we needed to show the dialog. |
|
Finnur
2016/03/03 14:15:43
s/if/whether/
dmurph
2016/04/26 21:43:12
Removed
|
| + */ |
| + protected final boolean showImportantOriginsDialog() { |
| + List<OriginEntry> origins = new ArrayList<>(); |
| + if (mSortedImportantOrigins == null || mSortedImportantOrigins.isEmpty()) { |
| + return false; |
| + } |
| + for (String url : mSortedImportantOrigins) { |
| + OriginEntry entry = new OriginEntry(); |
| + android.util.Log.i(TAG, "important " + url); |
| + entry.name = url; |
| + entry.url = url; |
| + origins.add(entry); |
| + } |
| + mConfirmImportantSitesDialog = new ConfirmImportantSitesDialogFragment( |
| + Profile.getLastUsedProfile(), origins, this); |
| + mConfirmImportantSitesDialog.show( |
| + getFragmentManager(), ConfirmImportantSitesDialogFragment.FRAGMENT_TAG); |
| + return true; |
| + } |
| + |
| @VisibleForTesting |
| ProgressDialog getProgressDialog() { |
| return mProgressDialog; |
| } |
| + |
| + @SuppressWarnings("unchecked") |
| + @Override |
| + public void onImportantOriginsReady(ArrayList sortedOrigins, HashMap map) { |
| + android.util.Log.i(TAG, "got importants"); |
| + mSortedImportantOrigins = (List<String>) sortedOrigins; |
| + mImportantOriginMap = (Map<String, ImportantOriginInfo>) map; |
| + if (mWaitingForOrigins) { |
| + boolean needed = showImportantOriginsDialog(); |
| + if (!needed) { |
|
Finnur
2016/03/03 14:15:43
You can collapse these two into one line.
dmurph
2016/04/26 21:43:12
REmoved
|
| + clearBrowsingData(getSelectedOptions()); |
| + } |
| + } |
| + } |
| + |
| + /* |
| + * This is the callback for the origin filter dialog. We should only clear if we get the |
| + * positive button response. |
| + */ |
| + @Override |
| + public void onClick(DialogInterface dialog, int whichButton) { |
| + if (whichButton == AlertDialog.BUTTON_POSITIVE) { |
| + // TODO(dmurph): Implement the origin filtering. |
| + clearBrowsingData(getSelectedOptions()); |
| + } else { |
| + dismissProgressDialog(); |
| + } |
| + } |
| } |