| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser.autofill; | |
| 6 | |
| 7 import org.chromium.base.VisibleForTesting; | |
| 8 import org.chromium.base.annotations.CalledByNative; | |
| 9 import org.chromium.base.annotations.JNINamespace; | |
| 10 import org.chromium.ui.base.WindowAndroid; | |
| 11 | |
| 12 /** | |
| 13 * Java-side AutofillDialog and AutofillDialogFactory interfaces, and | |
| 14 * JNI glue for C++ AutofillDialogControllerAndroid. | |
| 15 */ | |
| 16 @JNINamespace("autofill") | |
| 17 public class AutofillDialogControllerAndroid { | |
| 18 private static AutofillDialogFactory sDialogFactory; | |
| 19 | |
| 20 private long mNativeDelegate; // could be 0 after onDestroy(). | |
| 21 private AutofillDialog mDialog; | |
| 22 | |
| 23 /** | |
| 24 * An interface to the two possible continuations for the dialog. | |
| 25 * The dialog is expected to be dismissed when either of the calls is made. | |
| 26 */ | |
| 27 public interface AutofillDialogDelegate { | |
| 28 /** | |
| 29 * Cancels the requestAutocomplete. | |
| 30 */ | |
| 31 @VisibleForTesting | |
| 32 void dialogCancel(); | |
| 33 | |
| 34 /** | |
| 35 * Submits the data to the web-page and persists the last account/card/a
ddress choices. | |
| 36 * @param fullWallet Resulting billing/shipping information obtained fro
m the user | |
| 37 * @param lastUsedChoiceIsAutofill Whether the last selected data source
is Autofill | |
| 38 * @param lastUsedAccountName The last selected account name, or null | |
| 39 * @param guidLastUsedBilling GUID of the last selected Autofill billing
address, or null | |
| 40 * @param guidLastUsedShipping GUID of the last selected Autofill shippi
ng address, or null | |
| 41 * @param guidLastUsedCard GUID of the last selected Autofill credit car
d, or null | |
| 42 */ | |
| 43 @VisibleForTesting | |
| 44 void dialogContinue( | |
| 45 AutofillDialogResult.ResultWallet fullWallet, | |
| 46 boolean lastUsedChoiceIsAutofill, String lastUsedAccountName, | |
| 47 String guidLastUsedBilling, String guidLastUsedShipping, String
guidLastUsedCard); | |
| 48 } | |
| 49 | |
| 50 /** | |
| 51 * An interface that exposes the necessary functionality for an Autofill dia
log. | |
| 52 * Note that all information necessary to construct the dialog is passed to
the factory. | |
| 53 */ | |
| 54 public interface AutofillDialog { | |
| 55 /** | |
| 56 * Notifies the dialog that the C++ side is gone. | |
| 57 * The dialog needs to clear its reference to the no longer valid Autofi
llDialogDelegate. | |
| 58 */ | |
| 59 void onDestroy(); | |
| 60 } | |
| 61 | |
| 62 /** | |
| 63 * An interface to the factory that creates Autofill dialogs. | |
| 64 */ | |
| 65 public interface AutofillDialogFactory { | |
| 66 /** | |
| 67 * Creates the dialog. | |
| 68 * Reasonable attempts should be made to respect "initial choices", | |
| 69 * Initial choices don't have to be self-consistent or valid. | |
| 70 * | |
| 71 * @param delegate Continuations for the dialog | |
| 72 * @param windowAndroid Context in which the dialog should be shown | |
| 73 * @param requestFullBillingAddress Whether the full billing address is
required | |
| 74 * @param requestShippingAddress Whether the shipping address is require
d | |
| 75 * @param requestPhoneNumbers Whether the phone numbers are required in
addresses | |
| 76 * @param incognitoMode True if the dialog started from an incognito tab | |
| 77 * @param initialChoiceIsAutofill Whether the selected data source shoul
d be Autofill | |
| 78 * @param initialAccountName Account to be selected, or null | |
| 79 * @param initialBillingGuid GUID of the initial billing address selecti
on in Autofill | |
| 80 * @param initialShippingGuid GUID of the initial shipping address selec
tion in Autofill | |
| 81 * @param initialCardGuid GUID of the initial credit card selection in A
utofill | |
| 82 * @param merchantDomain Scheme+origin for the originating web page, or
null | |
| 83 * @param shippingCountries A list of allowed shipping countries, or nul
l | |
| 84 * @param creditCardTypes A list of allowed credit card types (e.g. "VIS
A"), or null | |
| 85 * @return The Autofill dialog that would later call into the delegate,
or null | |
| 86 */ | |
| 87 AutofillDialog createDialog( | |
| 88 final AutofillDialogDelegate delegate, | |
| 89 final WindowAndroid windowAndroid, | |
| 90 final boolean requestFullBillingAddress, final boolean requestSh
ippingAddress, | |
| 91 final boolean requestPhoneNumbers, | |
| 92 final boolean incognitoMode, | |
| 93 final boolean initialChoiceIsAutofill, final String initialAccou
ntName, | |
| 94 final String initialBillingGuid, final String initialShippingGui
d, | |
| 95 final String initialCardGuid, | |
| 96 final String merchantDomain, | |
| 97 final String[] shippingCountries, | |
| 98 final String[] creditCardTypes); | |
| 99 } | |
| 100 | |
| 101 /** | |
| 102 * Sets the factory to be used. | |
| 103 * @param factory An instance of the AutofillDialogFactory that will handle
requests. | |
| 104 */ | |
| 105 @VisibleForTesting | |
| 106 public static void setDialogFactory(AutofillDialogFactory factory) { | |
| 107 sDialogFactory = factory; | |
| 108 } | |
| 109 | |
| 110 @VisibleForTesting | |
| 111 private AutofillDialogControllerAndroid( | |
| 112 final long nativeAutofillDialogControllerAndroid, | |
| 113 final WindowAndroid windowAndroid, | |
| 114 final boolean requestFullBillingAddress, final boolean requestShippi
ngAddress, | |
| 115 final boolean requestPhoneNumbers, | |
| 116 final boolean incognitoMode, | |
| 117 final boolean initialChoiceIsAutofill, final String initialWalletAcc
ountName, | |
| 118 final String initialBillingGuid, final String initialShippingGuid, | |
| 119 final String initialCardGuid, | |
| 120 final String merchantDomain, | |
| 121 final String[] shippingCountries, | |
| 122 final String[] creditCardTypes) { | |
| 123 mNativeDelegate = nativeAutofillDialogControllerAndroid; | |
| 124 | |
| 125 if (sDialogFactory == null) { | |
| 126 nativeDialogCancel(mNativeDelegate); | |
| 127 return; | |
| 128 } | |
| 129 | |
| 130 AutofillDialogDelegate delegate = new AutofillDialogDelegate() { | |
| 131 @Override | |
| 132 public void dialogCancel() { | |
| 133 nativeDialogCancel(mNativeDelegate); | |
| 134 } | |
| 135 | |
| 136 @Override | |
| 137 public void dialogContinue( | |
| 138 AutofillDialogResult.ResultWallet fullWallet, | |
| 139 boolean lastUsedChoiceIsAutofill, String lastUsedAccountName
, | |
| 140 String guidLastUsedBilling, String guidLastUsedShipping, | |
| 141 String guidLastUsedCard) { | |
| 142 nativeDialogContinue(mNativeDelegate, fullWallet, | |
| 143 lastUsedChoiceIsAutofill, lastUsedAccountName, | |
| 144 guidLastUsedBilling, guidLastUsedShipping, guidLastUsedC
ard); | |
| 145 } | |
| 146 }; | |
| 147 | |
| 148 mDialog = sDialogFactory.createDialog( | |
| 149 delegate, | |
| 150 windowAndroid, | |
| 151 requestFullBillingAddress, requestShippingAddress, | |
| 152 requestPhoneNumbers, | |
| 153 incognitoMode, | |
| 154 initialChoiceIsAutofill, initialWalletAccountName, | |
| 155 initialBillingGuid, initialShippingGuid, initialCardGuid, | |
| 156 merchantDomain, | |
| 157 shippingCountries, | |
| 158 creditCardTypes); | |
| 159 if (mDialog == null) { | |
| 160 nativeDialogCancel(mNativeDelegate); | |
| 161 return; | |
| 162 } | |
| 163 } | |
| 164 | |
| 165 @CalledByNative | |
| 166 private static AutofillDialogControllerAndroid create( | |
| 167 final long nativeAutofillDialogControllerAndroid, | |
| 168 final WindowAndroid windowAndroid, | |
| 169 final boolean requestFullBillingAddress, final boolean requestShippi
ngAddress, | |
| 170 final boolean requestPhoneNumbers, | |
| 171 final boolean incognitoMode, | |
| 172 final boolean initialChoiceIsAutofill, final String initialWalletAcc
ountName, | |
| 173 final String initialBillingGuid, final String initialShippingGuid, | |
| 174 final String initialCreditCardGuid, | |
| 175 final String merchantDomain, | |
| 176 final String[] shippingCountries, | |
| 177 final String[] creditCardTypes) { | |
| 178 return new AutofillDialogControllerAndroid( | |
| 179 nativeAutofillDialogControllerAndroid, windowAndroid, | |
| 180 requestFullBillingAddress, requestShippingAddress, requestPhoneN
umbers, | |
| 181 incognitoMode, | |
| 182 initialChoiceIsAutofill, initialWalletAccountName, | |
| 183 initialBillingGuid, initialShippingGuid, | |
| 184 initialCreditCardGuid, | |
| 185 merchantDomain, | |
| 186 shippingCountries, | |
| 187 creditCardTypes); | |
| 188 } | |
| 189 | |
| 190 @CalledByNative | |
| 191 private static boolean isDialogAllowed(boolean isInvokedFromTheSameOrigin) { | |
| 192 // TODO(aruslan): cross-origin invocations should be allowed with a | |
| 193 // warning messge. | |
| 194 return isInvokedFromTheSameOrigin; | |
| 195 } | |
| 196 | |
| 197 @CalledByNative | |
| 198 private void onDestroy() { | |
| 199 if (mNativeDelegate == 0) return; | |
| 200 | |
| 201 if (mDialog != null) mDialog.onDestroy(); | |
| 202 | |
| 203 mDialog = null; | |
| 204 mNativeDelegate = 0; | |
| 205 } | |
| 206 | |
| 207 // Calls from Java to C++ AutofillDialogControllerAndroid: | |
| 208 | |
| 209 private native void nativeDialogCancel(long nativeAutofillDialogControllerAn
droid); | |
| 210 private native void nativeDialogContinue(long nativeAutofillDialogController
Android, | |
| 211 Object fullWallet, | |
| 212 boolean lastUsedChoiceIsAutofill, String lastUsedAccountName, | |
| 213 String guidLastUsedBilling, String guidLastUsedShipping, String guid
LastUsedCard); | |
| 214 } | |
| OLD | NEW |