Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: chrome/browser/android/preferences/autofill/autofill_profile_bridge.cc

Issue 952993003: [android] Handle unknown country codes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: known_country_names Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_country.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/android/preferences/autofill/autofill_profile_bridge.h" 5 #include "chrome/browser/android/preferences/autofill/autofill_profile_bridge.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
11 #include "base/android/jni_string.h" 11 #include "base/android/jni_string.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
14 #include "components/autofill/core/browser/autofill_country.h" 15 #include "components/autofill/core/browser/autofill_country.h"
15 #include "jni/AutofillProfileBridge_jni.h" 16 #include "jni/AutofillProfileBridge_jni.h"
16 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui .h" 17 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui .h"
17 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui _component.h" 18 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui _component.h"
18 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/localizati on.h" 19 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/localizati on.h"
19 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
20 21
21 using base::android::ConvertJavaStringToUTF8; 22 using base::android::ConvertJavaStringToUTF8;
22 using base::android::ConvertUTF8ToJavaString; 23 using base::android::ConvertUTF8ToJavaString;
(...skipping 29 matching lines...) Expand all
52 g_browser_process->GetApplicationLocale()); 53 g_browser_process->GetApplicationLocale());
53 return ConvertUTF8ToJavaString(env, default_country_code).Release(); 54 return ConvertUTF8ToJavaString(env, default_country_code).Release();
54 } 55 }
55 56
56 static void GetSupportedCountries(JNIEnv* env, 57 static void GetSupportedCountries(JNIEnv* env,
57 jclass clazz, 58 jclass clazz,
58 jobject j_country_code_list, 59 jobject j_country_code_list,
59 jobject j_country_name_list) { 60 jobject j_country_name_list) {
60 std::vector<std::string> country_codes = 61 std::vector<std::string> country_codes =
61 ::i18n::addressinput::GetRegionCodes(); 62 ::i18n::addressinput::GetRegionCodes();
62 std::vector<base::string16> country_names; 63 std::vector<std::string> known_country_codes;
64 std::vector<base::string16> known_country_names;
63 std::string locale = g_browser_process->GetApplicationLocale(); 65 std::string locale = g_browser_process->GetApplicationLocale();
64 for (auto country_code : country_codes) { 66 for (auto country_code : country_codes) {
65 country_names.push_back(l10n_util::GetDisplayNameForCountry(country_code, 67 const base::string16& country_name =
66 locale)); 68 l10n_util::GetDisplayNameForCountry(country_code, locale);
69 // Don't display a country code for which a name is not known yet.
70 if (country_name != base::UTF8ToUTF16(country_code)) {
71 known_country_codes.push_back(country_code);
72 known_country_names.push_back(country_name);
73 }
67 } 74 }
68 75
69 Java_AutofillProfileBridge_stringArrayToList(env, 76 Java_AutofillProfileBridge_stringArrayToList(
70 ToJavaArrayOfStrings( 77 env, ToJavaArrayOfStrings(env, known_country_codes).obj(),
71 env, country_codes).obj(), 78 j_country_code_list);
72 j_country_code_list); 79 Java_AutofillProfileBridge_stringArrayToList(
73 Java_AutofillProfileBridge_stringArrayToList(env, 80 env, ToJavaArrayOfStrings(env, known_country_names).obj(),
74 ToJavaArrayOfStrings( 81 j_country_name_list);
75 env, country_names).obj(),
76 j_country_name_list);
77 } 82 }
78 83
79 static jstring GetAddressUiComponents(JNIEnv* env, 84 static jstring GetAddressUiComponents(JNIEnv* env,
80 jclass clazz, 85 jclass clazz,
81 jstring j_country_code, 86 jstring j_country_code,
82 jstring j_language_code, 87 jstring j_language_code,
83 jobject j_id_list, 88 jobject j_id_list,
84 jobject j_name_list) { 89 jobject j_name_list) {
85 std::string best_language_tag; 90 std::string best_language_tag;
86 std::vector<int> component_ids; 91 std::vector<int> component_ids;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 153
149 return ConvertUTF8ToJavaString(env, best_language_tag).Release(); 154 return ConvertUTF8ToJavaString(env, best_language_tag).Release();
150 } 155 }
151 156
152 // static 157 // static
153 bool RegisterAutofillProfileBridge(JNIEnv* env) { 158 bool RegisterAutofillProfileBridge(JNIEnv* env) {
154 return RegisterNativesImpl(env); 159 return RegisterNativesImpl(env);
155 } 160 }
156 161
157 } // namespace autofill 162 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_country.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698