| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/autofill/address.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "base/string_util.h" | |
| 12 #include "chrome/browser/autofill/autofill_country.h" | |
| 13 #include "chrome/browser/autofill/autofill_type.h" | |
| 14 #include "chrome/browser/autofill/field_types.h" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 const char16 kAddressSplitChars[] = {'-', ',', '#', '.', ' ', 0}; | |
| 19 | |
| 20 } // namespace | |
| 21 | |
| 22 Address::Address() {} | |
| 23 | |
| 24 Address::Address(const Address& address) : FormGroup() { | |
| 25 *this = address; | |
| 26 } | |
| 27 | |
| 28 Address::~Address() {} | |
| 29 | |
| 30 Address& Address::operator=(const Address& address) { | |
| 31 if (this == &address) | |
| 32 return *this; | |
| 33 | |
| 34 line1_ = address.line1_; | |
| 35 line2_ = address.line2_; | |
| 36 city_ = address.city_; | |
| 37 state_ = address.state_; | |
| 38 country_code_ = address.country_code_; | |
| 39 zip_code_ = address.zip_code_; | |
| 40 return *this; | |
| 41 } | |
| 42 | |
| 43 void Address::GetSupportedTypes(FieldTypeSet* supported_types) const { | |
| 44 supported_types->insert(ADDRESS_HOME_LINE1); | |
| 45 supported_types->insert(ADDRESS_HOME_LINE2); | |
| 46 supported_types->insert(ADDRESS_HOME_CITY); | |
| 47 supported_types->insert(ADDRESS_HOME_STATE); | |
| 48 supported_types->insert(ADDRESS_HOME_ZIP); | |
| 49 supported_types->insert(ADDRESS_HOME_COUNTRY); | |
| 50 } | |
| 51 | |
| 52 string16 Address::GetRawInfo(AutofillFieldType type) const { | |
| 53 if (type == ADDRESS_HOME_LINE1) | |
| 54 return line1_; | |
| 55 | |
| 56 if (type == ADDRESS_HOME_LINE2) | |
| 57 return line2_; | |
| 58 | |
| 59 if (type == ADDRESS_HOME_CITY) | |
| 60 return city_; | |
| 61 | |
| 62 if (type == ADDRESS_HOME_STATE) | |
| 63 return state_; | |
| 64 | |
| 65 if (type == ADDRESS_HOME_ZIP) | |
| 66 return zip_code_; | |
| 67 | |
| 68 if (type == ADDRESS_HOME_COUNTRY) | |
| 69 return Country(); | |
| 70 | |
| 71 return string16(); | |
| 72 } | |
| 73 | |
| 74 void Address::SetRawInfo(AutofillFieldType type, const string16& value) { | |
| 75 type = AutofillType::GetEquivalentFieldType(type); | |
| 76 if (type == ADDRESS_HOME_LINE1) | |
| 77 line1_ = value; | |
| 78 else if (type == ADDRESS_HOME_LINE2) | |
| 79 line2_ = value; | |
| 80 else if (type == ADDRESS_HOME_CITY) | |
| 81 city_ = value; | |
| 82 else if (type == ADDRESS_HOME_STATE) | |
| 83 state_ = value; | |
| 84 else if (type == ADDRESS_HOME_COUNTRY) | |
| 85 // TODO(isherman): When setting the country, it should only be possible to | |
| 86 // call this with a country code, which means we should be able to drop the | |
| 87 // call to GetCountryCode() below. | |
| 88 country_code_ = | |
| 89 AutofillCountry::GetCountryCode(value, | |
| 90 AutofillCountry::ApplicationLocale()); | |
| 91 else if (type == ADDRESS_HOME_ZIP) | |
| 92 zip_code_ = value; | |
| 93 else | |
| 94 NOTREACHED(); | |
| 95 } | |
| 96 | |
| 97 void Address::GetMatchingTypes(const string16& text, | |
| 98 const std::string& app_locale, | |
| 99 FieldTypeSet* matching_types) const { | |
| 100 FormGroup::GetMatchingTypes(text, app_locale, matching_types); | |
| 101 | |
| 102 // Check to see if the |text| canonicalized as a country name is a match. | |
| 103 std::string country_code = AutofillCountry::GetCountryCode(text, app_locale); | |
| 104 if (!country_code.empty() && country_code_ == country_code) | |
| 105 matching_types->insert(ADDRESS_HOME_COUNTRY); | |
| 106 } | |
| 107 | |
| 108 string16 Address::Country() const { | |
| 109 if (country_code().empty()) | |
| 110 return string16(); | |
| 111 | |
| 112 std::string app_locale = AutofillCountry::ApplicationLocale(); | |
| 113 return AutofillCountry(country_code(), app_locale).name(); | |
| 114 } | |
| OLD | NEW |