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 profile->GetMultiInfo(type, app_locale_, &multi_values); |
Evan Stade
2014/07/14 17:47:40
I don't really see a huge advantage to this CL, bu
please use gerrit instead
2014/07/14 19:07:09
Done.
| |
569 | 575 |
570 // Names need to be in vertically compact form - i.e. a single line. Join | 576 AddressField field; |
571 // multi-line addresses into a single line, using a separator. | 577 if (!multi_values.empty() && |
572 // The separator is locale-specific. | 578 i18n::FieldForType(type.GetStorableType(), &field) && |
573 base::string16 compact_separator = | 579 field == STREET_ADDRESS) { |
574 base::UTF8ToUTF16(::i18n::addressinput::GetLineSeparatorForLanguage( | 580 // Street address should have a single value. |
575 profile->language_code())); | 581 DCHECK_EQ(1U, multi_values.size()); |
582 std::string line; | |
583 GetStreetAddressLinesAsSingleLine( | |
584 *i18n::CreateAddressDataFromAutofillProfile(*profile, app_locale_), | |
585 &line); | |
586 multi_values[0] = base::UTF8ToUTF16(line); | |
587 } | |
588 | |
576 for (size_t i = 0; i < multi_values.size(); ++i) { | 589 for (size_t i = 0; i < multi_values.size(); ++i) { |
577 // Create vertically compact form. | 590 // Only street address can have newlines, but it was collapsed into a |
578 base::ReplaceChars(multi_values[i], | 591 // single line above. |
579 base::ASCIIToUTF16("\n"), | 592 DCHECK(multi_values[i].find('\n') == std::string::npos); |
580 compact_separator, | |
581 &multi_values[i]); | |
582 if (!field_is_autofilled) { | 593 if (!field_is_autofilled) { |
583 // Suggest data that starts with what the user has typed. | 594 // Suggest data that starts with what the user has typed. |
584 if (!multi_values[i].empty() && | 595 if (!multi_values[i].empty() && |
585 StartsWith(multi_values[i], field_contents, false) && | 596 StartsWith(multi_values[i], field_contents, false) && |
586 (filter.is_null() || filter.Run(*profile))) { | 597 (filter.is_null() || filter.Run(*profile))) { |
587 matched_profiles.push_back(profile); | 598 matched_profiles.push_back(profile); |
588 values->push_back(multi_values[i]); | 599 values->push_back(multi_values[i]); |
589 guid_pairs->push_back(GUIDPair(profile->guid(), i)); | 600 guid_pairs->push_back(GUIDPair(profile->guid(), i)); |
590 } | 601 } |
591 } else { | 602 } else { |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1093 // Populates |auxiliary_profiles_|. | 1104 // Populates |auxiliary_profiles_|. |
1094 LoadAuxiliaryProfiles(record_metrics); | 1105 LoadAuxiliaryProfiles(record_metrics); |
1095 | 1106 |
1096 profiles_.insert(profiles_.end(), web_profiles_.begin(), web_profiles_.end()); | 1107 profiles_.insert(profiles_.end(), web_profiles_.begin(), web_profiles_.end()); |
1097 profiles_.insert( | 1108 profiles_.insert( |
1098 profiles_.end(), auxiliary_profiles_.begin(), auxiliary_profiles_.end()); | 1109 profiles_.end(), auxiliary_profiles_.begin(), auxiliary_profiles_.end()); |
1099 return profiles_; | 1110 return profiles_; |
1100 } | 1111 } |
1101 | 1112 |
1102 } // namespace autofill | 1113 } // namespace autofill |
OLD | NEW |