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

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

Issue 1308363003: Revert of jni_generator: Make all object-returning natives return ScopedJavaLocalRef. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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
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"
(...skipping 28 matching lines...) Expand all
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 ScopedJavaLocalRef<jstring> GetDefaultCountryCode(JNIEnv* env, 49 static 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); 54 return ConvertUTF8ToJavaString(env, default_country_code).Release();
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 ScopedJavaLocalRef<jstring> GetAddressUiComponents( 84 static jstring GetAddressUiComponents(JNIEnv* env,
85 JNIEnv* env, 85 jclass clazz,
86 jclass clazz, 86 jstring j_country_code,
87 jstring j_country_code, 87 jstring j_language_code,
88 jstring j_language_code, 88 jobject j_id_list,
89 jobject j_id_list, 89 jobject j_name_list) {
90 jobject j_name_list) {
91 std::string best_language_tag; 90 std::string best_language_tag;
92 std::vector<int> component_ids; 91 std::vector<int> component_ids;
93 std::vector<std::string> component_labels; 92 std::vector<std::string> component_labels;
94 ::i18n::addressinput::Localization localization; 93 ::i18n::addressinput::Localization localization;
95 localization.SetGetter(l10n_util::GetStringUTF8); 94 localization.SetGetter(l10n_util::GetStringUTF8);
96 95
97 std::string language_code; 96 std::string language_code;
98 if (j_language_code != NULL) { 97 if (j_language_code != NULL) {
99 language_code = ConvertJavaStringToUTF8(env, j_language_code); 98 language_code = ConvertJavaStringToUTF8(env, j_language_code);
100 } 99 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 144
146 Java_AutofillProfileBridge_intArrayToList(env, 145 Java_AutofillProfileBridge_intArrayToList(env,
147 ToJavaIntArray( 146 ToJavaIntArray(
148 env, component_ids).obj(), 147 env, component_ids).obj(),
149 j_id_list); 148 j_id_list);
150 Java_AutofillProfileBridge_stringArrayToList(env, 149 Java_AutofillProfileBridge_stringArrayToList(env,
151 ToJavaArrayOfStrings( 150 ToJavaArrayOfStrings(
152 env, component_labels).obj(), 151 env, component_labels).obj(),
153 j_name_list); 152 j_name_list);
154 153
155 return ConvertUTF8ToJavaString(env, best_language_tag); 154 return ConvertUTF8ToJavaString(env, best_language_tag).Release();
156 } 155 }
157 156
158 // static 157 // static
159 bool RegisterAutofillProfileBridge(JNIEnv* env) { 158 bool RegisterAutofillProfileBridge(JNIEnv* env) {
160 return RegisterNativesImpl(env); 159 return RegisterNativesImpl(env);
161 } 160 }
162 161
163 } // namespace autofill 162 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/android/password_ui_view_android.cc ('k') | chrome/browser/android/preferences/pref_service_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698