diff options
| -rw-r--r-- | Android.mk | 1 | ||||
| -rw-r--r-- | V8Binding/jni/jni_npobject.cpp | 2 | ||||
| -rw-r--r-- | V8Binding/jni/jni_runtime.h | 2 | ||||
| -rw-r--r-- | WebCore/Android.v8bindings.mk | 3 | ||||
| -rw-r--r-- | WebCore/bridge/jni/v8/JavaInstanceV8.cpp (renamed from V8Binding/jni/jni_instance.cpp) | 155 | ||||
| -rw-r--r-- | WebCore/bridge/jni/v8/JavaInstanceV8.h (renamed from V8Binding/jni/jni_instance.h) | 45 | ||||
| -rw-r--r-- | WebKit/android/jni/WebCoreFrameBridge.cpp | 2 |
7 files changed, 100 insertions, 110 deletions
@@ -185,7 +185,6 @@ BINDING_C_INCLUDES += \ $(LOCAL_PATH)/bridge/jni \ $(LOCAL_PATH)/bridge/jni/v8 JNI_SRC_FILES := \ - jni_instance.cpp \ jni_npobject.cpp \ jni_runtime.cpp WEBKIT_SRC_FILES += $(addprefix $(JNI_PATH)/,$(JNI_SRC_FILES)) diff --git a/V8Binding/jni/jni_npobject.cpp b/V8Binding/jni/jni_npobject.cpp index 31196fc..2c79fb6 100644 --- a/V8Binding/jni/jni_npobject.cpp +++ b/V8Binding/jni/jni_npobject.cpp @@ -29,7 +29,7 @@ #include "JNIUtility.h" #include "JavaClassV8.h" -#include "jni_instance.h" +#include "JavaInstanceV8.h" #include "jni_runtime.h" // This source file should be in bridge/jni, so it's OK to use the private // NPAPI header from here. diff --git a/V8Binding/jni/jni_runtime.h b/V8Binding/jni/jni_runtime.h index 4321097..eafede3 100644 --- a/V8Binding/jni/jni_runtime.h +++ b/V8Binding/jni/jni_runtime.h @@ -28,7 +28,7 @@ #define _JNI_RUNTIME_H_ #include "JNIUtility.h" -#include "jni_instance.h" +#include "JavaInstanceV8.h" #include "CString.h" diff --git a/WebCore/Android.v8bindings.mk b/WebCore/Android.v8bindings.mk index b9594a4..32f5a5a 100644 --- a/WebCore/Android.v8bindings.mk +++ b/WebCore/Android.v8bindings.mk @@ -173,4 +173,5 @@ LOCAL_SRC_FILES += \ LOCAL_SRC_FILES += \ bridge/jni/JNIUtility.cpp \ bridge/jni/v8/JNIUtilityPrivate.cpp \ - bridge/jni/v8/JavaClassV8.cpp + bridge/jni/v8/JavaClassV8.cpp \ + bridge/jni/v8/JavaInstanceV8.cpp diff --git a/V8Binding/jni/jni_instance.cpp b/WebCore/bridge/jni/v8/JavaInstanceV8.cpp index 205e3f4..13d4984 100644 --- a/V8Binding/jni/jni_instance.cpp +++ b/WebCore/bridge/jni/v8/JavaInstanceV8.cpp @@ -1,6 +1,5 @@ /* - * Copyright (C) 2003, 2008 Apple Inc. All rights reserved. - * Copyright 2009, The Android Open Source Project + * Copyright 2010, The Android Open Source Project * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -21,13 +20,11 @@ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define LOG_TAG "v8binding" - #include "config.h" -#include "jni_instance.h" +#include "JavaInstanceV8.h" #include "JNIUtility.h" #include "JavaClassV8.h" @@ -36,46 +33,45 @@ #include <assert.h> #include <utils/Log.h> +#define LOG_TAG "v8binding" + using namespace JSC::Bindings; -JavaInstance::JavaInstance (jobject instance) +JavaInstance::JavaInstance(jobject instance) { m_instance = new JObjectWrapper(instance); - _class = 0; + m_class = 0; } -JavaInstance::~JavaInstance () +JavaInstance::~JavaInstance() { m_instance = 0; - delete _class; + delete m_class; } -JavaClass* JavaInstance::getClass() const +JavaClass* JavaInstance::getClass() const { - if (_class == 0) { - _class = new JavaClass(javaInstance()); + if (!m_class) { + m_class = new JavaClass(javaInstance()); } - return _class; + return m_class; } bool JavaInstance::invokeMethod(const char* methodName, const NPVariant* args, int count, NPVariant* resultValue) { - int i; - jvalue *jArgs; - JavaMethod *method = 0; - VOID_TO_NPVARIANT(*resultValue); MethodList methodList = getClass()->methodsNamed(methodName); size_t numMethods = methodList.size(); - - // Try to find a good match for the overloaded method. The + + // Try to find a good match for the overloaded method. The // fundamental problem is that JavaScript doesn have the - // notion of method overloading and Java does. We could + // notion of method overloading and Java does. We could // get a bit more sophisticated and attempt to does some // type checking as we as checking the number of parameters. - JavaMethod *aMethod; + JavaMethod* aMethod; + JavaMethod* method = 0; for (size_t methodIndex = 0; methodIndex < numMethods; methodIndex++) { aMethod = methodList[methodIndex]; if (aMethod->numParameters() == count) { @@ -83,93 +79,90 @@ bool JavaInstance::invokeMethod(const char* methodName, const NPVariant* args, i break; } } - if (method == 0) { + if (!method) { LOGW("unable to find an appropiate method\n"); return false; } - - const JavaMethod *jMethod = static_cast<const JavaMethod*>(method); - - if (count > 0) { - jArgs = (jvalue *)malloc (count * sizeof(jvalue)); - } - else - jArgs = 0; - - for (i = 0; i < count; i++) { + + const JavaMethod* jMethod = static_cast<const JavaMethod*>(method); + + jvalue* jArgs = 0; + if (count > 0) + jArgs = (jvalue*)malloc (count * sizeof(jvalue)); + + for (int i = 0; i < count; i++) { JavaParameter* aParameter = jMethod->parameterAt(i); jArgs[i] = convertNPVariantToJValue(args[i], aParameter->getJNIType(), aParameter->type()); } - + jvalue result; // The following code can be conditionally removed once we have a Tiger update that // contains the new Java plugin. It is needed for builds prior to Tiger. - { + { jobject obj = javaInstance(); - switch (jMethod->JNIReturnType()){ - case void_type: - callJNIMethodIDA<void>(obj, jMethod->methodID(obj), jArgs); - break; - case object_type: - result.l = callJNIMethodIDA<jobject>(obj, jMethod->methodID(obj), jArgs); - break; - case boolean_type: - result.z = callJNIMethodIDA<jboolean>(obj, jMethod->methodID(obj), jArgs); - break; - case byte_type: - result.b = callJNIMethodIDA<jbyte>(obj, jMethod->methodID(obj), jArgs); - break; - case char_type: - result.c = callJNIMethodIDA<jchar>(obj, jMethod->methodID(obj), jArgs); - break; - case short_type: - result.s = callJNIMethodIDA<jshort>(obj, jMethod->methodID(obj), jArgs); - break; - case int_type: - result.i = callJNIMethodIDA<jint>(obj, jMethod->methodID(obj), jArgs); - break; - - case long_type: - result.j = callJNIMethodIDA<jlong>(obj, jMethod->methodID(obj), jArgs); - break; - case float_type: - result.f = callJNIMethodIDA<jfloat>(obj, jMethod->methodID(obj), jArgs); - break; - case double_type: - result.d = callJNIMethodIDA<jdouble>(obj, jMethod->methodID(obj), jArgs); - break; - case invalid_type: - default: - break; + switch (jMethod->JNIReturnType()) { + case void_type: + callJNIMethodIDA<void>(obj, jMethod->methodID(obj), jArgs); + break; + case object_type: + result.l = callJNIMethodIDA<jobject>(obj, jMethod->methodID(obj), jArgs); + break; + case boolean_type: + result.z = callJNIMethodIDA<jboolean>(obj, jMethod->methodID(obj), jArgs); + break; + case byte_type: + result.b = callJNIMethodIDA<jbyte>(obj, jMethod->methodID(obj), jArgs); + break; + case char_type: + result.c = callJNIMethodIDA<jchar>(obj, jMethod->methodID(obj), jArgs); + break; + case short_type: + result.s = callJNIMethodIDA<jshort>(obj, jMethod->methodID(obj), jArgs); + break; + case int_type: + result.i = callJNIMethodIDA<jint>(obj, jMethod->methodID(obj), jArgs); + break; + + case long_type: + result.j = callJNIMethodIDA<jlong>(obj, jMethod->methodID(obj), jArgs); + break; + case float_type: + result.f = callJNIMethodIDA<jfloat>(obj, jMethod->methodID(obj), jArgs); + break; + case double_type: + result.d = callJNIMethodIDA<jdouble>(obj, jMethod->methodID(obj), jArgs); + break; + case invalid_type: + default: + break; } } - + convertJValueToNPVariant(result, jMethod->JNIReturnType(), jMethod->returnType(), resultValue); - free (jArgs); + free(jArgs); return true; } JObjectWrapper::JObjectWrapper(jobject instance) -: _refCount(0) + : m_refCount(0) { - assert (instance != 0); + assert(instance); // Cache the JNIEnv used to get the global ref for this java instanace. // It'll be used to delete the reference. - _env = getJNIEnv(); + m_env = getJNIEnv(); - _instance = _env->NewGlobalRef(instance); + m_instance = m_env->NewGlobalRef(instance); - LOGV("new global ref %p for %p\n", _instance, instance); + LOGV("new global ref %p for %p\n", m_instance, instance); - if (_instance == NULL) { + if (!m_instance) fprintf (stderr, "%s: could not get GlobalRef for %p\n", __PRETTY_FUNCTION__, instance); - } } JObjectWrapper::~JObjectWrapper() { - LOGV("deleting global ref %p\n", _instance); - _env->DeleteGlobalRef(_instance); + LOGV("deleting global ref %p\n", m_instance); + m_env->DeleteGlobalRef(m_instance); } diff --git a/V8Binding/jni/jni_instance.h b/WebCore/bridge/jni/v8/JavaInstanceV8.h index f6c639d..dcd51e8 100644 --- a/V8Binding/jni/jni_instance.h +++ b/WebCore/bridge/jni/v8/JavaInstanceV8.h @@ -1,6 +1,5 @@ /* - * Copyright (C) 2003 Apple Computer, Inc. All rights reserved. - * Copyright 2009, The Android Open Source Project + * Copyright 2010, The Android Open Source Project * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -21,11 +20,11 @@ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _JNI_INSTANCE_H_ -#define _JNI_INSTANCE_H_ +#ifndef JavaInstanceV8_h +#define JavaInstanceV8_h #include "JNIUtilityPrivate.h" @@ -41,36 +40,34 @@ namespace Bindings { class JavaClass; -class JObjectWrapper -{ +class JObjectWrapper { friend class RefPtr<JObjectWrapper>; friend class JavaField; friend class JavaInstance; public: - jobject instance() const { return _instance; } - void setInstance(jobject instance) { _instance = instance; } + jobject instance() const { return m_instance; } + void setInstance(jobject instance) { m_instance = instance; } protected: - JObjectWrapper(jobject instance); + JObjectWrapper(jobject instance); ~JObjectWrapper(); - - void ref() { _refCount++; } - void deref() - { - if (--_refCount == 0) - delete this; + + void ref() { m_refCount++; } + void deref() + { + if (!(--m_refCount)) + delete this; } - jobject _instance; + jobject m_instance; private: - JNIEnv *_env; - unsigned int _refCount; + JNIEnv* m_env; + unsigned int m_refCount; }; -class JavaInstance : public RefCounted<JavaInstance> -{ +class JavaInstance : public RefCounted<JavaInstance> { public: JavaInstance(jobject instance); virtual ~JavaInstance(); @@ -79,7 +76,7 @@ public: bool invokeMethod(const char* name, const NPVariant* args, int argsCount, NPVariant* result); - jobject javaInstance() const { return m_instance->_instance; } + jobject javaInstance() const { return m_instance->m_instance; } // These functions are called before and after the main entry points into // the native implementations. They can be used to establish and cleanup @@ -89,7 +86,7 @@ public: protected: RefPtr<JObjectWrapper> m_instance; - mutable JavaClass* _class; + mutable JavaClass* m_class; virtual void virtualBegin() {} virtual void virtualEnd() {} @@ -99,4 +96,4 @@ protected: } // namespace JSC -#endif // _JNI_INSTANCE_H_ +#endif // JavaInstanceV8_h diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp index d807808..5c52d3c 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -67,7 +67,7 @@ #include <runtime/JSLock.h> #elif USE(V8) #include "jni_npobject.h" -#include "jni_instance.h" +#include "JavaInstanceV8.h" #endif // USE(JSC) #include "KURL.h" |
