summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authoryfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-14 15:55:20 +0000
committeryfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-14 15:55:20 +0000
commit8c2e869a100152a7f5759f548e0775c016b3cedb (patch)
tree98dcf23cf2c26d779762939e6fdc52114a72e7e1 /base
parent9520ef4703511304286dcc06f52b7aa2bde34552 (diff)
downloadchromium_src-8c2e869a100152a7f5759f548e0775c016b3cedb.zip
chromium_src-8c2e869a100152a7f5759f548e0775c016b3cedb.tar.gz
chromium_src-8c2e869a100152a7f5759f548e0775c016b3cedb.tar.bz2
[Android] Use generated JNI bindings for locale utils.
We're removing the often error-prone manual bindings with the JNI generator. NOTRY=true Review URL: https://chromiumcodereview.appspot.com/12598005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188087 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/android/java/src/org/chromium/base/LocaleUtils.java10
-rw-r--r--base/android/locale_utils.cc30
2 files changed, 19 insertions, 21 deletions
diff --git a/base/android/java/src/org/chromium/base/LocaleUtils.java b/base/android/java/src/org/chromium/base/LocaleUtils.java
index 11c1064..e57b45a 100644
--- a/base/android/java/src/org/chromium/base/LocaleUtils.java
+++ b/base/android/java/src/org/chromium/base/LocaleUtils.java
@@ -35,4 +35,14 @@ public class LocaleUtils {
}
return country.isEmpty() ? language : language + "-" + country;
}
+
+ @CalledByNative
+ private static Locale getJavaLocale(String language, String country, String variant) {
+ return new Locale(language, country, variant);
+ }
+
+ @CalledByNative
+ private static String getDisplayNameForLocale(Locale locale, Locale displayLocale) {
+ return locale.getDisplayName(displayLocale);
+ }
}
diff --git a/base/android/locale_utils.cc b/base/android/locale_utils.cc
index 49d3441..f9c030d 100644
--- a/base/android/locale_utils.cc
+++ b/base/android/locale_utils.cc
@@ -44,8 +44,6 @@ std::string GetLocaleComponent(const std::string& locale,
ScopedJavaLocalRef<jobject> NewJavaLocale(
JNIEnv* env,
- ScopedJavaLocalRef<jclass> locale_class,
- jmethodID constructor_id,
const std::string& locale) {
// TODO(wangxianzhu): Use new Locale API once Android supports scripts.
std::string language = GetLocaleComponent(
@@ -54,12 +52,10 @@ ScopedJavaLocalRef<jobject> NewJavaLocale(
locale, uloc_getCountry, ULOC_COUNTRY_CAPACITY);
std::string variant = GetLocaleComponent(
locale, uloc_getVariant, ULOC_FULLNAME_CAPACITY);
- return ScopedJavaLocalRef<jobject>(
- env, env->NewObject(
- locale_class.obj(), constructor_id,
+ return Java_LocaleUtils_getJavaLocale(env,
ConvertUTF8ToJavaString(env, language).obj(),
ConvertUTF8ToJavaString(env, country).obj(),
- ConvertUTF8ToJavaString(env, variant).obj()));
+ ConvertUTF8ToJavaString(env, variant).obj());
}
} // namespace
@@ -67,23 +63,15 @@ ScopedJavaLocalRef<jobject> NewJavaLocale(
string16 GetDisplayNameForLocale(const std::string& locale,
const std::string& display_locale) {
JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> java_locale =
+ NewJavaLocale(env, locale);
+ ScopedJavaLocalRef<jobject> java_display_locale =
+ NewJavaLocale(env, display_locale);
- ScopedJavaLocalRef<jclass> locale_class = GetClass(env, "java/util/Locale");
- jmethodID constructor_id = MethodID::Get<MethodID::TYPE_INSTANCE>(
- env, locale_class.obj(), "<init>",
- "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
- ScopedJavaLocalRef<jobject> java_locale = NewJavaLocale(
- env, locale_class, constructor_id, locale);
- ScopedJavaLocalRef<jobject> java_display_locale = NewJavaLocale(
- env, locale_class, constructor_id, display_locale);
-
- jmethodID method_id = MethodID::Get<MethodID::TYPE_INSTANCE>(
- env, locale_class.obj(), "getDisplayName",
- "(Ljava/util/Locale;)Ljava/lang/String;");
ScopedJavaLocalRef<jstring> java_result(
- env,
- static_cast<jstring>(env->CallObjectMethod(java_locale.obj(), method_id,
- java_display_locale.obj())));
+ Java_LocaleUtils_getDisplayNameForLocale(env,
+ java_locale.obj(),
+ java_display_locale.obj()));
return ConvertJavaStringToUTF16(java_result);
}