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

Unified Diff: chrome/browser/android/preferences/autofill/autofill_profile_bridge.cc

Issue 872023002: Use floating labels for preference forms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-fix findbugs Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
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..811b150c0398b6ee9fc94a8f08f8eef6fb0627c1
--- /dev/null
+++ b/chrome/browser/android/preferences/autofill/autofill_profile_bridge.cc
@@ -0,0 +1,145 @@
+// 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 "chrome/browser/browser_process.h"
+#include "components/autofill/core/browser/autofill_country.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::ConvertUTF8ToJavaString;
+using base::android::ToJavaArrayOfStrings;
+using base::android::ToJavaIntArray;
+
+namespace autofill {
+
+// Address field types, ordered by size, from largest to smallest.
+// This list must be kept in-sync with the corresponding AddressField class in
+// AutofillProfileBridge.java.
+enum AddressField {
newt (away) 2015/01/29 20:00:37 put this enum in an anonymous namespace so it can'
Evan Stade 2015/01/29 22:29:57 sorry if you already explained it, but why does th
Theresa 2015/01/29 22:31:12 Done.
Theresa 2015/01/29 22:49:42 It is duplicated. It exists because we need the ex
Evan Stade 2015/01/30 00:02:17 I think you should use ::i18n::addressinput::Addre
Theresa 2015/01/30 00:37:06 Whoever rolls libaddress could also see the build
+ COUNTRY, // Country code.
+ ADMIN_AREA, // Administrative area such as a state, province,
+ // island, etc.
+ LOCALITY, // City or locality.
+ DEPENDENT_LOCALITY, // Dependent locality (may be an inner-city district or
+ // a suburb).
+ SORTING_CODE, // Sorting code.
+ POSTAL_CODE, // Zip or postal code.
+ STREET_ADDRESS, // Street address lines.
+ ORGANIZATION, // Organization, company, firm, institution, etc.
+ RECIPIENT // Name.
+};
+
+static jstring GetDefaultCountryCode(JNIEnv* env,
+ jclass clazz) {
+ std::string defaultCountryCode =
+ autofill::AutofillCountry::CountryCodeForLocale(
+ g_browser_process->GetApplicationLocale());
+ return ConvertUTF8ToJavaString(env, defaultCountryCode).Release();
+}
+
+static void GetSupportedCountries(JNIEnv* env,
+ jclass clazz,
+ jobject j_country_code_list,
+ jobject j_country_name_list) {
+ std::vector<std::string> country_codes =
+ ::i18n::addressinput::GetRegionCodes();
+ std::vector<base::string16> country_names;
+ std::string locale = g_browser_process->GetApplicationLocale();
+ for (auto country_code : country_codes) {
+ country_names.push_back(
+ l10n_util::GetDisplayNameForCountry(country_code,
newt (away) 2015/01/29 20:00:37 one line?
Theresa 2015/01/29 22:31:12 Done.
+ locale));
+ }
+
+ Java_AutofillProfileBridge_stringArrayToList(env,
+ ToJavaArrayOfStrings(
+ env, country_codes).obj(),
+ j_country_code_list);
+ Java_AutofillProfileBridge_stringArrayToList(env,
+ ToJavaArrayOfStrings(
+ env, country_names).obj(),
+ j_country_name_list);
+}
+
+static void GetAddressUiComponents(JNIEnv* env,
+ jclass clazz,
+ jstring j_country_code,
+ jobject j_id_list,
+ jobject j_name_list) {
+ std::string best_language_tag;
+ std::string language_code;
newt (away) 2015/01/29 20:00:37 unused
Theresa 2015/01/29 22:31:12 Done.
+ std::vector<int> component_ids;
+ std::vector<std::string> component_labels;
+ ::i18n::addressinput::Localization localization;
+ localization.SetGetter(l10n_util::GetStringUTF8);
+
+ std::vector<::i18n::addressinput::AddressUiComponent> ui_components =
+ ::i18n::addressinput::BuildComponents(
+ ConvertJavaStringToUTF8(env, j_country_code), localization,
+ g_browser_process->GetApplicationLocale(), &best_language_tag);
+
+ for (auto ui_component : ui_components) {
+ component_labels.push_back(ui_component.name);
+
+ switch (ui_component.field) {
+ case ::i18n::addressinput::COUNTRY:
+ component_ids.push_back(AddressField::COUNTRY);
+ break;
+ case ::i18n::addressinput::ADMIN_AREA:
+ component_ids.push_back(AddressField::ADMIN_AREA);
+ break;
+ case ::i18n::addressinput::LOCALITY:
+ component_ids.push_back(AddressField::LOCALITY);
+ break;
+ case ::i18n::addressinput::DEPENDENT_LOCALITY:
+ component_ids.push_back(AddressField::DEPENDENT_LOCALITY);
+ break;
+ case ::i18n::addressinput::SORTING_CODE:
+ component_ids.push_back(AddressField::SORTING_CODE);
+ break;
+ case ::i18n::addressinput::POSTAL_CODE:
+ component_ids.push_back(AddressField::POSTAL_CODE);
+ break;
+ case ::i18n::addressinput::STREET_ADDRESS:
+ component_ids.push_back(AddressField::STREET_ADDRESS);
+ break;
+ case ::i18n::addressinput::ORGANIZATION:
+ component_ids.push_back(AddressField::ORGANIZATION);
+ break;
+ case ::i18n::addressinput::RECIPIENT:
+ component_ids.push_back(AddressField::RECIPIENT);
+ break;
+ default:
+ NOTREACHED();
+ }
+ }
+
+ 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);
+}
+
+} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698