Changeset 82950 in webkit


Ignore:
Timestamp:
Apr 5, 2011 10:11:39 AM (13 years ago)
Author:
steveblock@google.com
Message:

2011-04-04 Steve Block <steveblock@google.com>

Reviewed by Dimitri Glazkov.

JavaInstance should be a pure interface
https://bugs.webkit.org/show_bug.cgi?id=55383

This patch fixes JavaInstance for V8 only.

It factors out a JavaInstance interface which does not use JNI
types. This will allow the Java bridge to be used with objects
that don't use JNI directly. The existing jobject-backed
implementation is moved to a new JavaInstanceJobject class which
implements the interface.

No new tests, refactoring only.

  • Android.v8bindings.mk:
  • WebCore.gypi:
  • bridge/jni/JobjectWrapper.h:
  • bridge/jni/v8/JNIUtilityPrivate.cpp: (JSC::Bindings::jvalueToJavaValue): (JSC::Bindings::javaValueToJvalue):
  • bridge/jni/v8/JavaInstanceJobjectV8.cpp: (JavaInstanceJobject::JavaInstanceJobject): (JavaInstanceJobject::~JavaInstanceJobject): (JavaInstanceJobject::begin): (JavaInstanceJobject::end): (JavaInstanceJobject::getClass): (JavaInstanceJobject::invokeMethod): (JavaInstanceJobject::getField):
  • bridge/jni/v8/JavaInstanceJobjectV8.h: Copied from Source/WebCore/bridge/jni/v8/JavaInstanceV8.h. (JSC::Bindings::JavaInstanceJobject::javaInstance):
  • bridge/jni/v8/JavaInstanceV8.h: (JSC::Bindings::JavaInstance::~JavaInstance):
