| 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 | 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" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 if (method->is_static()) { | 140 if (method->is_static()) { |
| 141 cls = object_->GetLocalClassRef(env); | 141 cls = object_->GetLocalClassRef(env); |
| 142 } else { | 142 } else { |
| 143 obj = object_->GetLocalRef(env); | 143 obj = object_->GetLocalRef(env); |
| 144 } | 144 } |
| 145 if (obj.is_null() && cls.is_null()) { | 145 if (obj.is_null() && cls.is_null()) { |
| 146 SetInvocationError(kGinJavaBridgeObjectIsGone); | 146 SetInvocationError(kGinJavaBridgeObjectIsGone); |
| 147 return; | 147 return; |
| 148 } | 148 } |
| 149 | 149 |
| 150 GinJavaBridgeError coercion_error = kGinJavaBridgeNoError; |
| 150 std::vector<jvalue> parameters(method->num_parameters()); | 151 std::vector<jvalue> parameters(method->num_parameters()); |
| 151 for (size_t i = 0; i < method->num_parameters(); ++i) { | 152 for (size_t i = 0; i < method->num_parameters(); ++i) { |
| 152 const base::Value* argument; | 153 const base::Value* argument; |
| 153 arguments_->Get(i, &argument); | 154 arguments_->Get(i, &argument); |
| 154 parameters[i] = CoerceJavaScriptValueToJavaValue( | 155 parameters[i] = CoerceJavaScriptValueToJavaValue(env, |
| 155 env, argument, method->parameter_type(i), true, object_refs_); | 156 argument, |
| 157 method->parameter_type(i), |
| 158 true, |
| 159 object_refs_, |
| 160 &coercion_error); |
| 156 } | 161 } |
| 157 if (method->is_static()) { | 162 |
| 158 InvokeMethod( | 163 if (coercion_error == kGinJavaBridgeNoError) { |
| 159 NULL, cls.obj(), method->return_type(), method->id(), ¶meters[0]); | 164 if (method->is_static()) { |
| 165 InvokeMethod( |
| 166 NULL, cls.obj(), method->return_type(), method->id(), ¶meters[0]); |
| 167 } else { |
| 168 InvokeMethod( |
| 169 obj.obj(), NULL, method->return_type(), method->id(), ¶meters[0]); |
| 170 } |
| 160 } else { | 171 } else { |
| 161 InvokeMethod( | 172 SetInvocationError(coercion_error); |
| 162 obj.obj(), NULL, method->return_type(), method->id(), ¶meters[0]); | |
| 163 } | 173 } |
| 164 | 174 |
| 165 // Now that we're done with the jvalue, release any local references created | 175 // Now that we're done with the jvalue, release any local references created |
| 166 // by CoerceJavaScriptValueToJavaValue(). | 176 // by CoerceJavaScriptValueToJavaValue(). |
| 167 for (size_t i = 0; i < method->num_parameters(); ++i) { | 177 for (size_t i = 0; i < method->num_parameters(); ++i) { |
| 168 ReleaseJavaValueIfRequired(env, ¶meters[i], method->parameter_type(i)); | 178 ReleaseJavaValueIfRequired(env, ¶meters[i], method->parameter_type(i)); |
| 169 } | 179 } |
| 170 } | 180 } |
| 171 | 181 |
| 172 void GinJavaMethodInvocationHelper::SetInvocationError( | 182 void GinJavaMethodInvocationHelper::SetInvocationError( |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 } | 345 } |
| 336 // This is for all cases except JavaType::TypeObject. | 346 // This is for all cases except JavaType::TypeObject. |
| 337 if (!base::android::ClearException(env)) { | 347 if (!base::android::ClearException(env)) { |
| 338 SetPrimitiveResult(result_wrapper); | 348 SetPrimitiveResult(result_wrapper); |
| 339 } else { | 349 } else { |
| 340 SetInvocationError(kGinJavaBridgeJavaExceptionRaised); | 350 SetInvocationError(kGinJavaBridgeJavaExceptionRaised); |
| 341 } | 351 } |
| 342 } | 352 } |
| 343 | 353 |
| 344 } // namespace content | 354 } // namespace content |
| OLD | NEW |