Chromium Code Reviews| Index: content/browser/renderer_host/java/java_bound_object.cc |
| diff --git a/content/browser/renderer_host/java/java_bound_object.cc b/content/browser/renderer_host/java/java_bound_object.cc |
| index 73403247aea3aec6d2594fc888634e65566966ae..48ed300f6db40a2ef3b3bf1fd667adae17d59698 100644 |
| --- a/content/browser/renderer_host/java/java_bound_object.cc |
| +++ b/content/browser/renderer_host/java/java_bound_object.cc |
| @@ -588,8 +588,7 @@ jvalue CoerceJavaScriptObjectToJavaValue(const NPVariant& variant, |
| // LIVECONNECT_COMPLIANCE: Existing behavior is to pass all Java |
| // objects. Spec requires passing only Java objects which are |
| // assignment-compatibile. |
| - result.l = AttachCurrentThread()->NewLocalRef( |
| - JavaBoundObject::GetJavaObject(object)); |
| + result.l = JavaBoundObject::GetJavaObject(object); |
|
joth
2013/01/07 19:32:41
this may now be NULL. Any idea what that might bre
benm (inactive)
2013/01/08 14:43:05
I think this is for the case that during a JS -> j
joth
2013/01/09 00:28:22
Yes. I chatted with sgurun and looks like classic
benm (inactive)
2013/01/09 11:17:00
Happy to add this in a follow up change but just w
benm (inactive)
2013/01/09 14:46:13
For 3, I guess we could remove from the set in Jav
|
| } else { |
| // LIVECONNECT_COMPLIANCE: Existing behavior is to pass null. Spec |
| // requires converting if the target type is |
| @@ -742,7 +741,7 @@ NPObject* JavaBoundObject::Create( |
| JavaBoundObject::JavaBoundObject( |
| const JavaRef<jobject>& object, |
| base::android::JavaRef<jclass>& safe_annotation_clazz) |
| - : java_object_(object), |
| + : java_object_(AttachCurrentThread(), object.obj()), |
| are_methods_set_up_(false), |
| safe_annotation_clazz_(safe_annotation_clazz) { |
| // We don't do anything with our Java object when first created. We do it all |
| @@ -755,7 +754,8 @@ JavaBoundObject::~JavaBoundObject() { |
| jobject JavaBoundObject::GetJavaObject(NPObject* object) { |
| DCHECK_EQ(&JavaNPObject::kNPClass, object->_class); |
| JavaBoundObject* jbo = reinterpret_cast<JavaNPObject*>(object)->bound_object; |
| - return jbo->java_object_.obj(); |
| + JNIEnv* env = AttachCurrentThread(); |
| + return env->NewLocalRef(jbo->java_object_.get(env).obj()); |
| } |
| bool JavaBoundObject::HasMethod(const std::string& name) const { |
| @@ -795,10 +795,15 @@ bool JavaBoundObject::Invoke(const std::string& name, const NPVariant* args, |
| true); |
| } |
| - // Call |
| - bool ok = CallJNIMethod(java_object_.obj(), method->return_type(), |
| - method->id(), ¶meters[0], result, |
| - safe_annotation_clazz_); |
| + ScopedJavaLocalRef<jobject> obj = java_object_.get(AttachCurrentThread()); |
| + |
| + bool ok = false; |
| + if (!obj.is_null()) { |
| + // Call |
| + ok = CallJNIMethod(obj.obj(), method->return_type(), |
| + method->id(), ¶meters[0], result, |
| + safe_annotation_clazz_); |
| + } |
| // Now that we're done with the jvalue, release any local references created |
| // by CoerceJavaScriptValueToJavaValue(). |
| @@ -816,8 +821,12 @@ void JavaBoundObject::EnsureMethodsAreSetUp() const { |
| are_methods_set_up_ = true; |
| JNIEnv* env = AttachCurrentThread(); |
| + ScopedJavaLocalRef<jobject> obj = java_object_.get(env); |
| + |
| + DCHECK(!obj.is_null()); |
|
joth
2013/01/07 19:32:41
this could happen though. If the java side ophen's
benm (inactive)
2013/01/08 14:43:05
No, I think your first comment is correct. EnsureM
|
| + |
| ScopedJavaLocalRef<jclass> clazz(env, static_cast<jclass>( |
| - env->CallObjectMethod(java_object_.obj(), GetMethodIDFromClassName( |
| + env->CallObjectMethod(obj.obj(), GetMethodIDFromClassName( |
| env, |
| kJavaLangObject, |
| kGetClass, |