Changeset 82950 in webkit
- Timestamp:
- Apr 5, 2011 10:11:39 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/Android.v8bindings.mk
r82702 r82950 181 181 bridge/jni/v8/JavaClassJobjectV8.cpp \ 182 182 bridge/jni/v8/JavaFieldJobjectV8.cpp \ 183 bridge/jni/v8/JavaInstance V8.cpp \183 bridge/jni/v8/JavaInstanceJobjectV8.cpp \ 184 184 bridge/jni/v8/JavaNPObject.cpp \ 185 185 bridge/jni/v8/JobjectWrapper.cpp -
trunk/Source/WebCore/ChangeLog
r82948 r82950 1 2011-04-04 Steve Block <steveblock@google.com> 2 3 Reviewed by Dimitri Glazkov. 4 5 JavaInstance should be a pure interface 6 https://bugs.webkit.org/show_bug.cgi?id=55383 7 8 This patch fixes JavaInstance for V8 only. 9 10 It factors out a JavaInstance interface which does not use JNI 11 types. This will allow the Java bridge to be used with objects 12 that don't use JNI directly. The existing jobject-backed 13 implementation is moved to a new JavaInstanceJobject class which 14 implements the interface. 15 16 No new tests, refactoring only. 17 18 * Android.v8bindings.mk: 19 * WebCore.gypi: 20 * bridge/jni/JobjectWrapper.h: 21 * bridge/jni/v8/JNIUtilityPrivate.cpp: 22 (JSC::Bindings::jvalueToJavaValue): 23 (JSC::Bindings::javaValueToJvalue): 24 * bridge/jni/v8/JavaInstanceJobjectV8.cpp: 25 (JavaInstanceJobject::JavaInstanceJobject): 26 (JavaInstanceJobject::~JavaInstanceJobject): 27 (JavaInstanceJobject::begin): 28 (JavaInstanceJobject::end): 29 (JavaInstanceJobject::getClass): 30 (JavaInstanceJobject::invokeMethod): 31 (JavaInstanceJobject::getField): 32 * bridge/jni/v8/JavaInstanceJobjectV8.h: Copied from Source/WebCore/bridge/jni/v8/JavaInstanceV8.h. 33 (JSC::Bindings::JavaInstanceJobject::javaInstance): 34 * bridge/jni/v8/JavaInstanceV8.h: 35 (JSC::Bindings::JavaInstance::~JavaInstance): 36 1 37 2011-04-05 Dimitri Glazkov <dglazkov@chromium.org> 2 38 -
trunk/Source/WebCore/WebCore.gypi
r82899 r82950 2200 2200 'bridge/jni/v8/JavaFieldJobjectV8.h', 2201 2201 'bridge/jni/v8/JavaFieldV8.h', 2202 'bridge/jni/v8/JavaInstanceV8.cpp', 2202 'bridge/jni/v8/JavaInstanceJobjectV8.cpp', 2203 'bridge/jni/v8/JavaInstanceJobjectV8.h', 2203 2204 'bridge/jni/v8/JavaInstanceV8.h', 2204 2205 'bridge/jni/v8/JavaNPObjectV8.cpp', -
trunk/Source/WebCore/bridge/jni/JobjectWrapper.h
r82554 r82950 41 41 friend class JavaFieldJobject; 42 42 friend class JavaInstance; 43 friend class JavaInstanceJobject; 43 44 44 45 public: -
trunk/Source/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp
r82194 r82950 29 29 #if ENABLE(JAVA_BRIDGE) 30 30 31 #include "JavaInstance V8.h"31 #include "JavaInstanceJobjectV8.h" 32 32 #include "JavaNPObjectV8.h" 33 33 #include "JavaValueV8.h" … … 243 243 break; 244 244 case JavaTypeObject: 245 result.m_objectValue = new JavaInstance (value.l);245 result.m_objectValue = new JavaInstanceJobject(value.l); 246 246 break; 247 247 case JavaTypeString: … … 292 292 break; 293 293 case JavaTypeObject: 294 if (value.m_objectValue) 295 result.l = value.m_objectValue->javaInstance(); 294 if (value.m_objectValue) { 295 // This method is used only by JavaInstanceJobject, so we know the 296 // derived type of the object. 297 result.l = static_cast<JavaInstanceJobject*>(value.m_objectValue.get())->javaInstance(); 298 } 296 299 break; 297 300 case JavaTypeString: -
trunk/Source/WebCore/bridge/jni/v8/JavaInstanceJobjectV8.cpp
r82948 r82950 26 26 27 27 #include "config.h" 28 #include "JavaInstance V8.h"28 #include "JavaInstanceJobjectV8.h" 29 29 30 30 #if ENABLE(JAVA_BRIDGE) … … 36 36 37 37 #include <wtf/OwnArrayPtr.h> 38 #include <wtf/PassOwnPtr.h> 38 39 #include <wtf/text/CString.h> 39 40 40 41 using namespace JSC::Bindings; 41 42 42 JavaInstance::JavaInstance(jobject instance) 43 JavaInstanceJobject::JavaInstanceJobject(jobject instance) 44 : m_instance(new JobjectWrapper(instance)) 43 45 { 44 m_instance = new JobjectWrapper(instance);45 m_class = 0;46 }47 48 JavaInstance::~JavaInstance()49 {50 m_instance = 0;51 delete m_class;52 46 } 53 47 54 48 #define NUM_LOCAL_REFS 64 55 49 56 void JavaInstance ::virtualBegin()50 void JavaInstanceJobject::begin() 57 51 { 58 52 getJNIEnv()->PushLocalFrame(NUM_LOCAL_REFS); 59 53 } 60 54 61 void JavaInstance ::virtualEnd()55 void JavaInstanceJobject::end() 62 56 { 63 57 getJNIEnv()->PopLocalFrame(0); 64 58 } 65 59 66 JavaClass* JavaInstance ::getClass() const60 JavaClass* JavaInstanceJobject::getClass() const 67 61 { 68 62 if (!m_class) 69 m_class = new JavaClassJobject(javaInstance());70 return m_class ;63 m_class = adoptPtr(new JavaClassJobject(javaInstance())); 64 return m_class.get(); 71 65 } 72 66 73 JavaValue JavaInstance ::invokeMethod(const JavaMethod* method, JavaValue* args)67 JavaValue JavaInstanceJobject::invokeMethod(const JavaMethod* method, JavaValue* args) 74 68 { 75 69 ASSERT(getClass()->methodsNamed(method->name().utf8().data()).find(method) != notFound); … … 82 76 } 83 77 84 JavaValue JavaInstance ::getField(const JavaField* field)78 JavaValue JavaInstanceJobject::getField(const JavaField* field) 85 79 { 86 80 ASSERT(getClass()->fieldNamed(field->name().utf8().data()) == field); -
trunk/Source/WebCore/bridge/jni/v8/JavaInstanceJobjectV8.h
r82948 r82950 25 25 */ 26 26 27 #ifndef JavaInstance V8_h28 #define JavaInstance V8_h27 #ifndef JavaInstanceJobjectV8_h 28 #define JavaInstanceJobjectV8_h 29 29 30 30 #if ENABLE(JAVA_BRIDGE) 31 31 32 32 #include "JNIUtility.h" 33 #include "Java ValueV8.h"33 #include "JavaInstanceV8.h" 34 34 #include "JobjectWrapper.h" 35 #include "npruntime.h"36 35 37 #include <wtf/ RefCounted.h>36 #include <wtf/OwnPtr.h> 38 37 #include <wtf/RefPtr.h> 39 38 … … 44 43 namespace Bindings { 45 44 46 class Java Class;47 class JavaField; 48 class JavaMethod;45 class JavaInstanceJobject : public JavaInstance { 46 public: 47 JavaInstanceJobject(jobject instance); 49 48 50 class JavaInstance : public RefCounted<JavaInstance> { 51 public: 52 JavaInstance(jobject instance); 53 virtual ~JavaInstance(); 49 // JavaInstance implementation 50 virtual JavaClass* getClass() const; 51 virtual JavaValue invokeMethod(const JavaMethod*, JavaValue* args); 52 virtual JavaValue getField(const JavaField*); 53 virtual void begin(); 54 virtual void end(); 54 55 55 JavaClass* getClass() const;56 // args must be an array of length greater than or equal to the number of57 // arguments expected by the method.58 JavaValue invokeMethod(const JavaMethod*, JavaValue* args);59 JavaValue getField(const JavaField*);60 56 jobject javaInstance() const { return m_instance->m_instance; } 61 62 // These functions are called before and after the main entry points into63 // the native implementations. They can be used to establish and cleanup64 // any needed state.65 void begin() { virtualBegin(); }66 void end() { virtualEnd(); }67 57 68 58 protected: 69 59 RefPtr<JobjectWrapper> m_instance; 70 mutable JavaClass* m_class; 71 72 virtual void virtualBegin(); 73 virtual void virtualEnd(); 60 mutable OwnPtr<JavaClass> m_class; 74 61 }; 75 62 … … 80 67 #endif // ENABLE(JAVA_BRIDGE) 81 68 82 #endif // JavaInstance V8_h69 #endif // JavaInstanceJobjectV8_h -
trunk/Source/WebCore/bridge/jni/v8/JavaInstanceV8.h
r82361 r82950 30 30 #if ENABLE(JAVA_BRIDGE) 31 31 32 #include "JNIUtility.h"33 32 #include "JavaValueV8.h" 34 #include "JobjectWrapper.h"35 #include "npruntime.h"36 37 33 #include <wtf/RefCounted.h> 38 #include <wtf/RefPtr.h>39 34 40 35 using namespace WTF; … … 50 45 class JavaInstance : public RefCounted<JavaInstance> { 51 46 public: 52 JavaInstance(jobject instance); 53 virtual ~JavaInstance(); 47 virtual ~JavaInstance() {} 54 48 55 JavaClass* getClass() const;49 virtual JavaClass* getClass() const = 0; 56 50 // args must be an array of length greater than or equal to the number of 57 51 // arguments expected by the method. 58 JavaValue invokeMethod(const JavaMethod*, JavaValue* args); 59 JavaValue getField(const JavaField*); 60 jobject javaInstance() const { return m_instance->m_instance; } 52 virtual JavaValue invokeMethod(const JavaMethod*, JavaValue* args) = 0; 53 virtual JavaValue getField(const JavaField*) = 0; 61 54 62 55 // These functions are called before and after the main entry points into 63 56 // the native implementations. They can be used to establish and cleanup 64 57 // any needed state. 65 void begin() { virtualBegin(); } 66 void end() { virtualEnd(); } 67 68 protected: 69 RefPtr<JobjectWrapper> m_instance; 70 mutable JavaClass* m_class; 71 72 virtual void virtualBegin(); 73 virtual void virtualEnd(); 58 virtual void begin() = 0; 59 virtual void end() = 0; 74 60 }; 75 61
Note: See TracChangeset
for help on using the changeset viewer.