Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogControllerAndroid.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogControllerAndroid.java b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogControllerAndroid.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dd900f0c6a5c8dc9eb3a83adb3fbb730d87cd4b1 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogControllerAndroid.java |
| @@ -0,0 +1,189 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.autofill; |
| + |
| +import org.chromium.base.CalledByNative; |
| +import org.chromium.base.JNINamespace; |
| +import org.chromium.ui.WindowAndroid; |
| + |
| + |
|
Ted C
2013/08/10 01:33:35
i'd drop one of these blank lines
aruslan
2013/08/10 03:00:08
Done.
|
| +/** |
| + * Java-side AutofillDialog and AutofillDialogFactory interfaces, and |
| + * JNI glue for C++ AutofillDialogControllerAndroid. |
| + */ |
| +@JNINamespace("autofill") |
| +public class AutofillDialogControllerAndroid { |
| + private static final String TAG = "AutofillDialogControllerAndroid"; |
|
Ted C
2013/08/10 01:33:35
not used
aruslan
2013/08/10 03:00:08
Done.
|
| + private static AutofillDialogFactory mDialogFactory; |
| + |
| + private int mNativeDelegate; // could be 0 after onDestroy(). |
| + private AutofillDialog mDialog; |
| + |
| + /** |
| + * An interface to the two possible continuations for the dialog. |
| + * The dialog is expected to be dismissed when either of the calls is made. |
| + */ |
| + public interface AutofillDialogDelegate { |
| + /** |
| + * Cancels the requestAutocomplete. |
| + */ |
| + void dialogCancel(); |
| + |
| + /** |
| + * Submits the data to the web-page and persists the last account/card/address choices. |
| + * @param fullWallet Resulting billing/shipping information obtained from the user |
| + * @param lastUsedChoiceIsAutofill Whether the last selected data source is Autofill |
| + * @param lastUsedAccountName The last selected account name, or null |
| + * @param guidLastUsedBilling GUID of the last selected Autofill billing address, or null |
| + * @param guidLastUsedShipping GUID of the last selected Autofill shipping address, or null |
| + * @param guidLastUsedCard GUI of the last selected Autofill credit card, or null |
|
Ted C
2013/08/10 01:33:35
missing D at the end of GUI?
aruslan
2013/08/10 03:00:08
Done.
|
| + */ |
| + void dialogContinue( |
| + AutofillDialogResult.ResultWallet fullWallet, |
|
Ted C
2013/08/10 01:33:35
+4 indent
aruslan
2013/08/10 03:00:08
Done.
|
| + boolean lastUsedChoiceIsAutofill, String lastUsedAccountName, |
| + String guidLastUsedBilling, String guidLastUsedShipping, String guidLastUsedCard); |
| + } |
| + |
| + /** |
| + * An interface to the dialog. |
|
Ted C
2013/08/10 01:33:35
I would say something "Exposes the necessary funct
aruslan
2013/08/10 03:00:08
Done.
|
| + * Note that all information necessary to construct the dialog is passed to the factory. |
| + */ |
| + public interface AutofillDialog { |
| + /** |
| + * Notifies the dialog that the C++ side is gone. |
| + * The dialog needs to clear its reference to the no longer valid AutofillDialogDelegate. |
| + */ |
| + void onDestroy(); |
| + } |
| + |
| + /** |
| + * An interface to the factory that creates Autofill dialogs. |
| + */ |
| + public interface AutofillDialogFactory { |
| + /** |
| + * Creates the dialog. |
| + * Reasonable attempts should be made to respect "initial choices", |
| + * Initial choices don't have to be self-consistent or valid. |
| + * @param delegate Continuations for the dialog |
|
Ted C
2013/08/10 01:33:35
I would put a blank line above this to split it up
aruslan
2013/08/10 03:00:08
Done.
|
| + * @param windowAndroid Context in which the dialog should be shown |
| + * @param requestFullBillingAddress Whether the full billing address is required |
| + * @param requestShippingAddress Whether the shipping address is required |
| + * @param requestPhoneNumbers Whether the phone numbers are required in addresses |
| + * @param incognitoMode True if the dialog starts from the incognito tab |
|
Ted C
2013/08/10 01:33:35
started from an
aruslan
2013/08/10 03:00:08
Done.
|
| + * @param initialChoiceIsAutofill Whether the selected data source should be Autofill |
| + * @param initialAccountName Account to be selected, or null |
| + * @param initialBillingGuid GUID of the initial billing address selection in Autofill |
| + * @param initialShippingGuid GUID of the initial shipping address selection in Autofill |
| + * @param initialCardGuid GUID of the initial credit card selection in Autofill |
| + * @param merchantDomain Scheme+origin for the originating web page, or null |
| + * @return The Autofill dialog that would later call into the delegate, or null |
| + */ |
| + AutofillDialog createDialog( |
| + final AutofillDialogDelegate delegate, |
|
Ted C
2013/08/10 01:33:35
+4 indent
aruslan
2013/08/10 03:00:08
Done.
|
| + final WindowAndroid windowAndroid, |
| + final boolean requestFullBillingAddress, final boolean requestShippingAddress, |
| + final boolean requestPhoneNumbers, |
| + final boolean incognitoMode, |
| + final boolean initialChoiceIsAutofill, final String initialAccountName, |
| + final String initialBillingGuid, final String initialShippingGuid, |
| + final String initialCardGuid, |
| + final String merchantDomain); |
| + } |
| + |
| + /** |
| + * Sets the factory to be used. |
| + * @param factory An instance of the AutofillDialogFactory that will handle requests. |
| + */ |
| + public static void setDialogFactory(AutofillDialogFactory factory) { |
| + mDialogFactory = factory; |
| + } |
| + |
| + private AutofillDialogControllerAndroid( |
| + final int nativeAutofillDialogControllerAndroid, |
| + final WindowAndroid windowAndroid, |
| + final boolean requestFullBillingAddress, final boolean requestShippingAddress, |
| + final boolean requestPhoneNumbers, |
| + final boolean incognitoMode, |
| + final boolean initialChoiceIsAutofill, final String initialWalletAccountName, |
| + final String initialBillingGuid, final String initialShippingGuid, |
| + final String initialCardGuid, |
| + final String merchantDomain) { |
| + mNativeDelegate = nativeAutofillDialogControllerAndroid; |
| + |
| + if (mDialogFactory == null) { |
| + nativeDialogCancel(mNativeDelegate); |
| + return; |
| + } |
| + |
| + mDialog = mDialogFactory.createDialog( |
| + new AutofillDialogDelegate() { |
|
Ted C
2013/08/10 01:33:35
extract this as a param for readability
aruslan
2013/08/10 03:00:08
Done.
|
| + @Override |
| + public void dialogCancel() { |
| + nativeDialogCancel(mNativeDelegate); |
| + } |
| + |
| + @Override |
| + public void dialogContinue( |
| + AutofillDialogResult.ResultWallet fullWallet, |
| + boolean lastUsedChoiceIsAutofill, String lastUsedAccountName, |
| + String guidLastUsedBilling, String guidLastUsedShipping, |
| + String guidLastUsedCard) { |
| + nativeDialogContinue(mNativeDelegate, fullWallet, |
| + lastUsedChoiceIsAutofill, lastUsedAccountName, |
| + guidLastUsedBilling, guidLastUsedShipping, guidLastUsedCard); |
| + } |
| + }, |
| + windowAndroid, |
| + requestFullBillingAddress, requestShippingAddress, |
| + requestPhoneNumbers, |
| + incognitoMode, |
| + initialChoiceIsAutofill, initialWalletAccountName, |
| + initialBillingGuid, initialShippingGuid, initialCardGuid, |
| + merchantDomain); |
| + if (mDialog == null) { |
| + nativeDialogCancel(mNativeDelegate); |
| + return; |
| + } |
| + } |
| + |
| + @CalledByNative |
| + private static AutofillDialogControllerAndroid create( |
| + final int nativeAutofillDialogControllerAndroid, |
| + final WindowAndroid windowAndroid, |
| + final boolean requestFullBillingAddress, final boolean requestShippingAddress, |
| + final boolean requestPhoneNumbers, |
| + final boolean incognitoMode, |
| + final boolean initialChoiceIsAutofill, final String initialWalletAccountName, |
| + final String initialBillingGuid, final String initialShippingGuid, |
| + final String initialCreditCardGuid, |
| + final String merchantDomain) { |
| + return new AutofillDialogControllerAndroid( |
| + nativeAutofillDialogControllerAndroid, windowAndroid, |
| + requestFullBillingAddress, requestShippingAddress, requestPhoneNumbers, |
| + incognitoMode, |
| + initialChoiceIsAutofill, initialWalletAccountName, |
| + initialBillingGuid, initialShippingGuid, |
| + initialCreditCardGuid, |
| + merchantDomain); |
| + } |
| + |
| + @CalledByNative |
| + private void onDestroy() { |
| + if (mNativeDelegate == 0) return; |
| + |
| + if (mDialog != null) mDialog.onDestroy(); |
| + |
| + mDialog = null; |
| + mNativeDelegate = 0; |
| + } |
| + |
| + // Calls from Java to C++ AutofillDialogControllerAndroid: |
| + |
| + private native void nativeDialogCancel(int nativeAutofillDialogControllerAndroid); |
| + private native void nativeDialogContinue(int nativeAutofillDialogControllerAndroid, |
| + Object fullWallet, |
| + boolean lastUsedChoiceIsAutofill, String lastUsedAccountName, |
| + String guidLastUsedBilling, String guidLastUsedShipping, String guidLastUsedCard); |
| +} |