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

Side by Side Diff: content/browser/android/java/gin_java_method_invocation_helper.cc

Issue 377173002: [Android] Use Blink UTF8<->UTF16 strings conversion in Gin Java Bridge (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/android/java/gin_java_script_to_java_types_coercion.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/android/java/gin_java_method_invocation_helper.h" 5 #include "content/browser/android/java/gin_java_method_invocation_helper.h"
6 6
7 #include <unistd.h> 7 #include <unistd.h>
8 8
9 #include "base/android/event_log.h" 9 #include "base/android/event_log.h"
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
11 #include "base/android/jni_string.h"
12 #include "base/float_util.h" 11 #include "base/float_util.h"
13 #include "content/browser/android/java/gin_java_script_to_java_types_coercion.h" 12 #include "content/browser/android/java/gin_java_script_to_java_types_coercion.h"
14 #include "content/browser/android/java/java_method.h" 13 #include "content/browser/android/java/java_method.h"
15 #include "content/browser/android/java/jni_helper.h" 14 #include "content/browser/android/java/jni_helper.h"
16 #include "content/common/android/gin_java_bridge_value.h" 15 #include "content/common/android/gin_java_bridge_value.h"
17 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "third_party/WebKit/public/platform/WebString.h"
18 18
19 using base::android::AttachCurrentThread; 19 using base::android::AttachCurrentThread;
20 using base::android::ScopedJavaLocalRef; 20 using base::android::ScopedJavaLocalRef;
21 21
22 namespace content { 22 namespace content {
23 23
24 namespace { 24 namespace {
25 25
26 // See frameworks/base/core/java/android/webkit/EventLogTags.logtags 26 // See frameworks/base/core/java/android/webkit/EventLogTags.logtags
27 const int kObjectGetClassInvocationAttemptLogTag = 70151; 27 const int kObjectGetClassInvocationAttemptLogTag = 70151;
28 28
29 // This is an intermediate solution until we fix http://crbug.com/391492.
30 std::string ConvertJavaStringToUTF8(JNIEnv* env, jstring str) {
31 const jchar* chars = env->GetStringChars(str, NULL);
32 DCHECK(chars);
33 blink::WebString utf16(chars, env->GetStringLength(str));
34 env->ReleaseStringChars(str, chars);
35 return utf16.utf8();
36 }
37
29 } // namespace 38 } // namespace
30 39
31 GinJavaMethodInvocationHelper::GinJavaMethodInvocationHelper( 40 GinJavaMethodInvocationHelper::GinJavaMethodInvocationHelper(
32 scoped_ptr<ObjectDelegate> object, 41 scoped_ptr<ObjectDelegate> object,
33 const std::string& method_name, 42 const std::string& method_name,
34 const base::ListValue& arguments) 43 const base::ListValue& arguments)
35 : object_(object.Pass()), 44 : object_(object.Pass()),
36 method_name_(method_name), 45 method_name_(method_name),
37 arguments_(arguments.DeepCopy()), 46 arguments_(arguments.DeepCopy()),
38 invocation_error_(kGinJavaBridgeNoError) { 47 invocation_error_(kGinJavaBridgeNoError) {
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 } 303 }
295 ScopedJavaLocalRef<jstring> scoped_java_string(env, java_string); 304 ScopedJavaLocalRef<jstring> scoped_java_string(env, java_string);
296 if (!scoped_java_string.obj()) { 305 if (!scoped_java_string.obj()) {
297 // LIVECONNECT_COMPLIANCE: Existing behavior is to return undefined. 306 // LIVECONNECT_COMPLIANCE: Existing behavior is to return undefined.
298 // Spec requires returning a null string. 307 // Spec requires returning a null string.
299 result_wrapper.Append( 308 result_wrapper.Append(
300 GinJavaBridgeValue::CreateUndefinedValue().release()); 309 GinJavaBridgeValue::CreateUndefinedValue().release());
301 break; 310 break;
302 } 311 }
303 result_wrapper.AppendString( 312 result_wrapper.AppendString(
304 base::android::ConvertJavaStringToUTF8(scoped_java_string)); 313 ConvertJavaStringToUTF8(env, scoped_java_string.obj()));
305 break; 314 break;
306 } 315 }
307 case JavaType::TypeObject: { 316 case JavaType::TypeObject: {
308 // If an exception was raised, we must clear it before calling most JNI 317 // If an exception was raised, we must clear it before calling most JNI
309 // methods. ScopedJavaLocalRef is liable to make such calls, so we test 318 // methods. ScopedJavaLocalRef is liable to make such calls, so we test
310 // first. 319 // first.
311 jobject java_object = 320 jobject java_object =
312 object ? env->CallObjectMethodA(object, id, parameters) 321 object ? env->CallObjectMethodA(object, id, parameters)
313 : env->CallStaticObjectMethodA(clazz, id, parameters); 322 : env->CallStaticObjectMethodA(clazz, id, parameters);
314 if (base::android::ClearException(env)) { 323 if (base::android::ClearException(env)) {
(...skipping 11 matching lines...) Expand all
326 } 335 }
327 // This is for all cases except JavaType::TypeObject. 336 // This is for all cases except JavaType::TypeObject.
328 if (!base::android::ClearException(env)) { 337 if (!base::android::ClearException(env)) {
329 SetPrimitiveResult(result_wrapper); 338 SetPrimitiveResult(result_wrapper);
330 } else { 339 } else {
331 SetInvocationError(kGinJavaBridgeJavaExceptionRaised); 340 SetInvocationError(kGinJavaBridgeJavaExceptionRaised);
332 } 341 }
333 } 342 }
334 343
335 } // namespace content 344 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/android/java/gin_java_script_to_java_types_coercion.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698