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 #include "components/autofill/core/browser/autofill_profile.h" | 5 #include "components/autofill/core/browser/autofill_profile.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 #include "components/autofill/core/browser/autofill_type.h" | 29 #include "components/autofill/core/browser/autofill_type.h" |
| 30 #include "components/autofill/core/browser/contact_info.h" | 30 #include "components/autofill/core/browser/contact_info.h" |
| 31 #include "components/autofill/core/browser/phone_number.h" | 31 #include "components/autofill/core/browser/phone_number.h" |
| 32 #include "components/autofill/core/browser/phone_number_i18n.h" | 32 #include "components/autofill/core/browser/phone_number_i18n.h" |
| 33 #include "components/autofill/core/browser/state_names.h" | 33 #include "components/autofill/core/browser/state_names.h" |
| 34 #include "components/autofill/core/browser/validation.h" | 34 #include "components/autofill/core/browser/validation.h" |
| 35 #include "components/autofill/core/common/autofill_l10n_util.h" | 35 #include "components/autofill/core/common/autofill_l10n_util.h" |
| 36 #include "components/autofill/core/common/form_field_data.h" | 36 #include "components/autofill/core/common/form_field_data.h" |
| 37 #include "grit/components_strings.h" | 37 #include "grit/components_strings.h" |
| 38 #include "third_party/icu/source/common/unicode/uchar.h" | 38 #include "third_party/icu/source/common/unicode/uchar.h" |
| 39 #include "third_party/icu/source/common/unicode/utypes.h" | |
| 40 #include "third_party/icu/source/i18n/unicode/translit.h" | |
| 39 #include "third_party/libaddressinput/chromium/addressinput_util.h" | 41 #include "third_party/libaddressinput/chromium/addressinput_util.h" |
| 40 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h" | 42 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h" |
| 41 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fo rmatter.h" | 43 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fo rmatter.h" |
| 42 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_me tadata.h" | 44 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_me tadata.h" |
| 43 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
| 44 | 46 |
| 45 using base::ASCIIToUTF16; | 47 using base::ASCIIToUTF16; |
| 46 using base::UTF16ToUTF8; | 48 using base::UTF16ToUTF8; |
| 47 using i18n::addressinput::AddressData; | 49 using i18n::addressinput::AddressData; |
| 48 using i18n::addressinput::AddressField; | 50 using i18n::addressinput::AddressField; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 bool operator()(const base::string16& phone) { | 230 bool operator()(const base::string16& phone) { |
| 229 return i18n::PhoneNumbersMatch(phone, phone_, country_code_, app_locale_); | 231 return i18n::PhoneNumbersMatch(phone, phone_, country_code_, app_locale_); |
| 230 } | 232 } |
| 231 | 233 |
| 232 private: | 234 private: |
| 233 base::string16 phone_; | 235 base::string16 phone_; |
| 234 std::string country_code_; | 236 std::string country_code_; |
| 235 std::string app_locale_; | 237 std::string app_locale_; |
| 236 }; | 238 }; |
| 237 | 239 |
| 240 base::string16 NormalizeForComparison(const base::string16& text) { | |
| 241 using icu::UnicodeString; | |
| 242 using icu::Transliterator; | |
| 243 | |
| 244 // Remove diacritics and fold case. | |
|
Mathieu
2016/05/27 17:47:13
extra space before comment
Roger McFarlane (Chromium)
2016/05/27 20:20:42
Done.
| |
| 245 UErrorCode status = U_ZERO_ERROR; | |
| 246 std::unique_ptr<Transliterator> transliterator(Transliterator::createInstance( | |
| 247 "NFD; [:Nonspacing Mark:] Remove; Lower; NFC", UTRANS_FORWARD, status)); | |
|
Mathieu
2016/05/27 17:47:13
Can we put an explanation (or a link to the explan
Roger McFarlane (Chromium)
2016/05/27 20:20:43
Done.
| |
| 248 if (U_FAILURE(status)) { | |
| 249 // This should not happen. Log the error and fall back. | |
| 250 LOG(ERROR) << "normalization failed: " << u_errorName(status); | |
|
Mathieu
2016/05/27 17:47:13
Let's capitalize the comment and make it more expl
Roger McFarlane (Chromium)
2016/05/27 20:20:43
Done.
| |
| 251 return text; | |
| 252 } | |
| 253 | |
| 254 UnicodeString value = UnicodeString(text.data(), text.length()); | |
| 255 transliterator->transliterate(value); | |
|
Mathieu
2016/05/27 17:47:13
can we check "if (transliterator)" here? ICU has a
Roger McFarlane (Chromium)
2016/05/27 20:20:43
Done.
| |
| 256 | |
| 257 return base::string16(value.getBuffer(), value.length()); | |
| 258 } | |
| 259 | |
| 238 } // namespace | 260 } // namespace |
| 239 | 261 |
| 240 AutofillProfile::AutofillProfile(const std::string& guid, | 262 AutofillProfile::AutofillProfile(const std::string& guid, |
| 241 const std::string& origin) | 263 const std::string& origin) |
| 242 : AutofillDataModel(guid, origin), | 264 : AutofillDataModel(guid, origin), |
| 243 record_type_(LOCAL_PROFILE), | 265 record_type_(LOCAL_PROFILE), |
| 244 phone_number_(this) { | 266 phone_number_(this) { |
| 245 } | 267 } |
| 246 | 268 |
| 247 AutofillProfile::AutofillProfile(RecordType type, const std::string& server_id) | 269 AutofillProfile::AutofillProfile(RecordType type, const std::string& server_id) |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 822 case U_LINE_SEPARATOR: | 844 case U_LINE_SEPARATOR: |
| 823 case U_PARAGRAPH_SEPARATOR: | 845 case U_PARAGRAPH_SEPARATOR: |
| 824 // Convert sequences of spaces to single spaces. | 846 // Convert sequences of spaces to single spaces. |
| 825 if (!previous_was_whitespace) { | 847 if (!previous_was_whitespace) { |
| 826 ret.push_back(' '); | 848 ret.push_back(' '); |
| 827 previous_was_whitespace = true; | 849 previous_was_whitespace = true; |
| 828 } | 850 } |
| 829 break; | 851 break; |
| 830 | 852 |
| 831 case U_UPPERCASE_LETTER: | 853 case U_UPPERCASE_LETTER: |
| 832 case U_TITLECASE_LETTER: | 854 case U_TITLECASE_LETTER: |
|
Mathieu
2016/05/27 17:47:13
Will this now be done by the normalizer?
Roger McFarlane (Chromium)
2016/05/27 20:20:42
Yes! Done.
| |
| 833 previous_was_whitespace = false; | 855 previous_was_whitespace = false; |
| 834 base::WriteUnicodeCharacter(u_tolower(iter.get()), &ret); | 856 base::WriteUnicodeCharacter(u_tolower(iter.get()), &ret); |
| 835 break; | 857 break; |
| 836 | 858 |
| 837 default: | 859 default: |
| 838 previous_was_whitespace = false; | 860 previous_was_whitespace = false; |
| 839 base::WriteUnicodeCharacter(iter.get(), &ret); | 861 base::WriteUnicodeCharacter(iter.get(), &ret); |
| 840 break; | 862 break; |
| 841 } | 863 } |
| 842 iter.Advance(); | 864 iter.Advance(); |
| 843 } | 865 } |
| 844 | 866 |
| 845 // Trim off trailing whitespace if we left one. | 867 // Trim off trailing whitespace if we left one. |
| 846 if (previous_was_whitespace) | 868 if (previous_was_whitespace) |
| 847 ret.resize(ret.size() - 1); | 869 ret.resize(ret.size() - 1); |
| 848 | 870 |
| 849 return ret; | 871 return NormalizeForComparison(ret); |
| 850 } | 872 } |
| 851 | 873 |
| 852 // static | 874 // static |
| 853 bool AutofillProfile::AreProfileStringsSimilar(const base::string16& a, | 875 bool AutofillProfile::AreProfileStringsSimilar(const base::string16& a, |
| 854 const base::string16& b) { | 876 const base::string16& b) { |
| 855 return CanonicalizeProfileString(a) == CanonicalizeProfileString(b); | 877 return CanonicalizeProfileString(a) == CanonicalizeProfileString(b); |
| 856 } | 878 } |
| 857 | 879 |
| 858 void AutofillProfile::GetSupportedTypes( | 880 void AutofillProfile::GetSupportedTypes( |
| 859 ServerFieldTypeSet* supported_types) const { | 881 ServerFieldTypeSet* supported_types) const { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1084 << " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " " | 1106 << " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " " |
| 1085 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " " | 1107 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " " |
| 1086 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) << " " | 1108 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) << " " |
| 1087 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) << " " | 1109 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) << " " |
| 1088 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) << " " | 1110 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) << " " |
| 1089 << profile.language_code() << " " | 1111 << profile.language_code() << " " |
| 1090 << UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); | 1112 << UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); |
| 1091 } | 1113 } |
| 1092 | 1114 |
| 1093 } // namespace autofill | 1115 } // namespace autofill |
| OLD | NEW |