Commit 935a20a1 authored by knn's avatar knn Committed by Commit bot

Respect prefs::kAllowDeletingBrowserHistory in the Clear History UI on Android.

BUG=443095

Review URL: https://codereview.chromium.org/974463002

Cr-Commit-Position: refs/heads/master@{#319618}
parent f7f36509
...@@ -511,6 +511,13 @@ public final class PrefServiceBridge { ...@@ -511,6 +511,13 @@ public final class PrefServiceBridge {
nativeClearBrowsingData(history, cache, cookiesAndSiteData, passwords, formData); nativeClearBrowsingData(history, cache, cookiesAndSiteData, passwords, formData);
} }
/*
* Whether browser history can be deleted by the user.
*/
public boolean canDeleteBrowsingHistory() {
return nativeCanDeleteBrowsingHistory();
}
@CalledByNative @CalledByNative
private void browsingDataCleared() { private void browsingDataCleared() {
if (mClearBrowsingDataListener != null) { if (mClearBrowsingDataListener != null) {
...@@ -795,6 +802,7 @@ public final class PrefServiceBridge { ...@@ -795,6 +802,7 @@ public final class PrefServiceBridge {
private native void nativeGetJavaScriptExceptions(List<JavaScriptExceptionInfo> list); private native void nativeGetJavaScriptExceptions(List<JavaScriptExceptionInfo> list);
private native void nativeClearBrowsingData(boolean history, boolean cache, private native void nativeClearBrowsingData(boolean history, boolean cache,
boolean cookiesAndSiteData, boolean passwords, boolean formData); boolean cookiesAndSiteData, boolean passwords, boolean formData);
private native boolean nativeCanDeleteBrowsingHistory();
private native void nativeSetAllowCookiesEnabled(boolean allow); private native void nativeSetAllowCookiesEnabled(boolean allow);
private native void nativeSetBlockThirdPartyCookiesEnabled(boolean enabled); private native void nativeSetBlockThirdPartyCookiesEnabled(boolean enabled);
private native void nativeSetDoNotTrackEnabled(boolean enabled); private native void nativeSetDoNotTrackEnabled(boolean enabled);
......
...@@ -17,7 +17,10 @@ import android.text.method.LinkMovementMethod; ...@@ -17,7 +17,10 @@ import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan; import android.text.style.ClickableSpan;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckedTextView;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.PrefServiceBridge; import org.chromium.chrome.browser.preferences.PrefServiceBridge;
...@@ -70,6 +73,7 @@ public class ClearBrowsingDataDialogFragment extends DialogFragment implements ...@@ -70,6 +73,7 @@ public class ClearBrowsingDataDialogFragment extends DialogFragment implements
private DialogOption[] mOptions; private DialogOption[] mOptions;
private AlertDialog mDialog; private AlertDialog mDialog;
private ProgressDialog mProgressDialog; private ProgressDialog mProgressDialog;
private boolean mCanDeleteBrowsingHistory;
protected final void clearBrowsingData(EnumSet<DialogOption> selectedOptions) { protected final void clearBrowsingData(EnumSet<DialogOption> selectedOptions) {
PrefServiceBridge.getInstance().clearBrowsingData(this, PrefServiceBridge.getInstance().clearBrowsingData(this,
...@@ -107,8 +111,12 @@ public class ClearBrowsingDataDialogFragment extends DialogFragment implements ...@@ -107,8 +111,12 @@ public class ClearBrowsingDataDialogFragment extends DialogFragment implements
* @return EnumSet containing dialog options to be selected. * @return EnumSet containing dialog options to be selected.
*/ */
protected EnumSet<DialogOption> getDefaultDialogOptionsSelections() { protected EnumSet<DialogOption> getDefaultDialogOptionsSelections() {
return EnumSet.of(DialogOption.CLEAR_HISTORY, DialogOption.CLEAR_CACHE, EnumSet<DialogOption> defaultOptions = EnumSet.of(DialogOption.CLEAR_CACHE,
DialogOption.CLEAR_COOKIES_AND_SITE_DATA); DialogOption.CLEAR_COOKIES_AND_SITE_DATA);
if (mCanDeleteBrowsingHistory) {
defaultOptions.add(DialogOption.CLEAR_HISTORY);
}
return defaultOptions;
} }
// Called when "clear browsing data" completes. // Called when "clear browsing data" completes.
...@@ -136,16 +144,31 @@ public class ClearBrowsingDataDialogFragment extends DialogFragment implements ...@@ -136,16 +144,31 @@ public class ClearBrowsingDataDialogFragment extends DialogFragment implements
@Override @Override
public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) { public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
if (isChecked) { DialogOption clickedOption = mOptions[whichButton];
mSelectedOptions.add(mOptions[whichButton]); CheckedTextView clickedCheckBox =
(CheckedTextView) mDialog.getListView().getChildAt(whichButton);
if (!mCanDeleteBrowsingHistory) {
// Manually managing the Checkbox to handle disabled options.
if (clickedOption == DialogOption.CLEAR_HISTORY) {
Toast.makeText(getActivity(),
R.string.can_not_clear_browsing_history_toast,
Toast.LENGTH_SHORT).show();
return;
}
clickedCheckBox.toggle();
}
// isChecked is always false when ListView does not manage the Checkbox.
if (clickedCheckBox.isChecked()) {
mSelectedOptions.add(clickedOption);
} else { } else {
mSelectedOptions.remove(mOptions[whichButton]); mSelectedOptions.remove(clickedOption);
} }
updateButtonState(); updateButtonState();
} }
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
mCanDeleteBrowsingHistory = PrefServiceBridge.getInstance().canDeleteBrowsingHistory();
DialogOption[] options = getDialogOptions(); DialogOption[] options = getDialogOptions();
mOptions = Arrays.copyOf(options, options.length); mOptions = Arrays.copyOf(options, options.length);
mSelectedOptions = getDefaultDialogOptionsSelections(); mSelectedOptions = getDefaultDialogOptionsSelections();
...@@ -193,6 +216,19 @@ public class ClearBrowsingDataDialogFragment extends DialogFragment implements ...@@ -193,6 +216,19 @@ public class ClearBrowsingDataDialogFragment extends DialogFragment implements
} }
mDialog = builder.create(); mDialog = builder.create();
if (!mCanDeleteBrowsingHistory) {
// Disable management of the Checkboxes by the ListView.
mDialog.getListView().setChoiceMode(ListView.CHOICE_MODE_NONE);
// Children views of the ListView are not created until it is drawn.
mDialog.getListView().post(new Runnable() {
@Override
public void run() {
int positionOfHistoryElement =
Arrays.asList(mOptions).indexOf(DialogOption.CLEAR_HISTORY);
mDialog.getListView().getChildAt(positionOfHistoryElement).setEnabled(false);
}
});
}
return mDialog; return mDialog;
} }
......
...@@ -357,6 +357,9 @@ For example, some websites may respond to this request by showing you ads that a ...@@ -357,6 +357,9 @@ For example, some websites may respond to this request by showing you ads that a
<message name="IDS_CLEAR_BROWSING_DATA_PROGRESS_MESSAGE" desc='Message on the progress dialog used when waiting for "clear browsing data" to complete.'> <message name="IDS_CLEAR_BROWSING_DATA_PROGRESS_MESSAGE" desc='Message on the progress dialog used when waiting for "clear browsing data" to complete.'>
Please wait… Please wait…
</message> </message>
<message name="IDS_CAN_NOT_CLEAR_BROWSING_HISTORY_TOAST" desc="Message on the toast explaining that child account users can not clear their browsing history.">
Browsing history can't be cleared with Accounts for Kids.
</message>
<!-- Accessibility preferences --> <!-- Accessibility preferences -->
<message name="IDS_PREFS_ACCESSIBILITY" desc="Title of Accessibility settings, which allows the user to change webpage font sizes. [CHAR-LIMIT=32]"> <message name="IDS_PREFS_ACCESSIBILITY" desc="Title of Accessibility settings, which allows the user to change webpage font sizes. [CHAR-LIMIT=32]">
......
...@@ -341,6 +341,10 @@ static void ClearBrowsingData(JNIEnv* env, jobject obj, jboolean history, ...@@ -341,6 +341,10 @@ static void ClearBrowsingData(JNIEnv* env, jobject obj, jboolean history,
BrowsingDataHelper::UNPROTECTED_WEB); BrowsingDataHelper::UNPROTECTED_WEB);
} }
static jboolean CanDeleteBrowsingHistory(JNIEnv* env, jobject obj) {
return GetPrefService()->GetBoolean(prefs::kAllowDeletingBrowserHistory);
}
static void SetAllowCookiesEnabled(JNIEnv* env, jobject obj, jboolean allow) { static void SetAllowCookiesEnabled(JNIEnv* env, jobject obj, jboolean allow) {
HostContentSettingsMap* host_content_settings_map = HostContentSettingsMap* host_content_settings_map =
GetOriginalProfile()->GetHostContentSettingsMap(); GetOriginalProfile()->GetHostContentSettingsMap();
......
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