| 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/i18n/timezone.h" | 11 #include "base/i18n/timezone.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "components/autofill/core/browser/address_i18n.h" |
| 18 #include "components/autofill/core/browser/autofill-inl.h" | 19 #include "components/autofill/core/browser/autofill-inl.h" |
| 19 #include "components/autofill/core/browser/autofill_country.h" | 20 #include "components/autofill/core/browser/autofill_country.h" |
| 20 #include "components/autofill/core/browser/autofill_field.h" | 21 #include "components/autofill/core/browser/autofill_field.h" |
| 21 #include "components/autofill/core/browser/form_structure.h" | 22 #include "components/autofill/core/browser/form_structure.h" |
| 22 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 23 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
| 23 #include "components/autofill/core/browser/phone_number.h" | 24 #include "components/autofill/core/browser/phone_number.h" |
| 24 #include "components/autofill/core/browser/phone_number_i18n.h" | 25 #include "components/autofill/core/browser/phone_number_i18n.h" |
| 25 #include "components/autofill/core/browser/validation.h" | 26 #include "components/autofill/core/browser/validation.h" |
| 26 #include "components/autofill/core/common/autofill_pref_names.h" | 27 #include "components/autofill/core/common/autofill_pref_names.h" |
| 28 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da
ta.h" |
| 27 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fo
rmatter.h" | 29 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fo
rmatter.h" |
| 28 | 30 |
| 29 namespace autofill { | 31 namespace autofill { |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 34 using ::i18n::addressinput::AddressField; |
| 35 using ::i18n::addressinput::GetStreetAddressLinesAsSingleLine; |
| 36 using ::i18n::addressinput::STREET_ADDRESS; |
| 37 |
| 32 const base::string16::value_type kCreditCardPrefix[] = {'*', 0}; | 38 const base::string16::value_type kCreditCardPrefix[] = {'*', 0}; |
| 33 | 39 |
| 34 template<typename T> | 40 template<typename T> |
| 35 class FormGroupMatchesByGUIDFunctor { | 41 class FormGroupMatchesByGUIDFunctor { |
| 36 public: | 42 public: |
| 37 explicit FormGroupMatchesByGUIDFunctor(const std::string& guid) | 43 explicit FormGroupMatchesByGUIDFunctor(const std::string& guid) |
| 38 : guid_(guid) { | 44 : guid_(guid) { |
| 39 } | 45 } |
| 40 | 46 |
| 41 bool operator()(const T& form_group) { | 47 bool operator()(const T& form_group) { |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 guid_pairs->clear(); | 564 guid_pairs->clear(); |
| 559 | 565 |
| 560 const std::vector<AutofillProfile*>& profiles = GetProfiles(true); | 566 const std::vector<AutofillProfile*>& profiles = GetProfiles(true); |
| 561 std::vector<AutofillProfile*> matched_profiles; | 567 std::vector<AutofillProfile*> matched_profiles; |
| 562 for (std::vector<AutofillProfile*>::const_iterator iter = profiles.begin(); | 568 for (std::vector<AutofillProfile*>::const_iterator iter = profiles.begin(); |
| 563 iter != profiles.end(); ++iter) { | 569 iter != profiles.end(); ++iter) { |
| 564 AutofillProfile* profile = *iter; | 570 AutofillProfile* profile = *iter; |
| 565 | 571 |
| 566 // The value of the stored data for this field type in the |profile|. | 572 // The value of the stored data for this field type in the |profile|. |
| 567 std::vector<base::string16> multi_values; | 573 std::vector<base::string16> multi_values; |
| 568 profile->GetMultiInfo(type, app_locale_, &multi_values); | 574 AddressField address_field; |
| 575 if (i18n::FieldForType(type.GetStorableType(), &address_field) && |
| 576 address_field == STREET_ADDRESS) { |
| 577 std::string street_address_line; |
| 578 GetStreetAddressLinesAsSingleLine( |
| 579 *i18n::CreateAddressDataFromAutofillProfile(*profile, app_locale_), |
| 580 &street_address_line); |
| 581 multi_values.push_back(base::UTF8ToUTF16(street_address_line)); |
| 582 } else { |
| 583 profile->GetMultiInfo(type, app_locale_, &multi_values); |
| 584 } |
| 569 | 585 |
| 570 // Names need to be in vertically compact form - i.e. a single line. Join | |
| 571 // multi-line addresses into a single line, using a separator. | |
| 572 // The separator is locale-specific. | |
| 573 base::string16 compact_separator = | |
| 574 base::UTF8ToUTF16(::i18n::addressinput::GetLineSeparatorForLanguage( | |
| 575 profile->language_code())); | |
| 576 for (size_t i = 0; i < multi_values.size(); ++i) { | 586 for (size_t i = 0; i < multi_values.size(); ++i) { |
| 577 // Create vertically compact form. | 587 // Newlines can be found only in a street address, which was collapsed |
| 578 base::ReplaceChars(multi_values[i], | 588 // into a single line above. |
| 579 base::ASCIIToUTF16("\n"), | 589 DCHECK(multi_values[i].find('\n') == std::string::npos); |
| 580 compact_separator, | 590 |
| 581 &multi_values[i]); | |
| 582 if (!field_is_autofilled) { | 591 if (!field_is_autofilled) { |
| 583 // Suggest data that starts with what the user has typed. | 592 // Suggest data that starts with what the user has typed. |
| 584 if (!multi_values[i].empty() && | 593 if (!multi_values[i].empty() && |
| 585 StartsWith(multi_values[i], field_contents, false) && | 594 StartsWith(multi_values[i], field_contents, false) && |
| 586 (filter.is_null() || filter.Run(*profile))) { | 595 (filter.is_null() || filter.Run(*profile))) { |
| 587 matched_profiles.push_back(profile); | 596 matched_profiles.push_back(profile); |
| 588 values->push_back(multi_values[i]); | 597 values->push_back(multi_values[i]); |
| 589 guid_pairs->push_back(GUIDPair(profile->guid(), i)); | 598 guid_pairs->push_back(GUIDPair(profile->guid(), i)); |
| 590 } | 599 } |
| 591 } else { | 600 } else { |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 // Populates |auxiliary_profiles_|. | 1102 // Populates |auxiliary_profiles_|. |
| 1094 LoadAuxiliaryProfiles(record_metrics); | 1103 LoadAuxiliaryProfiles(record_metrics); |
| 1095 | 1104 |
| 1096 profiles_.insert(profiles_.end(), web_profiles_.begin(), web_profiles_.end()); | 1105 profiles_.insert(profiles_.end(), web_profiles_.begin(), web_profiles_.end()); |
| 1097 profiles_.insert( | 1106 profiles_.insert( |
| 1098 profiles_.end(), auxiliary_profiles_.begin(), auxiliary_profiles_.end()); | 1107 profiles_.end(), auxiliary_profiles_.begin(), auxiliary_profiles_.end()); |
| 1099 return profiles_; | 1108 return profiles_; |
| 1100 } | 1109 } |
| 1101 | 1110 |
| 1102 } // namespace autofill | 1111 } // namespace autofill |
| OLD | NEW |