| 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_field.h" | 5 #include "components/autofill/core/browser/autofill_field.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/i18n/string_search.h" | 10 #include "base/i18n/string_search.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 if (!full.empty() && SetSelectControlValueSubstringMatch(full, field)) { | 167 if (!full.empty() && SetSelectControlValueSubstringMatch(full, field)) { |
| 168 return true; | 168 return true; |
| 169 } | 169 } |
| 170 | 170 |
| 171 // Then try an inexact match of the abbreviation name. | 171 // Then try an inexact match of the abbreviation name. |
| 172 return !abbreviation.empty() && | 172 return !abbreviation.empty() && |
| 173 SetSelectControlValueTokenMatch(abbreviation, field); | 173 SetSelectControlValueTokenMatch(abbreviation, field); |
| 174 } | 174 } |
| 175 | 175 |
| 176 bool FillCountrySelectControl(const base::string16& value, | 176 bool FillCountrySelectControl(const base::string16& value, |
| 177 const std::string& app_locale, | |
| 178 FormFieldData* field_data) { | 177 FormFieldData* field_data) { |
| 179 std::string country_code = | 178 std::string country_code = CountryNames::GetInstance()->GetCountryCode(value); |
| 180 CountryNames::GetInstance()->GetCountryCode(value, app_locale); | |
| 181 if (country_code.empty()) | 179 if (country_code.empty()) |
| 182 return false; | 180 return false; |
| 183 | 181 |
| 184 DCHECK_EQ(field_data->option_values.size(), | 182 DCHECK_EQ(field_data->option_values.size(), |
| 185 field_data->option_contents.size()); | 183 field_data->option_contents.size()); |
| 186 for (size_t i = 0; i < field_data->option_values.size(); ++i) { | 184 for (size_t i = 0; i < field_data->option_values.size(); ++i) { |
| 187 // Canonicalize each <option> value to a country code, and compare to the | 185 // Canonicalize each <option> value to a country code, and compare to the |
| 188 // target country code. | 186 // target country code. |
| 189 base::string16 value = field_data->option_values[i]; | 187 base::string16 value = field_data->option_values[i]; |
| 190 base::string16 contents = field_data->option_contents[i]; | 188 base::string16 contents = field_data->option_contents[i]; |
| 191 if (country_code == | 189 if (country_code == CountryNames::GetInstance()->GetCountryCode(value) || |
| 192 CountryNames::GetInstance()->GetCountryCode(value, app_locale) || | 190 country_code == CountryNames::GetInstance()->GetCountryCode(contents)) { |
| 193 country_code == | |
| 194 CountryNames::GetInstance()->GetCountryCode(contents, app_locale)) { | |
| 195 field_data->value = value; | 191 field_data->value = value; |
| 196 return true; | 192 return true; |
| 197 } | 193 } |
| 198 } | 194 } |
| 199 | 195 |
| 200 return false; | 196 return false; |
| 201 } | 197 } |
| 202 | 198 |
| 203 bool FillExpirationMonthSelectControl(const base::string16& value, | 199 bool FillExpirationMonthSelectControl(const base::string16& value, |
| 204 const std::string& app_locale, | 200 const std::string& app_locale, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 return FillExpirationMonthSelectControl(value, app_locale, field); | 338 return FillExpirationMonthSelectControl(value, app_locale, field); |
| 343 | 339 |
| 344 // Search for exact matches. | 340 // Search for exact matches. |
| 345 if (SetSelectControlValue(value, field)) | 341 if (SetSelectControlValue(value, field)) |
| 346 return true; | 342 return true; |
| 347 | 343 |
| 348 // If that fails, try specific fallbacks based on the field type. | 344 // If that fails, try specific fallbacks based on the field type. |
| 349 if (storable_type == ADDRESS_HOME_STATE) { | 345 if (storable_type == ADDRESS_HOME_STATE) { |
| 350 return FillStateSelectControl(value, field); | 346 return FillStateSelectControl(value, field); |
| 351 } else if (storable_type == ADDRESS_HOME_COUNTRY) { | 347 } else if (storable_type == ADDRESS_HOME_COUNTRY) { |
| 352 return FillCountrySelectControl(value, app_locale, field); | 348 return FillCountrySelectControl(value, field); |
| 353 } else if (storable_type == CREDIT_CARD_EXP_2_DIGIT_YEAR || | 349 } else if (storable_type == CREDIT_CARD_EXP_2_DIGIT_YEAR || |
| 354 storable_type == CREDIT_CARD_EXP_4_DIGIT_YEAR) { | 350 storable_type == CREDIT_CARD_EXP_4_DIGIT_YEAR) { |
| 355 return FillYearSelectControl(value, field); | 351 return FillYearSelectControl(value, field); |
| 356 } else if (storable_type == CREDIT_CARD_TYPE) { | 352 } else if (storable_type == CREDIT_CARD_TYPE) { |
| 357 return FillCreditCardTypeSelectControl(value, field); | 353 return FillCreditCardTypeSelectControl(value, field); |
| 358 } | 354 } |
| 359 | 355 |
| 360 return false; | 356 return false; |
| 361 } | 357 } |
| 362 | 358 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 if (compare.StringsEqual(value_stripped, option_contents)) { | 592 if (compare.StringsEqual(value_stripped, option_contents)) { |
| 597 if (index) | 593 if (index) |
| 598 *index = i; | 594 *index = i; |
| 599 return true; | 595 return true; |
| 600 } | 596 } |
| 601 } | 597 } |
| 602 return false; | 598 return false; |
| 603 } | 599 } |
| 604 | 600 |
| 605 } // namespace autofill | 601 } // namespace autofill |
| OLD | NEW |