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 <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/address_i18n.h" |
| 20 #include "components/autofill/core/browser/autofill_country.h" | 20 #include "components/autofill/core/browser/autofill_country.h" |
| 21 #include "components/autofill/core/browser/autofill_field.h" | 21 #include "components/autofill/core/browser/autofill_field.h" |
| 22 #include "components/autofill/core/browser/autofill_type.h" | 22 #include "components/autofill/core/browser/autofill_type.h" |
| 23 #include "components/autofill/core/browser/contact_info.h" | 23 #include "components/autofill/core/browser/contact_info.h" |
| 24 #include "components/autofill/core/browser/phone_number.h" | 24 #include "components/autofill/core/browser/phone_number.h" |
| 25 #include "components/autofill/core/browser/phone_number_i18n.h" | 25 #include "components/autofill/core/browser/phone_number_i18n.h" |
| 26 #include "components/autofill/core/browser/validation.h" | 26 #include "components/autofill/core/browser/validation.h" |
| 27 #include "components/autofill/core/common/form_field_data.h" | 27 #include "components/autofill/core/common/form_field_data.h" |
| 28 #include "grit/components_strings.h" | 28 #include "grit/components_strings.h" |
| 29 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_data.h" | 29 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h" |
| 30 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fi eld.h" | |
| 31 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fo rmatter.h" | |
| 32 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_me tadata.h" | |
| 30 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 31 | 34 |
| 32 using base::ASCIIToUTF16; | 35 using base::ASCIIToUTF16; |
| 33 using base::UTF16ToUTF8; | 36 using base::UTF16ToUTF8; |
| 37 using ::i18n::addressinput::AddressData; | |
| 38 using ::i18n::addressinput::AddressField; | |
| 34 | 39 |
| 35 namespace autofill { | 40 namespace autofill { |
| 36 namespace { | 41 namespace { |
| 37 | 42 |
| 38 // Like |AutofillType::GetStorableType()|, but also returns |NAME_FULL| for | 43 // Like |AutofillType::GetStorableType()|, but also returns |NAME_FULL| for |
| 39 // first, middle, and last name field types. | 44 // first, middle, and last name field types. |
| 40 ServerFieldType GetStorableTypeCollapsingNames(ServerFieldType type) { | 45 ServerFieldType GetStorableTypeCollapsingNames(ServerFieldType type) { |
| 41 ServerFieldType storable_type = AutofillType(type).GetStorableType(); | 46 ServerFieldType storable_type = AutofillType(type).GetStorableType(); |
| 42 if (AutofillType(storable_type).group() == NAME) | 47 if (AutofillType(storable_type).group() == NAME) |
| 43 return NAME_FULL; | 48 return NAME_FULL; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 void AutofillProfile::SetRawInfo(ServerFieldType type, | 294 void AutofillProfile::SetRawInfo(ServerFieldType type, |
| 290 const base::string16& value) { | 295 const base::string16& value) { |
| 291 FormGroup* form_group = MutableFormGroupForType(AutofillType(type)); | 296 FormGroup* form_group = MutableFormGroupForType(AutofillType(type)); |
| 292 if (form_group) | 297 if (form_group) |
| 293 form_group->SetRawInfo(type, value); | 298 form_group->SetRawInfo(type, value); |
| 294 } | 299 } |
| 295 | 300 |
| 296 base::string16 AutofillProfile::GetInfo(const AutofillType& type, | 301 base::string16 AutofillProfile::GetInfo(const AutofillType& type, |
| 297 const std::string& app_locale) const { | 302 const std::string& app_locale) const { |
| 298 if (type.html_type() == HTML_TYPE_FULL_ADDRESS) { | 303 if (type.html_type() == HTML_TYPE_FULL_ADDRESS) { |
| 299 scoped_ptr< ::i18n::addressinput::AddressData> address_data = | 304 scoped_ptr<AddressData> address = |
| 300 i18n::CreateAddressDataFromAutofillProfile(*this, app_locale); | 305 i18n::CreateAddressDataFromAutofillProfile(*this, app_locale); |
| 301 if (!address_data->HasAllRequiredFields()) | 306 |
|
please use gerrit instead
2014/06/05 22:22:48
To reduce reviewer burden: Use the has_all_require
please use gerrit instead
2014/06/09 23:28:16
Done.
| |
| 302 return base::string16(); | 307 // TODO: Think about whether it makes sense to do this special check here in |
| 308 // Chromium, instead of just using the regular address validation feature of | |
| 309 // libaddressinput. | |
| 310 static const AddressField kFields[] = { | |
| 311 ::i18n::addressinput::COUNTRY, | |
| 312 ::i18n::addressinput::ADMIN_AREA, | |
| 313 ::i18n::addressinput::LOCALITY, | |
| 314 ::i18n::addressinput::DEPENDENT_LOCALITY, | |
| 315 ::i18n::addressinput::SORTING_CODE, | |
| 316 ::i18n::addressinput::POSTAL_CODE, | |
| 317 ::i18n::addressinput::STREET_ADDRESS, | |
| 318 ::i18n::addressinput::RECIPIENT | |
| 319 }; | |
| 320 | |
| 321 for (size_t i = 0; i < arraysize(kFields); ++i) { | |
| 322 AddressField field = kFields[i]; | |
| 323 if (address->IsFieldEmpty(field) && | |
| 324 ::i18n::addressinput::IsFieldRequired(field, address->region_code)) { | |
| 325 return base::string16(); | |
| 326 } | |
| 327 } | |
| 303 | 328 |
| 304 std::vector<std::string> lines; | 329 std::vector<std::string> lines; |
| 305 address_data->FormatForDisplay(&lines); | 330 ::i18n::addressinput::GetFormattedNationalAddress(*address, &lines); |
| 306 return base::UTF8ToUTF16(JoinString(lines, '\n')); | 331 return base::UTF8ToUTF16(JoinString(lines, '\n')); |
| 307 } | 332 } |
| 308 | 333 |
| 309 const FormGroup* form_group = FormGroupForType(type); | 334 const FormGroup* form_group = FormGroupForType(type); |
| 310 if (!form_group) | 335 if (!form_group) |
| 311 return base::string16(); | 336 return base::string16(); |
| 312 | 337 |
| 313 return form_group->GetInfo(type, app_locale); | 338 return form_group->GetInfo(type, app_locale); |
| 314 } | 339 } |
| 315 | 340 |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 867 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) | 892 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) |
| 868 << " " | 893 << " " |
| 869 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) | 894 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) |
| 870 << " " | 895 << " " |
| 871 << profile.language_code() | 896 << profile.language_code() |
| 872 << " " | 897 << " " |
| 873 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); | 898 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); |
| 874 } | 899 } |
| 875 | 900 |
| 876 } // namespace autofill | 901 } // namespace autofill |
| OLD | NEW |