diff options
Diffstat (limited to 'WebCore')
| -rw-r--r-- | WebCore/Android.jscbindings.mk | 3 | ||||
| -rw-r--r-- | WebCore/Android.v8bindings.mk | 4 | ||||
| -rw-r--r-- | WebCore/ChangeLog | 23 | ||||
| -rw-r--r-- | WebCore/GNUmakefile.am | 3 | ||||
| -rw-r--r-- | WebCore/WebCore.pro | 3 | ||||
| -rw-r--r-- | WebCore/WebCoreSources.bkl | 2 | ||||
| -rw-r--r-- | WebCore/bridge/Bridge.h | 110 | ||||
| -rw-r--r-- | WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp | 2 | ||||
| -rw-r--r-- | WebCore/bridge/jni/v8/JavaClassV8.cpp | 6 | ||||
| -rw-r--r-- | WebCore/bridge/jni/v8/JavaInstanceV8.cpp | 168 | ||||
| -rw-r--r-- | WebCore/bridge/jni/v8/JavaInstanceV8.h | 99 | ||||
| -rw-r--r-- | WebCore/bridge/jni/v8/JavaNPObjectV8.cpp | 166 | ||||
| -rw-r--r-- | WebCore/bridge/jni/v8/JavaNPObjectV8.h | 58 | ||||
| -rw-r--r-- | WebCore/bridge/jni/v8/JavaStringV8.h | 63 | ||||
| -rw-r--r-- | WebCore/bridge/jsc/BridgeJSC.cpp (renamed from WebCore/bridge/Bridge.cpp) | 3 | ||||
| -rw-r--r-- | WebCore/bridge/jsc/BridgeJSC.h | 151 |
16 files changed, 746 insertions, 118 deletions
diff --git a/WebCore/Android.jscbindings.mk b/WebCore/Android.jscbindings.mk index 2ceb268..428f99a 100644 --- a/WebCore/Android.jscbindings.mk +++ b/WebCore/Android.jscbindings.mk @@ -29,6 +29,7 @@ BINDING_C_INCLUDES := \ $(LOCAL_PATH)/bridge/c \ $(LOCAL_PATH)/bridge/jni \ $(LOCAL_PATH)/bridge/jni/jsc \ + $(LOCAL_PATH)/bridge/jsc \ \ $(JAVASCRIPTCORE_PATH)/API \ $(JAVASCRIPTCORE_PATH)/assembler \ @@ -181,7 +182,6 @@ LOCAL_SRC_FILES += \ \ bindings/ScriptControllerBase.cpp \ \ - bridge/Bridge.cpp \ bridge/IdentifierRep.cpp \ bridge/NP_jsobject.cpp \ bridge/c/c_class.cpp \ @@ -193,6 +193,7 @@ LOCAL_SRC_FILES += \ bridge/jni/jsc/JNIUtilityPrivate.cpp \ bridge/jni/jsc/JavaClassJSC.cpp \ bridge/jni/jsc/JavaInstanceJSC.cpp \ + bridge/jsc/BridgeJSC.cpp \ bridge/npruntime.cpp \ bridge/runtime_array.cpp \ bridge/runtime_method.cpp \ diff --git a/WebCore/Android.v8bindings.mk b/WebCore/Android.v8bindings.mk index b9594a4..d5eb37a 100644 --- a/WebCore/Android.v8bindings.mk +++ b/WebCore/Android.v8bindings.mk @@ -173,4 +173,6 @@ LOCAL_SRC_FILES += \ LOCAL_SRC_FILES += \ bridge/jni/JNIUtility.cpp \ bridge/jni/v8/JNIUtilityPrivate.cpp \ - bridge/jni/v8/JavaClassV8.cpp + bridge/jni/v8/JavaNPObjectV8.cpp \ + bridge/jni/v8/JavaClassV8.cpp \ + bridge/jni/v8/JavaInstanceV8.cpp diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index bd21b51..777f32b 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -2,6 +2,29 @@ Reviewed by David Levin. + Move bridge interfaces Field, Class, Instance and Array from Bridge to BridgeJSC + https://bugs.webkit.org/show_bug.cgi?id=33589 + + These interfaces use JSC-specific types, so are moved out of Bridge.h to allow the file to + be used with both JSC and V8. + + No new tests, refactoring only. + + * Android.jscbindings.mk: Modified. Removed Bridge.cpp and added BridgeJSC.cpp + * GNUmakefile.am: Modified. Removed Bridge.cpp and added BridgeJSC.[cpp|h] + * WebCore.pro: Modified. Removed Bridge.cpp and added BridgeJSC.[cpp|h] + * WebCore.xcodeproj/project.pbxproj: Modified. Removed Bridge.cpp and added BridgeJSC.[cpp|h] + * WebCoreSources.bkl: Modified. Removed Bridge.cpp and added BridgeJSC.cpp + * bridge/Bridge.cpp: Removed. + * bridge/Bridge.h: Modfied. Moved Field, Class, Instance and Array interfaces to BridgeJSC.h + * bridge/jsc: Added. + * bridge/jsc/BridgeJSC.cpp: Copied from WebCore/bridge/Bridge.cpp. + * bridge/jsc/BridgeJSC.h: Copied from WebCore/bridge/Bridge.h. + +2010-01-21 Steve Block <steveblock@google.com> + + Reviewed by David Levin. + Fixes style in WebCore/bridge/jni/JNIBridge https://bugs.webkit.org/show_bug.cgi?id=33914 diff --git a/WebCore/GNUmakefile.am b/WebCore/GNUmakefile.am index 744c754..9c5f000 100644 --- a/WebCore/GNUmakefile.am +++ b/WebCore/GNUmakefile.am @@ -484,7 +484,6 @@ webcore_sources += \ WebCore/bindings/js/SerializedScriptValue.h \ WebCore/bindings/js/StringSourceProvider.h \ WebCore/bindings/ScriptControllerBase.cpp \ - WebCore/bridge/Bridge.cpp \ WebCore/bridge/Bridge.h \ WebCore/bridge/IdentifierRep.cpp \ WebCore/bridge/IdentifierRep.h \ @@ -503,6 +502,8 @@ webcore_sources += \ WebCore/bridge/jni/jni_jsobject.h \ WebCore/bridge/jni/jsc/JavaClassJSC.h \ WebCore/bridge/jni/jsc/JavaInstanceJSC.h \ + WebCore/bridge/jsc/BridgeJSC.h \ + WebCore/bridge/jsc/BridgeJSC.cpp \ WebCore/bridge/npapi.h \ WebCore/bridge/npruntime.cpp \ WebCore/bridge/npruntime.h \ diff --git a/WebCore/WebCore.pro b/WebCore/WebCore.pro index b05a972..4dc1294 100644 --- a/WebCore/WebCore.pro +++ b/WebCore/WebCore.pro @@ -775,7 +775,6 @@ SOURCES += \ bindings/js/ScheduledAction.cpp \ bindings/js/SerializedScriptValue.cpp \ bindings/ScriptControllerBase.cpp \ - bridge/Bridge.cpp \ bridge/IdentifierRep.cpp \ bridge/NP_jsobject.cpp \ bridge/npruntime.cpp \ @@ -787,6 +786,7 @@ SOURCES += \ bridge/c/c_instance.cpp \ bridge/c/c_runtime.cpp \ bridge/c/c_utility.cpp \ + bridge/jsc/BridgeJSC.cpp \ css/CSSBorderImageValue.cpp \ css/CSSCanvasValue.cpp \ css/CSSCharsetRule.cpp \ @@ -1464,6 +1464,7 @@ HEADERS += \ bridge/c/c_instance.h \ bridge/c/c_runtime.h \ bridge/c/c_utility.h \ + bridge/jsc/BridgeJSC.h \ bridge/IdentifierRep.h \ bridge/NP_jsobject.h \ bridge/npruntime.h \ diff --git a/WebCore/WebCoreSources.bkl b/WebCore/WebCoreSources.bkl index 1254b06..50e6b94 100644 --- a/WebCore/WebCoreSources.bkl +++ b/WebCore/WebCoreSources.bkl @@ -165,13 +165,13 @@ This file contains the list of files needed to build WebCore. </set> <set append="1" var="WEBCORE_SOURCES_BRIDGE"> - bridge/Bridge.cpp bridge/IdentifierRep.cpp bridge/NP_jsobject.cpp bridge/c/c_class.cpp bridge/c/c_instance.cpp bridge/c/c_runtime.cpp bridge/c/c_utility.cpp + bridge/jsc/BridgeJSC.cpp bridge/npruntime.cpp bridge/runtime_array.cpp bridge/runtime_method.cpp diff --git a/WebCore/bridge/Bridge.h b/WebCore/bridge/Bridge.h index 71c72c3..d92cd15 100644 --- a/WebCore/bridge/Bridge.h +++ b/WebCore/bridge/Bridge.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2003, 2008, 2009 Apple Inc. All rights reserved. + * 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 @@ -26,35 +27,12 @@ #ifndef Bridge_h #define Bridge_h -#include <runtime/JSString.h> -#include <wtf/HashMap.h> -#include <wtf/RefCounted.h> -#include <wtf/Vector.h> +#include "BridgeJSC.h" namespace JSC { -class ArgList; -class Identifier; -class JSGlobalObject; -class PropertyNameArray; -class RuntimeObjectImp; - namespace Bindings { -class Instance; -class Method; -class RootObject; - -typedef Vector<Method*> MethodList; - -class Field { -public: - virtual JSValue valueFromInstance(ExecState*, const Instance*) const = 0; - virtual void setValueToInstance(ExecState*, const Instance*, JSValue) const = 0; - - virtual ~Field() { } -}; - class Method : public Noncopyable { public: virtual int numParameters() const = 0; @@ -62,90 +40,6 @@ public: virtual ~Method() { } }; -class Class : public Noncopyable { -public: - virtual MethodList methodsNamed(const Identifier&, Instance*) const = 0; - virtual Field* fieldNamed(const Identifier&, Instance*) const = 0; - virtual JSValue fallbackObject(ExecState*, Instance*, const Identifier&) { return jsUndefined(); } - - virtual ~Class() { } -}; - -typedef void (*KJSDidExecuteFunctionPtr)(ExecState*, JSObject* rootObject); - -class Instance : public RefCounted<Instance> { -public: - Instance(PassRefPtr<RootObject>); - - static void setDidExecuteFunction(KJSDidExecuteFunctionPtr func); - static KJSDidExecuteFunctionPtr didExecuteFunction(); - - // These functions are called before and after the main entry points into - // the native implementations. They can be used to establish and cleanup - // any needed state. - void begin(); - void end(); - - virtual Class* getClass() const = 0; - RuntimeObjectImp* createRuntimeObject(ExecState*); - void willInvalidateRuntimeObject(); - void willDestroyRuntimeObject(); - - // Returns false if the value was not set successfully. - virtual bool setValueOfUndefinedField(ExecState*, const Identifier&, JSValue) { return false; } - - virtual JSValue invokeMethod(ExecState*, const MethodList&, const ArgList& args) = 0; - - virtual bool supportsInvokeDefaultMethod() const { return false; } - virtual JSValue invokeDefaultMethod(ExecState*, const ArgList&) { return jsUndefined(); } - - virtual bool supportsConstruct() const { return false; } - virtual JSValue invokeConstruct(ExecState*, const ArgList&) { return JSValue(); } - - virtual void getPropertyNames(ExecState*, PropertyNameArray&) { } - - virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const = 0; - - virtual JSValue valueOf(ExecState* exec) const = 0; - - RootObject* rootObject() const; - - virtual ~Instance(); - - virtual bool getOwnPropertySlot(JSObject*, ExecState*, const Identifier&, PropertySlot&) { return false; } - virtual bool getOwnPropertyDescriptor(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&) { return false; } - virtual void put(JSObject*, ExecState*, const Identifier&, JSValue, PutPropertySlot&) { } - -protected: - virtual void virtualBegin() { } - virtual void virtualEnd() { } - virtual RuntimeObjectImp* newRuntimeObject(ExecState*); - - RefPtr<RootObject> m_rootObject; - -private: - RuntimeObjectImp* m_runtimeObject; -}; - -class Array : public Noncopyable { -public: - Array(PassRefPtr<RootObject>); - virtual ~Array(); - - virtual void setValueAt(ExecState*, unsigned index, JSValue) const = 0; - virtual JSValue valueAt(ExecState*, unsigned index) const = 0; - virtual unsigned int getLength() const = 0; - -protected: - RefPtr<RootObject> m_rootObject; -}; - -const char* signatureForParameters(const ArgList&); - -typedef HashMap<RefPtr<UString::Rep>, MethodList*> MethodListMap; -typedef HashMap<RefPtr<UString::Rep>, Method*> MethodMap; -typedef HashMap<RefPtr<UString::Rep>, Field*> FieldMap; - } // namespace Bindings } // namespace JSC 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/JavaClassV8.cpp b/WebCore/bridge/jni/v8/JavaClassV8.cpp index 54b40c9..c29cf86 100644 --- a/WebCore/bridge/jni/v8/JavaClassV8.cpp +++ b/WebCore/bridge/jni/v8/JavaClassV8.cpp @@ -56,7 +56,7 @@ JavaClass::JavaClass(jobject anInstance) jobject aJField = env->GetObjectArrayElement((jobjectArray)fields, i); JavaField* aField = new JavaField(env, aJField); // deleted in the JavaClass destructor { - m_fields.set(aField->name(), aField); + m_fields.set(aField->name().UTF8String(), aField); } env->DeleteLocalRef(aJField); } @@ -69,10 +69,10 @@ JavaClass::JavaClass(jobject anInstance) JavaMethod* aMethod = new JavaMethod(env, aJMethod); // deleted in the JavaClass destructor MethodList* methodList; { - methodList = m_methods.get(aMethod->name()); + methodList = m_methods.get(aMethod->name().UTF8String()); if (!methodList) { methodList = new MethodList(); - m_methods.set(aMethod->name(), methodList); + m_methods.set(aMethod->name().UTF8String(), methodList); } } methodList->append(aMethod); diff --git a/WebCore/bridge/jni/v8/JavaInstanceV8.cpp b/WebCore/bridge/jni/v8/JavaInstanceV8.cpp new file mode 100644 index 0000000..13d4984 --- /dev/null +++ b/WebCore/bridge/jni/v8/JavaInstanceV8.cpp @@ -0,0 +1,168 @@ +/* + * 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 "JavaInstanceV8.h" + +#include "JNIUtility.h" +#include "JavaClassV8.h" +#include "jni_runtime.h" + +#include <assert.h> +#include <utils/Log.h> + +#define LOG_TAG "v8binding" + +using namespace JSC::Bindings; + +JavaInstance::JavaInstance(jobject instance) +{ + m_instance = new JObjectWrapper(instance); + m_class = 0; +} + +JavaInstance::~JavaInstance() +{ + m_instance = 0; + delete m_class; +} + +JavaClass* JavaInstance::getClass() const +{ + if (!m_class) { + m_class = new JavaClass(javaInstance()); + } + return m_class; +} + +bool JavaInstance::invokeMethod(const char* methodName, const NPVariant* args, int count, NPVariant* resultValue) +{ + 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 + // fundamental problem is that JavaScript doesn have the + // 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* method = 0; + for (size_t methodIndex = 0; methodIndex < numMethods; methodIndex++) { + aMethod = methodList[methodIndex]; + if (aMethod->numParameters() == count) { + method = aMethod; + break; + } + } + if (!method) { + LOGW("unable to find an appropiate method\n"); + return false; + } + + 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; + } + } + + convertJValueToNPVariant(result, jMethod->JNIReturnType(), jMethod->returnType(), resultValue); + free(jArgs); + + return true; +} + +JObjectWrapper::JObjectWrapper(jobject instance) + : m_refCount(0) +{ + assert(instance); + + // Cache the JNIEnv used to get the global ref for this java instanace. + // It'll be used to delete the reference. + m_env = getJNIEnv(); + + m_instance = m_env->NewGlobalRef(instance); + + LOGV("new global ref %p for %p\n", m_instance, instance); + + if (!m_instance) + fprintf (stderr, "%s: could not get GlobalRef for %p\n", __PRETTY_FUNCTION__, instance); +} + +JObjectWrapper::~JObjectWrapper() { + LOGV("deleting global ref %p\n", m_instance); + m_env->DeleteGlobalRef(m_instance); +} diff --git a/WebCore/bridge/jni/v8/JavaInstanceV8.h b/WebCore/bridge/jni/v8/JavaInstanceV8.h new file mode 100644 index 0000000..dcd51e8 --- /dev/null +++ b/WebCore/bridge/jni/v8/JavaInstanceV8.h @@ -0,0 +1,99 @@ +/* + * 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 JavaInstanceV8_h +#define JavaInstanceV8_h + +#include "JNIUtilityPrivate.h" + +#include <JavaVM/jni.h> +#include <wtf/RefCounted.h> +#include <wtf/RefPtr.h> + +using namespace WTF; + +namespace JSC { + +namespace Bindings { + +class JavaClass; + +class JObjectWrapper { +friend class RefPtr<JObjectWrapper>; +friend class JavaField; +friend class JavaInstance; + +public: + jobject instance() const { return m_instance; } + void setInstance(jobject instance) { m_instance = instance; } + +protected: + JObjectWrapper(jobject instance); + ~JObjectWrapper(); + + void ref() { m_refCount++; } + void deref() + { + if (!(--m_refCount)) + delete this; + } + + jobject m_instance; + +private: + JNIEnv* m_env; + unsigned int m_refCount; +}; + +class JavaInstance : public RefCounted<JavaInstance> { +public: + JavaInstance(jobject instance); + virtual ~JavaInstance(); + + JavaClass* getClass() const; + + bool invokeMethod(const char* name, const NPVariant* args, int argsCount, NPVariant* result); + + 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 + // any needed state. + void begin() { virtualBegin(); } + void end() { virtualEnd(); } + +protected: + RefPtr<JObjectWrapper> m_instance; + mutable JavaClass* m_class; + + virtual void virtualBegin() {} + virtual void virtualEnd() {} +}; + +} // namespace Bindings + +} // namespace JSC + +#endif // JavaInstanceV8_h diff --git a/WebCore/bridge/jni/v8/JavaNPObjectV8.cpp b/WebCore/bridge/jni/v8/JavaNPObjectV8.cpp new file mode 100644 index 0000000..636d075 --- /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<JavaNPObject*>(malloc(sizeof(JavaNPObject))); + if (!obj) + return 0; + bzero(obj, sizeof(JavaNPObject)); + return reinterpret_cast<NPObject*>(obj); +} + +static void FreeJavaNPObject(NPObject* npobj) +{ + JavaNPObject* obj = reinterpret_cast<JavaNPObject*>(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<JavaNPObject*>(_NPN_CreateObject(0, &JavaNPObjectClass)); + object->m_instance = instance; + return reinterpret_cast<NPObject*>(object); +} + + +// Returns null if obj is not a wrapper of JavaInstance +JavaInstance* ExtractJavaInstance(NPObject* obj) { + if (obj->_class == &JavaNPObjectClass) { + return reinterpret_cast<JavaNPObject*>(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().UTF8String(), + 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 <JavaVM/jni.h> +#include <wtf/RefPtr.h> + + +namespace JSC { + +namespace Bindings { + +class JavaInstance; + +struct JavaNPObject { + NPObject m_object; + RefPtr<JavaInstance> 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/WebCore/bridge/jni/v8/JavaStringV8.h b/WebCore/bridge/jni/v8/JavaStringV8.h new file mode 100644 index 0000000..8788e58 --- /dev/null +++ b/WebCore/bridge/jni/v8/JavaStringV8.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2010 Apple Computer, Inc. All rights reserved. + * + * 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 THE COPYRIGHT OWNER 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 JavaStringV8_h +#define JavaStringV8_h + +#include "CString.h" +#include "JNIUtility.h" + + +namespace JSC { + +namespace Bindings { + +class JavaStringImpl { +public: + void init() {} + + void init(JNIEnv* e, jstring s) + { + int size = e->GetStringLength(s); + const char* cs = getCharactersFromJStringInEnv(e, s); + { + m_utf8String = WebCore::CString(cs, size); + } + releaseCharactersForJStringInEnv(e, s, cs); + } + + const char* UTF8String() const { return m_utf8String.data(); } + const jchar* uchars() const { return 0; } // Not implemented + int length() const { return m_utf8String.length(); } + +private: + WebCore::CString m_utf8String; +}; + +} // namespace Bindings + +} // namespace JSC + +#endif // JavaStringV8_h diff --git a/WebCore/bridge/Bridge.cpp b/WebCore/bridge/jsc/BridgeJSC.cpp index 2daf3eb..ed582d3 100644 --- a/WebCore/bridge/Bridge.cpp +++ b/WebCore/bridge/jsc/BridgeJSC.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved. + * 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 @@ -24,7 +25,7 @@ */ #include "config.h" -#include "Bridge.h" +#include "BridgeJSC.h" #include "runtime_object.h" #include "runtime_root.h" diff --git a/WebCore/bridge/jsc/BridgeJSC.h b/WebCore/bridge/jsc/BridgeJSC.h new file mode 100644 index 0000000..8e2cb2b --- /dev/null +++ b/WebCore/bridge/jsc/BridgeJSC.h @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2003, 2008, 2009 Apple Inc. All rights reserved. + * 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 BridgeJSC_h +#define BridgeJSC_h + +#if USE(JSC) + +#include <runtime/JSString.h> +#include <wtf/HashMap.h> +#include <wtf/RefCounted.h> +#include <wtf/Vector.h> + +namespace JSC { + +class ArgList; +class Identifier; +class JSGlobalObject; +class PropertyNameArray; +class RuntimeObjectImp; + +namespace Bindings { + +class Instance; +class Method; +class RootObject; + +typedef Vector<Method*> MethodList; + +class Field { +public: + virtual JSValue valueFromInstance(ExecState*, const Instance*) const = 0; + virtual void setValueToInstance(ExecState*, const Instance*, JSValue) const = 0; + + virtual ~Field() { } +}; + +class Class : public Noncopyable { +public: + virtual MethodList methodsNamed(const Identifier&, Instance*) const = 0; + virtual Field* fieldNamed(const Identifier&, Instance*) const = 0; + virtual JSValue fallbackObject(ExecState*, Instance*, const Identifier&) { return jsUndefined(); } + + virtual ~Class() { } +}; + +typedef void (*KJSDidExecuteFunctionPtr)(ExecState*, JSObject* rootObject); + +class Instance : public RefCounted<Instance> { +public: + Instance(PassRefPtr<RootObject>); + + static void setDidExecuteFunction(KJSDidExecuteFunctionPtr func); + static KJSDidExecuteFunctionPtr didExecuteFunction(); + + // These functions are called before and after the main entry points into + // the native implementations. They can be used to establish and cleanup + // any needed state. + void begin(); + void end(); + + virtual Class* getClass() const = 0; + RuntimeObjectImp* createRuntimeObject(ExecState*); + void willInvalidateRuntimeObject(); + void willDestroyRuntimeObject(); + + // Returns false if the value was not set successfully. + virtual bool setValueOfUndefinedField(ExecState*, const Identifier&, JSValue) { return false; } + + virtual JSValue invokeMethod(ExecState*, const MethodList&, const ArgList& args) = 0; + + virtual bool supportsInvokeDefaultMethod() const { return false; } + virtual JSValue invokeDefaultMethod(ExecState*, const ArgList&) { return jsUndefined(); } + + virtual bool supportsConstruct() const { return false; } + virtual JSValue invokeConstruct(ExecState*, const ArgList&) { return JSValue(); } + + virtual void getPropertyNames(ExecState*, PropertyNameArray&) { } + + virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const = 0; + + virtual JSValue valueOf(ExecState* exec) const = 0; + + RootObject* rootObject() const; + + virtual ~Instance(); + + virtual bool getOwnPropertySlot(JSObject*, ExecState*, const Identifier&, PropertySlot&) { return false; } + virtual bool getOwnPropertyDescriptor(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&) { return false; } + virtual void put(JSObject*, ExecState*, const Identifier&, JSValue, PutPropertySlot&) { } + +protected: + virtual void virtualBegin() { } + virtual void virtualEnd() { } + virtual RuntimeObjectImp* newRuntimeObject(ExecState*); + + RefPtr<RootObject> m_rootObject; + +private: + RuntimeObjectImp* m_runtimeObject; +}; + +class Array : public Noncopyable { +public: + Array(PassRefPtr<RootObject>); + virtual ~Array(); + + virtual void setValueAt(ExecState*, unsigned index, JSValue) const = 0; + virtual JSValue valueAt(ExecState*, unsigned index) const = 0; + virtual unsigned int getLength() const = 0; + +protected: + RefPtr<RootObject> m_rootObject; +}; + +const char* signatureForParameters(const ArgList&); + +typedef HashMap<RefPtr<UString::Rep>, MethodList*> MethodListMap; +typedef HashMap<RefPtr<UString::Rep>, Method*> MethodMap; +typedef HashMap<RefPtr<UString::Rep>, Field*> FieldMap; + +} // namespace Bindings + +} // namespace JSC + +#endif // USE(JSC) + +#endif |
