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/guid.h" | 14 #include "base/guid.h" |
15 #include "base/logging.h" | 15 #include "base/logging.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.h" | 18 #include "components/autofill/core/browser/address.h" |
| 19 #include "components/autofill/core/browser/address_i18n.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/autofill_type.h" | 22 #include "components/autofill/core/browser/autofill_type.h" |
22 #include "components/autofill/core/browser/contact_info.h" | 23 #include "components/autofill/core/browser/contact_info.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/form_field_data.h" | 27 #include "components/autofill/core/common/form_field_data.h" |
27 #include "grit/component_strings.h" | 28 #include "grit/component_strings.h" |
| 29 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_data.h" |
28 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
29 | 31 |
30 using base::ASCIIToUTF16; | 32 using base::ASCIIToUTF16; |
31 using base::UTF16ToUTF8; | 33 using base::UTF16ToUTF8; |
32 | 34 |
33 namespace autofill { | 35 namespace autofill { |
34 namespace { | 36 namespace { |
35 | 37 |
36 // Like |AutofillType::GetStorableType()|, but also returns |NAME_FULL| for | 38 // Like |AutofillType::GetStorableType()|, but also returns |NAME_FULL| for |
37 // first, middle, and last name field types. | 39 // first, middle, and last name field types. |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 | 288 |
287 void AutofillProfile::SetRawInfo(ServerFieldType type, | 289 void AutofillProfile::SetRawInfo(ServerFieldType type, |
288 const base::string16& value) { | 290 const base::string16& value) { |
289 FormGroup* form_group = MutableFormGroupForType(AutofillType(type)); | 291 FormGroup* form_group = MutableFormGroupForType(AutofillType(type)); |
290 if (form_group) | 292 if (form_group) |
291 form_group->SetRawInfo(type, value); | 293 form_group->SetRawInfo(type, value); |
292 } | 294 } |
293 | 295 |
294 base::string16 AutofillProfile::GetInfo(const AutofillType& type, | 296 base::string16 AutofillProfile::GetInfo(const AutofillType& type, |
295 const std::string& app_locale) const { | 297 const std::string& app_locale) const { |
| 298 if (type.html_type() == HTML_TYPE_FULL_ADDRESS) { |
| 299 scoped_ptr< ::i18n::addressinput::AddressData> address_data = |
| 300 i18n::CreateAddressDataFromAutofillProfile(*this, app_locale); |
| 301 if (!address_data->HasAllRequiredFields()) |
| 302 return base::string16(); |
| 303 |
| 304 std::vector<std::string> lines; |
| 305 address_data->FormatForDisplay(&lines); |
| 306 return base::UTF8ToUTF16(JoinString(lines, '\n')); |
| 307 } |
| 308 |
296 const FormGroup* form_group = FormGroupForType(type); | 309 const FormGroup* form_group = FormGroupForType(type); |
297 if (!form_group) | 310 if (!form_group) |
298 return base::string16(); | 311 return base::string16(); |
299 | 312 |
300 return form_group->GetInfo(type, app_locale); | 313 return form_group->GetInfo(type, app_locale); |
301 } | 314 } |
302 | 315 |
303 bool AutofillProfile::SetInfo(const AutofillType& type, | 316 bool AutofillProfile::SetInfo(const AutofillType& type, |
304 const base::string16& value, | 317 const base::string16& value, |
305 const std::string& app_locale) { | 318 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)) | 868 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) |
856 << " " | 869 << " " |
857 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) | 870 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) |
858 << " " | 871 << " " |
859 << profile.language_code() | 872 << profile.language_code() |
860 << " " | 873 << " " |
861 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); | 874 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); |
862 } | 875 } |
863 | 876 |
864 } // namespace autofill | 877 } // namespace autofill |
OLD | NEW |