| Index: chrome/browser/autofill/select_control_handler.cc
|
| diff --git a/chrome/browser/autofill/select_control_handler.cc b/chrome/browser/autofill/select_control_handler.cc
|
| index 4ceba0f9bc434ceac7f065fcb6a835abd1921ce7..63d7a0408d87e0c597ccd41033cba754b9ec10bb 100644
|
| --- a/chrome/browser/autofill/select_control_handler.cc
|
| +++ b/chrome/browser/autofill/select_control_handler.cc
|
| @@ -11,6 +11,8 @@
|
| #include "base/string_number_conversions.h"
|
| #include "base/string16.h"
|
| #include "base/utf_string_conversions.h"
|
| +#include "chrome/browser/autofill/autofill_country.h"
|
| +#include "chrome/browser/autofill/autofill_profile.h"
|
| #include "chrome/browser/autofill/form_group.h"
|
| #include "webkit/glue/form_field.h"
|
|
|
| @@ -99,280 +101,6 @@ string16 State::FullName(const string16& abbreviation) {
|
| return string16();
|
| }
|
|
|
| -// Holds valid country names, their 2 letter abbreviation, and maps from
|
| -// the former to the latter
|
| -class Country {
|
| - public:
|
| - const char* name;
|
| - const char* abbreviation;
|
| -
|
| - static const Country all_countries[];
|
| -
|
| - static string16 Abbreviation(const string16 &name);
|
| - static string16 FullName(const string16& abbreviation);
|
| -};
|
| -
|
| -// A list of all English country names and code elements. ISO 3166.
|
| -const Country Country::all_countries[] = {
|
| - { "united states", "us" },
|
| - { "afghanistan", "af" },
|
| - { "aland islands", "ax" },
|
| - { "albania", "al" },
|
| - { "algeria", "dz" },
|
| - { "american samoa", "as" },
|
| - { "andorra", "ad" },
|
| - { "angola", "ao" },
|
| - { "anguilla", "ai" },
|
| - { "antarctica", "aq" },
|
| - { "antigua and barbuda", "ag" },
|
| - { "argentina", "ar" },
|
| - { "armenia", "am" },
|
| - { "aruba", "aw" },
|
| - { "australia", "au" },
|
| - { "austria", "at" },
|
| - { "azerbaijan", "az" },
|
| - { "bahamas", "bs" },
|
| - { "bahrain", "bh" },
|
| - { "bangladesh", "bd" },
|
| - { "barbados", "bb" },
|
| - { "belarus", "by" },
|
| - { "belgium", "be" },
|
| - { "belize", "bz" },
|
| - { "benin", "bj" },
|
| - { "bermuda", "bm" },
|
| - { "bhutan", "bt" },
|
| - { "bolivia", "bo" },
|
| - { "bosnia and herzegovina", "ba" },
|
| - { "botswana", "bw" },
|
| - { "bouvet island", "bv" },
|
| - { "brazil", "br" },
|
| - { "british indian ocean territory", "io" },
|
| - { "brunei darussalam", "bn" },
|
| - { "bulgaria", "bg" },
|
| - { "burkina faso", "bf" },
|
| - { "burundi", "bi" },
|
| - { "cambodia", "kh" },
|
| - { "cameroon", "cm" },
|
| - { "canada", "ca" },
|
| - { "cape verde", "cv" },
|
| - { "cayman islands", "ky" },
|
| - { "central african republic", "cf" },
|
| - { "chad", "td" },
|
| - { "chile", "cl" },
|
| - { "china", "cn" },
|
| - { "christmas island", "cx" },
|
| - { "cocos (keeling) islands", "cc" },
|
| - { "colombia", "co" },
|
| - { "comoros", "km" },
|
| - { "congo", "cg" },
|
| - { "congo (dem. rep.)", "cd" },
|
| - { "cook islands", "ck" },
|
| - { "costa rica", "cr" },
|
| - { "cote d'ivoire", "ci" },
|
| - { "croatia", "hr" },
|
| - { "cuba", "cu" },
|
| - { "cyprus", "cy" },
|
| - { "czech republic", "cz" },
|
| - { "denmark", "dk" },
|
| - { "djibouti", "dj" },
|
| - { "dominica", "dm" },
|
| - { "dominican republic", "do" },
|
| - { "ecuador", "ec" },
|
| - { "egypt", "eg" },
|
| - { "el salvador", "sv" },
|
| - { "equatorial guinea", "gq" },
|
| - { "eritrea", "er" },
|
| - { "estonia", "ee" },
|
| - { "ethiopia", "et" },
|
| - { "falkland islands (malvinas)", "fk" },
|
| - { "faroe islands", "fo" },
|
| - { "fiji", "fj" },
|
| - { "finland", "fi" },
|
| - { "france", "fr" },
|
| - { "french guiana", "gf" },
|
| - { "french polynesia", "pf" },
|
| - { "gabon", "ga" },
|
| - { "gambia", "gm" },
|
| - { "georgia", "ge" },
|
| - { "germany", "de" },
|
| - { "ghana", "gh" },
|
| - { "gibraltar", "gi" },
|
| - { "greece", "gr" },
|
| - { "greenland", "gl" },
|
| - { "grenada", "gd" },
|
| - { "guadeloupe", "gp" },
|
| - { "guam", "gu" },
|
| - { "guatemala", "gt" },
|
| - { "guernsey", "cg" },
|
| - { "guinea", "gn" },
|
| - { "guinea-bissau", "gw" },
|
| - { "guyana", "gy" },
|
| - { "haiti", "ht" },
|
| - { "heard island and mcdonald islands", "hm" },
|
| - { "holy see (vatica city state)", "va" },
|
| - { "honduras", "hn" },
|
| - { "hong kong", "hk" },
|
| - { "hungary", "hu" },
|
| - { "iceland", "is" },
|
| - { "india", "in" },
|
| - { "indonesia", "id" },
|
| - { "iran", "ir" },
|
| - { "iraq", "iq" },
|
| - { "ireland", "ie" },
|
| - { "isle of man", "im" },
|
| - { "israel", "il" },
|
| - { "italy", "it" },
|
| - { "ivory coast", "ci" },
|
| - { "jamaica", "jm" },
|
| - { "japan", "jp" },
|
| - { "jersey", "je" },
|
| - { "jordan", "jo" },
|
| - { "kazakhstan", "kz" },
|
| - { "kenya", "ke" },
|
| - { "kiribati", "ki" },
|
| - { "korea (north)", "kp" },
|
| - { "korea (south)", "kr" },
|
| - { "kuwait", "kw" },
|
| - { "kyrgyzstan", "kg" },
|
| - { "laos", "la" },
|
| - { "latvia", "lv" },
|
| - { "lebanon", "lb" },
|
| - { "lesotho", "ls" },
|
| - { "liberia", "lr" },
|
| - { "libya", "ly" },
|
| - { "liechtenstein", "li" },
|
| - { "lithuania", "lt" },
|
| - { "luxembourg", "lu" },
|
| - { "macao", "mo" },
|
| - { "macedonia", "mk" },
|
| - { "madagascar", "mg" },
|
| - { "malawi", "mw" },
|
| - { "malaysia", "my" },
|
| - { "maldives", "mv" },
|
| - { "mali", "ml" },
|
| - { "malta", "mt" },
|
| - { "marshall islands", "mh" },
|
| - { "martinique", "mq" },
|
| - { "mauritania", "mr" },
|
| - { "mauritius", "mu" },
|
| - { "mayotte", "yt" },
|
| - { "mexico", "mx" },
|
| - { "micronesia", "fm" },
|
| - { "moldova", "md" },
|
| - { "monaco", "mc" },
|
| - { "mongolia", "mn" },
|
| - { "montserrat", "ms" },
|
| - { "morocco", "ma" },
|
| - { "mozambique", "mz" },
|
| - { "myanmar", "mm" },
|
| - { "namibia", "na" },
|
| - { "nepal", "np" },
|
| - { "netherlands", "nl" },
|
| - { "netherlands antilles", "an" },
|
| - { "new caledonia", "nc" },
|
| - { "new zealand", "nz" },
|
| - { "nicaragua", "ni" },
|
| - { "niger", "ne" },
|
| - { "nigeria", "ng" },
|
| - { "niue", "nu" },
|
| - { "norfolk island", "nf" },
|
| - { "northern mariana islands", "mp" },
|
| - { "norway", "no" },
|
| - { "oman", "om" },
|
| - { "pakistan", "pk" },
|
| - { "palau", "pw" },
|
| - { "palestine", "ps" },
|
| - { "panama", "pa" },
|
| - { "papua new guinea", "pg" },
|
| - { "paraguay", "py" },
|
| - { "peru", "pe" },
|
| - { "philippines", "ph" },
|
| - { "pitcairn", "pn" },
|
| - { "poland", "pl" },
|
| - { "portugal", "pt" },
|
| - { "puerto rico", "pr" },
|
| - { "qatar", "qa" },
|
| - { "reunion", "re" },
|
| - { "romania", "ro" },
|
| - { "russia", "ru" },
|
| - { "rwanda", "rw" },
|
| - { "saint helena", "sh" },
|
| - { "saint kitts and nevis", "kn" },
|
| - { "saint lucia", "lc" },
|
| - { "saint pierre and miquelon", "pm" },
|
| - { "saint vincent and the grenadines", "vc" },
|
| - { "samoa", "ws" },
|
| - { "san marino", "sm" },
|
| - { "sao tome and principe", "st" },
|
| - { "saudi arabia", "sa" },
|
| - { "senegal", "sn" },
|
| - { "serbia and montenegro", "cs" },
|
| - { "seychelles", "sc" },
|
| - { "sierra leone", "sl" },
|
| - { "singapore", "sg" },
|
| - { "slovakia", "sk" },
|
| - { "slovenia", "si" },
|
| - { "solomon islands", "sb" },
|
| - { "somalia", "so" },
|
| - { "south africa", "za" },
|
| - { "south georgia and the south sandwich islands", "gs" },
|
| - { "spain", "es" },
|
| - { "sri lanka", "lk" },
|
| - { "sudan", "sd" },
|
| - { "suriname", "sr" },
|
| - { "svalbard and jan mayen", "sj" },
|
| - { "swaziland", "sz" },
|
| - { "sweden", "se" },
|
| - { "switzerland", "ch" },
|
| - { "syria", "sy" },
|
| - { "taiwan", "tw" },
|
| - { "tajikistan", "tj" },
|
| - { "tanzania", "tz" },
|
| - { "thailand", "th" },
|
| - { "timor-leste", "tl" },
|
| - { "togo", "tg" },
|
| - { "tokelau", "tk" },
|
| - { "tonga", "to" },
|
| - { "trinidad and tobago", "tt" },
|
| - { "tunisia", "tn" },
|
| - { "turkey", "tr" },
|
| - { "turkmenistan", "tm" },
|
| - { "turks and caicos islands", "tc" },
|
| - { "tuvalu", "tv" },
|
| - { "uganda", "ug" },
|
| - { "ukraine", "ua" },
|
| - { "united arab emirates", "ae" },
|
| - { "united kingdom", "gb" },
|
| - { "u.s. minor outlying islands", "um" },
|
| - { "uruguay", "uy" },
|
| - { "uzbekistan", "uz" },
|
| - { "vanuatu", "vu" },
|
| - { "venezuela", "ve" },
|
| - { "vietnam", "vn" },
|
| - { "virgin islands, british", "vg" },
|
| - { "virgin islands, u.s.", "vi" },
|
| - { "wallis and futuna", "wf" },
|
| - { "western sahara", "eh" },
|
| - { "yemen", "ye" },
|
| - { "zambia", "zm" },
|
| - { "zimbabwe", "zw" },
|
| - { NULL, NULL }
|
| -};
|
| -
|
| -string16 Country::Abbreviation(const string16& name) {
|
| - for (const Country *s = all_countries ; s->name ; ++s)
|
| - if (LowerCaseEqualsASCII(name, s->name))
|
| - return ASCIIToUTF16(s->abbreviation);
|
| - return string16();
|
| -}
|
| -
|
| -string16 Country::FullName(const string16& abbreviation) {
|
| - for (const Country *s = all_countries ; s->name ; ++s)
|
| - if (LowerCaseEqualsASCII(abbreviation, s->abbreviation))
|
| - return ASCIIToUTF16(s->name);
|
| - return string16();
|
| -}
|
| -
|
| const char* const kMonthsAbbreviated[] = {
|
| NULL, // Padding so index 1 = month 1 = January.
|
| "Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
| @@ -410,9 +138,6 @@ bool SetSelectControlValue(const string16& value,
|
|
|
| bool FillStateSelectControl(const string16& value,
|
| webkit_glue::FormField* field) {
|
| - if (value.empty())
|
| - return false;
|
| -
|
| string16 abbrev, full;
|
| if (value.size() < 4U) {
|
| abbrev = value;
|
| @@ -432,38 +157,30 @@ bool FillStateSelectControl(const string16& value,
|
| return SetSelectControlValue(full, field);
|
| }
|
|
|
| -bool FillCountrySelectControl(const string16& value,
|
| +bool FillCountrySelectControl(const FormGroup& form_group,
|
| webkit_glue::FormField* field) {
|
| - if (value.empty())
|
| - return false;
|
| + const AutoFillProfile& profile =
|
| + static_cast<const AutoFillProfile&>(form_group);
|
| + std::string country_code = profile.CountryCode();
|
| + std::string app_locale = AutoFillCountry::ApplicationLocale();
|
|
|
| - string16 abbrev, full;
|
| - if (value.size() < 4U) {
|
| - abbrev = value;
|
| - full = Country::FullName(value);
|
| - } else {
|
| - abbrev = Country::Abbreviation(value);
|
| - full = value;
|
| + for (std::vector<string16>::const_iterator iter =
|
| + field->option_strings().begin();
|
| + iter != field->option_strings().end();
|
| + ++iter) {
|
| + // Canonicalize each <option> value to a country code, and compare to the
|
| + // target country code.
|
| + if (country_code == AutoFillCountry::GetCountryCode(*iter, app_locale)) {
|
| + field->set_value(*iter);
|
| + return true;
|
| + }
|
| }
|
|
|
| - // Try the abbreviation name first.
|
| - if (!abbrev.empty() && SetSelectControlValue(abbrev, field))
|
| - return true;
|
| -
|
| - if (full.empty())
|
| - return false;
|
| -
|
| - return SetSelectControlValue(full, field);
|
| + return false;
|
| }
|
|
|
| bool FillExpirationMonthSelectControl(const string16& value,
|
| webkit_glue::FormField* field) {
|
| - if (value.empty())
|
| - return false;
|
| -
|
| - if (SetSelectControlValue(value, field))
|
| - return true;
|
| -
|
| int index = 0;
|
| if (!base::StringToInt(value, &index) ||
|
| index <= 0 ||
|
| @@ -487,8 +204,11 @@ void FillSelectControl(const FormGroup& form_group,
|
| DCHECK(field);
|
| DCHECK_EQ(field->form_control_type(), ASCIIToUTF16("select-one"));
|
|
|
| - string16 value;
|
| string16 field_text = form_group.GetFieldText(type);
|
| + if (field_text.empty())
|
| + return;
|
| +
|
| + string16 value;
|
| for (size_t i = 0; i < field->option_strings().size(); ++i) {
|
| if (field_text == field->option_strings()[i]) {
|
| // An exact match, use it.
|
| @@ -514,7 +234,7 @@ void FillSelectControl(const FormGroup& form_group,
|
| FillStateSelectControl(field_text, field);
|
| } else if (type.field_type() == ADDRESS_HOME_COUNTRY ||
|
| type.field_type() == ADDRESS_BILLING_COUNTRY) {
|
| - FillCountrySelectControl(field_text, field);
|
| + FillCountrySelectControl(form_group, field);
|
| } else if (type.field_type() == CREDIT_CARD_EXP_MONTH) {
|
| FillExpirationMonthSelectControl(field_text, field);
|
| }
|
|
|