Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
[android] Handle unknown country codes.
Browse files Browse the repository at this point in the history
Don't show "Kosovo" (country code "XK") as an autofill country name
option on K devices, because K devices are not aware of it.

Add "XK" to the list of autofill countries to enable saving autofill
profiles with country name "Kosovo."

BUG=456246

Review URL: https://codereview.chromium.org/952993003

Cr-Commit-Position: refs/heads/master@{#318103}
  • Loading branch information
rsolomakhin authored and Commit bot committed Feb 25, 2015
1 parent 8cd63f8 commit 6dbf9a7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "base/bind.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "components/autofill/core/browser/autofill_country.h"
#include "jni/AutofillProfileBridge_jni.h"
Expand Down Expand Up @@ -59,21 +60,25 @@ static void GetSupportedCountries(JNIEnv* env,
jobject j_country_name_list) {
std::vector<std::string> country_codes =
::i18n::addressinput::GetRegionCodes();
std::vector<base::string16> country_names;
std::vector<std::string> known_country_codes;
std::vector<base::string16> known_country_names;
std::string locale = g_browser_process->GetApplicationLocale();
for (auto country_code : country_codes) {
country_names.push_back(l10n_util::GetDisplayNameForCountry(country_code,
locale));
const base::string16& country_name =
l10n_util::GetDisplayNameForCountry(country_code, locale);
// Don't display a country code for which a name is not known yet.
if (country_name != base::UTF8ToUTF16(country_code)) {
known_country_codes.push_back(country_code);
known_country_names.push_back(country_name);
}
}

Java_AutofillProfileBridge_stringArrayToList(env,
ToJavaArrayOfStrings(
env, country_codes).obj(),
j_country_code_list);
Java_AutofillProfileBridge_stringArrayToList(env,
ToJavaArrayOfStrings(
env, country_names).obj(),
j_country_name_list);
Java_AutofillProfileBridge_stringArrayToList(
env, ToJavaArrayOfStrings(env, known_country_codes).obj(),
j_country_code_list);
Java_AutofillProfileBridge_stringArrayToList(
env, ToJavaArrayOfStrings(env, known_country_names).obj(),
j_country_name_list);
}

static jstring GetAddressUiComponents(JNIEnv* env,
Expand Down
3 changes: 3 additions & 0 deletions components/autofill/core/browser/autofill_country.cc
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,9 @@ const StaticCountryData kCountryData[] = {
{ "WS", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE,
IDS_AUTOFILL_FIELD_LABEL_PROVINCE,
ADDRESS_REQUIREMENTS_UNKNOWN } },
{ "XK", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE,
IDS_AUTOFILL_FIELD_LABEL_PROVINCE,
ADDRESS_REQUIRES_CITY } },
{ "YE", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE,
IDS_AUTOFILL_FIELD_LABEL_PROVINCE,
ADDRESS_REQUIRES_CITY } },
Expand Down

0 comments on commit 6dbf9a7

Please sign in to comment.