OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.autofill; | 5 package org.chromium.chrome.browser.autofill; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 | 8 |
9 import org.chromium.base.ThreadUtils; | 9 import org.chromium.base.ThreadUtils; |
10 import org.chromium.base.VisibleForTesting; | 10 import org.chromium.base.VisibleForTesting; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 void onFullCardDetails(CreditCard card, String cvc); | 55 void onFullCardDetails(CreditCard card, String cvc); |
56 | 56 |
57 /** | 57 /** |
58 * Called when user did not provide full card details. | 58 * Called when user did not provide full card details. |
59 */ | 59 */ |
60 @CalledByNative("FullCardRequestDelegate") | 60 @CalledByNative("FullCardRequestDelegate") |
61 void onFullCardError(); | 61 void onFullCardError(); |
62 } | 62 } |
63 | 63 |
64 /** | 64 /** |
| 65 * Callback for normalized addresses. |
| 66 */ |
| 67 public interface NormalizedAddressRequestDelegate { |
| 68 /** |
| 69 * Called when the address has been sucessfully normalized. |
| 70 * |
| 71 * @param profile The profile with the normalized address. |
| 72 */ |
| 73 @CalledByNative("NormalizedAddressRequestDelegate") |
| 74 void onAddressNormalized(AutofillProfile profile); |
| 75 } |
| 76 |
| 77 /** |
65 * Autofill address information. | 78 * Autofill address information. |
66 */ | 79 */ |
67 public static class AutofillProfile { | 80 public static class AutofillProfile { |
68 private String mGUID; | 81 private String mGUID; |
69 private String mOrigin; | 82 private String mOrigin; |
70 private boolean mIsLocal; | 83 private boolean mIsLocal; |
71 private String mFullName; | 84 private String mFullName; |
72 private String mCompanyName; | 85 private String mCompanyName; |
73 private String mStreetAddress; | 86 private String mStreetAddress; |
74 private String mRegion; | 87 private String mRegion; |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 private static PersonalDataManager sManager; | 480 private static PersonalDataManager sManager; |
468 | 481 |
469 public static PersonalDataManager getInstance() { | 482 public static PersonalDataManager getInstance() { |
470 ThreadUtils.assertOnUiThread(); | 483 ThreadUtils.assertOnUiThread(); |
471 if (sManager == null) { | 484 if (sManager == null) { |
472 sManager = new PersonalDataManager(); | 485 sManager = new PersonalDataManager(); |
473 } | 486 } |
474 return sManager; | 487 return sManager; |
475 } | 488 } |
476 | 489 |
| 490 private static int sNormalizationTimeoutMs = 5000; |
| 491 |
477 private final long mPersonalDataManagerAndroid; | 492 private final long mPersonalDataManagerAndroid; |
478 private final List<PersonalDataManagerObserver> mDataObservers = | 493 private final List<PersonalDataManagerObserver> mDataObservers = |
479 new ArrayList<PersonalDataManagerObserver>(); | 494 new ArrayList<PersonalDataManagerObserver>(); |
480 | 495 |
481 private PersonalDataManager() { | 496 private PersonalDataManager() { |
482 // Note that this technically leaks the native object, however, Personal
DataManager | 497 // Note that this technically leaks the native object, however, Personal
DataManager |
483 // is a singleton that lives forever and there's no clean shutdown of Ch
rome on Android | 498 // is a singleton that lives forever and there's no clean shutdown of Ch
rome on Android |
484 mPersonalDataManagerAndroid = nativeInit(); | 499 mPersonalDataManagerAndroid = nativeInit(); |
485 } | 500 } |
486 | 501 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 return nativeGetCreditCardUseDateForTesting(mPersonalDataManagerAndroid,
guid); | 726 return nativeGetCreditCardUseDateForTesting(mPersonalDataManagerAndroid,
guid); |
712 } | 727 } |
713 | 728 |
714 @VisibleForTesting | 729 @VisibleForTesting |
715 long getCurrentDateForTesting() { | 730 long getCurrentDateForTesting() { |
716 ThreadUtils.assertOnUiThread(); | 731 ThreadUtils.assertOnUiThread(); |
717 return nativeGetCurrentDateForTesting(mPersonalDataManagerAndroid); | 732 return nativeGetCurrentDateForTesting(mPersonalDataManagerAndroid); |
718 } | 733 } |
719 | 734 |
720 /** | 735 /** |
| 736 * Starts loading the address validation rules for the specified {@code regi
onCode}. |
| 737 * |
| 738 * @param regionCode The code of the region for which to load the rules. |
| 739 */ |
| 740 public void loadRulesForRegion(String regionCode) { |
| 741 ThreadUtils.assertOnUiThread(); |
| 742 nativeLoadRulesForRegion(mPersonalDataManagerAndroid, regionCode); |
| 743 } |
| 744 |
| 745 /** |
| 746 * Normalizes the address of the profile associated with the {@code guid} if
the rules |
| 747 * associated with the {@code regionCode} are done loading. Otherwise sets u
p the callback to |
| 748 * start normalizing the address when the rules are loaded. The normalized p
rofile will be sent |
| 749 * to the {@code delegate}. |
| 750 * |
| 751 * @param guid The GUID of the profile to normalize. |
| 752 * @param regionCode The region code indicating which rules to use for norma
lization. |
| 753 * @param delegate The object requesting the normalization. |
| 754 * |
| 755 * @return Whether the normalization will happen asynchronously. |
| 756 */ |
| 757 public boolean normalizeAddress( |
| 758 String guid, String regionCode, NormalizedAddressRequestDelegate del
egate) { |
| 759 ThreadUtils.assertOnUiThread(); |
| 760 return nativeStartAddressNormalization( |
| 761 mPersonalDataManagerAndroid, guid, regionCode, delegate); |
| 762 } |
| 763 |
| 764 /** Cancels the pending address normalization. */ |
| 765 public void cancelPendingAddressNormalization() { |
| 766 ThreadUtils.assertOnUiThread(); |
| 767 nativeCancelPendingAddressNormalization(mPersonalDataManagerAndroid); |
| 768 } |
| 769 |
| 770 /** |
721 * @return Whether the Autofill feature is enabled. | 771 * @return Whether the Autofill feature is enabled. |
722 */ | 772 */ |
723 public static boolean isAutofillEnabled() { | 773 public static boolean isAutofillEnabled() { |
724 return nativeIsAutofillEnabled(); | 774 return nativeIsAutofillEnabled(); |
725 } | 775 } |
726 | 776 |
727 /** | 777 /** |
728 * Enables or disables the Autofill feature. | 778 * Enables or disables the Autofill feature. |
729 * @param enable True to disable Autofill, false otherwise. | 779 * @param enable True to disable Autofill, false otherwise. |
730 */ | 780 */ |
(...skipping 16 matching lines...) Expand all Loading... |
747 } | 797 } |
748 | 798 |
749 /** | 799 /** |
750 * Enables or disables the Payments integration. | 800 * Enables or disables the Payments integration. |
751 * @param enable True to enable Payments data import. | 801 * @param enable True to enable Payments data import. |
752 */ | 802 */ |
753 public static void setPaymentsIntegrationEnabled(boolean enable) { | 803 public static void setPaymentsIntegrationEnabled(boolean enable) { |
754 nativeSetPaymentsIntegrationEnabled(enable); | 804 nativeSetPaymentsIntegrationEnabled(enable); |
755 } | 805 } |
756 | 806 |
| 807 /** |
| 808 * @return The timeout value for normalization. |
| 809 */ |
| 810 public static int getNormalizationTimeoutMS() { |
| 811 return sNormalizationTimeoutMs; |
| 812 } |
| 813 |
| 814 @VisibleForTesting |
| 815 public static void setNormalizationTimeoutForTesting(int timeout) { |
| 816 sNormalizationTimeoutMs = timeout; |
| 817 } |
| 818 |
757 private native long nativeInit(); | 819 private native long nativeInit(); |
758 private native boolean nativeIsDataLoaded(long nativePersonalDataManagerAndr
oid); | 820 private native boolean nativeIsDataLoaded(long nativePersonalDataManagerAndr
oid); |
759 private native String[] nativeGetProfileGUIDsForSettings(long nativePersonal
DataManagerAndroid); | 821 private native String[] nativeGetProfileGUIDsForSettings(long nativePersonal
DataManagerAndroid); |
760 private native String[] nativeGetProfileGUIDsToSuggest(long nativePersonalDa
taManagerAndroid); | 822 private native String[] nativeGetProfileGUIDsToSuggest(long nativePersonalDa
taManagerAndroid); |
761 private native String[] nativeGetProfileLabelsForSettings( | 823 private native String[] nativeGetProfileLabelsForSettings( |
762 long nativePersonalDataManagerAndroid); | 824 long nativePersonalDataManagerAndroid); |
763 private native String[] nativeGetProfileLabelsToSuggest(long nativePersonalD
ataManagerAndroid, | 825 private native String[] nativeGetProfileLabelsToSuggest(long nativePersonalD
ataManagerAndroid, |
764 boolean includeName); | 826 boolean includeName); |
765 private native AutofillProfile nativeGetProfileByGUID(long nativePersonalDat
aManagerAndroid, | 827 private native AutofillProfile nativeGetProfileByGUID(long nativePersonalDat
aManagerAndroid, |
766 String guid); | 828 String guid); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 long nativePersonalDataManagerAndroid, String guid, int count, long
date); | 861 long nativePersonalDataManagerAndroid, String guid, int count, long
date); |
800 private native int nativeGetCreditCardUseCountForTesting(long nativePersonal
DataManagerAndroid, | 862 private native int nativeGetCreditCardUseCountForTesting(long nativePersonal
DataManagerAndroid, |
801 String guid); | 863 String guid); |
802 private native long nativeGetCreditCardUseDateForTesting(long nativePersonal
DataManagerAndroid, | 864 private native long nativeGetCreditCardUseDateForTesting(long nativePersonal
DataManagerAndroid, |
803 String guid); | 865 String guid); |
804 private native long nativeGetCurrentDateForTesting(long nativePersonalDataMa
nagerAndroid); | 866 private native long nativeGetCurrentDateForTesting(long nativePersonalDataMa
nagerAndroid); |
805 private native void nativeClearUnmaskedCache( | 867 private native void nativeClearUnmaskedCache( |
806 long nativePersonalDataManagerAndroid, String guid); | 868 long nativePersonalDataManagerAndroid, String guid); |
807 private native void nativeGetFullCardForPaymentRequest(long nativePersonalDa
taManagerAndroid, | 869 private native void nativeGetFullCardForPaymentRequest(long nativePersonalDa
taManagerAndroid, |
808 WebContents webContents, CreditCard card, FullCardRequestDelegate de
legate); | 870 WebContents webContents, CreditCard card, FullCardRequestDelegate de
legate); |
| 871 private native void nativeLoadRulesForRegion( |
| 872 long nativePersonalDataManagerAndroid, String regionCode); |
| 873 private native boolean nativeStartAddressNormalization(long nativePersonalDa
taManagerAndroid, |
| 874 String guid, String regionCode, NormalizedAddressRequestDelegate del
egate); |
| 875 private native void nativeCancelPendingAddressNormalization( |
| 876 long nativePersonalDataManagerAndroid); |
809 private static native boolean nativeIsAutofillEnabled(); | 877 private static native boolean nativeIsAutofillEnabled(); |
810 private static native void nativeSetAutofillEnabled(boolean enable); | 878 private static native void nativeSetAutofillEnabled(boolean enable); |
811 private static native boolean nativeIsAutofillManaged(); | 879 private static native boolean nativeIsAutofillManaged(); |
812 private static native boolean nativeIsPaymentsIntegrationEnabled(); | 880 private static native boolean nativeIsPaymentsIntegrationEnabled(); |
813 private static native void nativeSetPaymentsIntegrationEnabled(boolean enabl
e); | 881 private static native void nativeSetPaymentsIntegrationEnabled(boolean enabl
e); |
814 private static native String nativeToCountryCode(String countryName); | 882 private static native String nativeToCountryCode(String countryName); |
815 } | 883 } |
OLD | NEW |