Location:
trunk/Source/WebCore
Files:
6 edited
1 copied
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/Android.v8bindings.mk

    r82702 r82950  
    181181        bridge/jni/v8/JavaClassJobjectV8.cpp \
    182182        bridge/jni/v8/JavaFieldJobjectV8.cpp \
    183         bridge/jni/v8/JavaInstanceV8.cpp \
     183        bridge/jni/v8/JavaInstanceJobjectV8.cpp \
    184184        bridge/jni/v8/JavaNPObject.cpp \
    185185        bridge/jni/v8/JobjectWrapper.cpp
  • trunk/Source/WebCore/ChangeLog

    r82948 r82950  
     12011-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
    1372011-04-05  Dimitri Glazkov  <dglazkov@chromium.org>
    238
  • trunk/Source/WebCore/WebCore.gypi

    r82899 r82950  
    22002200            'bridge/jni/v8/JavaFieldJobjectV8.h',
    22012201            'bridge/jni/v8/JavaFieldV8.h',
    2202             'bridge/jni/v8/JavaInstanceV8.cpp',
     2202            'bridge/jni/v8/JavaInstanceJobjectV8.cpp',
     2203            'bridge/jni/v8/JavaInstanceJobjectV8.h',
    22032204            'bridge/jni/v8/JavaInstanceV8.h',
    22042205            'bridge/jni/v8/JavaNPObjectV8.cpp',
  • trunk/Source/WebCore/bridge/jni/JobjectWrapper.h

    r82554 r82950  
    4141friend class JavaFieldJobject;
    4242friend class JavaInstance;
     43friend class JavaInstanceJobject;
    4344
    4445public:
  • trunk/Source/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp

    r82194 r82950  
    2929#if ENABLE(JAVA_BRIDGE)
    3030
    31 #include "JavaInstanceV8.h"
     31#include "JavaInstanceJobjectV8.h"
    3232#include "JavaNPObjectV8.h"
    3333#include "JavaValueV8.h"
     
    243243        break;
    244244    case JavaTypeObject:
    245         result.m_objectValue = new JavaInstance(value.l);
     245        result.m_objectValue = new JavaInstanceJobject(value.l);
    246246        break;
    247247    case JavaTypeString:
     
    292292        break;
    293293    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        }
    296299        break;
    297300    case JavaTypeString:
  • trunk/Source/WebCore/bridge/jni/v8/JavaInstanceJobjectV8.cpp

    r82948 r82950  
    2626
    2727#include "config.h"
    28 #include "JavaInstanceV8.h"
     28#include "JavaInstanceJobjectV8.h"
    2929
    3030#if ENABLE(JAVA_BRIDGE)
     
    3636
    3737#include <wtf/OwnArrayPtr.h>
     38#include <wtf/PassOwnPtr.h>
    3839#include <wtf/text/CString.h>
    3940
    4041using namespace JSC::Bindings;
    4142
    42 JavaInstance::JavaInstance(jobject instance)
     43JavaInstanceJobject::JavaInstanceJobject(jobject instance)
     44    : m_instance(new JobjectWrapper(instance))
    4345{
    44     m_instance = new JobjectWrapper(instance);
    45     m_class = 0;
    46 }
    47 
    48 JavaInstance::~JavaInstance()
    49 {
    50     m_instance = 0;
    51     delete m_class;
    5246}
    5347
    5448#define NUM_LOCAL_REFS 64
    5549
    56 void JavaInstance::virtualBegin()
     50void JavaInstanceJobject::begin()
    5751{
    5852    getJNIEnv()->PushLocalFrame(NUM_LOCAL_REFS);
    5953}
    6054
    61 void JavaInstance::virtualEnd()
     55void JavaInstanceJobject::end()
    6256{
    6357    getJNIEnv()->PopLocalFrame(0);
    6458}
    6559
    66 JavaClass* JavaInstance::getClass() const
     60JavaClass* JavaInstanceJobject::getClass() const
    6761{
    6862    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();
    7165}
    7266
    73 JavaValue JavaInstance::invokeMethod(const JavaMethod* method, JavaValue* args)
     67JavaValue JavaInstanceJobject::invokeMethod(const JavaMethod* method, JavaValue* args)
    7468{
    7569    ASSERT(getClass()->methodsNamed(method->name().utf8().data()).find(method) != notFound);
     
    8276}
    8377
    84 JavaValue JavaInstance::getField(const JavaField* field)
     78JavaValue JavaInstanceJobject::getField(const JavaField* field)
    8579{
    8680    ASSERT(getClass()->fieldNamed(field->name().utf8().data()) == field);
  • trunk/Source/WebCore/bridge/jni/v8/JavaInstanceJobjectV8.h

    r82948 r82950  
    2525 */
    2626
    27 #ifndef JavaInstanceV8_h
    28 #define JavaInstanceV8_h
     27#ifndef JavaInstanceJobjectV8_h
     28#define JavaInstanceJobjectV8_h
    2929
    3030#if ENABLE(JAVA_BRIDGE)
    3131
    3232#include "JNIUtility.h"
    33 #include "JavaValueV8.h"
     33#include "JavaInstanceV8.h"
    3434#include "JobjectWrapper.h"
    35 #include "npruntime.h"
    3635
    37 #include <wtf/RefCounted.h>
     36#include <wtf/OwnPtr.h>
    3837#include <wtf/RefPtr.h>
    3938
     
    4443namespace Bindings {
    4544
    46 class JavaClass;
    47 class JavaField;
    48 class JavaMethod;
     45class JavaInstanceJobject : public JavaInstance {
     46public:
     47    JavaInstanceJobject(jobject instance);
    4948
    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();
    5455
    55     JavaClass* getClass() const;
    56     // args must be an array of length greater than or equal to the number of
    57     // arguments expected by the method.
    58     JavaValue invokeMethod(const JavaMethod*, JavaValue* args);
    59     JavaValue getField(const JavaField*);
    6056    jobject javaInstance() const { return m_instance->m_instance; }
    61 
    62     // These functions are called before and after the main entry points into
    63     // the native implementations.  They can be used to establish and cleanup
    64     // any needed state.
    65     void begin() { virtualBegin(); }
    66     void end() { virtualEnd(); }
    6757
    6858protected:
    6959    RefPtr<JobjectWrapper> m_instance;
    70     mutable JavaClass* m_class;
    71 
    72     virtual void virtualBegin();
    73     virtual void virtualEnd();
     60    mutable OwnPtr<JavaClass> m_class;
    7461};
    7562
     
    8067#endif // ENABLE(JAVA_BRIDGE)
    8168
    82 #endif // JavaInstanceV8_h
     69#endif // JavaInstanceJobjectV8_h
  • trunk/Source/WebCore/bridge/jni/v8/JavaInstanceV8.h

    r82361 r82950  
    3030#if ENABLE(JAVA_BRIDGE)
    3131
    32 #include "JNIUtility.h"
    3332#include "JavaValueV8.h"
    34 #include "JobjectWrapper.h"
    35 #include "npruntime.h"
    36 
    3733#include <wtf/RefCounted.h>
    38 #include <wtf/RefPtr.h>
    3934
    4035using namespace WTF;
     
    5045class JavaInstance : public RefCounted<JavaInstance> {
    5146public:
    52     JavaInstance(jobject instance);
    53     virtual ~JavaInstance();
     47    virtual ~JavaInstance() {}
    5448
    55     JavaClass* getClass() const;
     49    virtual JavaClass* getClass() const = 0;
    5650    // args must be an array of length greater than or equal to the number of
    5751    // 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;
    6154
    6255    // These functions are called before and after the main entry points into
    6356    // the native implementations.  They can be used to establish and cleanup
    6457    // 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;
    7460};
    7561
Note: See TracChangeset for help on using the changeset viewer.