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 29 matching lines...) Expand all Loading... |
40 POSTAL_CODE, // Zip or postal code. | 40 POSTAL_CODE, // Zip or postal code. |
41 STREET_ADDRESS, // Street address lines. | 41 STREET_ADDRESS, // Street address lines. |
42 ORGANIZATION, // Organization, company, firm, institution, etc. | 42 ORGANIZATION, // Organization, company, firm, institution, etc. |
43 RECIPIENT // Name. | 43 RECIPIENT // Name. |
44 }; | 44 }; |
45 | 45 |
46 } // namespace | 46 } // namespace |
47 | 47 |
48 static jstring GetDefaultCountryCode(JNIEnv* env, | 48 static jstring GetDefaultCountryCode(JNIEnv* env, |
49 jclass clazz) { | 49 jclass clazz) { |
50 std::string defaultCountryCode = | 50 std::string default_country_code = |
51 autofill::AutofillCountry::CountryCodeForLocale( | 51 autofill::AutofillCountry::CountryCodeForLocale( |
52 g_browser_process->GetApplicationLocale()); | 52 g_browser_process->GetApplicationLocale()); |
53 return ConvertUTF8ToJavaString(env, defaultCountryCode).Release(); | 53 return ConvertUTF8ToJavaString(env, default_country_code).Release(); |
54 } | 54 } |
55 | 55 |
56 static void GetSupportedCountries(JNIEnv* env, | 56 static void GetSupportedCountries(JNIEnv* env, |
57 jclass clazz, | 57 jclass clazz, |
58 jobject j_country_code_list, | 58 jobject j_country_code_list, |
59 jobject j_country_name_list) { | 59 jobject j_country_name_list) { |
60 std::vector<std::string> country_codes = | 60 std::vector<std::string> country_codes = |
61 ::i18n::addressinput::GetRegionCodes(); | 61 ::i18n::addressinput::GetRegionCodes(); |
62 std::vector<base::string16> country_names; | 62 std::vector<base::string16> country_names; |
63 std::string locale = g_browser_process->GetApplicationLocale(); | 63 std::string locale = g_browser_process->GetApplicationLocale(); |
64 for (auto country_code : country_codes) { | 64 for (auto country_code : country_codes) { |
65 country_names.push_back(l10n_util::GetDisplayNameForCountry(country_code, | 65 country_names.push_back(l10n_util::GetDisplayNameForCountry(country_code, |
66 locale)); | 66 locale)); |
67 } | 67 } |
68 | 68 |
69 Java_AutofillProfileBridge_stringArrayToList(env, | 69 Java_AutofillProfileBridge_stringArrayToList(env, |
70 ToJavaArrayOfStrings( | 70 ToJavaArrayOfStrings( |
71 env, country_codes).obj(), | 71 env, country_codes).obj(), |
72 j_country_code_list); | 72 j_country_code_list); |
73 Java_AutofillProfileBridge_stringArrayToList(env, | 73 Java_AutofillProfileBridge_stringArrayToList(env, |
74 ToJavaArrayOfStrings( | 74 ToJavaArrayOfStrings( |
75 env, country_names).obj(), | 75 env, country_names).obj(), |
76 j_country_name_list); | 76 j_country_name_list); |
77 } | 77 } |
78 | 78 |
79 static void GetAddressUiComponents(JNIEnv* env, | 79 static jstring GetAddressUiComponents(JNIEnv* env, |
80 jclass clazz, | 80 jclass clazz, |
81 jstring j_country_code, | 81 jstring j_country_code, |
| 82 jstring j_language_code, |
82 jobject j_id_list, | 83 jobject j_id_list, |
83 jobject j_name_list) { | 84 jobject j_name_list) { |
84 std::string best_language_tag; | 85 std::string best_language_tag; |
85 std::vector<int> component_ids; | 86 std::vector<int> component_ids; |
86 std::vector<std::string> component_labels; | 87 std::vector<std::string> component_labels; |
87 ::i18n::addressinput::Localization localization; | 88 ::i18n::addressinput::Localization localization; |
88 localization.SetGetter(l10n_util::GetStringUTF8); | 89 localization.SetGetter(l10n_util::GetStringUTF8); |
89 | 90 |
| 91 std::string language_code; |
| 92 if (j_language_code != NULL) { |
| 93 language_code = ConvertJavaStringToUTF8(env, j_language_code); |
| 94 } |
| 95 if (language_code.empty()) { |
| 96 language_code = g_browser_process->GetApplicationLocale(); |
| 97 } |
| 98 |
90 std::vector<::i18n::addressinput::AddressUiComponent> ui_components = | 99 std::vector<::i18n::addressinput::AddressUiComponent> ui_components = |
91 ::i18n::addressinput::BuildComponents( | 100 ::i18n::addressinput::BuildComponents( |
92 ConvertJavaStringToUTF8(env, j_country_code), localization, | 101 ConvertJavaStringToUTF8(env, j_country_code), localization, |
93 g_browser_process->GetApplicationLocale(), &best_language_tag); | 102 language_code, &best_language_tag); |
94 | 103 |
95 for (auto ui_component : ui_components) { | 104 for (auto ui_component : ui_components) { |
96 component_labels.push_back(ui_component.name); | 105 component_labels.push_back(ui_component.name); |
97 | 106 |
98 switch (ui_component.field) { | 107 switch (ui_component.field) { |
99 case ::i18n::addressinput::COUNTRY: | 108 case ::i18n::addressinput::COUNTRY: |
100 component_ids.push_back(AddressField::COUNTRY); | 109 component_ids.push_back(AddressField::COUNTRY); |
101 break; | 110 break; |
102 case ::i18n::addressinput::ADMIN_AREA: | 111 case ::i18n::addressinput::ADMIN_AREA: |
103 component_ids.push_back(AddressField::ADMIN_AREA); | 112 component_ids.push_back(AddressField::ADMIN_AREA); |
(...skipping 25 matching lines...) Expand all Loading... |
129 } | 138 } |
130 | 139 |
131 Java_AutofillProfileBridge_intArrayToList(env, | 140 Java_AutofillProfileBridge_intArrayToList(env, |
132 ToJavaIntArray( | 141 ToJavaIntArray( |
133 env, component_ids).obj(), | 142 env, component_ids).obj(), |
134 j_id_list); | 143 j_id_list); |
135 Java_AutofillProfileBridge_stringArrayToList(env, | 144 Java_AutofillProfileBridge_stringArrayToList(env, |
136 ToJavaArrayOfStrings( | 145 ToJavaArrayOfStrings( |
137 env, component_labels).obj(), | 146 env, component_labels).obj(), |
138 j_name_list); | 147 j_name_list); |
| 148 |
| 149 return ConvertUTF8ToJavaString(env, best_language_tag).Release(); |
139 } | 150 } |
140 | 151 |
141 // static | 152 // static |
142 bool RegisterAutofillProfileBridge(JNIEnv* env) { | 153 bool RegisterAutofillProfileBridge(JNIEnv* env) { |
143 return RegisterNativesImpl(env); | 154 return RegisterNativesImpl(env); |
144 } | 155 } |
145 | 156 |
146 } // namespace autofill | 157 } // namespace autofill |
OLD | NEW |