Chromium Code Reviews| 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..0be5cbc838aa9a6b70d2c080853757e7a259f764 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,12 @@ 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 = null; |
|
Ted C
2015/05/14 21:56:39
No need for = null; as it is the default
Evan Stade
2015/05/14 23:12:05
Done.
|
| + private final Context mContext; |
| public AutofillPopupBridge(long nativeAutofillPopupViewAndroid, WindowAndroid windowAndroid, |
| ViewAndroidDelegate containerViewDelegate) { |
| @@ -31,6 +38,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 +49,7 @@ public class AutofillPopupBridge implements AutofillPopupDelegate{ |
| }); |
| } else { |
| mAutofillPopup = new AutofillPopup(activity, containerViewDelegate, this); |
| + mContext = activity; |
| } |
| } |
| @@ -61,12 +70,25 @@ public class AutofillPopupBridge implements AutofillPopupDelegate{ |
| nativeSuggestionSelected(mNativeAutofillPopup, listIndex); |
| } |
| + @Override |
| + public void deleteSuggestion(int listIndex) { |
|
Ted C
2015/05/14 21:56:39
from my comment in the c++ side, I think it would
|
| + nativeDeleteSuggestion(mNativeAutofillPopup, listIndex); |
| + } |
| + |
| + @Override |
| + public void onClick(DialogInterface dialog, int which) { |
| + if (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 +112,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, this) |
|
Ted C
2015/05/14 21:56:39
do you know if the listener can be null in this ca
Evan Stade
2015/05/14 23:12:05
seems to work
|
| + .setPositiveButton(R.string.ok, this) |
| + .create(); |
| + mDeletionDialog.show(); |
| + } |
| + |
| // Helper methods for AutofillSuggestion |
| @CalledByNative |
| @@ -104,15 +137,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 nativeDeleteSuggestion(long nativeAutofillPopupViewAndroid, |
| + int listIndex); |
| + private native void nativeDeletionConfirmed(long nativeAutofillPopupViewAndroid); |
| + private native void nativePopupDismissed(long nativeAutofillPopupViewAndroid); |
| } |