Chromium Code Reviews| 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.chrome.R; | 13 import org.chromium.chrome.R; |
| 14 import org.chromium.chrome.browser.ResourceId; | 14 import org.chromium.chrome.browser.ResourceId; |
| 15 import org.chromium.chrome.browser.preferences.autofill.AutofillAndPaymentsPrefe rences; | 15 import org.chromium.chrome.browser.preferences.autofill.AutofillAndPaymentsPrefe rences; |
| 16 import org.chromium.content_public.browser.WebContents; | 16 import org.chromium.content_public.browser.WebContents; |
| 17 | 17 |
| 18 import java.util.ArrayList; | 18 import java.util.ArrayList; |
| 19 import java.util.List; | 19 import java.util.List; |
| 20 import java.util.Locale; | 20 import java.util.Locale; |
| 21 import java.util.concurrent.TimeUnit; | |
| 21 | 22 |
| 22 /** | 23 /** |
| 23 * Android wrapper of the PersonalDataManager which provides access from the Jav a | 24 * Android wrapper of the PersonalDataManager which provides access from the Jav a |
| 24 * layer. | 25 * layer. |
| 25 * | 26 * |
| 26 * Only usable from the UI thread as it's primary purpose is for supporting the Android | 27 * Only usable from the UI thread as it's primary purpose is for supporting the Android |
| 27 * preferences UI. | 28 * preferences UI. |
| 28 * | 29 * |
| 29 * See chrome/browser/autofill/personal_data_manager.h for more details. | 30 * See chrome/browser/autofill/personal_data_manager.h for more details. |
| 30 */ | 31 */ |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 55 void onFullCardDetails(CreditCard card, String cvc); | 56 void onFullCardDetails(CreditCard card, String cvc); |
| 56 | 57 |
| 57 /** | 58 /** |
| 58 * Called when user did not provide full card details. | 59 * Called when user did not provide full card details. |
| 59 */ | 60 */ |
| 60 @CalledByNative("FullCardRequestDelegate") | 61 @CalledByNative("FullCardRequestDelegate") |
| 61 void onFullCardError(); | 62 void onFullCardError(); |
| 62 } | 63 } |
| 63 | 64 |
| 64 /** | 65 /** |
| 66 * Callback for subKeys request. | |
| 67 */ | |
| 68 public interface GetSubKeysRequestDelegate { | |
| 69 /** | |
| 70 * Called when the sub-keys are received sucessfully. | |
| 71 * | |
| 72 * @param subKeys The subKeys. | |
| 73 */ | |
| 74 @CalledByNative("GetSubKeysRequestDelegate") | |
| 75 /** | |
| 76 * Callback of the sub-keys request that is called when the sub-keys are loaded. | |
| 77 * Here the sub-keys are admin areas (sub-keys of the region=country.) | |
| 78 */ | |
|
gone
2017/04/05 20:21:38
Double-javadocing doesn't work. Combine this comm
Parastoo
2017/04/05 20:44:32
Done.
| |
| 79 void onSubKeysReceived(String[] subKeys); | |
| 80 } | |
| 81 | |
| 82 /** | |
| 65 * Callback for normalized addresses. | 83 * Callback for normalized addresses. |
| 66 */ | 84 */ |
| 67 public interface NormalizedAddressRequestDelegate { | 85 public interface NormalizedAddressRequestDelegate { |
| 68 /** | 86 /** |
| 69 * Called when the address has been sucessfully normalized. | 87 * Called when the address has been sucessfully normalized. |
| 70 * | 88 * |
| 71 * @param profile The profile with the normalized address. | 89 * @param profile The profile with the normalized address. |
| 72 */ | 90 */ |
| 73 @CalledByNative("NormalizedAddressRequestDelegate") | 91 @CalledByNative("NormalizedAddressRequestDelegate") |
| 74 void onAddressNormalized(AutofillProfile profile); | 92 void onAddressNormalized(AutofillProfile profile); |
| (...skipping 723 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 public static long getRequestTimeoutMS() { | |
| 936 return TimeUnit.SECONDS.toMillis(sNormalizationTimeoutSeconds); | |
| 937 } | |
| 938 | |
| 891 private native long nativeInit(); | 939 private native long nativeInit(); |
| 892 private native boolean nativeIsDataLoaded(long nativePersonalDataManagerAndr oid); | 940 private native boolean nativeIsDataLoaded(long nativePersonalDataManagerAndr oid); |
| 893 private native String[] nativeGetProfileGUIDsForSettings(long nativePersonal DataManagerAndroid); | 941 private native String[] nativeGetProfileGUIDsForSettings(long nativePersonal DataManagerAndroid); |
| 894 private native String[] nativeGetProfileGUIDsToSuggest(long nativePersonalDa taManagerAndroid); | 942 private native String[] nativeGetProfileGUIDsToSuggest(long nativePersonalDa taManagerAndroid); |
| 895 private native String[] nativeGetProfileLabelsForSettings( | 943 private native String[] nativeGetProfileLabelsForSettings( |
| 896 long nativePersonalDataManagerAndroid); | 944 long nativePersonalDataManagerAndroid); |
| 897 private native String[] nativeGetProfileLabelsToSuggest(long nativePersonalD ataManagerAndroid, | 945 private native String[] nativeGetProfileLabelsToSuggest(long nativePersonalD ataManagerAndroid, |
| 898 boolean includeNameInLabel, boolean includeOrganizationInLabel, | 946 boolean includeNameInLabel, boolean includeOrganizationInLabel, |
| 899 boolean includeCountryInLabel); | 947 boolean includeCountryInLabel); |
| 900 private native AutofillProfile nativeGetProfileByGUID(long nativePersonalDat aManagerAndroid, | 948 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); | 988 long nativePersonalDataManagerAndroid, String guid, int count, long date); |
| 941 private native int nativeGetCreditCardUseCountForTesting(long nativePersonal DataManagerAndroid, | 989 private native int nativeGetCreditCardUseCountForTesting(long nativePersonal DataManagerAndroid, |
| 942 String guid); | 990 String guid); |
| 943 private native long nativeGetCreditCardUseDateForTesting(long nativePersonal DataManagerAndroid, | 991 private native long nativeGetCreditCardUseDateForTesting(long nativePersonal DataManagerAndroid, |
| 944 String guid); | 992 String guid); |
| 945 private native long nativeGetCurrentDateForTesting(long nativePersonalDataMa nagerAndroid); | 993 private native long nativeGetCurrentDateForTesting(long nativePersonalDataMa nagerAndroid); |
| 946 private native void nativeClearUnmaskedCache( | 994 private native void nativeClearUnmaskedCache( |
| 947 long nativePersonalDataManagerAndroid, String guid); | 995 long nativePersonalDataManagerAndroid, String guid); |
| 948 private native void nativeGetFullCardForPaymentRequest(long nativePersonalDa taManagerAndroid, | 996 private native void nativeGetFullCardForPaymentRequest(long nativePersonalDa taManagerAndroid, |
| 949 WebContents webContents, CreditCard card, FullCardRequestDelegate de legate); | 997 WebContents webContents, CreditCard card, FullCardRequestDelegate de legate); |
| 950 private native void nativeLoadRulesForRegion( | 998 private native void nativeLoadRulesForAddressNormalization( |
| 999 long nativePersonalDataManagerAndroid, String regionCode); | |
| 1000 private native void nativeLoadRulesForSubKeys( | |
| 951 long nativePersonalDataManagerAndroid, String regionCode); | 1001 long nativePersonalDataManagerAndroid, String regionCode); |
| 952 private native void nativeStartAddressNormalization(long nativePersonalDataM anagerAndroid, | 1002 private native void nativeStartAddressNormalization(long nativePersonalDataM anagerAndroid, |
| 953 AutofillProfile profile, String regionCode, int timeoutSeconds, | 1003 AutofillProfile profile, String regionCode, int timeoutSeconds, |
| 954 NormalizedAddressRequestDelegate delegate); | 1004 NormalizedAddressRequestDelegate delegate); |
| 1005 private native void nativeStartRegionSubKeysRequest(long nativePersonalDataM anagerAndroid, | |
| 1006 String regionCode, GetSubKeysRequestDelegate delegate); | |
| 955 private static native boolean nativeHasProfiles(long nativePersonalDataManag erAndroid); | 1007 private static native boolean nativeHasProfiles(long nativePersonalDataManag erAndroid); |
| 956 private static native boolean nativeHasCreditCards(long nativePersonalDataMa nagerAndroid); | 1008 private static native boolean nativeHasCreditCards(long nativePersonalDataMa nagerAndroid); |
| 957 private static native boolean nativeIsAutofillEnabled(); | 1009 private static native boolean nativeIsAutofillEnabled(); |
| 958 private static native void nativeSetAutofillEnabled(boolean enable); | 1010 private static native void nativeSetAutofillEnabled(boolean enable); |
| 959 private static native boolean nativeIsAutofillManaged(); | 1011 private static native boolean nativeIsAutofillManaged(); |
| 960 private static native boolean nativeIsPaymentsIntegrationEnabled(); | 1012 private static native boolean nativeIsPaymentsIntegrationEnabled(); |
| 961 private static native void nativeSetPaymentsIntegrationEnabled(boolean enabl e); | 1013 private static native void nativeSetPaymentsIntegrationEnabled(boolean enabl e); |
| 962 private static native String nativeToCountryCode(String countryName); | 1014 private static native String nativeToCountryCode(String countryName); |
| 1015 private static native void nativeCancelPendingGetSubKeys(long nativePersonal DataManagerAndroid); | |
| 963 } | 1016 } |
| OLD | NEW |