| Index: chrome/android/java/src/org/chromium/chrome/browser/autofill/CreditCardScanner.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/autofill/CreditCardScanner.java b/chrome/android/java/src/org/chromium/chrome/browser/autofill/CreditCardScanner.java
|
| index 847a0bc6271e743917196c6caebfb60fc5c9986e..ffcb98041808804edeac51d49e2a8736502c83b1 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/autofill/CreditCardScanner.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/CreditCardScanner.java
|
| @@ -6,8 +6,7 @@ package org.chromium.chrome.browser.autofill;
|
|
|
| import android.content.Context;
|
|
|
| -import org.chromium.base.annotations.CalledByNative;
|
| -import org.chromium.base.annotations.JNINamespace;
|
| +import org.chromium.base.annotations.SuppressFBWarnings;
|
| import org.chromium.ui.base.WindowAndroid;
|
|
|
| /**
|
| @@ -15,45 +14,59 @@ import org.chromium.ui.base.WindowAndroid;
|
| * cards. The default implementation cannot scan cards. An implementing subclass must provide a
|
| * factory that builds its instances.
|
| */
|
| -@JNINamespace("autofill")
|
| public class CreditCardScanner {
|
| /**
|
| * Can be used to build subclasses of the scanner without the user of the class knowing about
|
| * the subclass name.
|
| */
|
| - static Factory sFactory;
|
| + private static Factory sFactory;
|
|
|
| - /**
|
| - * Pointer to the native object that receives scanning callbacks.
|
| - */
|
| - protected long mNativeScanner;
|
| + /** The delegate to notify of scanning result. */
|
| + protected final Delegate mDelegate;
|
|
|
| - /**
|
| - * Application context.
|
| - */
|
| - protected Context mContext;
|
| + /** Application context. Used in subclass. */
|
| + @SuppressFBWarnings({"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"})
|
| + protected final Context mContext;
|
|
|
| - /**
|
| - * The window that's requesting a scan.
|
| - */
|
| - protected WindowAndroid mWindow;
|
| + /** The window that's requesting a scan. Used in subclass. */
|
| + @SuppressFBWarnings({"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"})
|
| + protected final WindowAndroid mWindow;
|
|
|
| - /**
|
| - * Builds instances of credit card scanners.
|
| - */
|
| + /** Builds instances of credit card scanners. */
|
| public interface Factory {
|
| /**
|
| * Builds an instance of credit card scanner.
|
| - * @param nativeScanner Pointer to the native object that receives scanning callbacks.
|
| - * @param context Application context.
|
| - * @param window The window that's requesting a scan.
|
| + *
|
| + * @param context Application context.
|
| + * @param window The window that's requesting a scan.
|
| + * @param delegate The delegate to notify of scanning result.
|
| * @return An object that can scan a credit card.
|
| */
|
| - CreditCardScanner create(long nativeScanner, Context context, WindowAndroid window);
|
| + CreditCardScanner create(Context context, WindowAndroid window, Delegate delegate);
|
| + }
|
| +
|
| + /** The delegate for credit card scanning. */
|
| + public interface Delegate {
|
| + /**
|
| + * Notifies the delegate that scanning was cancelled.
|
| + */
|
| + void onScanCancelled();
|
| +
|
| + /**
|
| + * Notifies the delegate that scanning was successful.
|
| + *
|
| + * @param cardHolderName The card holder name.
|
| + * @param cardNumber Credit card number.
|
| + * @param expirationMonth Expiration month in the range [1, 12].
|
| + * @param expirationYear Expiration year, e.g. 2000.
|
| + */
|
| + void onScanCompleted(
|
| + String cardHolderName, String cardNumber, int expirationMonth, int expirationYear);
|
| }
|
|
|
| /**
|
| * Sets the factory that can build instances of credit card scanners.
|
| + *
|
| * @param factory Can build instances of credit card scanners.
|
| */
|
| public static void setFactory(Factory factory) {
|
| @@ -61,62 +74,45 @@ public class CreditCardScanner {
|
| }
|
|
|
| /**
|
| - * Called by the native object to create an instance of a credit card scanner.
|
| - * @param nativeScanner Pointer to the native object that receives scanning callbacks.
|
| - * @param context Application context.
|
| - * @param window The window that's requesting a scan.
|
| + * Creates an instance of a credit card scanner.
|
| + *
|
| + * @param context Application context.
|
| + * @param window The window that's requesting a scan.
|
| + * @param delegate The delegate to notify of scanning result.
|
| * @return An object that can scan a credit card.
|
| */
|
| - @CalledByNative
|
| - private static CreditCardScanner create(long nativeScanner, Context context,
|
| - WindowAndroid window) {
|
| - return sFactory != null ? sFactory.create(nativeScanner, context, window)
|
| - : new CreditCardScanner(nativeScanner, context, window);
|
| + public static CreditCardScanner create(
|
| + Context context, WindowAndroid window, Delegate delegate) {
|
| + return sFactory != null ? sFactory.create(context, window, delegate)
|
| + : new CreditCardScanner(context, window, delegate);
|
| }
|
|
|
| /**
|
| * Constructor for the credit card scanner.
|
| - * @param nativeScanner Pointer to the native object that receives scanning callbacks.
|
| - * @param context Application context.
|
| - * @param window The window that's requesting a scan.
|
| + *
|
| + * @param context Application context.
|
| + * @param window The window that's requesting a scan.
|
| + * @param delegate The delegate to notify of scanning result.
|
| */
|
| - protected CreditCardScanner(long nativeScanner, Context context, WindowAndroid window) {
|
| - mNativeScanner = nativeScanner;
|
| + protected CreditCardScanner(Context context, WindowAndroid window, Delegate delegate) {
|
| mContext = context;
|
| mWindow = window;
|
| + mDelegate = delegate;
|
| }
|
|
|
| /**
|
| * Returns true if this instance has the ability to scan credit cards.
|
| + *
|
| * @return True if has ability to scan credit cards.
|
| */
|
| - @CalledByNative
|
| - protected boolean canScan() {
|
| + public boolean canScan() {
|
| return false;
|
| }
|
|
|
| /**
|
| - * Scans a credit card. Will invoke a native callback with the result.
|
| + * Scans a credit card. Will invoke a delegate callback with the result.
|
| */
|
| - @CalledByNative
|
| - protected void scan() {
|
| - nativeScanCancelled(mNativeScanner);
|
| + public void scan() {
|
| + mDelegate.onScanCancelled();
|
| }
|
| -
|
| - /**
|
| - * Notifies the native object that scanning was cancelled.
|
| - * @param nativeCreditCardScannerViewAndroid Pointer to the native object.
|
| - */
|
| - protected native void nativeScanCancelled(long nativeCreditCardScannerViewAndroid);
|
| -
|
| - /**
|
| - * Notifies the native object that scanning was successful.
|
| - * @param nativeCreditCardScannerViewAndroid Pointer to the native object.
|
| - * @param cardHolderName The card holder name.
|
| - * @param cardNumber Credit card number.
|
| - * @param expirationMonth Expiration month in the range [1, 12].
|
| - * @param expirationYear Expiration year, e.g. 2000.
|
| - */
|
| - protected native void nativeScanCompleted(long nativeCreditCardScannerViewAndroid,
|
| - String cardHolderName, String cardNumber, int expirationMonth, int expirationYear);
|
| }
|
|
|