From 54dec9637e20bfba1857f3d54df3c43ce94ff97b Mon Sep 17 00:00:00 2001 From: Steve Block Date: Thu, 21 Jan 2010 15:58:20 +0000 Subject: Move V8 jni_npobject to bridge/jni/v8/JavaNPObjectV8 and fix style Change-Id: Icf99c709929ef14551de61e55780b97767575f01 --- Android.mk | 1 - V8Binding/jni/jni_npobject.cpp | 167 ---------------------------- V8Binding/jni/jni_npobject.h | 52 --------- WebCore/Android.v8bindings.mk | 1 + WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp | 2 +- WebCore/bridge/jni/v8/JavaNPObjectV8.cpp | 166 +++++++++++++++++++++++++++ WebCore/bridge/jni/v8/JavaNPObjectV8.h | 58 ++++++++++ WebKit/android/jni/WebCoreFrameBridge.cpp | 2 +- 8 files changed, 227 insertions(+), 222 deletions(-) delete mode 100644 V8Binding/jni/jni_npobject.cpp delete mode 100644 V8Binding/jni/jni_npobject.h create mode 100644 WebCore/bridge/jni/v8/JavaNPObjectV8.cpp create mode 100644 WebCore/bridge/jni/v8/JavaNPObjectV8.h diff --git a/Android.mk b/Android.mk index 6ca9589..8c96e53 100644 --- a/Android.mk +++ b/Android.mk @@ -185,7 +185,6 @@ BINDING_C_INCLUDES += \ $(LOCAL_PATH)/bridge/jni \ $(LOCAL_PATH)/bridge/jni/v8 JNI_SRC_FILES := \ - jni_npobject.cpp \ jni_runtime.cpp WEBKIT_SRC_FILES += $(addprefix $(JNI_PATH)/,$(JNI_SRC_FILES)) endif diff --git a/V8Binding/jni/jni_npobject.cpp b/V8Binding/jni/jni_npobject.cpp deleted file mode 100644 index 2c79fb6..0000000 --- a/V8Binding/jni/jni_npobject.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright 2009, The Android Open Source Project - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * 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. - */ - - -#include "config.h" -#include "jni_npobject.h" - -#include "JNIUtility.h" -#include "JavaClassV8.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. -#include "npruntime_impl.h" - -namespace JSC { namespace Bindings { -static NPObject* AllocJavaNPObject(NPP, NPClass*) -{ - JavaNPObject* obj = - static_cast(malloc(sizeof(JavaNPObject))); - if (obj == 0) - return 0; - bzero(obj, sizeof(JavaNPObject)); - return reinterpret_cast(obj); -} - -static void FreeJavaNPObject(NPObject* npobj) -{ - JavaNPObject* obj = reinterpret_cast(npobj); - obj->_instance = 0; // free does not call the destructor - free(obj); -} - -static NPClass JavaNPObjectClass = { - NP_CLASS_STRUCT_VERSION, - AllocJavaNPObject, // allocate, - FreeJavaNPObject, // free, - 0, // invalidate - JavaNPObject_HasMethod, - JavaNPObject_Invoke, - 0, // invokeDefault, - JavaNPObject_HasProperty, - JavaNPObject_GetProperty, - 0, // setProperty - 0, // removeProperty - 0, // enumerate - 0 // construct -}; - - -NPObject* JavaInstanceToNPObject(JavaInstance* instance) { - JavaNPObject* object = reinterpret_cast(_NPN_CreateObject(0, &JavaNPObjectClass)); - object->_instance = instance; - return reinterpret_cast(object); -} - - -// Returns null if obj is not a wrapper of JavaInstance -JavaInstance* ExtractJavaInstance(NPObject* obj) { - if (obj->_class == &JavaNPObjectClass) { - return reinterpret_cast(obj)->_instance.get(); - } - return 0; -} - -bool JavaNPObject_HasMethod(NPObject* obj, NPIdentifier identifier) { - JavaInstance* instance = ExtractJavaInstance(obj); - if (instance == 0) - return false; - NPUTF8* name = _NPN_UTF8FromIdentifier(identifier); - if (name == 0) - return false; - - instance->begin(); - bool result = (instance->getClass()->methodsNamed(name).size() > 0); - instance->end(); - - // TODO: use NPN_MemFree - free(name); - - return result; -} - -bool JavaNPObject_Invoke(NPObject* obj, NPIdentifier identifier, - const NPVariant* args, uint32_t argCount, NPVariant* result) { - JavaInstance* instance = ExtractJavaInstance(obj); - if (instance == 0) - return false; - NPUTF8* name = _NPN_UTF8FromIdentifier(identifier); - if (name == 0) - return false; - - instance->begin(); - bool r = instance->invokeMethod(name, args, argCount, result); - instance->end(); - - // TODO: use NPN_MemFree - free(name); - return r; - -} - -bool JavaNPObject_HasProperty(NPObject* obj, NPIdentifier identifier) { - JavaInstance* instance = ExtractJavaInstance(obj); - if (instance == 0) - return false; - NPUTF8* name = _NPN_UTF8FromIdentifier(identifier); - if (name == 0) - return false; - instance->begin(); - bool result = instance->getClass()->fieldNamed(name) != 0; - instance->end(); - free(name); - return result; -} - -bool JavaNPObject_GetProperty(NPObject* obj, NPIdentifier identifier, NPVariant* result) { - VOID_TO_NPVARIANT(*result); - JavaInstance* instance = ExtractJavaInstance(obj); - if (instance == 0) - return false; - NPUTF8* name = _NPN_UTF8FromIdentifier(identifier); - if (name == 0) - return false; - - instance->begin(); - JavaField* field = instance->getClass()->fieldNamed(name); - instance->end(); - free(name); // TODO: use NPN_MemFree - - if (field == 0) { - return false; - } - - jvalue value = getJNIField(instance->javaInstance(), - field->getJNIType(), - field->name(), - field->type()); - - convertJValueToNPVariant(value, field->getJNIType(), field->type(), result); - - return true; -} - -}} // namespace diff --git a/V8Binding/jni/jni_npobject.h b/V8Binding/jni/jni_npobject.h deleted file mode 100644 index 943b661..0000000 --- a/V8Binding/jni/jni_npobject.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2009, The Android Open Source Project - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * 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. - */ - -#ifndef JNI_NPOBJECT_H_ -#define JNI_NPOBJECT_H_ - -#include "npruntime.h" -#include "jni_runtime.h" - -#include -#include - -namespace JSC { namespace Bindings { - -struct JavaNPObject { - NPObject _object; - RefPtr _instance; -}; - -NPObject* JavaInstanceToNPObject(JavaInstance* instance); -JavaInstance* ExtractJavaInstance(NPObject* obj); - -bool JavaNPObject_HasMethod(NPObject* obj, NPIdentifier name); -bool JavaNPObject_Invoke(NPObject* obj, NPIdentifier methodName, const NPVariant* args, uint32_t argCount, NPVariant* result); -bool JavaNPObject_HasProperty(NPObject* obj, NPIdentifier name); -bool JavaNPObject_GetProperty(NPObject* obj, NPIdentifier name, NPVariant* ressult); - -} } - -#endif JNI_NPOBJECT_H_ diff --git a/WebCore/Android.v8bindings.mk b/WebCore/Android.v8bindings.mk index 32f5a5a..d5eb37a 100644 --- a/WebCore/Android.v8bindings.mk +++ b/WebCore/Android.v8bindings.mk @@ -173,5 +173,6 @@ LOCAL_SRC_FILES += \ LOCAL_SRC_FILES += \ bridge/jni/JNIUtility.cpp \ bridge/jni/v8/JNIUtilityPrivate.cpp \ + bridge/jni/v8/JavaNPObjectV8.cpp \ bridge/jni/v8/JavaClassV8.cpp \ bridge/jni/v8/JavaInstanceV8.cpp diff --git a/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp b/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp index 1d2a029..a817bc0 100644 --- a/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp +++ b/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp @@ -26,7 +26,7 @@ #include "config.h" #include "JNIUtilityPrivate.h" -#include "jni_npobject.h" +#include "JavaNPObjectV8.h" #include "jni_runtime.h" namespace JSC { diff --git a/WebCore/bridge/jni/v8/JavaNPObjectV8.cpp b/WebCore/bridge/jni/v8/JavaNPObjectV8.cpp new file mode 100644 index 0000000..416cc9e --- /dev/null +++ b/WebCore/bridge/jni/v8/JavaNPObjectV8.cpp @@ -0,0 +1,166 @@ +/* + * Copyright 2009, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * 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. + */ + + +#include "config.h" +#include "JavaNPObjectV8.h" + +#include "JNIUtility.h" +#include "JavaClassV8.h" +#include "JavaInstanceV8.h" +#include "jni_runtime.h" +#include "npruntime_impl.h" + +namespace JSC { + +namespace Bindings { + +static NPObject* AllocJavaNPObject(NPP, NPClass*) +{ + JavaNPObject* obj = static_cast(malloc(sizeof(JavaNPObject))); + if (!obj) + return 0; + bzero(obj, sizeof(JavaNPObject)); + return reinterpret_cast(obj); +} + +static void FreeJavaNPObject(NPObject* npobj) +{ + JavaNPObject* obj = reinterpret_cast(npobj); + obj->m_instance = 0; // free does not call the destructor + free(obj); +} + +static NPClass JavaNPObjectClass = { + NP_CLASS_STRUCT_VERSION, + AllocJavaNPObject, // allocate, + FreeJavaNPObject, // free, + 0, // invalidate + JavaNPObject_HasMethod, + JavaNPObject_Invoke, + 0, // invokeDefault, + JavaNPObject_HasProperty, + JavaNPObject_GetProperty, + 0, // setProperty + 0, // removeProperty + 0, // enumerate + 0 // construct +}; + + +NPObject* JavaInstanceToNPObject(JavaInstance* instance) { + JavaNPObject* object = reinterpret_cast(_NPN_CreateObject(0, &JavaNPObjectClass)); + object->m_instance = instance; + return reinterpret_cast(object); +} + + +// Returns null if obj is not a wrapper of JavaInstance +JavaInstance* ExtractJavaInstance(NPObject* obj) { + if (obj->_class == &JavaNPObjectClass) { + return reinterpret_cast(obj)->m_instance.get(); + } + return 0; +} + +bool JavaNPObject_HasMethod(NPObject* obj, NPIdentifier identifier) { + JavaInstance* instance = ExtractJavaInstance(obj); + if (!instance) + return false; + NPUTF8* name = _NPN_UTF8FromIdentifier(identifier); + if (!name) + return false; + + instance->begin(); + bool result = (instance->getClass()->methodsNamed(name).size() > 0); + instance->end(); + + // TODO: use NPN_MemFree + free(name); + + return result; +} + +bool JavaNPObject_Invoke(NPObject* obj, NPIdentifier identifier, const NPVariant* args, uint32_t argCount, NPVariant* result) { + JavaInstance* instance = ExtractJavaInstance(obj); + if (!instance) + return false; + NPUTF8* name = _NPN_UTF8FromIdentifier(identifier); + if (!name) + return false; + + instance->begin(); + bool r = instance->invokeMethod(name, args, argCount, result); + instance->end(); + + // TODO: use NPN_MemFree + free(name); + return r; +} + +bool JavaNPObject_HasProperty(NPObject* obj, NPIdentifier identifier) { + JavaInstance* instance = ExtractJavaInstance(obj); + if (!instance) + return false; + NPUTF8* name = _NPN_UTF8FromIdentifier(identifier); + if (!name) + return false; + instance->begin(); + bool result = instance->getClass()->fieldNamed(name); + instance->end(); + free(name); + return result; +} + +bool JavaNPObject_GetProperty(NPObject* obj, NPIdentifier identifier, NPVariant* result) { + VOID_TO_NPVARIANT(*result); + JavaInstance* instance = ExtractJavaInstance(obj); + if (!instance) + return false; + NPUTF8* name = _NPN_UTF8FromIdentifier(identifier); + if (!name) + return false; + + instance->begin(); + JavaField* field = instance->getClass()->fieldNamed(name); + instance->end(); + free(name); // TODO: use NPN_MemFree + + if (!field) + return false; + + jvalue value = getJNIField(instance->javaInstance(), + field->getJNIType(), + field->name(), + field->type()); + + convertJValueToNPVariant(value, field->getJNIType(), field->type(), result); + + return true; +} + +} // namespace Bindings + +} // namespace JSC diff --git a/WebCore/bridge/jni/v8/JavaNPObjectV8.h b/WebCore/bridge/jni/v8/JavaNPObjectV8.h new file mode 100644 index 0000000..c36ef70 --- /dev/null +++ b/WebCore/bridge/jni/v8/JavaNPObjectV8.h @@ -0,0 +1,58 @@ +/* + * 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 + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * 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. + */ + +#ifndef JavaNPObjectV8_h +#define JavaNPObjectV8_h + +#include "jni_runtime.h" +#include "npruntime.h" +#include +#include + + +namespace JSC { + +namespace Bindings { + +class JavaInstance; + +struct JavaNPObject { + NPObject m_object; + RefPtr m_instance; +}; + +NPObject* JavaInstanceToNPObject(JavaInstance*); +JavaInstance* ExtractJavaInstance(NPObject*); + +bool JavaNPObject_HasMethod(NPObject*, NPIdentifier name); +bool JavaNPObject_Invoke(NPObject*, NPIdentifier methodName, const NPVariant* args, uint32_t argCount, NPVariant* result); +bool JavaNPObject_HasProperty(NPObject*, NPIdentifier name); +bool JavaNPObject_GetProperty(NPObject*, NPIdentifier name, NPVariant* result); + +} // namespace Bindings + +} // namespace JSC + +#endif // JavaNPObjectV8_h diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp index 5c52d3c..6f11487 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -66,7 +66,7 @@ #include "JSDOMWindow.h" #include #elif USE(V8) -#include "jni_npobject.h" +#include "JavaNPObjectV8.h" #include "JavaInstanceV8.h" #endif // USE(JSC) -- cgit v1.1