summaryrefslogtreecommitdiffstats
path: root/WebKit/android
diff options
context:
space:
mode:
authorIain Merrick <husky@google.com>2010-10-21 17:56:42 +0100
committerIain Merrick <husky@google.com>2010-10-21 17:59:16 +0100
commit5b7723d28caa3e8a979bcd40a9d634b410c23ec2 (patch)
treea9efeb8cd9dd1af1982380e9ba5f8d6e7388db2a /WebKit/android
parent583f3b2e7b569ec9f88e9c481db1eb86a8c0224b (diff)
downloadexternal_webkit-5b7723d28caa3e8a979bcd40a9d634b410c23ec2.zip
external_webkit-5b7723d28caa3e8a979bcd40a9d634b410c23ec2.tar.gz
external_webkit-5b7723d28caa3e8a979bcd40a9d634b410c23ec2.tar.bz2
Move jstringToStdString into WebCoreJni.h
Also tweaked the implementation slightly to match jstringToString16, which is more robust. Change-Id: I614576615a6f429ea1632c395d5bc4e068c32cfb
Diffstat (limited to 'WebKit/android')
-rw-r--r--WebKit/android/jni/WebCoreFrameBridge.cpp9
-rw-r--r--WebKit/android/jni/WebCoreJni.cpp14
-rw-r--r--WebKit/android/jni/WebCoreJni.h2
3 files changed, 16 insertions, 9 deletions
diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp
index 010c6df..6b3f009 100644
--- a/WebKit/android/jni/WebCoreFrameBridge.cpp
+++ b/WebKit/android/jni/WebCoreFrameBridge.cpp
@@ -1826,15 +1826,6 @@ static void OrientationChanged(JNIEnv *env, jobject obj, int orientation)
pFrame->sendOrientationChangeEvent(orientation);
}
-static std::string jstringToStdString(JNIEnv* env, jstring jstr) {
- jsize size = env->GetStringUTFLength(jstr);
- jboolean isCopy;
- const char* cstr = env->GetStringUTFChars(jstr, &isCopy);
- std::string result(cstr, cstr + size);
- env->ReleaseStringUTFChars(jstr, cstr);
- return result;
-}
-
#if USE(CHROME_NETWORK_STACK)
static void AuthenticationProceed(JNIEnv *env, jobject obj, int handle, jstring jUsername, jstring jPassword)
diff --git a/WebKit/android/jni/WebCoreJni.cpp b/WebKit/android/jni/WebCoreJni.cpp
index 5bcb2e1..1b9619b 100644
--- a/WebKit/android/jni/WebCoreJni.cpp
+++ b/WebKit/android/jni/WebCoreJni.cpp
@@ -87,4 +87,18 @@ string16 jstringToString16(JNIEnv* env, jstring jstr)
}
#endif
+std::string jstringToStdString(JNIEnv* env, jstring jstr)
+{
+ if (!jstr || !env)
+ return std::string();
+
+ const char* s = env->GetStringUTFChars(jstr, 0);
+ if (!s)
+ return std::string();
+ std::string str(s);
+ env->ReleaseStringUTFChars(jstr, s);
+ checkException(env);
+ return str;
+}
+
}
diff --git a/WebKit/android/jni/WebCoreJni.h b/WebKit/android/jni/WebCoreJni.h
index 8bfca7e..d4a9821 100644
--- a/WebKit/android/jni/WebCoreJni.h
+++ b/WebKit/android/jni/WebCoreJni.h
@@ -77,6 +77,8 @@ WTF::String jstringToWtfString(JNIEnv* env, jstring str);
string16 jstringToString16(JNIEnv* env, jstring jstr);
#endif
+std::string jstringToStdString(JNIEnv* env, jstring jstr);
+
}
#endif