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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 const base::string16& country_name = | 60 const base::string16& country_name = |
61 l10n_util::GetDisplayNameForCountry(country_code, locale); | 61 l10n_util::GetDisplayNameForCountry(country_code, locale); |
62 // Don't display a country code for which a name is not known yet. | 62 // Don't display a country code for which a name is not known yet. |
63 if (country_name != base::UTF8ToUTF16(country_code)) { | 63 if (country_name != base::UTF8ToUTF16(country_code)) { |
64 known_country_codes.push_back(country_code); | 64 known_country_codes.push_back(country_code); |
65 known_country_names.push_back(country_name); | 65 known_country_names.push_back(country_name); |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 Java_AutofillProfileBridge_stringArrayToList( | 69 Java_AutofillProfileBridge_stringArrayToList( |
70 env, ToJavaArrayOfStrings(env, known_country_codes).obj(), | 70 env, ToJavaArrayOfStrings(env, known_country_codes), j_country_code_list); |
71 j_country_code_list); | |
72 Java_AutofillProfileBridge_stringArrayToList( | 71 Java_AutofillProfileBridge_stringArrayToList( |
73 env, ToJavaArrayOfStrings(env, known_country_names).obj(), | 72 env, ToJavaArrayOfStrings(env, known_country_names), j_country_name_list); |
74 j_country_name_list); | |
75 } | 73 } |
76 | 74 |
77 static void GetRequiredFields( | 75 static void GetRequiredFields( |
78 JNIEnv* env, | 76 JNIEnv* env, |
79 const JavaParamRef<jclass>& clazz, | 77 const JavaParamRef<jclass>& clazz, |
80 const JavaParamRef<jstring>& j_country_code, | 78 const JavaParamRef<jstring>& j_country_code, |
81 const JavaParamRef<jobject>& j_required_fields_list) { | 79 const JavaParamRef<jobject>& j_required_fields_list) { |
82 std::string country_code = ConvertJavaStringToUTF8(env, j_country_code); | 80 std::string country_code = ConvertJavaStringToUTF8(env, j_country_code); |
83 std::vector<int> required; | 81 std::vector<int> required; |
84 | 82 |
85 // Should iterate over all fields in: | 83 // Should iterate over all fields in: |
86 // third_party/libaddressinput/src/cpp/include/libaddressinput/address_field.h | 84 // third_party/libaddressinput/src/cpp/include/libaddressinput/address_field.h |
87 for (int i = COUNTRY; i <= RECIPIENT; ++i) { | 85 for (int i = COUNTRY; i <= RECIPIENT; ++i) { |
88 AddressField field = static_cast<AddressField>(i); | 86 AddressField field = static_cast<AddressField>(i); |
89 if (IsFieldRequired(field, country_code)) { | 87 if (IsFieldRequired(field, country_code)) { |
90 required.push_back(field); | 88 required.push_back(field); |
91 } | 89 } |
92 } | 90 } |
93 | 91 |
94 Java_AutofillProfileBridge_intArrayToList( | 92 Java_AutofillProfileBridge_intArrayToList(env, ToJavaIntArray(env, required), |
95 env, ToJavaIntArray(env, required).obj(), j_required_fields_list); | 93 j_required_fields_list); |
96 } | 94 } |
97 | 95 |
98 static ScopedJavaLocalRef<jstring> GetAddressUiComponents( | 96 static ScopedJavaLocalRef<jstring> GetAddressUiComponents( |
99 JNIEnv* env, | 97 JNIEnv* env, |
100 const JavaParamRef<jclass>& clazz, | 98 const JavaParamRef<jclass>& clazz, |
101 const JavaParamRef<jstring>& j_country_code, | 99 const JavaParamRef<jstring>& j_country_code, |
102 const JavaParamRef<jstring>& j_language_code, | 100 const JavaParamRef<jstring>& j_language_code, |
103 const JavaParamRef<jobject>& j_id_list, | 101 const JavaParamRef<jobject>& j_id_list, |
104 const JavaParamRef<jobject>& j_name_list, | 102 const JavaParamRef<jobject>& j_name_list, |
105 const JavaParamRef<jobject>& j_required_list, | 103 const JavaParamRef<jobject>& j_required_list, |
(...skipping 21 matching lines...) Expand all Loading... |
127 for (const auto& ui_component : ui_components) { | 125 for (const auto& ui_component : ui_components) { |
128 component_labels.push_back(ui_component.name); | 126 component_labels.push_back(ui_component.name); |
129 component_required.push_back( | 127 component_required.push_back( |
130 IsFieldRequired(ui_component.field, country_code)); | 128 IsFieldRequired(ui_component.field, country_code)); |
131 component_length.push_back(ui_component.length_hint == | 129 component_length.push_back(ui_component.length_hint == |
132 AddressUiComponent::HINT_LONG); | 130 AddressUiComponent::HINT_LONG); |
133 component_ids.push_back(ui_component.field); | 131 component_ids.push_back(ui_component.field); |
134 } | 132 } |
135 | 133 |
136 Java_AutofillProfileBridge_intArrayToList( | 134 Java_AutofillProfileBridge_intArrayToList( |
137 env, ToJavaIntArray(env, component_ids).obj(), j_id_list); | 135 env, ToJavaIntArray(env, component_ids), j_id_list); |
138 Java_AutofillProfileBridge_stringArrayToList( | 136 Java_AutofillProfileBridge_stringArrayToList( |
139 env, ToJavaArrayOfStrings(env, component_labels).obj(), j_name_list); | 137 env, ToJavaArrayOfStrings(env, component_labels), j_name_list); |
140 Java_AutofillProfileBridge_intArrayToList( | 138 Java_AutofillProfileBridge_intArrayToList( |
141 env, ToJavaIntArray(env, component_required).obj(), j_required_list); | 139 env, ToJavaIntArray(env, component_required), j_required_list); |
142 Java_AutofillProfileBridge_intArrayToList( | 140 Java_AutofillProfileBridge_intArrayToList( |
143 env, ToJavaIntArray(env, component_length).obj(), j_length_list); | 141 env, ToJavaIntArray(env, component_length), j_length_list); |
144 | 142 |
145 return ConvertUTF8ToJavaString(env, best_language_tag); | 143 return ConvertUTF8ToJavaString(env, best_language_tag); |
146 } | 144 } |
147 | 145 |
148 // static | 146 // static |
149 bool RegisterAutofillProfileBridge(JNIEnv* env) { | 147 bool RegisterAutofillProfileBridge(JNIEnv* env) { |
150 return RegisterNativesImpl(env); | 148 return RegisterNativesImpl(env); |
151 } | 149 } |
152 | 150 |
153 } // namespace autofill | 151 } // namespace autofill |
OLD | NEW |