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 #include <algorithm> | 8 #include <algorithm> |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 } | 55 } |
56 | 56 |
57 PrefService* GetPrefs() { | 57 PrefService* GetPrefs() { |
58 return GetProfile()->GetPrefs(); | 58 return GetProfile()->GetPrefs(); |
59 } | 59 } |
60 | 60 |
61 ScopedJavaLocalRef<jobject> CreateJavaProfileFromNative( | 61 ScopedJavaLocalRef<jobject> CreateJavaProfileFromNative( |
62 JNIEnv* env, | 62 JNIEnv* env, |
63 const AutofillProfile& profile) { | 63 const AutofillProfile& profile) { |
64 return Java_AutofillProfile_create( | 64 return Java_AutofillProfile_create( |
65 env, ConvertUTF8ToJavaString(env, profile.guid()).obj(), | 65 env, ConvertUTF8ToJavaString(env, profile.guid()), |
66 ConvertUTF8ToJavaString(env, profile.origin()).obj(), | 66 ConvertUTF8ToJavaString(env, profile.origin()), |
67 profile.record_type() == AutofillProfile::LOCAL_PROFILE, | 67 profile.record_type() == AutofillProfile::LOCAL_PROFILE, |
68 ConvertUTF16ToJavaString(env, profile.GetInfo( | |
69 AutofillType(NAME_FULL), | |
70 g_browser_process->GetApplicationLocale())).obj(), | |
71 ConvertUTF16ToJavaString(env, profile.GetRawInfo(COMPANY_NAME)).obj(), | |
72 ConvertUTF16ToJavaString( | 68 ConvertUTF16ToJavaString( |
73 env, profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)).obj(), | 69 env, profile.GetInfo(AutofillType(NAME_FULL), |
| 70 g_browser_process->GetApplicationLocale())), |
| 71 ConvertUTF16ToJavaString(env, profile.GetRawInfo(COMPANY_NAME)), |
| 72 ConvertUTF16ToJavaString(env, |
| 73 profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)), |
| 74 ConvertUTF16ToJavaString(env, profile.GetRawInfo(ADDRESS_HOME_STATE)), |
| 75 ConvertUTF16ToJavaString(env, profile.GetRawInfo(ADDRESS_HOME_CITY)), |
74 ConvertUTF16ToJavaString( | 76 ConvertUTF16ToJavaString( |
75 env, profile.GetRawInfo(ADDRESS_HOME_STATE)).obj(), | 77 env, profile.GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY)), |
76 ConvertUTF16ToJavaString( | 78 ConvertUTF16ToJavaString(env, profile.GetRawInfo(ADDRESS_HOME_ZIP)), |
77 env, profile.GetRawInfo(ADDRESS_HOME_CITY)).obj(), | 79 ConvertUTF16ToJavaString(env, |
78 ConvertUTF16ToJavaString( | 80 profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)), |
79 env, profile.GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY)).obj(), | 81 ConvertUTF16ToJavaString(env, profile.GetRawInfo(ADDRESS_HOME_COUNTRY)), |
80 ConvertUTF16ToJavaString(env, profile.GetRawInfo(ADDRESS_HOME_ZIP)).obj(), | 82 ConvertUTF16ToJavaString(env, |
81 ConvertUTF16ToJavaString( | 83 profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)), |
82 env, profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)).obj(), | 84 ConvertUTF16ToJavaString(env, profile.GetRawInfo(EMAIL_ADDRESS)), |
83 ConvertUTF16ToJavaString( | 85 ConvertUTF8ToJavaString(env, profile.language_code())); |
84 env, profile.GetRawInfo(ADDRESS_HOME_COUNTRY)).obj(), | |
85 ConvertUTF16ToJavaString( | |
86 env, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)).obj(), | |
87 ConvertUTF16ToJavaString(env, profile.GetRawInfo(EMAIL_ADDRESS)).obj(), | |
88 ConvertUTF8ToJavaString(env, profile.language_code()).obj()); | |
89 } | 86 } |
90 | 87 |
91 void MaybeSetRawInfo(AutofillProfile* profile, | 88 void MaybeSetRawInfo(AutofillProfile* profile, |
92 autofill::ServerFieldType type, | 89 autofill::ServerFieldType type, |
93 const base::android::JavaRef<jstring>& jstr) { | 90 const base::android::JavaRef<jstring>& jstr) { |
94 if (!jstr.is_null()) | 91 if (!jstr.is_null()) |
95 profile->SetRawInfo(type, ConvertJavaStringToUTF16(jstr)); | 92 profile->SetRawInfo(type, ConvertJavaStringToUTF16(jstr)); |
96 } | 93 } |
97 | 94 |
98 void PopulateNativeProfileFromJava( | 95 void PopulateNativeProfileFromJava( |
99 const JavaParamRef<jobject>& jprofile, | 96 const JavaParamRef<jobject>& jprofile, |
100 JNIEnv* env, | 97 JNIEnv* env, |
101 AutofillProfile* profile) { | 98 AutofillProfile* profile) { |
102 profile->set_origin( | 99 profile->set_origin( |
103 ConvertJavaStringToUTF8( | 100 ConvertJavaStringToUTF8(Java_AutofillProfile_getOrigin(env, jprofile))); |
104 Java_AutofillProfile_getOrigin(env, jprofile.obj()))); | 101 profile->SetInfo( |
105 profile->SetInfo(AutofillType(NAME_FULL), | 102 AutofillType(NAME_FULL), |
106 ConvertJavaStringToUTF16( | 103 ConvertJavaStringToUTF16(Java_AutofillProfile_getFullName(env, jprofile)), |
107 Java_AutofillProfile_getFullName(env, jprofile.obj())), | 104 g_browser_process->GetApplicationLocale()); |
108 g_browser_process->GetApplicationLocale()); | |
109 MaybeSetRawInfo(profile, autofill::COMPANY_NAME, | 105 MaybeSetRawInfo(profile, autofill::COMPANY_NAME, |
110 Java_AutofillProfile_getCompanyName(env, jprofile.obj())); | 106 Java_AutofillProfile_getCompanyName(env, jprofile)); |
111 MaybeSetRawInfo(profile, autofill::ADDRESS_HOME_STREET_ADDRESS, | 107 MaybeSetRawInfo(profile, autofill::ADDRESS_HOME_STREET_ADDRESS, |
112 Java_AutofillProfile_getStreetAddress(env, jprofile.obj())); | 108 Java_AutofillProfile_getStreetAddress(env, jprofile)); |
113 MaybeSetRawInfo(profile, autofill::ADDRESS_HOME_STATE, | 109 MaybeSetRawInfo(profile, autofill::ADDRESS_HOME_STATE, |
114 Java_AutofillProfile_getRegion(env, jprofile.obj())); | 110 Java_AutofillProfile_getRegion(env, jprofile)); |
115 MaybeSetRawInfo(profile, autofill::ADDRESS_HOME_CITY, | 111 MaybeSetRawInfo(profile, autofill::ADDRESS_HOME_CITY, |
116 Java_AutofillProfile_getLocality(env, jprofile.obj())); | 112 Java_AutofillProfile_getLocality(env, jprofile)); |
117 MaybeSetRawInfo( | 113 MaybeSetRawInfo(profile, autofill::ADDRESS_HOME_DEPENDENT_LOCALITY, |
118 profile, autofill::ADDRESS_HOME_DEPENDENT_LOCALITY, | 114 Java_AutofillProfile_getDependentLocality(env, jprofile)); |
119 Java_AutofillProfile_getDependentLocality(env, jprofile.obj())); | |
120 MaybeSetRawInfo(profile, autofill::ADDRESS_HOME_ZIP, | 115 MaybeSetRawInfo(profile, autofill::ADDRESS_HOME_ZIP, |
121 Java_AutofillProfile_getPostalCode(env, jprofile.obj())); | 116 Java_AutofillProfile_getPostalCode(env, jprofile)); |
122 MaybeSetRawInfo(profile, autofill::ADDRESS_HOME_SORTING_CODE, | 117 MaybeSetRawInfo(profile, autofill::ADDRESS_HOME_SORTING_CODE, |
123 Java_AutofillProfile_getSortingCode(env, jprofile.obj())); | 118 Java_AutofillProfile_getSortingCode(env, jprofile)); |
124 ScopedJavaLocalRef<jstring> country_code = | 119 ScopedJavaLocalRef<jstring> country_code = |
125 Java_AutofillProfile_getCountryCode(env, jprofile.obj()); | 120 Java_AutofillProfile_getCountryCode(env, jprofile); |
126 if (!country_code.is_null()) { | 121 if (!country_code.is_null()) { |
127 profile->SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), | 122 profile->SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), |
128 ConvertJavaStringToUTF16(country_code), | 123 ConvertJavaStringToUTF16(country_code), |
129 g_browser_process->GetApplicationLocale()); | 124 g_browser_process->GetApplicationLocale()); |
130 } | 125 } |
131 MaybeSetRawInfo(profile, autofill::PHONE_HOME_WHOLE_NUMBER, | 126 MaybeSetRawInfo(profile, autofill::PHONE_HOME_WHOLE_NUMBER, |
132 Java_AutofillProfile_getPhoneNumber(env, jprofile.obj())); | 127 Java_AutofillProfile_getPhoneNumber(env, jprofile)); |
133 MaybeSetRawInfo(profile, autofill::EMAIL_ADDRESS, | 128 MaybeSetRawInfo(profile, autofill::EMAIL_ADDRESS, |
134 Java_AutofillProfile_getEmailAddress(env, jprofile.obj())); | 129 Java_AutofillProfile_getEmailAddress(env, jprofile)); |
135 profile->set_language_code( | 130 profile->set_language_code(ConvertJavaStringToUTF8( |
136 ConvertJavaStringToUTF8( | 131 Java_AutofillProfile_getLanguageCode(env, jprofile))); |
137 Java_AutofillProfile_getLanguageCode(env, jprofile.obj()))); | |
138 } | 132 } |
139 | 133 |
140 // Mapping from Chrome card types to PaymentRequest basic card payment spec and | 134 // Mapping from Chrome card types to PaymentRequest basic card payment spec and |
141 // icons. Note that "generic" is not in the spec. | 135 // icons. Note that "generic" is not in the spec. |
142 // https://w3c.github.io/webpayments-methods-card/#method-id | 136 // https://w3c.github.io/webpayments-methods-card/#method-id |
143 const struct PaymentRequestData { | 137 const struct PaymentRequestData { |
144 const char* card_type; | 138 const char* card_type; |
145 const char* basic_card_payment_type; | 139 const char* basic_card_payment_type; |
146 const int icon_resource_id; | 140 const int icon_resource_id; |
147 } kPaymentRequestData[] { | 141 } kPaymentRequestData[] { |
(...skipping 18 matching lines...) Expand all Loading... |
166 } | 160 } |
167 return kPaymentRequestData[0]; | 161 return kPaymentRequestData[0]; |
168 } | 162 } |
169 | 163 |
170 ScopedJavaLocalRef<jobject> CreateJavaCreditCardFromNative( | 164 ScopedJavaLocalRef<jobject> CreateJavaCreditCardFromNative( |
171 JNIEnv* env, | 165 JNIEnv* env, |
172 const CreditCard& card) { | 166 const CreditCard& card) { |
173 const PaymentRequestData& payment_request_data = | 167 const PaymentRequestData& payment_request_data = |
174 GetPaymentRequestData(card.type()); | 168 GetPaymentRequestData(card.type()); |
175 return Java_CreditCard_create( | 169 return Java_CreditCard_create( |
176 env, ConvertUTF8ToJavaString(env, card.guid()).obj(), | 170 env, ConvertUTF8ToJavaString(env, card.guid()), |
177 ConvertUTF8ToJavaString(env, card.origin()).obj(), | 171 ConvertUTF8ToJavaString(env, card.origin()), |
178 card.record_type() == CreditCard::LOCAL_CARD, | 172 card.record_type() == CreditCard::LOCAL_CARD, |
179 card.record_type() == CreditCard::FULL_SERVER_CARD, | 173 card.record_type() == CreditCard::FULL_SERVER_CARD, |
180 ConvertUTF16ToJavaString(env, card.GetRawInfo(CREDIT_CARD_NAME_FULL)) | 174 ConvertUTF16ToJavaString(env, card.GetRawInfo(CREDIT_CARD_NAME_FULL)), |
181 .obj(), | 175 ConvertUTF16ToJavaString(env, card.GetRawInfo(CREDIT_CARD_NUMBER)), |
182 ConvertUTF16ToJavaString(env, card.GetRawInfo(CREDIT_CARD_NUMBER)).obj(), | 176 ConvertUTF16ToJavaString(env, card.TypeAndLastFourDigits()), |
183 ConvertUTF16ToJavaString(env, card.TypeAndLastFourDigits()).obj(), | 177 ConvertUTF16ToJavaString(env, card.GetRawInfo(CREDIT_CARD_EXP_MONTH)), |
184 ConvertUTF16ToJavaString(env, card.GetRawInfo(CREDIT_CARD_EXP_MONTH)) | |
185 .obj(), | |
186 ConvertUTF16ToJavaString(env, | 178 ConvertUTF16ToJavaString(env, |
187 card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)) | 179 card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)), |
188 .obj(), | 180 ConvertUTF8ToJavaString(env, |
189 ConvertUTF8ToJavaString(env, payment_request_data.basic_card_payment_type) | 181 payment_request_data.basic_card_payment_type), |
190 .obj(), | |
191 ResourceMapper::MapFromChromiumId(payment_request_data.icon_resource_id), | 182 ResourceMapper::MapFromChromiumId(payment_request_data.icon_resource_id), |
192 ConvertUTF8ToJavaString(env, card.billing_address_id()) .obj(), | 183 ConvertUTF8ToJavaString(env, card.billing_address_id()), |
193 ConvertUTF8ToJavaString(env, card.server_id()) .obj()); | 184 ConvertUTF8ToJavaString(env, card.server_id())); |
194 } | 185 } |
195 | 186 |
196 const char* GetCardTypeForBasicCardPaymentType( | 187 const char* GetCardTypeForBasicCardPaymentType( |
197 const std::string& basic_card_payment_type) { | 188 const std::string& basic_card_payment_type) { |
198 for (size_t i = 0; i < arraysize(kPaymentRequestData); ++i) { | 189 for (size_t i = 0; i < arraysize(kPaymentRequestData); ++i) { |
199 if (basic_card_payment_type == | 190 if (basic_card_payment_type == |
200 kPaymentRequestData[i].basic_card_payment_type) | 191 kPaymentRequestData[i].basic_card_payment_type) |
201 return kPaymentRequestData[i].card_type; | 192 return kPaymentRequestData[i].card_type; |
202 } | 193 } |
203 return kPaymentRequestData[0].card_type; | 194 return kPaymentRequestData[0].card_type; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 } | 278 } |
288 | 279 |
289 private: | 280 private: |
290 virtual ~FullCardRequester() {} | 281 virtual ~FullCardRequester() {} |
291 | 282 |
292 // payments::FullCardRequest::Delegate: | 283 // payments::FullCardRequest::Delegate: |
293 void OnFullCardDetails(const CreditCard& card, | 284 void OnFullCardDetails(const CreditCard& card, |
294 const base::string16& cvc) override { | 285 const base::string16& cvc) override { |
295 JNIEnv* env = base::android::AttachCurrentThread(); | 286 JNIEnv* env = base::android::AttachCurrentThread(); |
296 Java_FullCardRequestDelegate_onFullCardDetails( | 287 Java_FullCardRequestDelegate_onFullCardDetails( |
297 env, jdelegate_.obj(), CreateJavaCreditCardFromNative(env, card).obj(), | 288 env, jdelegate_, CreateJavaCreditCardFromNative(env, card), |
298 base::android::ConvertUTF16ToJavaString(env, cvc).obj()); | 289 base::android::ConvertUTF16ToJavaString(env, cvc)); |
299 delete this; | 290 delete this; |
300 } | 291 } |
301 | 292 |
302 // payments::FullCardRequest::Delegate: | 293 // payments::FullCardRequest::Delegate: |
303 void OnFullCardError() override { | 294 void OnFullCardError() override { |
304 JNIEnv* env = base::android::AttachCurrentThread(); | 295 JNIEnv* env = base::android::AttachCurrentThread(); |
305 Java_FullCardRequestDelegate_onFullCardError(env, jdelegate_.obj()); | 296 Java_FullCardRequestDelegate_onFullCardError(env, jdelegate_); |
306 delete this; | 297 delete this; |
307 } | 298 } |
308 | 299 |
309 std::unique_ptr<CreditCard> card_; | 300 std::unique_ptr<CreditCard> card_; |
310 ScopedJavaGlobalRef<jobject> jdelegate_; | 301 ScopedJavaGlobalRef<jobject> jdelegate_; |
311 | 302 |
312 DISALLOW_COPY_AND_ASSIGN(FullCardRequester); | 303 DISALLOW_COPY_AND_ASSIGN(FullCardRequester); |
313 }; | 304 }; |
314 | 305 |
315 } // namespace | 306 } // namespace |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 // Self-deleting object. | 526 // Self-deleting object. |
536 (new FullCardRequester())->GetFullCard( | 527 (new FullCardRequester())->GetFullCard( |
537 env, jweb_contents, jdelegate, std::move(card)); | 528 env, jweb_contents, jdelegate, std::move(card)); |
538 } | 529 } |
539 | 530 |
540 void PersonalDataManagerAndroid::OnPersonalDataChanged() { | 531 void PersonalDataManagerAndroid::OnPersonalDataChanged() { |
541 JNIEnv* env = base::android::AttachCurrentThread(); | 532 JNIEnv* env = base::android::AttachCurrentThread(); |
542 if (weak_java_obj_.get(env).is_null()) | 533 if (weak_java_obj_.get(env).is_null()) |
543 return; | 534 return; |
544 | 535 |
545 Java_PersonalDataManager_personalDataChanged(env, | 536 Java_PersonalDataManager_personalDataChanged(env, weak_java_obj_.get(env)); |
546 weak_java_obj_.get(env).obj()); | |
547 } | 537 } |
548 | 538 |
549 // static | 539 // static |
550 bool PersonalDataManagerAndroid::Register(JNIEnv* env) { | 540 bool PersonalDataManagerAndroid::Register(JNIEnv* env) { |
551 return RegisterNativesImpl(env); | 541 return RegisterNativesImpl(env); |
552 } | 542 } |
553 | 543 |
554 void PersonalDataManagerAndroid::RecordAndLogProfileUse( | 544 void PersonalDataManagerAndroid::RecordAndLogProfileUse( |
555 JNIEnv* env, | 545 JNIEnv* env, |
556 const JavaParamRef<jobject>& unused_obj, | 546 const JavaParamRef<jobject>& unused_obj, |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 base::android::ConvertJavaStringToUTF16(env, jcountry_name))); | 726 base::android::ConvertJavaStringToUTF16(env, jcountry_name))); |
737 } | 727 } |
738 | 728 |
739 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 729 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
740 PersonalDataManagerAndroid* personal_data_manager_android = | 730 PersonalDataManagerAndroid* personal_data_manager_android = |
741 new PersonalDataManagerAndroid(env, obj); | 731 new PersonalDataManagerAndroid(env, obj); |
742 return reinterpret_cast<intptr_t>(personal_data_manager_android); | 732 return reinterpret_cast<intptr_t>(personal_data_manager_android); |
743 } | 733 } |
744 | 734 |
745 } // namespace autofill | 735 } // namespace autofill |
OLD | NEW |