From 7728885e97a2af41cfee93c614a8bbc66a426a31 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Mon, 18 Jan 2010 18:49:13 +0000 Subject: Cherry-pick WebKit change 53412 to move jni_instance to JavaInstanceJSC See http://trac.webkit.org/changeset/53412 Note that changes to WebCoreFrameBridge.cpp cpp were required as a result of this cherry-pick. Change-Id: I0a6f6fafc5b0d5d9337ef4e339c6a0c5dd188eb9 --- WebCore/Android.jscbindings.mk | 2 +- WebCore/ChangeLog | 19 ++ WebCore/GNUmakefile.am | 3 +- WebCore/WebCore.xcodeproj/project.pbxproj | 16 +- WebCore/bindings/js/ScriptControllerMac.mm | 2 +- WebCore/bridge/jni/jni_instance.cpp | 335 ----------------------------- WebCore/bridge/jni/jni_instance.h | 110 ---------- WebCore/bridge/jni/jni_runtime.h | 4 +- WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp | 335 +++++++++++++++++++++++++++++ WebCore/bridge/jni/jsc/JavaInstanceJSC.h | 110 ++++++++++ WebKit/android/jni/WebCoreFrameBridge.cpp | 2 +- 11 files changed, 479 insertions(+), 459 deletions(-) delete mode 100644 WebCore/bridge/jni/jni_instance.cpp delete mode 100644 WebCore/bridge/jni/jni_instance.h create mode 100644 WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp create mode 100644 WebCore/bridge/jni/jsc/JavaInstanceJSC.h diff --git a/WebCore/Android.jscbindings.mk b/WebCore/Android.jscbindings.mk index 6dd55ff..31edd49 100644 --- a/WebCore/Android.jscbindings.mk +++ b/WebCore/Android.jscbindings.mk @@ -188,9 +188,9 @@ LOCAL_SRC_FILES += \ bridge/c/c_runtime.cpp \ bridge/c/c_utility.cpp \ bridge/jni/jni_class.cpp \ - bridge/jni/jni_instance.cpp \ bridge/jni/jni_runtime.cpp \ bridge/jni/jni_utility.cpp \ + bridge/jni/jsc/JavaInstanceJSC.cpp \ bridge/jni/jsc/jni_utility_private.cpp \ bridge/npruntime.cpp \ bridge/runtime.cpp \ diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index 67567ab..d60de59 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,22 @@ +2010-01-18 Steve Block + + Reviewed by Adam Barth. + + Moves JSC-specific version of JavaInstance from bridge/jni/jni_instance to bridge/jni/jsc/JavaInstanceJSC + https://bugs.webkit.org/show_bug.cgi?id=33672 + + No new tests, refactoring only. + + * Android.jscbindings.mk: Modified. Removed jni_instance.cpp and added JavaInstanceJSC.cpp + * GNUmakefile.am: Modified. Removed jni_instance.h and added JavaInstanceJSC.h + * WebCore.xcodeproj/project.pbxproj: Modified. Removed jni_instance.[cpp|h] and added JavaInstanceJSC.[cpp|h] + * bindings/js/ScriptControllerMac.mm: Modified. Includes JavaInstanceJSC.h + * bridge/jni/jni_instance.cpp: Removed. + * bridge/jni/jni_instance.h: Removed. + * bridge/jni/jni_runtime.h: Modified. Includes JavaInstanceJSC.h + * bridge/jni/jsc/JavaInstanceJSC.cpp: Copied from WebCore/bridge/jni/jni_instance.cpp. + * bridge/jni/jsc/JavaInstanceJSC.h: Copied from WebCore/bridge/jni/jni_instance.h. + 2009-12-10 Alexey Proskuryakov Reviewed by Darin Adler. diff --git a/WebCore/GNUmakefile.am b/WebCore/GNUmakefile.am index f8fa302..220801a 100644 --- a/WebCore/GNUmakefile.am +++ b/WebCore/GNUmakefile.am @@ -14,6 +14,7 @@ webcore_cppflags += \ -I$(srcdir)/WebCore/bindings/js \ -I$(srcdir)/WebCore/bridge \ -I$(srcdir)/WebCore/bridge/c \ + -I$(srcdir)/WebCore/bridge/jni/jsc \ -I$(srcdir)/WebCore/css \ -I$(srcdir)/WebCore/dom \ -I$(srcdir)/WebCore/dom/default \ @@ -496,10 +497,10 @@ webcore_sources += \ WebCore/bridge/c/c_utility.cpp \ WebCore/bridge/c/c_utility.h \ WebCore/bridge/jni/jni_class.h \ - WebCore/bridge/jni/jni_instance.h \ WebCore/bridge/jni/jni_jsobject.h \ WebCore/bridge/jni/jni_runtime.h \ WebCore/bridge/jni/jni_utility.h \ + WebCore/bridge/jni/jsc/JavaInstanceJSC.h \ WebCore/bridge/npapi.h \ WebCore/bridge/npruntime.cpp \ WebCore/bridge/npruntime.h \ diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj index 2d0b804..c008276 100644 --- a/WebCore/WebCore.xcodeproj/project.pbxproj +++ b/WebCore/WebCore.xcodeproj/project.pbxproj @@ -297,8 +297,6 @@ 1A569CFE0D7E2B82007C3983 /* c_utility.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A569CCD0D7E2B82007C3983 /* c_utility.h */; }; 1A569CFF0D7E2B82007C3983 /* jni_class.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A569CCF0D7E2B82007C3983 /* jni_class.cpp */; }; 1A569D000D7E2B82007C3983 /* jni_class.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A569CD00D7E2B82007C3983 /* jni_class.h */; }; - 1A569D010D7E2B82007C3983 /* jni_instance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A569CD10D7E2B82007C3983 /* jni_instance.cpp */; }; - 1A569D020D7E2B82007C3983 /* jni_instance.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A569CD20D7E2B82007C3983 /* jni_instance.h */; }; 1A569D030D7E2B82007C3983 /* jni_jsobject.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A569CD30D7E2B82007C3983 /* jni_jsobject.mm */; }; 1A569D040D7E2B82007C3983 /* jni_jsobject.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A569CD40D7E2B82007C3983 /* jni_jsobject.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1A569D050D7E2B82007C3983 /* jni_objc.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A569CD50D7E2B82007C3983 /* jni_objc.mm */; }; @@ -1103,6 +1101,8 @@ 550A0BCA085F6039007353D6 /* QualifiedName.h in Headers */ = {isa = PBXBuildFile; fileRef = 550A0BC8085F6039007353D6 /* QualifiedName.h */; settings = {ATTRIBUTES = (Private, ); }; }; 599D1E3210C97D6E00E0EF12 /* jni_utility_private.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 599D1E3010C97D6E00E0EF12 /* jni_utility_private.cpp */; }; 599D1E3310C97D6E00E0EF12 /* jni_utility_private.h in Headers */ = {isa = PBXBuildFile; fileRef = 599D1E3110C97D6E00E0EF12 /* jni_utility_private.h */; }; + 59A9E7B01104758800DFB4C1 /* JavaInstanceJSC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 59A9E7AF1104758800DFB4C1 /* JavaInstanceJSC.cpp */; }; + 59A9E7B21104759400DFB4C1 /* JavaInstanceJSC.h in Headers */ = {isa = PBXBuildFile; fileRef = 59A9E7B11104759400DFB4C1 /* JavaInstanceJSC.h */; }; 59C77F2A10545B3B00506104 /* GeolocationServiceMock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 59C77F2810545B3B00506104 /* GeolocationServiceMock.cpp */; }; 59C77F2B10545B3B00506104 /* GeolocationServiceMock.h in Headers */ = {isa = PBXBuildFile; fileRef = 59C77F2910545B3B00506104 /* GeolocationServiceMock.h */; settings = {ATTRIBUTES = (Private, ); }; }; 5D15E3AB0F9E6AC1009E0E3F /* XMLTokenizerScope.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5D15E3A90F9E6AC1009E0E3F /* XMLTokenizerScope.cpp */; }; @@ -5517,8 +5517,6 @@ 1A569CCD0D7E2B82007C3983 /* c_utility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = c_utility.h; sourceTree = ""; }; 1A569CCF0D7E2B82007C3983 /* jni_class.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jni_class.cpp; sourceTree = ""; }; 1A569CD00D7E2B82007C3983 /* jni_class.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jni_class.h; sourceTree = ""; }; - 1A569CD10D7E2B82007C3983 /* jni_instance.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jni_instance.cpp; sourceTree = ""; }; - 1A569CD20D7E2B82007C3983 /* jni_instance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jni_instance.h; sourceTree = ""; }; 1A569CD30D7E2B82007C3983 /* jni_jsobject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = jni_jsobject.mm; sourceTree = ""; }; 1A569CD40D7E2B82007C3983 /* jni_jsobject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jni_jsobject.h; sourceTree = ""; }; 1A569CD50D7E2B82007C3983 /* jni_objc.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = jni_objc.mm; sourceTree = ""; }; @@ -6427,6 +6425,8 @@ 550A0BC8085F6039007353D6 /* QualifiedName.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = QualifiedName.h; sourceTree = ""; tabWidth = 8; usesTabs = 0; }; 599D1E3010C97D6E00E0EF12 /* jni_utility_private.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = jni_utility_private.cpp; path = jsc/jni_utility_private.cpp; sourceTree = ""; }; 599D1E3110C97D6E00E0EF12 /* jni_utility_private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jni_utility_private.h; path = jsc/jni_utility_private.h; sourceTree = ""; }; + 59A9E7AF1104758800DFB4C1 /* JavaInstanceJSC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JavaInstanceJSC.cpp; path = jsc/JavaInstanceJSC.cpp; sourceTree = ""; }; + 59A9E7B11104759400DFB4C1 /* JavaInstanceJSC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JavaInstanceJSC.h; path = jsc/JavaInstanceJSC.h; sourceTree = ""; }; 59C77F2810545B3B00506104 /* GeolocationServiceMock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = GeolocationServiceMock.cpp; path = mock/GeolocationServiceMock.cpp; sourceTree = ""; }; 59C77F2910545B3B00506104 /* GeolocationServiceMock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GeolocationServiceMock.h; path = mock/GeolocationServiceMock.h; sourceTree = ""; }; 5D15E3A90F9E6AC1009E0E3F /* XMLTokenizerScope.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XMLTokenizerScope.cpp; sourceTree = ""; }; @@ -10283,8 +10283,6 @@ 599D1E2F10C97D4C00E0EF12 /* jsc */, 1A569CCF0D7E2B82007C3983 /* jni_class.cpp */, 1A569CD00D7E2B82007C3983 /* jni_class.h */, - 1A569CD10D7E2B82007C3983 /* jni_instance.cpp */, - 1A569CD20D7E2B82007C3983 /* jni_instance.h */, 1A569CD40D7E2B82007C3983 /* jni_jsobject.h */, 1A569CD30D7E2B82007C3983 /* jni_jsobject.mm */, 1A569CD50D7E2B82007C3983 /* jni_objc.mm */, @@ -10986,6 +10984,8 @@ 599D1E2F10C97D4C00E0EF12 /* jsc */ = { isa = PBXGroup; children = ( + 59A9E7B11104759400DFB4C1 /* JavaInstanceJSC.h */, + 59A9E7AF1104758800DFB4C1 /* JavaInstanceJSC.cpp */, 599D1E3010C97D6E00E0EF12 /* jni_utility_private.cpp */, 599D1E3110C97D6E00E0EF12 /* jni_utility_private.h */, ); @@ -17055,7 +17055,6 @@ 1C81BA010E9733CB00266E07 /* JavaScriptProfile.h in Headers */, 1C81B9FF0E9733CB00266E07 /* JavaScriptProfileNode.h in Headers */, 1A569D000D7E2B82007C3983 /* jni_class.h in Headers */, - 1A569D020D7E2B82007C3983 /* jni_instance.h in Headers */, 1A569D040D7E2B82007C3983 /* jni_jsobject.h in Headers */, 1A569D070D7E2B82007C3983 /* jni_runtime.h in Headers */, 1A569D090D7E2B82007C3983 /* jni_utility.h in Headers */, @@ -18262,6 +18261,7 @@ 1CC93C640DAE929600E4BC3A /* Copy Forwarding and ICU Headers */, 93F199FD08245E59001E9ABC /* Resources */, 1C81BA330E97357C00266E07 /* Copy Inspector Resources */, + 59A9E7B21104759400DFB4C1 /* JavaInstanceJSC.h in Headers */, 1C5F9D760E09A1B400E91D0A /* Streamline Inspector Source */, 93F19A0C08245E59001E9ABC /* Sources */, 93F19B1208245E59001E9ABC /* Frameworks */, @@ -19213,7 +19213,6 @@ 1C81BA020E9733CB00266E07 /* JavaScriptProfile.cpp in Sources */, 1C81BA000E9733CB00266E07 /* JavaScriptProfileNode.cpp in Sources */, 1A569CFF0D7E2B82007C3983 /* jni_class.cpp in Sources */, - 1A569D010D7E2B82007C3983 /* jni_instance.cpp in Sources */, 1A569D030D7E2B82007C3983 /* jni_jsobject.mm in Sources */, 1A569D050D7E2B82007C3983 /* jni_objc.mm in Sources */, 1A569D060D7E2B82007C3983 /* jni_runtime.cpp in Sources */, @@ -20411,6 +20410,7 @@ /* Begin PBXTargetDependency section */ DD041FF109D9E3250010AF2A /* PBXTargetDependency */ = { isa = PBXTargetDependency; + 59A9E7B01104758800DFB4C1 /* JavaInstanceJSC.cpp in Sources */, target = DD041FBE09D9DDBE0010AF2A /* Derived Sources */; targetProxy = DD041FF009D9E3250010AF2A /* PBXContainerItemProxy */; }; diff --git a/WebCore/bindings/js/ScriptControllerMac.mm b/WebCore/bindings/js/ScriptControllerMac.mm index 21ec0f2..7d3b267 100644 --- a/WebCore/bindings/js/ScriptControllerMac.mm +++ b/WebCore/bindings/js/ScriptControllerMac.mm @@ -51,7 +51,7 @@ #import "runtime.h" #if ENABLE(MAC_JAVA_BRIDGE) -#import "jni_instance.h" +#import "JavaInstanceJSC.h" #endif @interface NSObject (WebPlugin) diff --git a/WebCore/bridge/jni/jni_instance.cpp b/WebCore/bridge/jni/jni_instance.cpp deleted file mode 100644 index 3783d10..0000000 --- a/WebCore/bridge/jni/jni_instance.cpp +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Copyright (C) 2003, 2008 Apple 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: - * 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 "jni_instance.h" - -#if ENABLE(MAC_JAVA_BRIDGE) - -#include "jni_class.h" -#include "jni_runtime.h" -#include "jni_utility.h" -#include "jni_utility_private.h" -#include "runtime_object.h" -#include "runtime_root.h" -#include -#include -#include - -#if PLATFORM(ANDROID) -#include -#endif - -#ifdef NDEBUG -#define JS_LOG(formatAndArgs...) ((void)0) -#else -#define JS_LOG(formatAndArgs...) { \ - fprintf (stderr, "%s:%d -- %s: ", __FILE__, __LINE__, __FUNCTION__); \ - fprintf(stderr, formatAndArgs); \ -} -#endif - -using namespace JSC::Bindings; -using namespace JSC; - -JavaInstance::JavaInstance (jobject instance, PassRefPtr rootObject) - : Instance(rootObject) -{ - _instance = new JObjectWrapper (instance); - _class = 0; -} - -JavaInstance::~JavaInstance () -{ - delete _class; -} - -#define NUM_LOCAL_REFS 64 - -void JavaInstance::virtualBegin() -{ - getJNIEnv()->PushLocalFrame (NUM_LOCAL_REFS); -} - -void JavaInstance::virtualEnd() -{ - getJNIEnv()->PopLocalFrame (NULL); -} - -Class *JavaInstance::getClass() const -{ - if (_class == 0) - _class = new JavaClass (_instance->_instance); - return _class; -} - -JSValue JavaInstance::stringValue(ExecState* exec) const -{ - JSLock lock(SilenceAssertionsOnly); - - jstring stringValue = (jstring)callJNIMethod(_instance->_instance, "toString", "()Ljava/lang/String;"); - JNIEnv *env = getJNIEnv(); - const jchar *c = getUCharactersFromJStringInEnv(env, stringValue); - UString u((const UChar *)c, (int)env->GetStringLength(stringValue)); - releaseUCharactersForJStringInEnv(env, stringValue, c); - return jsString(exec, u); -} - -JSValue JavaInstance::numberValue(ExecState* exec) const -{ - jdouble doubleValue = callJNIMethod(_instance->_instance, "doubleValue", "()D"); - return jsNumber(exec, doubleValue); -} - -JSValue JavaInstance::booleanValue() const -{ - jboolean booleanValue = callJNIMethod(_instance->_instance, "booleanValue", "()Z"); - return jsBoolean(booleanValue); -} - -JSValue JavaInstance::invokeMethod (ExecState *exec, const MethodList &methodList, const ArgList &args) -{ - int i, count = args.size(); - jvalue *jArgs; - JSValue resultValue; - Method *method = 0; - 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. - Method *aMethod; - for (size_t methodIndex = 0; methodIndex < numMethods; methodIndex++) { - aMethod = methodList[methodIndex]; - if (aMethod->numParameters() == count) { - method = aMethod; - break; - } - } - if (method == 0) { - JS_LOG ("unable to find an appropiate method\n"); - return jsUndefined(); - } - - const JavaMethod *jMethod = static_cast(method); - JS_LOG ("call %s %s on %p\n", UString(jMethod->name()).UTF8String().c_str(), jMethod->signature(), _instance->_instance); - - if (count > 0) { - jArgs = (jvalue *)malloc (count * sizeof(jvalue)); - } - else - jArgs = 0; - - for (i = 0; i < count; i++) { - JavaParameter* aParameter = jMethod->parameterAt(i); - jArgs[i] = convertValueToJValue(exec, args.at(i), aParameter->getJNIType(), aParameter->type()); - JS_LOG("arg[%d] = %s\n", i, args.at(i).toString(exec).ascii()); - } - - jvalue result; - - // Try to use the JNI abstraction first, otherwise fall back to - // nornmal JNI. The JNI dispatch abstraction allows the Java plugin - // to dispatch the call on the appropriate internal VM thread. - RootObject* rootObject = this->rootObject(); - if (!rootObject) - return jsUndefined(); - - bool handled = false; - if (rootObject->nativeHandle()) { - jobject obj = _instance->_instance; - JSValue exceptionDescription; - const char *callingURL = 0; // FIXME, need to propagate calling URL to Java - handled = dispatchJNICall(exec, rootObject->nativeHandle(), obj, jMethod->isStatic(), jMethod->JNIReturnType(), jMethod->methodID(obj), jArgs, result, callingURL, exceptionDescription); - if (exceptionDescription) { - throwError(exec, GeneralError, exceptionDescription.toString(exec)); - free (jArgs); - return jsUndefined(); - } - } - - // 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. - if (!handled) { - jobject obj = _instance->_instance; - switch (jMethod->JNIReturnType()){ - case void_type: - callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case object_type: - result.l = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case boolean_type: - result.z = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case byte_type: - result.b = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case char_type: - result.c = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case short_type: - result.s = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case int_type: - result.i = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - - case long_type: - result.j = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case float_type: - result.f = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case double_type: - result.d = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); - break; - case invalid_type: - default: - break; - } - } - - switch (jMethod->JNIReturnType()){ - case void_type: { - resultValue = jsUndefined(); - } - break; - - case object_type: { - if (result.l != 0) { - const char *arrayType = jMethod->returnType(); - if (arrayType[0] == '[') { - resultValue = JavaArray::convertJObjectToArray(exec, result.l, arrayType, rootObject); - } - else { - resultValue = JavaInstance::create(result.l, rootObject)->createRuntimeObject(exec); - } - } - else { - resultValue = jsUndefined(); - } - } - break; - - case boolean_type: { - resultValue = jsBoolean(result.z); - } - break; - - case byte_type: { - resultValue = jsNumber(exec, result.b); - } - break; - - case char_type: { - resultValue = jsNumber(exec, result.c); - } - break; - - case short_type: { - resultValue = jsNumber(exec, result.s); - } - break; - - case int_type: { - resultValue = jsNumber(exec, result.i); - } - break; - - case long_type: { - resultValue = jsNumber(exec, result.j); - } - break; - - case float_type: { - resultValue = jsNumber(exec, result.f); - } - break; - - case double_type: { - resultValue = jsNumber(exec, result.d); - } - break; - - case invalid_type: - default: { - resultValue = jsUndefined(); - } - break; - } - - free (jArgs); - - return resultValue; -} - -JSValue JavaInstance::defaultValue(ExecState* exec, PreferredPrimitiveType hint) const -{ - if (hint == PreferString) - return stringValue(exec); - if (hint == PreferNumber) - return numberValue(exec); - JavaClass *aClass = static_cast(getClass()); - if (aClass->isStringClass()) - return stringValue(exec); - if (aClass->isNumberClass()) - return numberValue(exec); - if (aClass->isBooleanClass()) - return booleanValue(); - return valueOf(exec); -} - -JSValue JavaInstance::valueOf(ExecState* exec) const -{ - return stringValue(exec); -} - -JObjectWrapper::JObjectWrapper(jobject instance) -: _refCount(0) -{ - assert (instance != 0); - - // Cache the JNIEnv used to get the global ref for this java instanace. - // It'll be used to delete the reference. - _env = getJNIEnv(); - - _instance = _env->NewGlobalRef (instance); - - JS_LOG ("new global ref %p for %p\n", _instance, instance); - - if (_instance == NULL) { - fprintf (stderr, "%s: could not get GlobalRef for %p\n", __PRETTY_FUNCTION__, instance); - } -} - -JObjectWrapper::~JObjectWrapper() { - JS_LOG ("deleting global ref %p\n", _instance); - _env->DeleteGlobalRef (_instance); -} - -#endif // ENABLE(MAC_JAVA_BRIDGE) diff --git a/WebCore/bridge/jni/jni_instance.h b/WebCore/bridge/jni/jni_instance.h deleted file mode 100644 index 049bfdb..0000000 --- a/WebCore/bridge/jni/jni_instance.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2003 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: - * 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 _JNI_INSTANCE_H_ -#define _JNI_INSTANCE_H_ - -#if ENABLE(MAC_JAVA_BRIDGE) - -#include "runtime.h" -#include "runtime_root.h" - -#include - -namespace JSC { - -namespace Bindings { - -class JavaClass; - -class JObjectWrapper -{ -friend class RefPtr; -friend class JavaArray; -friend class JavaField; -friend class JavaInstance; -friend class JavaMethod; - -public: - jobject instance() const { return _instance; } - void setInstance(jobject instance) { _instance = instance; } - -protected: - JObjectWrapper(jobject instance); - ~JObjectWrapper(); - - void ref() { _refCount++; } - void deref() - { - if (--_refCount == 0) - delete this; - } - - jobject _instance; - -private: - JNIEnv *_env; - unsigned int _refCount; -}; - -class JavaInstance : public Instance -{ -public: - static PassRefPtr create(jobject instance, PassRefPtr rootObject) - { - return adoptRef(new JavaInstance(instance, rootObject)); - } - - ~JavaInstance(); - - virtual Class *getClass() const; - - virtual JSValue valueOf(ExecState*) const; - virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const; - - virtual JSValue invokeMethod(ExecState* exec, const MethodList& method, const ArgList& args); - - jobject javaInstance() const { return _instance->_instance; } - - JSValue stringValue(ExecState*) const; - JSValue numberValue(ExecState*) const; - JSValue booleanValue() const; - -protected: - JavaInstance(jobject instance, PassRefPtr); - virtual void virtualBegin(); - virtual void virtualEnd(); - - RefPtr _instance; - mutable JavaClass *_class; -}; - -} // namespace Bindings - -} // namespace JSC - -#endif // ENABLE(MAC_JAVA_BRIDGE) - -#endif // _JNI_INSTANCE_H_ diff --git a/WebCore/bridge/jni/jni_runtime.h b/WebCore/bridge/jni/jni_runtime.h index 81484ff..e18b9a1 100644 --- a/WebCore/bridge/jni/jni_runtime.h +++ b/WebCore/bridge/jni/jni_runtime.h @@ -28,8 +28,8 @@ #if ENABLE(MAC_JAVA_BRIDGE) -#include -#include +#include "JavaInstanceJSC.h" +#include "jni_utility.h" #include diff --git a/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp b/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp new file mode 100644 index 0000000..3f88002 --- /dev/null +++ b/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp @@ -0,0 +1,335 @@ +/* + * Copyright (C) 2003, 2008 Apple 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: + * 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 "JavaInstanceJSC.h" + +#if ENABLE(MAC_JAVA_BRIDGE) + +#include "jni_class.h" +#include "jni_runtime.h" +#include "jni_utility.h" +#include "jni_utility_private.h" +#include "runtime_object.h" +#include "runtime_root.h" +#include +#include +#include + +#if PLATFORM(ANDROID) +#include +#endif + +#ifdef NDEBUG +#define JS_LOG(formatAndArgs...) ((void)0) +#else +#define JS_LOG(formatAndArgs...) { \ + fprintf (stderr, "%s:%d -- %s: ", __FILE__, __LINE__, __FUNCTION__); \ + fprintf(stderr, formatAndArgs); \ +} +#endif + +using namespace JSC::Bindings; +using namespace JSC; + +JavaInstance::JavaInstance (jobject instance, PassRefPtr rootObject) + : Instance(rootObject) +{ + _instance = new JObjectWrapper (instance); + _class = 0; +} + +JavaInstance::~JavaInstance () +{ + delete _class; +} + +#define NUM_LOCAL_REFS 64 + +void JavaInstance::virtualBegin() +{ + getJNIEnv()->PushLocalFrame (NUM_LOCAL_REFS); +} + +void JavaInstance::virtualEnd() +{ + getJNIEnv()->PopLocalFrame (NULL); +} + +Class *JavaInstance::getClass() const +{ + if (_class == 0) + _class = new JavaClass (_instance->_instance); + return _class; +} + +JSValue JavaInstance::stringValue(ExecState* exec) const +{ + JSLock lock(SilenceAssertionsOnly); + + jstring stringValue = (jstring)callJNIMethod(_instance->_instance, "toString", "()Ljava/lang/String;"); + JNIEnv *env = getJNIEnv(); + const jchar *c = getUCharactersFromJStringInEnv(env, stringValue); + UString u((const UChar *)c, (int)env->GetStringLength(stringValue)); + releaseUCharactersForJStringInEnv(env, stringValue, c); + return jsString(exec, u); +} + +JSValue JavaInstance::numberValue(ExecState* exec) const +{ + jdouble doubleValue = callJNIMethod(_instance->_instance, "doubleValue", "()D"); + return jsNumber(exec, doubleValue); +} + +JSValue JavaInstance::booleanValue() const +{ + jboolean booleanValue = callJNIMethod(_instance->_instance, "booleanValue", "()Z"); + return jsBoolean(booleanValue); +} + +JSValue JavaInstance::invokeMethod (ExecState *exec, const MethodList &methodList, const ArgList &args) +{ + int i, count = args.size(); + jvalue *jArgs; + JSValue resultValue; + Method *method = 0; + 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. + Method *aMethod; + for (size_t methodIndex = 0; methodIndex < numMethods; methodIndex++) { + aMethod = methodList[methodIndex]; + if (aMethod->numParameters() == count) { + method = aMethod; + break; + } + } + if (method == 0) { + JS_LOG ("unable to find an appropiate method\n"); + return jsUndefined(); + } + + const JavaMethod *jMethod = static_cast(method); + JS_LOG ("call %s %s on %p\n", UString(jMethod->name()).UTF8String().c_str(), jMethod->signature(), _instance->_instance); + + if (count > 0) { + jArgs = (jvalue *)malloc (count * sizeof(jvalue)); + } + else + jArgs = 0; + + for (i = 0; i < count; i++) { + JavaParameter* aParameter = jMethod->parameterAt(i); + jArgs[i] = convertValueToJValue(exec, args.at(i), aParameter->getJNIType(), aParameter->type()); + JS_LOG("arg[%d] = %s\n", i, args.at(i).toString(exec).ascii()); + } + + jvalue result; + + // Try to use the JNI abstraction first, otherwise fall back to + // nornmal JNI. The JNI dispatch abstraction allows the Java plugin + // to dispatch the call on the appropriate internal VM thread. + RootObject* rootObject = this->rootObject(); + if (!rootObject) + return jsUndefined(); + + bool handled = false; + if (rootObject->nativeHandle()) { + jobject obj = _instance->_instance; + JSValue exceptionDescription; + const char *callingURL = 0; // FIXME, need to propagate calling URL to Java + handled = dispatchJNICall(exec, rootObject->nativeHandle(), obj, jMethod->isStatic(), jMethod->JNIReturnType(), jMethod->methodID(obj), jArgs, result, callingURL, exceptionDescription); + if (exceptionDescription) { + throwError(exec, GeneralError, exceptionDescription.toString(exec)); + free (jArgs); + return jsUndefined(); + } + } + + // 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. + if (!handled) { + jobject obj = _instance->_instance; + switch (jMethod->JNIReturnType()){ + case void_type: + callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case object_type: + result.l = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case boolean_type: + result.z = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case byte_type: + result.b = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case char_type: + result.c = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case short_type: + result.s = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case int_type: + result.i = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + + case long_type: + result.j = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case float_type: + result.f = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case double_type: + result.d = callJNIMethodIDA(obj, jMethod->methodID(obj), jArgs); + break; + case invalid_type: + default: + break; + } + } + + switch (jMethod->JNIReturnType()){ + case void_type: { + resultValue = jsUndefined(); + } + break; + + case object_type: { + if (result.l != 0) { + const char *arrayType = jMethod->returnType(); + if (arrayType[0] == '[') { + resultValue = JavaArray::convertJObjectToArray(exec, result.l, arrayType, rootObject); + } + else { + resultValue = JavaInstance::create(result.l, rootObject)->createRuntimeObject(exec); + } + } + else { + resultValue = jsUndefined(); + } + } + break; + + case boolean_type: { + resultValue = jsBoolean(result.z); + } + break; + + case byte_type: { + resultValue = jsNumber(exec, result.b); + } + break; + + case char_type: { + resultValue = jsNumber(exec, result.c); + } + break; + + case short_type: { + resultValue = jsNumber(exec, result.s); + } + break; + + case int_type: { + resultValue = jsNumber(exec, result.i); + } + break; + + case long_type: { + resultValue = jsNumber(exec, result.j); + } + break; + + case float_type: { + resultValue = jsNumber(exec, result.f); + } + break; + + case double_type: { + resultValue = jsNumber(exec, result.d); + } + break; + + case invalid_type: + default: { + resultValue = jsUndefined(); + } + break; + } + + free (jArgs); + + return resultValue; +} + +JSValue JavaInstance::defaultValue(ExecState* exec, PreferredPrimitiveType hint) const +{ + if (hint == PreferString) + return stringValue(exec); + if (hint == PreferNumber) + return numberValue(exec); + JavaClass *aClass = static_cast(getClass()); + if (aClass->isStringClass()) + return stringValue(exec); + if (aClass->isNumberClass()) + return numberValue(exec); + if (aClass->isBooleanClass()) + return booleanValue(); + return valueOf(exec); +} + +JSValue JavaInstance::valueOf(ExecState* exec) const +{ + return stringValue(exec); +} + +JObjectWrapper::JObjectWrapper(jobject instance) +: _refCount(0) +{ + assert (instance != 0); + + // Cache the JNIEnv used to get the global ref for this java instanace. + // It'll be used to delete the reference. + _env = getJNIEnv(); + + _instance = _env->NewGlobalRef (instance); + + JS_LOG ("new global ref %p for %p\n", _instance, instance); + + if (_instance == NULL) { + fprintf (stderr, "%s: could not get GlobalRef for %p\n", __PRETTY_FUNCTION__, instance); + } +} + +JObjectWrapper::~JObjectWrapper() { + JS_LOG ("deleting global ref %p\n", _instance); + _env->DeleteGlobalRef (_instance); +} + +#endif // ENABLE(MAC_JAVA_BRIDGE) diff --git a/WebCore/bridge/jni/jsc/JavaInstanceJSC.h b/WebCore/bridge/jni/jsc/JavaInstanceJSC.h new file mode 100644 index 0000000..a9b83e3 --- /dev/null +++ b/WebCore/bridge/jni/jsc/JavaInstanceJSC.h @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2003 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: + * 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 JavaInstanceJSC_h +#define JavaInstanceJSC_h + +#if ENABLE(MAC_JAVA_BRIDGE) + +#include "runtime.h" +#include "runtime_root.h" + +#include + +namespace JSC { + +namespace Bindings { + +class JavaClass; + +class JObjectWrapper +{ +friend class RefPtr; +friend class JavaArray; +friend class JavaField; +friend class JavaInstance; +friend class JavaMethod; + +public: + jobject instance() const { return _instance; } + void setInstance(jobject instance) { _instance = instance; } + +protected: + JObjectWrapper(jobject instance); + ~JObjectWrapper(); + + void ref() { _refCount++; } + void deref() + { + if (--_refCount == 0) + delete this; + } + + jobject _instance; + +private: + JNIEnv *_env; + unsigned int _refCount; +}; + +class JavaInstance : public Instance +{ +public: + static PassRefPtr create(jobject instance, PassRefPtr rootObject) + { + return adoptRef(new JavaInstance(instance, rootObject)); + } + + ~JavaInstance(); + + virtual Class *getClass() const; + + virtual JSValue valueOf(ExecState*) const; + virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const; + + virtual JSValue invokeMethod(ExecState* exec, const MethodList& method, const ArgList& args); + + jobject javaInstance() const { return _instance->_instance; } + + JSValue stringValue(ExecState*) const; + JSValue numberValue(ExecState*) const; + JSValue booleanValue() const; + +protected: + JavaInstance(jobject instance, PassRefPtr); + virtual void virtualBegin(); + virtual void virtualEnd(); + + RefPtr _instance; + mutable JavaClass *_class; +}; + +} // namespace Bindings + +} // namespace JSC + +#endif // ENABLE(MAC_JAVA_BRIDGE) + +#endif // JavaInstanceJSC_h diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp index ee39462..14d26f9 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -103,7 +103,7 @@ #include "jni.h" #if USE(JSC) -#include "jni_instance.h" +#include "JavaInstanceJSC.h" #endif // USE(JSC) #include -- cgit v1.1