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/address.h" | 5 #include "components/autofill/core/browser/address.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "components/autofill/core/browser/autofill_country.h" | 14 #include "components/autofill/core/browser/autofill_country.h" |
| 15 #include "components/autofill/core/browser/autofill_field.h" | 15 #include "components/autofill/core/browser/autofill_field.h" |
| 16 #include "components/autofill/core/browser/autofill_profile.h" | |
| 16 #include "components/autofill/core/browser/autofill_type.h" | 17 #include "components/autofill/core/browser/autofill_type.h" |
| 17 #include "components/autofill/core/browser/country_names.h" | 18 #include "components/autofill/core/browser/country_names.h" |
| 19 #include "components/autofill/core/browser/state_names.h" | |
| 20 #include "components/autofill/core/common/autofill_l10n_util.h" | |
| 18 | 21 |
| 19 namespace autofill { | 22 namespace autofill { |
| 20 | 23 |
| 21 Address::Address() {} | 24 Address::Address() {} |
| 22 | 25 |
| 23 Address::Address(const Address& address) : FormGroup() { | 26 Address::Address(const Address& address) : FormGroup() { |
| 24 *this = address; | 27 *this = address; |
| 25 } | 28 } |
| 26 | 29 |
| 27 Address::~Address() {} | 30 Address::~Address() {} |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 | 194 |
| 192 void Address::GetMatchingTypes(const base::string16& text, | 195 void Address::GetMatchingTypes(const base::string16& text, |
| 193 const std::string& app_locale, | 196 const std::string& app_locale, |
| 194 ServerFieldTypeSet* matching_types) const { | 197 ServerFieldTypeSet* matching_types) const { |
| 195 FormGroup::GetMatchingTypes(text, app_locale, matching_types); | 198 FormGroup::GetMatchingTypes(text, app_locale, matching_types); |
| 196 | 199 |
| 197 // Check to see if the |text| canonicalized as a country name is a match. | 200 // Check to see if the |text| canonicalized as a country name is a match. |
| 198 std::string country_code = CountryNames::GetInstance()->GetCountryCode(text); | 201 std::string country_code = CountryNames::GetInstance()->GetCountryCode(text); |
| 199 if (!country_code.empty() && country_code_ == country_code) | 202 if (!country_code.empty() && country_code_ == country_code) |
| 200 matching_types->insert(ADDRESS_HOME_COUNTRY); | 203 matching_types->insert(ADDRESS_HOME_COUNTRY); |
| 204 | |
| 205 // Check to see if the |text| could be the full name or abbreviation of a | |
| 206 // state. | |
| 207 base::string16 canon_text = AutofillProfile::CanonicalizeProfileString(text); | |
| 208 base::string16 state_name; | |
| 209 base::string16 state_abbreviation; | |
| 210 state_names::GetNameAndAbbreviation(canon_text, &state_name, | |
| 211 &state_abbreviation); | |
| 212 if (!state_name.empty() || !state_abbreviation.empty()) { | |
|
Mathieu
2016/03/18 13:56:04
At this point, we're pretty certain the field is a
sebsg
2016/03/18 14:25:54
It was to be cautious and also consistent with all
Mathieu
2016/03/18 14:35:20
Another case of the New York, New York case is Que
| |
| 213 l10n::CaseInsensitiveCompare compare; | |
| 214 base::string16 canon_profile_state = | |
| 215 AutofillProfile::CanonicalizeProfileString( | |
| 216 GetInfo(AutofillType(ADDRESS_HOME_STATE), app_locale)); | |
| 217 if ((!state_name.empty() && | |
| 218 compare.StringsEqual(state_name, canon_profile_state)) || | |
| 219 (!state_abbreviation.empty() && | |
| 220 compare.StringsEqual(state_abbreviation, canon_profile_state))) { | |
| 221 matching_types->insert(ADDRESS_HOME_STATE); | |
| 222 } | |
| 223 } | |
| 201 } | 224 } |
| 202 | 225 |
| 203 void Address::GetSupportedTypes(ServerFieldTypeSet* supported_types) const { | 226 void Address::GetSupportedTypes(ServerFieldTypeSet* supported_types) const { |
| 204 supported_types->insert(ADDRESS_HOME_LINE1); | 227 supported_types->insert(ADDRESS_HOME_LINE1); |
| 205 supported_types->insert(ADDRESS_HOME_LINE2); | 228 supported_types->insert(ADDRESS_HOME_LINE2); |
| 206 supported_types->insert(ADDRESS_HOME_LINE3); | 229 supported_types->insert(ADDRESS_HOME_LINE3); |
| 207 supported_types->insert(ADDRESS_HOME_STREET_ADDRESS); | 230 supported_types->insert(ADDRESS_HOME_STREET_ADDRESS); |
| 208 supported_types->insert(ADDRESS_HOME_DEPENDENT_LOCALITY); | 231 supported_types->insert(ADDRESS_HOME_DEPENDENT_LOCALITY); |
| 209 supported_types->insert(ADDRESS_HOME_CITY); | 232 supported_types->insert(ADDRESS_HOME_CITY); |
| 210 supported_types->insert(ADDRESS_HOME_STATE); | 233 supported_types->insert(ADDRESS_HOME_STATE); |
| 211 supported_types->insert(ADDRESS_HOME_ZIP); | 234 supported_types->insert(ADDRESS_HOME_ZIP); |
| 212 supported_types->insert(ADDRESS_HOME_SORTING_CODE); | 235 supported_types->insert(ADDRESS_HOME_SORTING_CODE); |
| 213 supported_types->insert(ADDRESS_HOME_COUNTRY); | 236 supported_types->insert(ADDRESS_HOME_COUNTRY); |
| 214 } | 237 } |
| 215 | 238 |
| 216 void Address::TrimStreetAddress() { | 239 void Address::TrimStreetAddress() { |
| 217 while (!street_address_.empty() && street_address_.back().empty()) { | 240 while (!street_address_.empty() && street_address_.back().empty()) { |
| 218 street_address_.pop_back(); | 241 street_address_.pop_back(); |
| 219 } | 242 } |
| 220 } | 243 } |
| 221 | 244 |
| 222 } // namespace autofill | 245 } // namespace autofill |
| OLD | NEW |