| OLD | NEW |
| 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 #include <cmath> | 8 #include <cmath> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 object ? env->CallLongMethodA(object, id, parameters) | 251 object ? env->CallLongMethodA(object, id, parameters) |
| 252 : env->CallStaticLongMethodA(clazz, id, parameters)); | 252 : env->CallStaticLongMethodA(clazz, id, parameters)); |
| 253 break; | 253 break; |
| 254 case JavaType::TypeFloat: { | 254 case JavaType::TypeFloat: { |
| 255 float result = object | 255 float result = object |
| 256 ? env->CallFloatMethodA(object, id, parameters) | 256 ? env->CallFloatMethodA(object, id, parameters) |
| 257 : env->CallStaticFloatMethodA(clazz, id, parameters); | 257 : env->CallStaticFloatMethodA(clazz, id, parameters); |
| 258 if (std::isfinite(result)) { | 258 if (std::isfinite(result)) { |
| 259 result_wrapper.AppendDouble(result); | 259 result_wrapper.AppendDouble(result); |
| 260 } else { | 260 } else { |
| 261 result_wrapper.Append( | 261 result_wrapper.Append(GinJavaBridgeValue::CreateNonFiniteValue(result)); |
| 262 GinJavaBridgeValue::CreateNonFiniteValue(result).release()); | |
| 263 } | 262 } |
| 264 break; | 263 break; |
| 265 } | 264 } |
| 266 case JavaType::TypeDouble: { | 265 case JavaType::TypeDouble: { |
| 267 double result = object | 266 double result = object |
| 268 ? env->CallDoubleMethodA(object, id, parameters) | 267 ? env->CallDoubleMethodA(object, id, parameters) |
| 269 : env->CallStaticDoubleMethodA(clazz, id, parameters); | 268 : env->CallStaticDoubleMethodA(clazz, id, parameters); |
| 270 if (std::isfinite(result)) { | 269 if (std::isfinite(result)) { |
| 271 result_wrapper.AppendDouble(result); | 270 result_wrapper.AppendDouble(result); |
| 272 } else { | 271 } else { |
| 273 result_wrapper.Append( | 272 result_wrapper.Append(GinJavaBridgeValue::CreateNonFiniteValue(result)); |
| 274 GinJavaBridgeValue::CreateNonFiniteValue(result).release()); | |
| 275 } | 273 } |
| 276 break; | 274 break; |
| 277 } | 275 } |
| 278 case JavaType::TypeVoid: | 276 case JavaType::TypeVoid: |
| 279 if (object) | 277 if (object) |
| 280 env->CallVoidMethodA(object, id, parameters); | 278 env->CallVoidMethodA(object, id, parameters); |
| 281 else | 279 else |
| 282 env->CallStaticVoidMethodA(clazz, id, parameters); | 280 env->CallStaticVoidMethodA(clazz, id, parameters); |
| 283 result_wrapper.Append( | 281 result_wrapper.Append(GinJavaBridgeValue::CreateUndefinedValue()); |
| 284 GinJavaBridgeValue::CreateUndefinedValue().release()); | |
| 285 break; | 282 break; |
| 286 case JavaType::TypeArray: | 283 case JavaType::TypeArray: |
| 287 // LIVECONNECT_COMPLIANCE: Existing behavior is to not call methods that | 284 // LIVECONNECT_COMPLIANCE: Existing behavior is to not call methods that |
| 288 // return arrays. Spec requires calling the method and converting the | 285 // return arrays. Spec requires calling the method and converting the |
| 289 // result to a JavaScript array. | 286 // result to a JavaScript array. |
| 290 result_wrapper.Append( | 287 result_wrapper.Append(GinJavaBridgeValue::CreateUndefinedValue()); |
| 291 GinJavaBridgeValue::CreateUndefinedValue().release()); | |
| 292 break; | 288 break; |
| 293 case JavaType::TypeString: { | 289 case JavaType::TypeString: { |
| 294 jstring java_string = static_cast<jstring>( | 290 jstring java_string = static_cast<jstring>( |
| 295 object ? env->CallObjectMethodA(object, id, parameters) | 291 object ? env->CallObjectMethodA(object, id, parameters) |
| 296 : env->CallStaticObjectMethodA(clazz, id, parameters)); | 292 : env->CallStaticObjectMethodA(clazz, id, parameters)); |
| 297 // If an exception was raised, we must clear it before calling most JNI | 293 // If an exception was raised, we must clear it before calling most JNI |
| 298 // methods. ScopedJavaLocalRef is liable to make such calls, so we test | 294 // methods. ScopedJavaLocalRef is liable to make such calls, so we test |
| 299 // first. | 295 // first. |
| 300 if (base::android::ClearException(env)) { | 296 if (base::android::ClearException(env)) { |
| 301 SetInvocationError(kGinJavaBridgeJavaExceptionRaised); | 297 SetInvocationError(kGinJavaBridgeJavaExceptionRaised); |
| 302 return; | 298 return; |
| 303 } | 299 } |
| 304 ScopedJavaLocalRef<jstring> scoped_java_string(env, java_string); | 300 ScopedJavaLocalRef<jstring> scoped_java_string(env, java_string); |
| 305 if (!scoped_java_string.obj()) { | 301 if (!scoped_java_string.obj()) { |
| 306 // LIVECONNECT_COMPLIANCE: Existing behavior is to return undefined. | 302 // LIVECONNECT_COMPLIANCE: Existing behavior is to return undefined. |
| 307 // Spec requires returning a null string. | 303 // Spec requires returning a null string. |
| 308 result_wrapper.Append( | 304 result_wrapper.Append(GinJavaBridgeValue::CreateUndefinedValue()); |
| 309 GinJavaBridgeValue::CreateUndefinedValue().release()); | |
| 310 break; | 305 break; |
| 311 } | 306 } |
| 312 result_wrapper.AppendString( | 307 result_wrapper.AppendString( |
| 313 base::android::ConvertJavaStringToUTF8(scoped_java_string)); | 308 base::android::ConvertJavaStringToUTF8(scoped_java_string)); |
| 314 break; | 309 break; |
| 315 } | 310 } |
| 316 case JavaType::TypeObject: { | 311 case JavaType::TypeObject: { |
| 317 // If an exception was raised, we must clear it before calling most JNI | 312 // If an exception was raised, we must clear it before calling most JNI |
| 318 // methods. ScopedJavaLocalRef is liable to make such calls, so we test | 313 // methods. ScopedJavaLocalRef is liable to make such calls, so we test |
| 319 // first. | 314 // first. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 335 } | 330 } |
| 336 // This is for all cases except JavaType::TypeObject. | 331 // This is for all cases except JavaType::TypeObject. |
| 337 if (!base::android::ClearException(env)) { | 332 if (!base::android::ClearException(env)) { |
| 338 SetPrimitiveResult(result_wrapper); | 333 SetPrimitiveResult(result_wrapper); |
| 339 } else { | 334 } else { |
| 340 SetInvocationError(kGinJavaBridgeJavaExceptionRaised); | 335 SetInvocationError(kGinJavaBridgeJavaExceptionRaised); |
| 341 } | 336 } |
| 342 } | 337 } |
| 343 | 338 |
| 344 } // namespace content | 339 } // namespace content |
| OLD | NEW |