| 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; |
| 11 import org.chromium.base.annotations.CalledByNative; | 11 import org.chromium.base.annotations.CalledByNative; |
| 12 import org.chromium.base.annotations.JNINamespace; | 12 import org.chromium.base.annotations.JNINamespace; |
| 13 import org.chromium.base.annotations.SuppressFBWarnings; |
| 13 import org.chromium.chrome.R; | 14 import org.chromium.chrome.R; |
| 14 import org.chromium.chrome.browser.ResourceId; | 15 import org.chromium.chrome.browser.ResourceId; |
| 15 import org.chromium.chrome.browser.preferences.autofill.AutofillAndPaymentsPrefe
rences; | 16 import org.chromium.chrome.browser.preferences.autofill.AutofillAndPaymentsPrefe
rences; |
| 16 import org.chromium.content_public.browser.WebContents; | 17 import org.chromium.content_public.browser.WebContents; |
| 17 | 18 |
| 18 import java.util.ArrayList; | 19 import java.util.ArrayList; |
| 19 import java.util.List; | 20 import java.util.List; |
| 20 import java.util.Locale; | 21 import java.util.Locale; |
| 22 import java.util.concurrent.TimeUnit; |
| 21 | 23 |
| 22 /** | 24 /** |
| 23 * Android wrapper of the PersonalDataManager which provides access from the Jav
a | 25 * Android wrapper of the PersonalDataManager which provides access from the Jav
a |
| 24 * layer. | 26 * layer. |
| 25 * | 27 * |
| 26 * Only usable from the UI thread as it's primary purpose is for supporting the
Android | 28 * Only usable from the UI thread as it's primary purpose is for supporting the
Android |
| 27 * preferences UI. | 29 * preferences UI. |
| 28 * | 30 * |
| 29 * See chrome/browser/autofill/personal_data_manager.h for more details. | 31 * See chrome/browser/autofill/personal_data_manager.h for more details. |
| 30 */ | 32 */ |
| (...skipping 24 matching lines...) Expand all Loading... |
| 55 void onFullCardDetails(CreditCard card, String cvc); | 57 void onFullCardDetails(CreditCard card, String cvc); |
| 56 | 58 |
| 57 /** | 59 /** |
| 58 * Called when user did not provide full card details. | 60 * Called when user did not provide full card details. |
| 59 */ | 61 */ |
| 60 @CalledByNative("FullCardRequestDelegate") | 62 @CalledByNative("FullCardRequestDelegate") |
| 61 void onFullCardError(); | 63 void onFullCardError(); |
| 62 } | 64 } |
| 63 | 65 |
| 64 /** | 66 /** |
| 67 * Callback for subKeys request. |
| 68 */ |
| 69 public interface GetSubKeysRequestDelegate { |
| 70 /** |
| 71 * Called when the sub-keys are received sucessfully. |
| 72 * Here the sub-keys are admin areas. |
| 73 * |
| 74 * @param subKeys The subKeys. |
| 75 */ |
| 76 @CalledByNative("GetSubKeysRequestDelegate") |
| 77 void onSubKeysReceived(String[] subKeys); |
| 78 } |
| 79 |
| 80 /** |
| 65 * Callback for normalized addresses. | 81 * Callback for normalized addresses. |
| 66 */ | 82 */ |
| 67 public interface NormalizedAddressRequestDelegate { | 83 public interface NormalizedAddressRequestDelegate { |
| 68 /** | 84 /** |
| 69 * Called when the address has been sucessfully normalized. | 85 * Called when the address has been sucessfully normalized. |
| 70 * | 86 * |
| 71 * @param profile The profile with the normalized address. | 87 * @param profile The profile with the normalized address. |
| 72 */ | 88 */ |
| 73 @CalledByNative("NormalizedAddressRequestDelegate") | 89 @CalledByNative("NormalizedAddressRequestDelegate") |
| 74 void onAddressNormalized(AutofillProfile profile); | 90 void onAddressNormalized(AutofillProfile profile); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 mIssuerIconDrawableId = id; | 521 mIssuerIconDrawableId = id; |
| 506 } | 522 } |
| 507 | 523 |
| 508 public void setBillingAddressId(String id) { | 524 public void setBillingAddressId(String id) { |
| 509 mBillingAddressId = id; | 525 mBillingAddressId = id; |
| 510 } | 526 } |
| 511 } | 527 } |
| 512 | 528 |
| 513 private static PersonalDataManager sManager; | 529 private static PersonalDataManager sManager; |
| 514 | 530 |
| 531 // Suppress FindBugs warning, since |sManager| is only used on the UI thread
. |
| 532 @SuppressFBWarnings("LI_LAZY_INIT_STATIC") |
| 515 public static PersonalDataManager getInstance() { | 533 public static PersonalDataManager getInstance() { |
| 516 ThreadUtils.assertOnUiThread(); | 534 ThreadUtils.assertOnUiThread(); |
| 517 if (sManager == null) { | 535 if (sManager == null) { |
| 518 sManager = new PersonalDataManager(); | 536 sManager = new PersonalDataManager(); |
| 519 } | 537 } |
| 520 return sManager; | 538 return sManager; |
| 521 } | 539 } |
| 522 | 540 |
| 523 private static int sNormalizationTimeoutSeconds = 5; | 541 private static int sNormalizationTimeoutSeconds = 5; |
| 524 | 542 |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 long getCurrentDateForTesting() { | 816 long getCurrentDateForTesting() { |
| 799 ThreadUtils.assertOnUiThread(); | 817 ThreadUtils.assertOnUiThread(); |
| 800 return nativeGetCurrentDateForTesting(mPersonalDataManagerAndroid); | 818 return nativeGetCurrentDateForTesting(mPersonalDataManagerAndroid); |
| 801 } | 819 } |
| 802 | 820 |
| 803 /** | 821 /** |
| 804 * Starts loading the address validation rules for the specified {@code regi
onCode}. | 822 * Starts loading the address validation rules for the specified {@code regi
onCode}. |
| 805 * | 823 * |
| 806 * @param regionCode The code of the region for which to load the rules. | 824 * @param regionCode The code of the region for which to load the rules. |
| 807 */ | 825 */ |
| 808 public void loadRulesForRegion(String regionCode) { | 826 public void loadRulesForAddressNormalization(String regionCode) { |
| 809 ThreadUtils.assertOnUiThread(); | 827 ThreadUtils.assertOnUiThread(); |
| 810 nativeLoadRulesForRegion(mPersonalDataManagerAndroid, regionCode); | 828 nativeLoadRulesForAddressNormalization(mPersonalDataManagerAndroid, regi
onCode); |
| 811 } | 829 } |
| 812 | 830 |
| 813 /** | 831 /** |
| 814 * Normalizes the address of the {@code profile} if the rules associated wit
h the | 832 * Starts loading the sub-key request rules for the specified {@code regionC
ode}. |
| 815 * {@code regionCode} are done loading. Otherwise sets up the callback to st
art normalizing the | 833 * |
| 816 * address when the rules are loaded. The normalized profile will be sent to
the | 834 * @param regionCode The code of the region for which to load the rules. |
| 817 * {@code delegate}. If the profile is not normalized in the specified | 835 */ |
| 836 public void loadRulesForSubKeys(String regionCode) { |
| 837 ThreadUtils.assertOnUiThread(); |
| 838 nativeLoadRulesForSubKeys(mPersonalDataManagerAndroid, regionCode); |
| 839 } |
| 840 |
| 841 /** |
| 842 * Starts loading the sub keys for the specified {@code regionCode}. |
| 843 * |
| 844 * @param regionCode The code of the region for which to load the sub keys. |
| 845 */ |
| 846 public void getRegionSubKeys(String regionCode, GetSubKeysRequestDelegate de
legate) { |
| 847 ThreadUtils.assertOnUiThread(); |
| 848 nativeStartRegionSubKeysRequest(mPersonalDataManagerAndroid, regionCode,
delegate); |
| 849 } |
| 850 |
| 851 /** Cancels the pending sub keys request. */ |
| 852 public void cancelPendingGetSubKeys() { |
| 853 ThreadUtils.assertOnUiThread(); |
| 854 nativeCancelPendingGetSubKeys(mPersonalDataManagerAndroid); |
| 855 } |
| 856 |
| 857 /** |
| 858 * Normalizes the address of the profile associated with the {@code guid} if
the rules |
| 859 * associated with the {@code regionCode} are done loading. Otherwise sets u
p the callback to |
| 860 * start normalizing the address when the rules are loaded. The normalized p
rofile will be sent |
| 861 * to the {@code delegate}. If the profile is not normalized in the specifie
d |
| 818 * {@code sNormalizationTimeoutSeconds}, the {@code delegate} will be notifi
ed. | 862 * {@code sNormalizationTimeoutSeconds}, the {@code delegate} will be notifi
ed. |
| 819 * | 863 * |
| 820 * @param profile The profile to normalize. | 864 * @param profile The profile to normalize. |
| 821 * @param regionCode The region code indicating which rules to use for norma
lization. | 865 * @param regionCode The region code indicating which rules to use for norma
lization. |
| 822 * @param delegate The object requesting the normalization. | 866 * @param delegate The object requesting the normalization. |
| 823 */ | 867 */ |
| 824 public void normalizeAddress( | 868 public void normalizeAddress( |
| 825 AutofillProfile profile, String regionCode, NormalizedAddressRequest
Delegate delegate) { | 869 AutofillProfile profile, String regionCode, NormalizedAddressRequest
Delegate delegate) { |
| 826 ThreadUtils.assertOnUiThread(); | 870 ThreadUtils.assertOnUiThread(); |
| 827 nativeStartAddressNormalization(mPersonalDataManagerAndroid, profile, re
gionCode, | 871 nativeStartAddressNormalization(mPersonalDataManagerAndroid, profile, re
gionCode, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 */ | 925 */ |
| 882 public static void setPaymentsIntegrationEnabled(boolean enable) { | 926 public static void setPaymentsIntegrationEnabled(boolean enable) { |
| 883 nativeSetPaymentsIntegrationEnabled(enable); | 927 nativeSetPaymentsIntegrationEnabled(enable); |
| 884 } | 928 } |
| 885 | 929 |
| 886 @VisibleForTesting | 930 @VisibleForTesting |
| 887 public static void setNormalizationTimeoutForTesting(int timeout) { | 931 public static void setNormalizationTimeoutForTesting(int timeout) { |
| 888 sNormalizationTimeoutSeconds = timeout; | 932 sNormalizationTimeoutSeconds = timeout; |
| 889 } | 933 } |
| 890 | 934 |
| 935 /** |
| 936 * @return The sub-key request timeout in milliseconds. |
| 937 */ |
| 938 public static long getRequestTimeoutMS() { |
| 939 return TimeUnit.SECONDS.toMillis(sNormalizationTimeoutSeconds); |
| 940 } |
| 941 |
| 891 private native long nativeInit(); | 942 private native long nativeInit(); |
| 892 private native boolean nativeIsDataLoaded(long nativePersonalDataManagerAndr
oid); | 943 private native boolean nativeIsDataLoaded(long nativePersonalDataManagerAndr
oid); |
| 893 private native String[] nativeGetProfileGUIDsForSettings(long nativePersonal
DataManagerAndroid); | 944 private native String[] nativeGetProfileGUIDsForSettings(long nativePersonal
DataManagerAndroid); |
| 894 private native String[] nativeGetProfileGUIDsToSuggest(long nativePersonalDa
taManagerAndroid); | 945 private native String[] nativeGetProfileGUIDsToSuggest(long nativePersonalDa
taManagerAndroid); |
| 895 private native String[] nativeGetProfileLabelsForSettings( | 946 private native String[] nativeGetProfileLabelsForSettings( |
| 896 long nativePersonalDataManagerAndroid); | 947 long nativePersonalDataManagerAndroid); |
| 897 private native String[] nativeGetProfileLabelsToSuggest(long nativePersonalD
ataManagerAndroid, | 948 private native String[] nativeGetProfileLabelsToSuggest(long nativePersonalD
ataManagerAndroid, |
| 898 boolean includeNameInLabel, boolean includeOrganizationInLabel, | 949 boolean includeNameInLabel, boolean includeOrganizationInLabel, |
| 899 boolean includeCountryInLabel); | 950 boolean includeCountryInLabel); |
| 900 private native AutofillProfile nativeGetProfileByGUID(long nativePersonalDat
aManagerAndroid, | 951 private native AutofillProfile nativeGetProfileByGUID(long nativePersonalDat
aManagerAndroid, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 long nativePersonalDataManagerAndroid, String guid, int count, long
date); | 991 long nativePersonalDataManagerAndroid, String guid, int count, long
date); |
| 941 private native int nativeGetCreditCardUseCountForTesting(long nativePersonal
DataManagerAndroid, | 992 private native int nativeGetCreditCardUseCountForTesting(long nativePersonal
DataManagerAndroid, |
| 942 String guid); | 993 String guid); |
| 943 private native long nativeGetCreditCardUseDateForTesting(long nativePersonal
DataManagerAndroid, | 994 private native long nativeGetCreditCardUseDateForTesting(long nativePersonal
DataManagerAndroid, |
| 944 String guid); | 995 String guid); |
| 945 private native long nativeGetCurrentDateForTesting(long nativePersonalDataMa
nagerAndroid); | 996 private native long nativeGetCurrentDateForTesting(long nativePersonalDataMa
nagerAndroid); |
| 946 private native void nativeClearUnmaskedCache( | 997 private native void nativeClearUnmaskedCache( |
| 947 long nativePersonalDataManagerAndroid, String guid); | 998 long nativePersonalDataManagerAndroid, String guid); |
| 948 private native void nativeGetFullCardForPaymentRequest(long nativePersonalDa
taManagerAndroid, | 999 private native void nativeGetFullCardForPaymentRequest(long nativePersonalDa
taManagerAndroid, |
| 949 WebContents webContents, CreditCard card, FullCardRequestDelegate de
legate); | 1000 WebContents webContents, CreditCard card, FullCardRequestDelegate de
legate); |
| 950 private native void nativeLoadRulesForRegion( | 1001 private native void nativeLoadRulesForAddressNormalization( |
| 1002 long nativePersonalDataManagerAndroid, String regionCode); |
| 1003 private native void nativeLoadRulesForSubKeys( |
| 951 long nativePersonalDataManagerAndroid, String regionCode); | 1004 long nativePersonalDataManagerAndroid, String regionCode); |
| 952 private native void nativeStartAddressNormalization(long nativePersonalDataM
anagerAndroid, | 1005 private native void nativeStartAddressNormalization(long nativePersonalDataM
anagerAndroid, |
| 953 AutofillProfile profile, String regionCode, int timeoutSeconds, | 1006 AutofillProfile profile, String regionCode, int timeoutSeconds, |
| 954 NormalizedAddressRequestDelegate delegate); | 1007 NormalizedAddressRequestDelegate delegate); |
| 1008 private native void nativeStartRegionSubKeysRequest(long nativePersonalDataM
anagerAndroid, |
| 1009 String regionCode, GetSubKeysRequestDelegate delegate); |
| 955 private static native boolean nativeHasProfiles(long nativePersonalDataManag
erAndroid); | 1010 private static native boolean nativeHasProfiles(long nativePersonalDataManag
erAndroid); |
| 956 private static native boolean nativeHasCreditCards(long nativePersonalDataMa
nagerAndroid); | 1011 private static native boolean nativeHasCreditCards(long nativePersonalDataMa
nagerAndroid); |
| 957 private static native boolean nativeIsAutofillEnabled(); | 1012 private static native boolean nativeIsAutofillEnabled(); |
| 958 private static native void nativeSetAutofillEnabled(boolean enable); | 1013 private static native void nativeSetAutofillEnabled(boolean enable); |
| 959 private static native boolean nativeIsAutofillManaged(); | 1014 private static native boolean nativeIsAutofillManaged(); |
| 960 private static native boolean nativeIsPaymentsIntegrationEnabled(); | 1015 private static native boolean nativeIsPaymentsIntegrationEnabled(); |
| 961 private static native void nativeSetPaymentsIntegrationEnabled(boolean enabl
e); | 1016 private static native void nativeSetPaymentsIntegrationEnabled(boolean enabl
e); |
| 962 private static native String nativeToCountryCode(String countryName); | 1017 private static native String nativeToCountryCode(String countryName); |
| 1018 private static native void nativeCancelPendingGetSubKeys(long nativePersonal
DataManagerAndroid); |
| 963 } | 1019 } |
| OLD | NEW |