Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3232)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillPopupBridge.java

Issue 1134793004: Autofill item deletion on android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test fix Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillPopupBridge.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillPopupBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillPopupBridge.java
index 773632c8f9175f2550fe1f78ebc09b86e98e29c4..147f6a934ad5b8f1b47d5d9e4f2e6aa9ce4e2cf1 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillPopupBridge.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillPopupBridge.java
@@ -5,10 +5,14 @@
package org.chromium.chrome.browser.autofill;
import android.app.Activity;
+import android.content.Context;
+import android.content.DialogInterface;
import android.os.Handler;
+import android.support.v7.app.AlertDialog;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
+import org.chromium.chrome.R;
import org.chromium.chrome.browser.ResourceId;
import org.chromium.ui.DropdownItem;
import org.chromium.ui.autofill.AutofillPopup;
@@ -21,9 +25,11 @@ import org.chromium.ui.base.WindowAndroid;
* JNI call glue for AutofillExternalDelagate C++ and Java objects.
*/
@JNINamespace("autofill")
-public class AutofillPopupBridge implements AutofillPopupDelegate{
+public class AutofillPopupBridge implements AutofillPopupDelegate, DialogInterface.OnClickListener {
private final long mNativeAutofillPopup;
private final AutofillPopup mAutofillPopup;
+ private AlertDialog mDeletionDialog;
+ private final Context mContext;
public AutofillPopupBridge(long nativeAutofillPopupViewAndroid, WindowAndroid windowAndroid,
ViewAndroidDelegate containerViewDelegate) {
@@ -31,6 +37,7 @@ public class AutofillPopupBridge implements AutofillPopupDelegate{
Activity activity = windowAndroid.getActivity().get();
if (activity == null) {
mAutofillPopup = null;
+ mContext = null;
// Clean up the native counterpart. This is posted to allow the native counterpart
// to fully finish the construction of this glue object before we attempt to delete it.
new Handler().post(new Runnable() {
@@ -41,6 +48,7 @@ public class AutofillPopupBridge implements AutofillPopupDelegate{
});
} else {
mAutofillPopup = new AutofillPopup(activity, containerViewDelegate, this);
+ mContext = activity;
}
}
@@ -61,12 +69,24 @@ public class AutofillPopupBridge implements AutofillPopupDelegate{
nativeSuggestionSelected(mNativeAutofillPopup, listIndex);
}
+ @Override
+ public void deleteSuggestion(int listIndex) {
+ nativeDeletionRequested(mNativeAutofillPopup, listIndex);
+ }
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ assert which == DialogInterface.BUTTON_POSITIVE;
+ nativeDeletionConfirmed(mNativeAutofillPopup);
+ }
+
/**
* Hides the Autofill Popup and removes its anchor from the ContainerView.
*/
@CalledByNative
private void dismiss() {
if (mAutofillPopup != null) mAutofillPopup.dismiss();
+ if (mDeletionDialog != null) mDeletionDialog.dismiss();
}
/**
@@ -90,6 +110,17 @@ public class AutofillPopupBridge implements AutofillPopupDelegate{
if (mAutofillPopup != null) mAutofillPopup.setAnchorRect(x, y, width, height);
}
+ @CalledByNative
+ private void confirmDeletion(String title, String body) {
+ mDeletionDialog = new AlertDialog.Builder(mContext, R.style.AlertDialogTheme)
+ .setTitle(title)
+ .setMessage(body)
+ .setNegativeButton(R.string.cancel, null)
+ .setPositiveButton(R.string.ok, this)
+ .create();
+ mDeletionDialog.show();
+ }
+
// Helper methods for AutofillSuggestion
@CalledByNative
@@ -104,15 +135,19 @@ public class AutofillPopupBridge implements AutofillPopupDelegate{
* @param sublabel Second line of the suggestion.
* @param iconId The resource ID for the icon associated with the suggestion, or 0 for no icon.
* @param suggestionId Identifier for the suggestion type.
+ * @param deletable Whether this item is deletable.
*/
@CalledByNative
private static void addToAutofillSuggestionArray(AutofillSuggestion[] array, int index,
- String label, String sublabel, int iconId, int suggestionId) {
+ String label, String sublabel, int iconId, int suggestionId, boolean deletable) {
int drawableId = iconId == 0 ? DropdownItem.NO_ICON : ResourceId.mapToDrawableId(iconId);
- array[index] = new AutofillSuggestion(label, sublabel, drawableId, suggestionId);
+ array[index] = new AutofillSuggestion(label, sublabel, drawableId, suggestionId, deletable);
}
- private native void nativePopupDismissed(long nativeAutofillPopupViewAndroid);
private native void nativeSuggestionSelected(long nativeAutofillPopupViewAndroid,
int listIndex);
+ private native void nativeDeletionRequested(long nativeAutofillPopupViewAndroid,
+ int listIndex);
+ private native void nativeDeletionConfirmed(long nativeAutofillPopupViewAndroid);
+ private native void nativePopupDismissed(long nativeAutofillPopupViewAndroid);
}

Powered by Google App Engine
This is Rietveld 408576698