Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/android/preferences/autofill/autofill_profile_bridge.h" | |
| 6 | |
| 7 #include <jni.h> | |
| 8 | |
| 9 #include "base/android/jni_android.h" | |
| 10 #include "base/android/jni_array.h" | |
| 11 #include "base/android/jni_string.h" | |
| 12 #include "base/bind.h" | |
| 13 #include "jni/AutofillProfileBridge_jni.h" | |
| 14 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui .h" | |
| 15 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui _component.h" | |
| 16 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/localizati on.h" | |
| 17 #include "ui/base/l10n/l10n_util.h" | |
| 18 | |
| 19 using base::android::ConvertJavaStringToUTF8; | |
| 20 using base::android::ToJavaArrayOfStrings; | |
| 21 using base::android::ToJavaIntArray; | |
| 22 | |
|
Evan Stade
2015/01/28 03:07:47
namespace autofill
Theresa
2015/01/28 03:33:47
Re comment from newt@: consensus on chromium-dev@
Evan Stade
2015/01/29 01:07:22
The convention in autofill code in src/chrome is t
Theresa
2015/01/29 05:22:14
I am using a method from components/autofill now,
| |
| 23 static void GetAvailableCountries(JNIEnv* env, | |
| 24 jclass clazz, | |
| 25 jobject j_country_list) { | |
| 26 std::vector<std::string> region_codes = | |
| 27 ::i18n::addressinput::GetRegionCodes(); | |
| 28 Java_AutofillProfileBridge_stringArrayToList(env, | |
| 29 ToJavaArrayOfStrings( | |
| 30 env, region_codes).obj(), | |
| 31 j_country_list); | |
| 32 } | |
| 33 | |
| 34 static void GetAddressUiComponents(JNIEnv* env, | |
| 35 jclass clazz, | |
| 36 jstring j_country_code, | |
| 37 jstring j_language_tag, | |
| 38 jobject j_id_list, | |
| 39 jobject j_name_list) { | |
| 40 std::string best_language_tag; | |
| 41 std::string language_code; | |
| 42 std::vector<int> component_ids; | |
| 43 std::vector<std::string> component_labels; | |
| 44 ::i18n::addressinput::Localization localization; | |
| 45 localization.SetGetter(l10n_util::GetStringUTF8); | |
| 46 | |
| 47 // Format ui_langage_tag by replacing _'s with -'s. The Java strings coming | |
| 48 // from Android are in the format en_US and the C++ equivalent is en-US | |
|
Evan Stade
2015/01/28 03:07:47
It's not Java vs. C++. Hypens are used in the IETF
newt (away)
2015/01/28 03:15:26
Also, beware the Java's Locale.getDefault() return
Theresa
2015/01/28 03:33:47
estade@ - This string does come from Android, arou
| |
| 49 std::string language_tag = ConvertJavaStringToUTF8(env, j_language_tag); | |
| 50 std::replace(language_tag.begin(), language_tag.end(), '_', '-'); | |
| 51 | |
| 52 std::vector<::i18n::addressinput::AddressUiComponent> ui_components = | |
| 53 ::i18n::addressinput::BuildComponents( | |
| 54 ConvertJavaStringToUTF8(env, j_country_code), localization, | |
| 55 language_tag, &best_language_tag); | |
| 56 | |
| 57 for (auto ui_component : ui_components) { | |
| 58 component_ids.push_back(ui_component.field); | |
| 59 component_labels.push_back(ui_component.name); | |
| 60 } | |
| 61 | |
| 62 Java_AutofillProfileBridge_intArrayToList(env, | |
| 63 ToJavaIntArray( | |
| 64 env, component_ids).obj(), | |
| 65 j_id_list); | |
| 66 Java_AutofillProfileBridge_stringArrayToList(env, | |
| 67 ToJavaArrayOfStrings( | |
| 68 env, component_labels).obj(), | |
| 69 j_name_list); | |
| 70 } | |
| 71 | |
| 72 // static | |
| 73 bool RegisterAutofillProfileBridge(JNIEnv* env) { | |
| 74 return RegisterNativesImpl(env); | |
| 75 } | |
| OLD | NEW |