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 "components/autofill/core/browser/personal_data_manager.h" | 5 #include "components/autofill/core/browser/personal_data_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <iterator> | 9 #include <iterator> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/i18n/case_conversion.h" |
12 #include "base/i18n/timezone.h" | 13 #include "base/i18n/timezone.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
16 #include "base/profiler/scoped_tracker.h" | 17 #include "base/profiler/scoped_tracker.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
20 #include "components/autofill/core/browser/address_i18n.h" | 21 #include "components/autofill/core/browser/address_i18n.h" |
21 #include "components/autofill/core/browser/autofill-inl.h" | 22 #include "components/autofill/core/browser/autofill-inl.h" |
(...skipping 766 matching lines...) Loading... |
788 | 789 |
789 std::vector<Suggestion> suggestions; | 790 std::vector<Suggestion> suggestions; |
790 // Match based on a prefix search. | 791 // Match based on a prefix search. |
791 std::vector<AutofillProfile*> matched_profiles; | 792 std::vector<AutofillProfile*> matched_profiles; |
792 for (AutofillProfile* profile : profiles) { | 793 for (AutofillProfile* profile : profiles) { |
793 base::string16 value = GetInfoInOneLine(profile, type, app_locale_); | 794 base::string16 value = GetInfoInOneLine(profile, type, app_locale_); |
794 if (value.empty()) | 795 if (value.empty()) |
795 continue; | 796 continue; |
796 base::string16 value_canon = | 797 base::string16 value_canon = |
797 AutofillProfile::CanonicalizeProfileString(value); | 798 AutofillProfile::CanonicalizeProfileString(value); |
798 if (base::StartsWith(value_canon, field_contents_canon, true)) { | 799 if (base::StartsWith(value_canon, field_contents_canon, |
| 800 base::CompareCase::SENSITIVE)) { |
799 // Prefix match, add suggestion. | 801 // Prefix match, add suggestion. |
800 matched_profiles.push_back(profile); | 802 matched_profiles.push_back(profile); |
801 suggestions.push_back(Suggestion(value)); | 803 suggestions.push_back(Suggestion(value)); |
802 suggestions.back().backend_id = profile->guid(); | 804 suggestions.back().backend_id = profile->guid(); |
803 } | 805 } |
804 } | 806 } |
805 | 807 |
806 // Don't show two suggestions if one is a subset of the other. | 808 // Don't show two suggestions if one is a subset of the other. |
807 std::vector<AutofillProfile*> unique_matched_profiles; | 809 std::vector<AutofillProfile*> unique_matched_profiles; |
808 std::vector<Suggestion> unique_suggestions; | 810 std::vector<Suggestion> unique_suggestions; |
(...skipping 38 matching lines...) Loading... |
847 return unique_suggestions; | 849 return unique_suggestions; |
848 } | 850 } |
849 | 851 |
850 std::vector<Suggestion> PersonalDataManager::GetCreditCardSuggestions( | 852 std::vector<Suggestion> PersonalDataManager::GetCreditCardSuggestions( |
851 const AutofillType& type, | 853 const AutofillType& type, |
852 const base::string16& field_contents) { | 854 const base::string16& field_contents) { |
853 if (IsInAutofillSuggestionsDisabledExperiment()) | 855 if (IsInAutofillSuggestionsDisabledExperiment()) |
854 return std::vector<Suggestion>(); | 856 return std::vector<Suggestion>(); |
855 | 857 |
856 std::list<const CreditCard*> cards_to_suggest; | 858 std::list<const CreditCard*> cards_to_suggest; |
| 859 base::string16 field_contents_lower = base::i18n::ToLower(field_contents); |
857 for (const CreditCard* credit_card : GetCreditCards()) { | 860 for (const CreditCard* credit_card : GetCreditCards()) { |
858 // The value of the stored data for this field type in the |credit_card|. | 861 // The value of the stored data for this field type in the |credit_card|. |
859 base::string16 creditcard_field_value = | 862 base::string16 creditcard_field_value = |
860 credit_card->GetInfo(type, app_locale_); | 863 credit_card->GetInfo(type, app_locale_); |
861 if (creditcard_field_value.empty()) | 864 if (creditcard_field_value.empty()) |
862 continue; | 865 continue; |
| 866 base::string16 creditcard_field_lower = |
| 867 base::i18n::ToLower(creditcard_field_value); |
863 | 868 |
864 // For card number fields, suggest the card if: | 869 // For card number fields, suggest the card if: |
865 // - the number matches any part of the card, or | 870 // - the number matches any part of the card, or |
866 // - it's a masked card and there are 6 or fewers typed so far. | 871 // - it's a masked card and there are 6 or fewers typed so far. |
867 // For other fields, require that the field contents match the beginning of | 872 // For other fields, require that the field contents match the beginning of |
868 // the stored data. | 873 // the stored data. |
869 if (type.GetStorableType() == CREDIT_CARD_NUMBER) { | 874 if (type.GetStorableType() == CREDIT_CARD_NUMBER) { |
870 if (creditcard_field_value.find(field_contents) == base::string16::npos && | 875 if (creditcard_field_lower.find(field_contents_lower) == |
| 876 base::string16::npos && |
871 (credit_card->record_type() != CreditCard::MASKED_SERVER_CARD || | 877 (credit_card->record_type() != CreditCard::MASKED_SERVER_CARD || |
872 field_contents.size() >= 6)) { | 878 field_contents.size() >= 6)) { |
873 continue; | 879 continue; |
874 } | 880 } |
875 } else if (!base::StartsWith(creditcard_field_value, field_contents, | 881 } else if (!base::StartsWith(creditcard_field_lower, field_contents_lower, |
876 false)) { | 882 base::CompareCase::SENSITIVE)) { |
877 continue; | 883 continue; |
878 } | 884 } |
879 | 885 |
880 cards_to_suggest.push_back(credit_card); | 886 cards_to_suggest.push_back(credit_card); |
881 } | 887 } |
882 | 888 |
883 // De-dupe card suggestions. Full server cards shadow local cards, and | 889 // De-dupe card suggestions. Full server cards shadow local cards, and |
884 // local cards shadow masked server cards. | 890 // local cards shadow masked server cards. |
885 for (auto outer_it = cards_to_suggest.begin(); | 891 for (auto outer_it = cards_to_suggest.begin(); |
886 outer_it != cards_to_suggest.end(); | 892 outer_it != cards_to_suggest.end(); |
(...skipping 446 matching lines...) Loading... |
1333 } | 1339 } |
1334 if (IsExperimentalWalletIntegrationEnabled() && | 1340 if (IsExperimentalWalletIntegrationEnabled() && |
1335 pref_service_->GetBoolean(prefs::kAutofillWalletImportEnabled)) { | 1341 pref_service_->GetBoolean(prefs::kAutofillWalletImportEnabled)) { |
1336 profiles_.insert( | 1342 profiles_.insert( |
1337 profiles_.end(), server_profiles_.begin(), server_profiles_.end()); | 1343 profiles_.end(), server_profiles_.begin(), server_profiles_.end()); |
1338 } | 1344 } |
1339 return profiles_; | 1345 return profiles_; |
1340 } | 1346 } |
1341 | 1347 |
1342 } // namespace autofill | 1348 } // namespace autofill |
OLD | NEW |