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

Side by Side Diff: content/browser/renderer_host/java/java_bound_object.cc

Issue 18570003: Move Renderer-side NPObject owner tracking to JavaBridgeChannel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move some comment cleanup to crrev.com/17428003 Created 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/renderer_host/java/java_bound_object.h" 5 #include "content/browser/renderer_host/java/java_bound_object.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // first. 206 // first.
207 jobject java_object = env->CallObjectMethodA(object, id, parameters); 207 jobject java_object = env->CallObjectMethodA(object, id, parameters);
208 if (base::android::ClearException(env)) { 208 if (base::android::ClearException(env)) {
209 return false; 209 return false;
210 } 210 }
211 ScopedJavaLocalRef<jobject> scoped_java_object(env, java_object); 211 ScopedJavaLocalRef<jobject> scoped_java_object(env, java_object);
212 if (!scoped_java_object.obj()) { 212 if (!scoped_java_object.obj()) {
213 NULL_TO_NPVARIANT(*result); 213 NULL_TO_NPVARIANT(*result);
214 break; 214 break;
215 } 215 }
216 OBJECT_TO_NPVARIANT(JavaBoundObject::Create(scoped_java_object, 216 // Every NPObject must have an owner. All JavaBoundObjects are owned by
217 // the JavaBridgeDispatcherHostManager, so if it's already gone, return
218 // null instead of an object.
219 if (!manager) {
220 NULL_TO_NPVARIANT(*result);
221 break;
222 }
223 OBJECT_TO_NPVARIANT(JavaBoundObject::Create(manager->object_owner_id(),
224 scoped_java_object,
217 safe_annotation_clazz, 225 safe_annotation_clazz,
218 manager), 226 manager),
219 *result); 227 *result);
220 break; 228 break;
221 } 229 }
222 } 230 }
223 return !base::android::ClearException(env); 231 return !base::android::ClearException(env);
224 } 232 }
225 233
226 double RoundDoubleTowardsZero(const double& x) { 234 double RoundDoubleTowardsZero(const double& x) {
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 return CoerceJavaScriptNullOrUndefinedToJavaValue(variant, target_type, 777 return CoerceJavaScriptNullOrUndefinedToJavaValue(variant, target_type,
770 coerce_to_string); 778 coerce_to_string);
771 } 779 }
772 NOTREACHED(); 780 NOTREACHED();
773 return jvalue(); 781 return jvalue();
774 } 782 }
775 783
776 } // namespace 784 } // namespace
777 785
778 NPObject* JavaBoundObject::Create( 786 NPObject* JavaBoundObject::Create(
787 struct _NPP* object_owner_id,
779 const JavaRef<jobject>& object, 788 const JavaRef<jobject>& object,
780 const JavaRef<jclass>& safe_annotation_clazz, 789 const JavaRef<jclass>& safe_annotation_clazz,
781 const base::WeakPtr<JavaBridgeDispatcherHostManager>& manager) { 790 const base::WeakPtr<JavaBridgeDispatcherHostManager>& manager) {
782 // The first argument (a plugin's instance handle) is passed through to the
783 // allocate function directly, and we don't use it, so it's ok to be 0.
784 // The object is created with a ref count of one. 791 // The object is created with a ref count of one.
785 NPObject* np_object = WebBindings::createObject(0, const_cast<NPClass*>( 792 NPObject* np_object = WebBindings::createObject(object_owner_id,
786 &JavaNPObject::kNPClass)); 793 const_cast<NPClass*>(&JavaNPObject::kNPClass));
787 // The NPObject takes ownership of the JavaBoundObject. 794 // The NPObject takes ownership of the JavaBoundObject.
788 reinterpret_cast<JavaNPObject*>(np_object)->bound_object = 795 reinterpret_cast<JavaNPObject*>(np_object)->bound_object =
789 new JavaBoundObject(object, safe_annotation_clazz, manager); 796 new JavaBoundObject(object, safe_annotation_clazz, manager);
790 return np_object; 797 return np_object;
791 } 798 }
792 799
793 JavaBoundObject::JavaBoundObject( 800 JavaBoundObject::JavaBoundObject(
794 const JavaRef<jobject>& object, 801 const JavaRef<jobject>& object,
795 const JavaRef<jclass>& safe_annotation_clazz, 802 const JavaRef<jclass>& safe_annotation_clazz,
796 const base::WeakPtr<JavaBridgeDispatcherHostManager>& manager) 803 const base::WeakPtr<JavaBridgeDispatcherHostManager>& manager)
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 if (!safe) 936 if (!safe)
930 continue; 937 continue;
931 } 938 }
932 939
933 JavaMethod* method = new JavaMethod(java_method); 940 JavaMethod* method = new JavaMethod(java_method);
934 methods_.insert(std::make_pair(method->name(), method)); 941 methods_.insert(std::make_pair(method->name(), method));
935 } 942 }
936 } 943 }
937 944
938 } // namespace content 945 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698