Index: chrome/browser/android/preferences/autofill/autofill_profile_bridge.cc |
diff --git a/chrome/browser/android/preferences/autofill/autofill_profile_bridge.cc b/chrome/browser/android/preferences/autofill/autofill_profile_bridge.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..adc2e19aa16297c54c352ac197776b1552ee47a4 |
--- /dev/null |
+++ b/chrome/browser/android/preferences/autofill/autofill_profile_bridge.cc |
@@ -0,0 +1,75 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/android/preferences/autofill/autofill_profile_bridge.h" |
+ |
+#include <jni.h> |
+ |
+#include "base/android/jni_android.h" |
+#include "base/android/jni_array.h" |
+#include "base/android/jni_string.h" |
+#include "base/bind.h" |
+#include "jni/AutofillProfileBridge_jni.h" |
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui.h" |
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui_component.h" |
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/localization.h" |
+#include "ui/base/l10n/l10n_util.h" |
+ |
+using base::android::ConvertJavaStringToUTF8; |
+using base::android::ToJavaArrayOfStrings; |
+using base::android::ToJavaIntArray; |
+ |
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,
|
+static void GetAvailableCountries(JNIEnv* env, |
+ jclass clazz, |
+ jobject j_country_list) { |
+ std::vector<std::string> region_codes = |
+ ::i18n::addressinput::GetRegionCodes(); |
+ Java_AutofillProfileBridge_stringArrayToList(env, |
+ ToJavaArrayOfStrings( |
+ env, region_codes).obj(), |
+ j_country_list); |
+} |
+ |
+static void GetAddressUiComponents(JNIEnv* env, |
+ jclass clazz, |
+ jstring j_country_code, |
+ jstring j_language_tag, |
+ jobject j_id_list, |
+ jobject j_name_list) { |
+ std::string best_language_tag; |
+ std::string language_code; |
+ std::vector<int> component_ids; |
+ std::vector<std::string> component_labels; |
+ ::i18n::addressinput::Localization localization; |
+ localization.SetGetter(l10n_util::GetStringUTF8); |
+ |
+ // Format ui_langage_tag by replacing _'s with -'s. The Java strings coming |
+ // 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
|
+ std::string language_tag = ConvertJavaStringToUTF8(env, j_language_tag); |
+ std::replace(language_tag.begin(), language_tag.end(), '_', '-'); |
+ |
+ std::vector<::i18n::addressinput::AddressUiComponent> ui_components = |
+ ::i18n::addressinput::BuildComponents( |
+ ConvertJavaStringToUTF8(env, j_country_code), localization, |
+ language_tag, &best_language_tag); |
+ |
+ for (auto ui_component : ui_components) { |
+ component_ids.push_back(ui_component.field); |
+ component_labels.push_back(ui_component.name); |
+ } |
+ |
+ Java_AutofillProfileBridge_intArrayToList(env, |
+ ToJavaIntArray( |
+ env, component_ids).obj(), |
+ j_id_list); |
+ Java_AutofillProfileBridge_stringArrayToList(env, |
+ ToJavaArrayOfStrings( |
+ env, component_labels).obj(), |
+ j_name_list); |
+} |
+ |
+// static |
+bool RegisterAutofillProfileBridge(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |