Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataDialogFragment.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataDialogFragment.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataDialogFragment.java |
| index fdaac2f632d31a8a3a548baf57b91763001faff6..cf9eb7e22a6328746dc53207134c4520c379db4d 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataDialogFragment.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/ClearBrowsingDataDialogFragment.java |
| @@ -17,7 +17,10 @@ import android.text.method.LinkMovementMethod; |
| import android.text.style.ClickableSpan; |
| import android.view.View; |
| import android.widget.Button; |
| +import android.widget.CheckedTextView; |
| +import android.widget.ListView; |
| import android.widget.TextView; |
| +import android.widget.Toast; |
| import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
| @@ -70,6 +73,7 @@ public class ClearBrowsingDataDialogFragment extends DialogFragment implements |
| private DialogOption[] mOptions; |
| private AlertDialog mDialog; |
| private ProgressDialog mProgressDialog; |
| + private boolean mCanDeleteBrowsingHistory; |
| protected final void clearBrowsingData(EnumSet<DialogOption> selectedOptions) { |
| PrefServiceBridge.getInstance().clearBrowsingData(this, |
| @@ -107,8 +111,11 @@ public class ClearBrowsingDataDialogFragment extends DialogFragment implements |
| * @return EnumSet containing dialog options to be selected. |
| */ |
| protected EnumSet<DialogOption> getDefaultDialogOptionsSelections() { |
| - return EnumSet.of(DialogOption.CLEAR_HISTORY, DialogOption.CLEAR_CACHE, |
| - DialogOption.CLEAR_COOKIES_AND_SITE_DATA); |
| + if (mCanDeleteBrowsingHistory) { |
| + return EnumSet.of(DialogOption.CLEAR_HISTORY, DialogOption.CLEAR_CACHE, |
| + DialogOption.CLEAR_COOKIES_AND_SITE_DATA); |
| + } |
| + return EnumSet.of(DialogOption.CLEAR_CACHE, DialogOption.CLEAR_COOKIES_AND_SITE_DATA); |
|
Bernhard Bauer
2015/03/03 14:26:20
Maybe start with the base EnumSet, then add CLEAR_
knn
2015/03/03 15:03:43
Done.
|
| } |
| // Called when "clear browsing data" completes. |
| @@ -136,16 +143,25 @@ public class ClearBrowsingDataDialogFragment extends DialogFragment implements |
| @Override |
| public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) { |
| - if (isChecked) { |
| - mSelectedOptions.add(mOptions[whichButton]); |
| + DialogOption selectedOption = mOptions[whichButton]; |
| + if (!mCanDeleteBrowsingHistory && selectedOption == DialogOption.CLEAR_HISTORY) { |
| + Toast.makeText(getActivity(), |
| + R.string.can_not_clear_browsing_history_toast, |
| + Toast.LENGTH_SHORT).show(); |
| + return; |
| + } |
| + ((CheckedTextView) mDialog.getListView().getChildAt(whichButton)).toggle(); |
|
Bernhard Bauer
2015/03/03 14:26:20
Why do you need to do this manually?
knn
2015/03/03 15:03:43
Yes. The ListView is forbidden from managing the C
|
| + if (mSelectedOptions.contains(selectedOption)) { |
|
Bernhard Bauer
2015/03/03 14:26:21
I would be a bit more at ease if we would keep usi
knn
2015/03/03 15:03:43
isChecked is set by the ListView which does not al
Bernhard Bauer
2015/03/03 15:25:29
OK... But presumably we could still get the state
knn
2015/03/03 15:55:56
The ListView gets the isChecked value from its int
Bernhard Bauer
2015/03/03 16:00:45
Right. What I meant was this:
* If we are not mana
knn
2015/03/03 16:22:31
Done.
|
| + mSelectedOptions.remove(selectedOption); |
| } else { |
| - mSelectedOptions.remove(mOptions[whichButton]); |
| + mSelectedOptions.add(selectedOption); |
| } |
| updateButtonState(); |
| } |
| @Override |
| public Dialog onCreateDialog(Bundle savedInstanceState) { |
| + mCanDeleteBrowsingHistory = PrefServiceBridge.getInstance().canDeleteBrowsingHistory(); |
| DialogOption[] options = getDialogOptions(); |
| mOptions = Arrays.copyOf(options, options.length); |
| mSelectedOptions = getDefaultDialogOptionsSelections(); |
| @@ -193,6 +209,17 @@ public class ClearBrowsingDataDialogFragment extends DialogFragment implements |
| } |
| mDialog = builder.create(); |
| + if (!mCanDeleteBrowsingHistory) { |
| + mDialog.getListView().post(new Runnable() { |
|
Bernhard Bauer
2015/03/03 14:26:20
Any particular reason you're doing this on the nex
knn
2015/03/03 15:03:43
The children of the list view are not created unti
|
| + @Override |
| + public void run() { |
| + int positionOfHistoryElement = |
| + Arrays.asList(mOptions).indexOf(DialogOption.CLEAR_HISTORY); |
| + mDialog.getListView().getChildAt(positionOfHistoryElement).setEnabled(false); |
| + mDialog.getListView().setChoiceMode(ListView.CHOICE_MODE_NONE); |
| + } |
| + }); |
| + } |
| return mDialog; |
| } |