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 <ostream> | 10 #include <ostream> |
11 #include <set> | 11 #include <set> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/bind.h" | |
14 #include "base/guid.h" | 15 #include "base/guid.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
18 #include "components/autofill/core/browser/address.h" | 19 #include "components/autofill/core/browser/address.h" |
20 #include "components/autofill/core/browser/address_i18n.h" | |
19 #include "components/autofill/core/browser/autofill_country.h" | 21 #include "components/autofill/core/browser/autofill_country.h" |
20 #include "components/autofill/core/browser/autofill_field.h" | 22 #include "components/autofill/core/browser/autofill_field.h" |
21 #include "components/autofill/core/browser/autofill_type.h" | 23 #include "components/autofill/core/browser/autofill_type.h" |
22 #include "components/autofill/core/browser/contact_info.h" | 24 #include "components/autofill/core/browser/contact_info.h" |
23 #include "components/autofill/core/browser/phone_number.h" | 25 #include "components/autofill/core/browser/phone_number.h" |
24 #include "components/autofill/core/browser/phone_number_i18n.h" | 26 #include "components/autofill/core/browser/phone_number_i18n.h" |
25 #include "components/autofill/core/browser/validation.h" | 27 #include "components/autofill/core/browser/validation.h" |
26 #include "components/autofill/core/common/form_field_data.h" | 28 #include "components/autofill/core/common/form_field_data.h" |
27 #include "grit/component_strings.h" | 29 #include "grit/component_strings.h" |
30 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_data.h" | |
28 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
29 | 32 |
33 | |
Ilya Sherman
2014/05/07 01:19:19
nit: Spurious newline.
Evan Stade
2014/05/09 22:14:59
Done.
| |
30 using base::ASCIIToUTF16; | 34 using base::ASCIIToUTF16; |
31 using base::UTF16ToUTF8; | 35 using base::UTF16ToUTF8; |
32 | 36 |
33 namespace autofill { | 37 namespace autofill { |
34 namespace { | 38 namespace { |
35 | 39 |
36 // Like |AutofillType::GetStorableType()|, but also returns |NAME_FULL| for | 40 // Like |AutofillType::GetStorableType()|, but also returns |NAME_FULL| for |
37 // first, middle, and last name field types. | 41 // first, middle, and last name field types. |
38 ServerFieldType GetStorableTypeCollapsingNames(ServerFieldType type) { | 42 ServerFieldType GetStorableTypeCollapsingNames(ServerFieldType type) { |
39 ServerFieldType storable_type = AutofillType(type).GetStorableType(); | 43 ServerFieldType storable_type = AutofillType(type).GetStorableType(); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 // Functor used to check for case-insensitive equality of two strings. | 218 // Functor used to check for case-insensitive equality of two strings. |
215 struct CaseInsensitiveStringEquals | 219 struct CaseInsensitiveStringEquals |
216 : public std::binary_function<base::string16, base::string16, bool> | 220 : public std::binary_function<base::string16, base::string16, bool> |
217 { | 221 { |
218 bool operator()(const base::string16& x, const base::string16& y) const { | 222 bool operator()(const base::string16& x, const base::string16& y) const { |
219 return | 223 return |
220 x.size() == y.size() && StringToLowerASCII(x) == StringToLowerASCII(y); | 224 x.size() == y.size() && StringToLowerASCII(x) == StringToLowerASCII(y); |
221 } | 225 } |
222 }; | 226 }; |
223 | 227 |
228 base::string16 GetInfoHelper(const AutofillProfile* profile, | |
Ilya Sherman
2014/05/07 01:19:19
nit: Why not const-ref?
Evan Stade
2014/05/09 22:14:59
Done.
| |
229 const std::string& app_locale, | |
230 const AutofillType& type) { | |
231 return profile->GetInfo(type, app_locale); | |
232 } | |
233 | |
224 } // namespace | 234 } // namespace |
225 | 235 |
226 AutofillProfile::AutofillProfile(const std::string& guid, | 236 AutofillProfile::AutofillProfile(const std::string& guid, |
227 const std::string& origin) | 237 const std::string& origin) |
228 : AutofillDataModel(guid, origin), | 238 : AutofillDataModel(guid, origin), |
229 name_(1), | 239 name_(1), |
230 email_(1), | 240 email_(1), |
231 phone_number_(1, PhoneNumber(this)) { | 241 phone_number_(1, PhoneNumber(this)) { |
232 } | 242 } |
233 | 243 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 | 296 |
287 void AutofillProfile::SetRawInfo(ServerFieldType type, | 297 void AutofillProfile::SetRawInfo(ServerFieldType type, |
288 const base::string16& value) { | 298 const base::string16& value) { |
289 FormGroup* form_group = MutableFormGroupForType(AutofillType(type)); | 299 FormGroup* form_group = MutableFormGroupForType(AutofillType(type)); |
290 if (form_group) | 300 if (form_group) |
291 form_group->SetRawInfo(type, value); | 301 form_group->SetRawInfo(type, value); |
292 } | 302 } |
293 | 303 |
294 base::string16 AutofillProfile::GetInfo(const AutofillType& type, | 304 base::string16 AutofillProfile::GetInfo(const AutofillType& type, |
295 const std::string& app_locale) const { | 305 const std::string& app_locale) const { |
306 if (type.html_type() == HTML_TYPE_FULL_ADDRESS) { | |
307 scoped_ptr<::i18n::addressinput::AddressData> address_data = | |
308 i18n::CreateAddressData(base::Bind(&GetInfoHelper, this, app_locale)); | |
309 address_data->language_code = language_code(); | |
310 std::vector<std::string> lines; | |
311 address_data->FormatForDisplay(&lines); | |
312 return base::UTF8ToUTF16(JoinString(lines, '\n')); | |
313 } | |
314 | |
296 const FormGroup* form_group = FormGroupForType(type); | 315 const FormGroup* form_group = FormGroupForType(type); |
297 if (!form_group) | 316 if (!form_group) |
298 return base::string16(); | 317 return base::string16(); |
299 | 318 |
300 return form_group->GetInfo(type, app_locale); | 319 return form_group->GetInfo(type, app_locale); |
301 } | 320 } |
302 | 321 |
303 bool AutofillProfile::SetInfo(const AutofillType& type, | 322 bool AutofillProfile::SetInfo(const AutofillType& type, |
304 const base::string16& value, | 323 const base::string16& value, |
305 const std::string& app_locale) { | 324 const std::string& app_locale) { |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
855 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) | 874 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) |
856 << " " | 875 << " " |
857 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) | 876 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) |
858 << " " | 877 << " " |
859 << profile.language_code() | 878 << profile.language_code() |
860 << " " | 879 << " " |
861 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); | 880 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); |
862 } | 881 } |
863 | 882 |
864 } // namespace autofill | 883 } // namespace autofill |
OLD | NEW |