OLD | NEW |
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" |
(...skipping 28 matching lines...) Expand all Loading... |
39 // a suburb). | 39 // a suburb). |
40 SORTING_CODE, // Sorting code. | 40 SORTING_CODE, // Sorting code. |
41 POSTAL_CODE, // Zip or postal code. | 41 POSTAL_CODE, // Zip or postal code. |
42 STREET_ADDRESS, // Street address lines. | 42 STREET_ADDRESS, // Street address lines. |
43 ORGANIZATION, // Organization, company, firm, institution, etc. | 43 ORGANIZATION, // Organization, company, firm, institution, etc. |
44 RECIPIENT // Name. | 44 RECIPIENT // Name. |
45 }; | 45 }; |
46 | 46 |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 static jstring GetDefaultCountryCode(JNIEnv* env, | 49 static ScopedJavaLocalRef<jstring> GetDefaultCountryCode(JNIEnv* env, |
50 jclass clazz) { | 50 jclass clazz) { |
51 std::string default_country_code = | 51 std::string default_country_code = |
52 autofill::AutofillCountry::CountryCodeForLocale( | 52 autofill::AutofillCountry::CountryCodeForLocale( |
53 g_browser_process->GetApplicationLocale()); | 53 g_browser_process->GetApplicationLocale()); |
54 return ConvertUTF8ToJavaString(env, default_country_code).Release(); | 54 return ConvertUTF8ToJavaString(env, default_country_code); |
55 } | 55 } |
56 | 56 |
57 static void GetSupportedCountries(JNIEnv* env, | 57 static void GetSupportedCountries(JNIEnv* env, |
58 jclass clazz, | 58 jclass clazz, |
59 jobject j_country_code_list, | 59 jobject j_country_code_list, |
60 jobject j_country_name_list) { | 60 jobject j_country_name_list) { |
61 std::vector<std::string> country_codes = | 61 std::vector<std::string> country_codes = |
62 ::i18n::addressinput::GetRegionCodes(); | 62 ::i18n::addressinput::GetRegionCodes(); |
63 std::vector<std::string> known_country_codes; | 63 std::vector<std::string> known_country_codes; |
64 std::vector<base::string16> known_country_names; | 64 std::vector<base::string16> known_country_names; |
65 std::string locale = g_browser_process->GetApplicationLocale(); | 65 std::string locale = g_browser_process->GetApplicationLocale(); |
66 for (auto country_code : country_codes) { | 66 for (auto country_code : country_codes) { |
67 const base::string16& country_name = | 67 const base::string16& country_name = |
68 l10n_util::GetDisplayNameForCountry(country_code, locale); | 68 l10n_util::GetDisplayNameForCountry(country_code, locale); |
69 // Don't display a country code for which a name is not known yet. | 69 // Don't display a country code for which a name is not known yet. |
70 if (country_name != base::UTF8ToUTF16(country_code)) { | 70 if (country_name != base::UTF8ToUTF16(country_code)) { |
71 known_country_codes.push_back(country_code); | 71 known_country_codes.push_back(country_code); |
72 known_country_names.push_back(country_name); | 72 known_country_names.push_back(country_name); |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 Java_AutofillProfileBridge_stringArrayToList( | 76 Java_AutofillProfileBridge_stringArrayToList( |
77 env, ToJavaArrayOfStrings(env, known_country_codes).obj(), | 77 env, ToJavaArrayOfStrings(env, known_country_codes).obj(), |
78 j_country_code_list); | 78 j_country_code_list); |
79 Java_AutofillProfileBridge_stringArrayToList( | 79 Java_AutofillProfileBridge_stringArrayToList( |
80 env, ToJavaArrayOfStrings(env, known_country_names).obj(), | 80 env, ToJavaArrayOfStrings(env, known_country_names).obj(), |
81 j_country_name_list); | 81 j_country_name_list); |
82 } | 82 } |
83 | 83 |
84 static jstring GetAddressUiComponents(JNIEnv* env, | 84 static ScopedJavaLocalRef<jstring> GetAddressUiComponents( |
85 jclass clazz, | 85 JNIEnv* env, |
86 jstring j_country_code, | 86 jclass clazz, |
87 jstring j_language_code, | 87 jstring j_country_code, |
88 jobject j_id_list, | 88 jstring j_language_code, |
89 jobject j_name_list) { | 89 jobject j_id_list, |
| 90 jobject j_name_list) { |
90 std::string best_language_tag; | 91 std::string best_language_tag; |
91 std::vector<int> component_ids; | 92 std::vector<int> component_ids; |
92 std::vector<std::string> component_labels; | 93 std::vector<std::string> component_labels; |
93 ::i18n::addressinput::Localization localization; | 94 ::i18n::addressinput::Localization localization; |
94 localization.SetGetter(l10n_util::GetStringUTF8); | 95 localization.SetGetter(l10n_util::GetStringUTF8); |
95 | 96 |
96 std::string language_code; | 97 std::string language_code; |
97 if (j_language_code != NULL) { | 98 if (j_language_code != NULL) { |
98 language_code = ConvertJavaStringToUTF8(env, j_language_code); | 99 language_code = ConvertJavaStringToUTF8(env, j_language_code); |
99 } | 100 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 145 |
145 Java_AutofillProfileBridge_intArrayToList(env, | 146 Java_AutofillProfileBridge_intArrayToList(env, |
146 ToJavaIntArray( | 147 ToJavaIntArray( |
147 env, component_ids).obj(), | 148 env, component_ids).obj(), |
148 j_id_list); | 149 j_id_list); |
149 Java_AutofillProfileBridge_stringArrayToList(env, | 150 Java_AutofillProfileBridge_stringArrayToList(env, |
150 ToJavaArrayOfStrings( | 151 ToJavaArrayOfStrings( |
151 env, component_labels).obj(), | 152 env, component_labels).obj(), |
152 j_name_list); | 153 j_name_list); |
153 | 154 |
154 return ConvertUTF8ToJavaString(env, best_language_tag).Release(); | 155 return ConvertUTF8ToJavaString(env, best_language_tag); |
155 } | 156 } |
156 | 157 |
157 // static | 158 // static |
158 bool RegisterAutofillProfileBridge(JNIEnv* env) { | 159 bool RegisterAutofillProfileBridge(JNIEnv* env) { |
159 return RegisterNativesImpl(env); | 160 return RegisterNativesImpl(env); |
160 } | 161 } |
161 | 162 |
162 } // namespace autofill | 163 } // namespace autofill |
OLD | NEW |