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

Unified Diff: base/android/jni_string.cc

Issue 7828084: Refactor ScopedJavaRef (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: operator= docs Created 9 years, 3 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: base/android/jni_string.cc
diff --git a/base/android/jni_string.cc b/base/android/jni_string.cc
index 3f3ba826d6d7f2d02f4da3edf06ef8a7fd63c16b..26e7114fd60e8f74f118e21187e2ba7e008501a5 100644
--- a/base/android/jni_string.cc
+++ b/base/android/jni_string.cc
@@ -17,10 +17,15 @@ std::string ConvertJavaStringToUTF8(JNIEnv* env, jstring str) {
return UTF16ToUTF8(ConvertJavaStringToUTF16(env, str));
}
-jstring ConvertUTF8ToJavaString(JNIEnv* env, const std::string& str) {
- jstring result = env->NewStringUTF(str.c_str());
- CheckException(env);
- return result;
+jstring ConvertUTF8ToJavaString(JNIEnv* env, const base::StringPiece& str) {
+ // JNI's NewStringUTF expects "modified" UTF8 so instead create the string
+ // via our own UTF16 conversion utility.
+ // Further, Dalvik requires the string passed into NewStringUTF() to come from
+ // a trusted source. We can't guarantee that all UTF8 will be sanitized before
+ // it gets here, so constructing via UTF16 side-steps this issue.
+ // (Dalvik stores strings internally as UTF16 anyway, so there shouldn't be
+ // a significant performance hit by doing it this way).
+ return ConvertUTF16ToJavaString(env, UTF8ToUTF16(str));
}
string16 ConvertJavaStringToUTF16(JNIEnv* env, jstring str) {

Powered by Google App Engine
This is Rietveld 408576698