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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 personal_data_manager_->UpdateProfile(profile); | 361 personal_data_manager_->UpdateProfile(profile); |
362 } | 362 } |
363 | 363 |
364 return ConvertUTF8ToJavaString(env, profile.guid()); | 364 return ConvertUTF8ToJavaString(env, profile.guid()); |
365 } | 365 } |
366 | 366 |
367 ScopedJavaLocalRef<jobjectArray> | 367 ScopedJavaLocalRef<jobjectArray> |
368 PersonalDataManagerAndroid::GetProfileLabelsForSettings( | 368 PersonalDataManagerAndroid::GetProfileLabelsForSettings( |
369 JNIEnv* env, | 369 JNIEnv* env, |
370 const JavaParamRef<jobject>& unused_obj) { | 370 const JavaParamRef<jobject>& unused_obj) { |
371 return GetProfileLabels(env, false, personal_data_manager_->GetProfiles()); | 371 return GetProfileLabels(env, false, false, |
| 372 personal_data_manager_->GetProfiles()); |
372 } | 373 } |
373 | 374 |
374 ScopedJavaLocalRef<jobjectArray> | 375 ScopedJavaLocalRef<jobjectArray> |
375 PersonalDataManagerAndroid::GetProfileLabelsToSuggest( | 376 PersonalDataManagerAndroid::GetProfileLabelsToSuggest( |
376 JNIEnv* env, | 377 JNIEnv* env, |
377 const JavaParamRef<jobject>& unused_obj) { | 378 const JavaParamRef<jobject>& unused_obj, |
378 return GetProfileLabels(env, true, | 379 jboolean include_name) { |
| 380 return GetProfileLabels(env, true, include_name, |
379 personal_data_manager_->GetProfilesToSuggest()); | 381 personal_data_manager_->GetProfilesToSuggest()); |
380 } | 382 } |
381 | 383 |
382 base::android::ScopedJavaLocalRef<jstring> | 384 base::android::ScopedJavaLocalRef<jstring> |
383 PersonalDataManagerAndroid::GetAddressLabelForPaymentRequest( | 385 PersonalDataManagerAndroid::GetAddressLabelForPaymentRequest( |
384 JNIEnv* env, | 386 JNIEnv* env, |
385 const base::android::JavaParamRef<jobject>& unused_obj, | 387 const base::android::JavaParamRef<jobject>& unused_obj, |
386 const base::android::JavaParamRef<jobject>& jprofile) { | 388 const base::android::JavaParamRef<jobject>& jprofile) { |
387 std::vector<ServerFieldType> label_fields; | 389 std::vector<ServerFieldType> label_fields; |
388 label_fields.push_back(COMPANY_NAME); | 390 label_fields.push_back(COMPANY_NAME); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 std::vector<base::string16> guids; | 652 std::vector<base::string16> guids; |
651 for (CreditCard* credit_card : credit_cards) | 653 for (CreditCard* credit_card : credit_cards) |
652 guids.push_back(base::UTF8ToUTF16(credit_card->guid())); | 654 guids.push_back(base::UTF8ToUTF16(credit_card->guid())); |
653 | 655 |
654 return base::android::ToJavaArrayOfStrings(env, guids); | 656 return base::android::ToJavaArrayOfStrings(env, guids); |
655 } | 657 } |
656 | 658 |
657 ScopedJavaLocalRef<jobjectArray> PersonalDataManagerAndroid::GetProfileLabels( | 659 ScopedJavaLocalRef<jobjectArray> PersonalDataManagerAndroid::GetProfileLabels( |
658 JNIEnv* env, | 660 JNIEnv* env, |
659 bool address_only, | 661 bool address_only, |
| 662 bool include_name, |
660 std::vector<AutofillProfile*> profiles) { | 663 std::vector<AutofillProfile*> profiles) { |
661 std::unique_ptr<std::vector<ServerFieldType>> suggested_fields; | 664 std::unique_ptr<std::vector<ServerFieldType>> suggested_fields; |
662 size_t minimal_fields_shown = 2; | 665 size_t minimal_fields_shown = 2; |
663 if (address_only) { | 666 if (address_only) { |
664 suggested_fields.reset(new std::vector<ServerFieldType>); | 667 suggested_fields.reset(new std::vector<ServerFieldType>); |
| 668 if (include_name) |
| 669 suggested_fields->push_back(NAME_FULL); |
665 suggested_fields->push_back(COMPANY_NAME); | 670 suggested_fields->push_back(COMPANY_NAME); |
666 suggested_fields->push_back(ADDRESS_HOME_LINE1); | 671 suggested_fields->push_back(ADDRESS_HOME_LINE1); |
667 suggested_fields->push_back(ADDRESS_HOME_LINE2); | 672 suggested_fields->push_back(ADDRESS_HOME_LINE2); |
668 suggested_fields->push_back(ADDRESS_HOME_DEPENDENT_LOCALITY); | 673 suggested_fields->push_back(ADDRESS_HOME_DEPENDENT_LOCALITY); |
669 suggested_fields->push_back(ADDRESS_HOME_CITY); | 674 suggested_fields->push_back(ADDRESS_HOME_CITY); |
670 suggested_fields->push_back(ADDRESS_HOME_STATE); | 675 suggested_fields->push_back(ADDRESS_HOME_STATE); |
671 suggested_fields->push_back(ADDRESS_HOME_ZIP); | 676 suggested_fields->push_back(ADDRESS_HOME_ZIP); |
672 suggested_fields->push_back(ADDRESS_HOME_SORTING_CODE); | 677 suggested_fields->push_back(ADDRESS_HOME_SORTING_CODE); |
673 suggested_fields->push_back(ADDRESS_HOME_COUNTRY); | 678 suggested_fields->push_back(ADDRESS_HOME_COUNTRY); |
674 minimal_fields_shown = suggested_fields->size(); | 679 minimal_fields_shown = suggested_fields->size(); |
675 } | 680 } |
676 | 681 |
| 682 ServerFieldType excluded_field = include_name ? UNKNOWN_TYPE : NAME_FULL; |
| 683 |
677 std::vector<base::string16> labels; | 684 std::vector<base::string16> labels; |
678 AutofillProfile::CreateInferredLabels( | 685 AutofillProfile::CreateInferredLabels( |
679 profiles, suggested_fields.get(), NAME_FULL, minimal_fields_shown, | 686 profiles, suggested_fields.get(), excluded_field, minimal_fields_shown, |
680 g_browser_process->GetApplicationLocale(), &labels); | 687 g_browser_process->GetApplicationLocale(), &labels); |
681 | 688 |
682 return base::android::ToJavaArrayOfStrings(env, labels); | 689 return base::android::ToJavaArrayOfStrings(env, labels); |
683 } | 690 } |
684 | 691 |
685 // Returns whether the Autofill feature is enabled. | 692 // Returns whether the Autofill feature is enabled. |
686 static jboolean IsAutofillEnabled(JNIEnv* env, | 693 static jboolean IsAutofillEnabled(JNIEnv* env, |
687 const JavaParamRef<jclass>& clazz) { | 694 const JavaParamRef<jclass>& clazz) { |
688 return GetPrefs()->GetBoolean(autofill::prefs::kAutofillEnabled); | 695 return GetPrefs()->GetBoolean(autofill::prefs::kAutofillEnabled); |
689 } | 696 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 base::android::ConvertJavaStringToUTF16(env, jcountry_name))); | 733 base::android::ConvertJavaStringToUTF16(env, jcountry_name))); |
727 } | 734 } |
728 | 735 |
729 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 736 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
730 PersonalDataManagerAndroid* personal_data_manager_android = | 737 PersonalDataManagerAndroid* personal_data_manager_android = |
731 new PersonalDataManagerAndroid(env, obj); | 738 new PersonalDataManagerAndroid(env, obj); |
732 return reinterpret_cast<intptr_t>(personal_data_manager_android); | 739 return reinterpret_cast<intptr_t>(personal_data_manager_android); |
733 } | 740 } |
734 | 741 |
735 } // namespace autofill | 742 } // namespace autofill |
OLD | NEW |