| 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 #include "chrome/browser/autofill/android/personal_data_manager_android.h" | 5 #include "chrome/browser/autofill/android/personal_data_manager_android.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/android/jni_array.h" | 9 #include "base/android/jni_array.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "components/autofill/core/browser/autofill_country.h" | 24 #include "components/autofill/core/browser/autofill_country.h" |
| 25 #include "components/autofill/core/browser/autofill_type.h" | 25 #include "components/autofill/core/browser/autofill_type.h" |
| 26 #include "components/autofill/core/browser/country_names.h" | 26 #include "components/autofill/core/browser/country_names.h" |
| 27 #include "components/autofill/core/browser/field_types.h" | 27 #include "components/autofill/core/browser/field_types.h" |
| 28 #include "components/autofill/core/browser/payments/full_card_request.h" | 28 #include "components/autofill/core/browser/payments/full_card_request.h" |
| 29 #include "components/autofill/core/browser/personal_data_manager.h" | 29 #include "components/autofill/core/browser/personal_data_manager.h" |
| 30 #include "components/autofill/core/common/autofill_pref_names.h" | 30 #include "components/autofill/core/common/autofill_pref_names.h" |
| 31 #include "components/autofill/core/common/autofill_switches.h" | 31 #include "components/autofill/core/common/autofill_switches.h" |
| 32 #include "components/prefs/pref_service.h" | 32 #include "components/prefs/pref_service.h" |
| 33 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 34 #include "grit/components_scaled_resources.h" |
| 34 #include "jni/PersonalDataManager_jni.h" | 35 #include "jni/PersonalDataManager_jni.h" |
| 35 | 36 |
| 36 using base::android::ConvertJavaStringToUTF8; | 37 using base::android::ConvertJavaStringToUTF8; |
| 37 using base::android::ConvertUTF16ToJavaString; | 38 using base::android::ConvertUTF16ToJavaString; |
| 38 using base::android::ConvertUTF8ToJavaString; | 39 using base::android::ConvertUTF8ToJavaString; |
| 39 using base::android::ScopedJavaGlobalRef; | 40 using base::android::ScopedJavaGlobalRef; |
| 40 using base::android::ScopedJavaLocalRef; | 41 using base::android::ScopedJavaLocalRef; |
| 41 | 42 |
| 42 namespace autofill { | 43 namespace autofill { |
| 43 namespace { | 44 namespace { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 123 } |
| 123 MaybeSetRawInfo(profile, autofill::PHONE_HOME_WHOLE_NUMBER, | 124 MaybeSetRawInfo(profile, autofill::PHONE_HOME_WHOLE_NUMBER, |
| 124 Java_AutofillProfile_getPhoneNumber(env, jprofile.obj())); | 125 Java_AutofillProfile_getPhoneNumber(env, jprofile.obj())); |
| 125 MaybeSetRawInfo(profile, autofill::EMAIL_ADDRESS, | 126 MaybeSetRawInfo(profile, autofill::EMAIL_ADDRESS, |
| 126 Java_AutofillProfile_getEmailAddress(env, jprofile.obj())); | 127 Java_AutofillProfile_getEmailAddress(env, jprofile.obj())); |
| 127 profile->set_language_code( | 128 profile->set_language_code( |
| 128 ConvertJavaStringToUTF8( | 129 ConvertJavaStringToUTF8( |
| 129 Java_AutofillProfile_getLanguageCode(env, jprofile.obj()))); | 130 Java_AutofillProfile_getLanguageCode(env, jprofile.obj()))); |
| 130 } | 131 } |
| 131 | 132 |
| 132 // Mapping from Chrome card types to basic card payment spec. | 133 // Mapping from Chrome card types to PaymentRequest basic card payment spec and |
| 134 // icons. Note that "generic" is not in the spec. |
| 133 // https://w3c.github.io/browser-payment-api/specs/basic-card-payment.html#metho
d-id | 135 // https://w3c.github.io/browser-payment-api/specs/basic-card-payment.html#metho
d-id |
| 134 // Note that "generic" is not in the spec. | 136 const struct PaymentRequestData { |
| 135 const struct { | |
| 136 const char* card_type; | 137 const char* card_type; |
| 137 const char* basic_card_payment_type; | 138 const char* basic_card_payment_type; |
| 138 } kBasicCardPaymentTypes[] { | 139 const int icon_resource_id; |
| 139 {"genericCC", "generic"}, | 140 } kPaymentRequestData[] { |
| 140 {"americanExpressCC", "amex"}, | 141 {"genericCC", "generic", IDR_AUTOFILL_PR_GENERIC}, |
| 141 {"dinersCC", "diners"}, | 142 {"americanExpressCC", "amex", IDR_AUTOFILL_PR_AMEX}, |
| 142 {"discoverCC", "discover"}, | 143 {"dinersCC", "diners", IDR_AUTOFILL_PR_GENERIC}, |
| 143 {"jcbCC", "jcb"}, | 144 {"discoverCC", "discover", IDR_AUTOFILL_PR_DISCOVER}, |
| 144 {"masterCardCC", "mastercard"}, | 145 {"jcbCC", "jcb", IDR_AUTOFILL_PR_GENERIC}, |
| 145 {"visaCC", "visa"} | 146 {"masterCardCC", "mastercard", IDR_AUTOFILL_PR_MASTERCARD}, |
| 147 {"visaCC", "visa", IDR_AUTOFILL_PR_VISA} |
| 146 }; | 148 }; |
| 147 | 149 |
| 148 // Returns the type of this card according to the basic card payment spec. Will | 150 // Converts the card type into PaymentRequest type according to the basic card |
| 149 // return "generic" for unrecognized card type. | 151 // payment spec and an icon. Will set the type and the icon to "generic" for |
| 150 const char* ConvertToBasicCardPaymentType(const std::string& type) { | 152 // unrecognized card type. |
| 151 for (size_t i = 0; i < arraysize(kBasicCardPaymentTypes); ++i) { | 153 const PaymentRequestData* GetPaymentRequestData(const std::string& type) { |
| 152 if (type == kBasicCardPaymentTypes[i].card_type) | 154 for (size_t i = 0; i < arraysize(kPaymentRequestData); ++i) { |
| 153 return kBasicCardPaymentTypes[i].basic_card_payment_type; | 155 if (type == kPaymentRequestData[i].card_type) |
| 156 return &kPaymentRequestData[i]; |
| 154 } | 157 } |
| 155 return kBasicCardPaymentTypes[0].basic_card_payment_type; | 158 return &kPaymentRequestData[0]; |
| 156 } | 159 } |
| 157 | 160 |
| 158 ScopedJavaLocalRef<jobject> CreateJavaCreditCardFromNative( | 161 ScopedJavaLocalRef<jobject> CreateJavaCreditCardFromNative( |
| 159 JNIEnv* env, | 162 JNIEnv* env, |
| 160 const CreditCard& card) { | 163 const CreditCard& card) { |
| 164 const PaymentRequestData* payment_request_data = |
| 165 GetPaymentRequestData(card.type()); |
| 161 return Java_CreditCard_create( | 166 return Java_CreditCard_create( |
| 162 env, ConvertUTF8ToJavaString(env, card.guid()).obj(), | 167 env, ConvertUTF8ToJavaString(env, card.guid()).obj(), |
| 163 ConvertUTF8ToJavaString(env, card.origin()).obj(), | 168 ConvertUTF8ToJavaString(env, card.origin()).obj(), |
| 164 card.record_type() == CreditCard::LOCAL_CARD, | 169 card.record_type() == CreditCard::LOCAL_CARD, |
| 165 card.record_type() == CreditCard::FULL_SERVER_CARD, | 170 card.record_type() == CreditCard::FULL_SERVER_CARD, |
| 166 ConvertUTF16ToJavaString(env, card.GetRawInfo(CREDIT_CARD_NAME_FULL)) | 171 ConvertUTF16ToJavaString(env, card.GetRawInfo(CREDIT_CARD_NAME_FULL)) |
| 167 .obj(), | 172 .obj(), |
| 168 ConvertUTF16ToJavaString(env, card.GetRawInfo(CREDIT_CARD_NUMBER)).obj(), | 173 ConvertUTF16ToJavaString(env, card.GetRawInfo(CREDIT_CARD_NUMBER)).obj(), |
| 169 ConvertUTF16ToJavaString(env, card.TypeAndLastFourDigits()).obj(), | 174 ConvertUTF16ToJavaString(env, card.TypeAndLastFourDigits()).obj(), |
| 170 ConvertUTF16ToJavaString(env, card.GetRawInfo(CREDIT_CARD_EXP_MONTH)) | 175 ConvertUTF16ToJavaString(env, card.GetRawInfo(CREDIT_CARD_EXP_MONTH)) |
| 171 .obj(), | 176 .obj(), |
| 172 ConvertUTF16ToJavaString(env, | 177 ConvertUTF16ToJavaString(env, |
| 173 card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)) | 178 card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)) |
| 174 .obj(), | 179 .obj(), |
| 175 ConvertUTF8ToJavaString(env, ConvertToBasicCardPaymentType(card.type())) | 180 ConvertUTF8ToJavaString(env, |
| 181 payment_request_data->basic_card_payment_type) |
| 176 .obj(), | 182 .obj(), |
| 177 ResourceMapper::MapFromChromiumId( | 183 ResourceMapper::MapFromChromiumId( |
| 178 CreditCard::IconResourceId(card.type()))); | 184 payment_request_data->icon_resource_id)); |
| 179 } | 185 } |
| 180 | 186 |
| 181 void PopulateNativeCreditCardFromJava( | 187 void PopulateNativeCreditCardFromJava( |
| 182 const jobject& jcard, | 188 const jobject& jcard, |
| 183 JNIEnv* env, | 189 JNIEnv* env, |
| 184 CreditCard* card) { | 190 CreditCard* card) { |
| 185 card->set_origin( | 191 card->set_origin( |
| 186 ConvertJavaStringToUTF8(Java_CreditCard_getOrigin(env, jcard))); | 192 ConvertJavaStringToUTF8(Java_CreditCard_getOrigin(env, jcard))); |
| 187 card->SetRawInfo( | 193 card->SetRawInfo( |
| 188 CREDIT_CARD_NAME_FULL, | 194 CREDIT_CARD_NAME_FULL, |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 base::android::ConvertJavaStringToUTF16(env, jcountry_name))); | 482 base::android::ConvertJavaStringToUTF16(env, jcountry_name))); |
| 477 } | 483 } |
| 478 | 484 |
| 479 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 485 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 480 PersonalDataManagerAndroid* personal_data_manager_android = | 486 PersonalDataManagerAndroid* personal_data_manager_android = |
| 481 new PersonalDataManagerAndroid(env, obj); | 487 new PersonalDataManagerAndroid(env, obj); |
| 482 return reinterpret_cast<intptr_t>(personal_data_manager_android); | 488 return reinterpret_cast<intptr_t>(personal_data_manager_android); |
| 483 } | 489 } |
| 484 | 490 |
| 485 } // namespace autofill | 491 } // namespace autofill |
| OLD | NEW |