[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

rjw rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:14:01 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit e2fbcda75fc1eaa49ad1a0e94e059f17bf045834
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Nov 19 22:41:04 2003 +0000

    Forget to check these in earlier.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5592 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 420de64..52fff27 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,56 @@
+2003-11-19  Richard Williamson   <rjw at apple.com>
+
+	More LiveConnect stuff.
+
+        Reviewed by Ken.
+
+        * JavaScriptCore.pbproj/project.pbxproj:
+        * bindings/jni/jni_class.cpp: Added.
+        (JavaClass::_commonInit):
+        (JavaClass::JavaClass):
+        (_createClassesByNameIfNecessary):
+        (JavaClass::classForName):
+        (JavaClass::classForInstance):
+        (JavaClass::methodNamed):
+        (JavaClass::fieldNamed):
+        * bindings/jni/jni_class.h: Added.
+        (Bindings::JavaClass::_commonDelete):
+        (Bindings::JavaClass::~JavaClass):
+        (Bindings::JavaClass::_commonCopy):
+        (Bindings::JavaClass::JavaClass):
+        (Bindings::JavaClass::operator=):
+        (Bindings::JavaClass::name):
+        (Bindings::JavaClass::constructorAt):
+        (Bindings::JavaClass::numConstructors):
+        * bindings/jni/jni_instance.cpp: Added.
+        (JavaInstance::JavaInstance):
+        (JavaInstance::~JavaInstance):
+        * bindings/jni/jni_instance.h: Added.
+        (Bindings::JObjectWrapper::JObjectWrapper):
+        (Bindings::JObjectWrapper::~JObjectWrapper):
+        (Bindings::JObjectWrapper::ref):
+        (Bindings::JObjectWrapper::deref):
+        (Bindings::JavaInstance::getClass):
+        (Bindings::JavaInstance::operator=):
+        * bindings/jni/jni_runtime.cpp:
+        (JavaMethod::JavaMethod):
+        * bindings/jni/jni_runtime.h:
+        (Bindings::JavaString::JavaString):
+        (Bindings::JavaString::~JavaString):
+        (Bindings::JavaString::operator=):
+        * bindings/jni/jni_utility.cpp:
+        (getJavaVM):
+        (getJNIEnv):
+        (getCharactersFromJString):
+        (releaseCharactersForJString):
+        (getCharactersFromJStringInEnv):
+        (releaseCharactersForJStringInEnv):
+        * bindings/jni/jni_utility.h:
+        * bindings/runtime.cpp:
+        (Instance::createBindingForLanguageInstance):
+        * bindings/runtime.h:
+        (Bindings::Instance::):
+
 2003-11-18  Richard Williamson   <rjw at apple.com>
 
 	More live connect stubs.  We're getting close.
diff --git a/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj b/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
index a7e2ccb..5030736 100644
--- a/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
+++ b/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
@@ -238,6 +238,8 @@
 				511B0878056468BB0080E486,
 				704FD35405697E6D003DBED9,
 				70B16A290569A10A00DB756D,
+				517D52DF056BF2F6003851BD,
+				517D534A056BFB5D003851BD,
 			);
 			isa = PBXHeadersBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -294,6 +296,8 @@
 				511B0879056468BB0080E486,
 				704FD44605698F17003DBED9,
 				70B16A280569A10A00DB756D,
+				517D52DE056BF2F6003851BD,
+				517D5349056BFB5D003851BD,
 			);
 			isa = PBXSourcesBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -476,6 +480,66 @@
 			settings = {
 			};
 		};
+		517D52DC056BF2F5003851BD = {
+			expectedFileType = sourcecode.cpp.cpp;
+			fileEncoding = 30;
+			isa = PBXFileReference;
+			name = jni_class.cpp;
+			path = bindings/jni/jni_class.cpp;
+			refType = 4;
+			sourceTree = "<group>";
+		};
+		517D52DD056BF2F6003851BD = {
+			expectedFileType = sourcecode.c.h;
+			fileEncoding = 30;
+			isa = PBXFileReference;
+			name = jni_class.h;
+			path = bindings/jni/jni_class.h;
+			refType = 4;
+			sourceTree = "<group>";
+		};
+		517D52DE056BF2F6003851BD = {
+			fileRef = 517D52DC056BF2F5003851BD;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
+		517D52DF056BF2F6003851BD = {
+			fileRef = 517D52DD056BF2F6003851BD;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
+		517D5347056BFB5D003851BD = {
+			expectedFileType = sourcecode.cpp.cpp;
+			fileEncoding = 30;
+			isa = PBXFileReference;
+			name = jni_instance.cpp;
+			path = bindings/jni/jni_instance.cpp;
+			refType = 4;
+			sourceTree = "<group>";
+		};
+		517D5348056BFB5D003851BD = {
+			expectedFileType = sourcecode.c.h;
+			fileEncoding = 30;
+			isa = PBXFileReference;
+			name = jni_instance.h;
+			path = bindings/jni/jni_instance.h;
+			refType = 4;
+			sourceTree = "<group>";
+		};
+		517D5349056BFB5D003851BD = {
+			fileRef = 517D5347056BFB5D003851BD;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
+		517D534A056BFB5D003851BD = {
+			fileRef = 517D5348056BFB5D003851BD;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
 		51856D8F0562EE95008B9D83 = {
 			expectedFileType = sourcecode.cpp.cpp;
 			fileEncoding = 30;
@@ -508,14 +572,18 @@
 		};
 		51856D950562EE9C008B9D83 = {
 			children = (
-				511B0870056468730080E486,
 				511B0877056468BB0080E486,
 				511B0876056468BB0080E486,
 				51856D8F0562EE95008B9D83,
 				51856D900562EE95008B9D83,
 				704FD44505698F17003DBED9,
+				511B0870056468730080E486,
 				70B16A260569A10900DB756D,
 				70B16A270569A10900DB756D,
+				517D52DC056BF2F5003851BD,
+				517D52DD056BF2F6003851BD,
+				517D5347056BFB5D003851BD,
+				517D5348056BFB5D003851BD,
 			);
 			isa = PBXGroup;
 			name = bindings;
diff --git a/JavaScriptCore/bindings/jni/jni_runtime.cpp b/JavaScriptCore/bindings/jni/jni_class.cpp
similarity index 50%
copy from JavaScriptCore/bindings/jni/jni_runtime.cpp
copy to JavaScriptCore/bindings/jni/jni_class.cpp
index 8595615..d4fa308 100644
--- a/JavaScriptCore/bindings/jni/jni_runtime.cpp
+++ b/JavaScriptCore/bindings/jni/jni_class.cpp
@@ -22,93 +22,41 @@
  * (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 <jni_class.h>
+
 #include <jni_utility.h>
 #include <jni_runtime.h>
- 
-using namespace Bindings;
-
-JavaField::JavaField (JNIEnv *env, jobject aField)
-{
-    // Get field type
-    jobject fieldType = callJNIObjectMethod (aField, "getType", "()Ljava/lang/Class;");
-    jstring fieldTypeName = (jstring)callJNIObjectMethod (fieldType, "toString", "()Ljava/lang/String;");
-    _type = new JavaString(env, fieldTypeName);
-
-    // Get field name
-    jstring fieldName = (jstring)callJNIObjectMethod (aField, "getName", "()Ljava/lang/String;");
-    _name = new JavaString(env, fieldName);
-}
-
-JavaConstructor::JavaConstructor (JNIEnv *env, jobject aConstructor)
-{
-    // Get parameters
-    jarray jparameters = (jarray)callJNIObjectMethod (aConstructor, "getParameterTypes", "()[Ljava/lang/Class;");
-    _numParameters = env->GetArrayLength (jparameters);
-    _parameters = new JavaParameter[_numParameters];
-    
-    int i;
-    for (i = 0; i < _numParameters; i++) {
-        jobject aParameter = env->GetObjectArrayElement ((jobjectArray)jparameters, i);
-        jstring parameterName = (jstring)callJNIObjectMethod (aParameter, "getName", "()Ljava/lang/String;");
-        _parameters[i] = JavaParameter(env, parameterName);
-    }
-}
-
-JavaMethod::JavaMethod (JNIEnv *env, jobject aMethod)
-{
-    // Get parameters
-    jarray jparameters = (jarray)callJNIObjectMethod (aMethod, "getParameterTypes", "()[Ljava/lang/Class;");
-    _numParameters = env->GetArrayLength (jparameters);
-    _parameters = new JavaParameter[_numParameters];
-    
-    int i;
-    for (i = 0; i < _numParameters; i++) {
-        jobject aParameter = env->GetObjectArrayElement ((jobjectArray)jparameters, i);
-        jstring parameterName = (jstring)callJNIObjectMethod (aParameter, "getName", "()Ljava/lang/String;");
-        _parameters[i] = JavaParameter(env, parameterName);
-    }
 
-    // Get return type
-    jobject returnType = callJNIObjectMethod (aMethod, "getReturnType", "()Ljava/lang/Class;");
-    jstring returnTypeName = (jstring)callJNIObjectMethod (returnType, "getName", "()Ljava/lang/String;");
-    _returnType = new JavaString (env, returnTypeName);
-
-    // Get method name
-    jstring methodName = (jstring)callJNIObjectMethod (aMethod, "getName", "()Ljava/lang/String;");
-    _name = new JavaString (env, methodName);
-}
+using namespace Bindings;
 
-JavaClass::JavaClass (JNIEnv *env, const char *className)
+void JavaClass::_commonInit (jobject aClass)
 {
     long i;
 
-    _name = strdup (className);
+    JNIEnv *env = getJNIEnv();
     
-    // Get the class
-    jclass aClass = env->FindClass(_name);
-    if (!aClass){   
-        fprintf (stderr, "%s:  unable to find class %s\n", __PRETTY_FUNCTION__, _name);
-        return;
-    }
-
     // Get the fields
     jarray fields = (jarray)callJNIObjectMethod (aClass, "getFields", "()[Ljava/lang/reflect/Field;");
     long numFields = env->GetArrayLength (fields);    
-    _fields = CFDictionaryCreateMutable(NULL, numFields, NULL, NULL);
+    _fields = CFDictionaryCreateMutable(NULL, numFields, &kCFTypeDictionaryKeyCallBacks, NULL);
     for (i = 0; i < numFields; i++) {
         jobject aJField = env->GetObjectArrayElement ((jobjectArray)fields, i);
         Field *aField = new JavaField (env, aJField);
-        CFDictionaryAddValue ((CFMutableDictionaryRef)_fields, aField->name(), aField);
+        CFStringRef fieldName = CFStringCreateWithCString(NULL, aField->name(), kCFStringEncodingASCII);
+        CFDictionaryAddValue ((CFMutableDictionaryRef)_fields, fieldName, aField);
+        CFRelease (fieldName);
     }
     
     // Get the methods
     jarray methods = (jarray)callJNIObjectMethod (aClass, "getMethods", "()[Ljava/lang/reflect/Method;");
     long numMethods = env->GetArrayLength (methods);    
-    _methods = CFDictionaryCreateMutable(NULL, numMethods, NULL, NULL);
+    _methods = CFDictionaryCreateMutable(NULL, numMethods, &kCFTypeDictionaryKeyCallBacks, NULL);
     for (i = 0; i < numMethods; i++) {
         jobject aJMethod = env->GetObjectArrayElement ((jobjectArray)methods, i);
         Method *aMethod = new JavaMethod (env, aJMethod);
-        CFDictionaryAddValue ((CFMutableDictionaryRef)_methods, aMethod->name(), aMethod);
+        CFStringRef methodName = CFStringCreateWithCString(NULL, aMethod->name(), kCFStringEncodingASCII);
+        CFDictionaryAddValue ((CFMutableDictionaryRef)_methods, methodName, aMethod);
+        CFRelease (methodName);
     }
 
     // Get the constructors
@@ -121,22 +69,75 @@ JavaClass::JavaClass (JNIEnv *env, const char *className)
     }
 }
 
-JavaInstance::JavaInstance (JNIEnv *env, jobject instance, JavaClass *aClass) {
-    // Classes are cached, not need to retain.
-    _class = aClass;
+JavaClass::JavaClass (const char *className)
+{
+    JNIEnv *env = getJNIEnv();
     
-    _env = env;
+    _name = strdup (className);
     
-    _instance = env->NewGlobalRef (instance);
-    env->DeleteLocalRef (instance);
+    // Get the class
+    jclass aClass = env->FindClass(_name);
+    if (!aClass){   
+        fprintf (stderr, "%s:  unable to find class %s\n", __PRETTY_FUNCTION__, _name);
+        return;
+    }
+
+    _commonInit (aClass);
+}
+
+JavaClass::JavaClass (jobject aClass)
+{
+    _commonInit (aClass);
+}
+
+static CFMutableDictionaryRef classesByName = 0;
+
+static void _createClassesByNameIfNecessary()
+{
+    if (classesByName == 0)
+        classesByName = CFDictionaryCreateMutable (NULL, 0, &kCFTypeDictionaryKeyCallBacks, NULL);
+}
+
+JavaClass *JavaClass::classForName (const char *name)
+{
+    _createClassesByNameIfNecessary();
     
-    if  (_instance == NULL) {
-        fprintf (stderr, "%s:  out of memory!\n", __PRETTY_FUNCTION__);
+    CFStringRef stringName = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
+    JavaClass *aClass = (JavaClass *)CFDictionaryGetValue(classesByName, name);
+    if (aClass == NULL) {
+        aClass = new JavaClass (name);
+        CFDictionaryAddValue (classesByName, stringName, aClass);
     }
-};
+    CFRelease (stringName);
 
-JavaInstance::~JavaInstance () {
-    _env->DeleteGlobalRef (_instance);
+    return aClass;
 }
 
+JavaClass *JavaClass::classForInstance (jobject instance)
+{
+    _createClassesByNameIfNecessary();
+    
+    jobject classOfInstance = callJNIObjectMethod(instance, "getClass", "()Ljava/lang/Class;");
+    jstring className = (jstring)callJNIObjectMethod(classOfInstance, "getName", "()Ljava/lang/String;");
+    
+    const char *classNameC = getCharactersFromJString (className);
+    JavaClass *aClass = classForName(classNameC);
+    releaseCharactersForJString(className, classNameC);
+
+    return aClass;
+}
+
+Method *JavaClass::methodNamed(const char *name) const {
+    CFStringRef methodName = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
+    Method *aMethod = (Method *)CFDictionaryGetValue(_methods, methodName);
+    CFRelease (methodName);
+    return aMethod;
+};
+
+Field *JavaClass::fieldNamed(const char *name) const {
+    CFStringRef fieldName = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
+    Field *aField = (Field *)CFDictionaryGetValue(_fields, fieldName);
+    CFRelease (fieldName);
+    return aField;
+};
 
diff --git a/JavaScriptCore/bindings/jni/jni_class.h b/JavaScriptCore/bindings/jni/jni_class.h
new file mode 100644
index 0000000..8edcebc
--- /dev/null
+++ b/JavaScriptCore/bindings/jni/jni_class.h
@@ -0,0 +1,119 @@
+/*
+ * 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_CLASS_H_
+#define _JNI_CLASS_H_
+
+#include <CoreFoundation/CoreFoundation.h>
+
+#include <JavaVM/jni.h>
+
+#include <jni_runtime.h>
+
+#include <runtime.h>
+
+namespace Bindings {
+
+class JavaClass : public Class
+{
+    // Use the public static factory methods to get instances of JavaClass.
+    
+protected:
+    void _commonInit (jobject aClass);
+
+    JavaClass (const char *name);
+    
+    JavaClass (jobject aClass);
+    
+public:
+    // Return the cached JavaClass from the class of the jobject.
+    static JavaClass *classForInstance (jobject anInstance);
+
+    // Return the cached JavaClass of the specified name.
+    static JavaClass *classForName (const char *name);
+    
+    void _commonDelete() {
+        free((void *)_name);
+        CFRelease (_fields);
+        CFRelease (_methods);
+        delete _constructors;
+    }
+    
+    ~JavaClass () {
+        _commonDelete();
+    }
+
+    void _commonCopy(const JavaClass &other) {
+        long i;
+
+        _name = strdup (other._name);
+
+        _methods = CFDictionaryCreateCopy (NULL, other._methods);
+        _fields = CFDictionaryCreateCopy (NULL, other._fields);
+        
+        _numConstructors = other._numConstructors;
+        _constructors = new JavaConstructor[_numConstructors];
+        for (i = 0; i < _numConstructors; i++) {
+            _constructors[i] = other._constructors[i];
+        }
+    }
+    
+    JavaClass (const JavaClass &other) 
+            : Class() {
+        _commonCopy (other);
+    };
+
+    JavaClass &operator=(const JavaClass &other)
+    {
+        if (this == &other)
+            return *this;
+            
+        _commonDelete();
+        _commonCopy (other);
+        
+        return *this;
+    }
+
+    virtual const char *name() const { return _name; };
+    
+    virtual Method *methodNamed(const char *name) const;
+    
+    virtual Field *fieldNamed(const char *name) const;
+    
+    virtual Constructor *constructorAt(long i) const {
+        return &_constructors[i]; 
+    };
+    
+    virtual long numConstructors() const { return _numConstructors; };
+    
+private:
+    const char *_name;
+    CFDictionaryRef _fields;
+    CFDictionaryRef _methods;
+    JavaConstructor *_constructors;
+    long _numConstructors;
+};
+
+}
+#endif
\ No newline at end of file
diff --git a/JavaScriptCore/bindings/runtime.cpp b/JavaScriptCore/bindings/jni/jni_instance.cpp
similarity index 79%
copy from JavaScriptCore/bindings/runtime.cpp
copy to JavaScriptCore/bindings/jni/jni_instance.cpp
index 8614165..f09758d 100644
--- a/JavaScriptCore/bindings/runtime.cpp
+++ b/JavaScriptCore/bindings/jni/jni_instance.cpp
@@ -22,7 +22,22 @@
  * (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 "runtime.h"
+#include <jni_utility.h>
+#include <jni_runtime.h>
+#include <jni_instance.h>
 
-using namespace KJS;
 using namespace Bindings;
+
+JavaInstance::JavaInstance (jobject instance) {
+    _instance = new JObjectWrapper (instance);
+};
+
+JavaInstance::~JavaInstance () {
+    _instance->deref();
+}
+
+
+JavaInstance::JavaInstance (const JavaInstance &other) : Instance() {
+    _instance = other._instance;
+    _instance->ref();
+};
diff --git a/JavaScriptCore/bindings/jni/jni_instance.h b/JavaScriptCore/bindings/jni/jni_instance.h
new file mode 100644
index 0000000..38c0438
--- /dev/null
+++ b/JavaScriptCore/bindings/jni/jni_instance.h
@@ -0,0 +1,106 @@
+/*
+ * 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_
+
+#include <CoreFoundation/CoreFoundation.h>
+
+#include <JavaVM/jni.h>
+
+#include <jni_runtime.h>
+#include <jni_utility.h>
+#include <jni_class.h>
+#include <jni_instance.h>
+
+namespace Bindings {
+
+class JObjectWrapper
+{
+friend class JavaInstance;
+
+protected:
+    JObjectWrapper(jobject instance) : _ref(1) {
+        // 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);
+        _env->DeleteLocalRef (instance);
+        
+        if  (_instance == NULL) {
+            fprintf (stderr, "%s:  out of memory!\n", __PRETTY_FUNCTION__);
+        }
+    }
+    
+    ~JObjectWrapper() {
+        _env->DeleteGlobalRef (_instance);
+    }
+    
+    void ref() { _ref++; }
+    void deref() { 
+        _ref--;
+        if (_ref == 0)
+            delete this;
+    }
+    
+    jobject _instance;
+
+private:
+    JNIEnv *_env;
+    unsigned int _ref;
+};
+
+class JavaInstance : public Instance
+{
+public:
+    JavaInstance (jobject instance);
+        
+    ~JavaInstance ();
+    
+    virtual Class *getClass() const {
+        return JavaClass::classForInstance (_instance->_instance);
+    }
+
+    JavaInstance (const JavaInstance &other);
+
+    JavaInstance &operator=(const JavaInstance &other){
+        if (this == &other)
+            return *this;
+        
+        JObjectWrapper *_oldInstance = _instance;
+        _instance = other._instance;
+        _instance->ref();
+        _oldInstance->deref();
+        
+        return *this;
+    };
+    
+private:
+    JObjectWrapper *_instance;
+};
+
+}
+
+#endif
diff --git a/JavaScriptCore/bindings/jni/jni_runtime.cpp b/JavaScriptCore/bindings/jni/jni_runtime.cpp
index 8595615..824875d 100644
--- a/JavaScriptCore/bindings/jni/jni_runtime.cpp
+++ b/JavaScriptCore/bindings/jni/jni_runtime.cpp
@@ -77,66 +77,3 @@ JavaMethod::JavaMethod (JNIEnv *env, jobject aMethod)
     jstring methodName = (jstring)callJNIObjectMethod (aMethod, "getName", "()Ljava/lang/String;");
     _name = new JavaString (env, methodName);
 }
-
-JavaClass::JavaClass (JNIEnv *env, const char *className)
-{
-    long i;
-
-    _name = strdup (className);
-    
-    // Get the class
-    jclass aClass = env->FindClass(_name);
-    if (!aClass){   
-        fprintf (stderr, "%s:  unable to find class %s\n", __PRETTY_FUNCTION__, _name);
-        return;
-    }
-
-    // Get the fields
-    jarray fields = (jarray)callJNIObjectMethod (aClass, "getFields", "()[Ljava/lang/reflect/Field;");
-    long numFields = env->GetArrayLength (fields);    
-    _fields = CFDictionaryCreateMutable(NULL, numFields, NULL, NULL);
-    for (i = 0; i < numFields; i++) {
-        jobject aJField = env->GetObjectArrayElement ((jobjectArray)fields, i);
-        Field *aField = new JavaField (env, aJField);
-        CFDictionaryAddValue ((CFMutableDictionaryRef)_fields, aField->name(), aField);
-    }
-    
-    // Get the methods
-    jarray methods = (jarray)callJNIObjectMethod (aClass, "getMethods", "()[Ljava/lang/reflect/Method;");
-    long numMethods = env->GetArrayLength (methods);    
-    _methods = CFDictionaryCreateMutable(NULL, numMethods, NULL, NULL);
-    for (i = 0; i < numMethods; i++) {
-        jobject aJMethod = env->GetObjectArrayElement ((jobjectArray)methods, i);
-        Method *aMethod = new JavaMethod (env, aJMethod);
-        CFDictionaryAddValue ((CFMutableDictionaryRef)_methods, aMethod->name(), aMethod);
-    }
-
-    // Get the constructors
-    jarray constructors = (jarray)callJNIObjectMethod (aClass, "getConstructors", "()[Ljava/lang/reflect/Constructor;");
-    _numConstructors = env->GetArrayLength (constructors);    
-    _constructors = new JavaConstructor[_numConstructors];
-    for (i = 0; i < _numConstructors; i++) {
-        jobject aConstructor = env->GetObjectArrayElement ((jobjectArray)constructors, i);
-        _constructors[i] = JavaConstructor (env, aConstructor);
-    }
-}
-
-JavaInstance::JavaInstance (JNIEnv *env, jobject instance, JavaClass *aClass) {
-    // Classes are cached, not need to retain.
-    _class = aClass;
-    
-    _env = env;
-    
-    _instance = env->NewGlobalRef (instance);
-    env->DeleteLocalRef (instance);
-    
-    if  (_instance == NULL) {
-        fprintf (stderr, "%s:  out of memory!\n", __PRETTY_FUNCTION__);
-    }
-};
-
-JavaInstance::~JavaInstance () {
-    _env->DeleteGlobalRef (_instance);
-}
-
-
diff --git a/JavaScriptCore/bindings/jni/jni_runtime.h b/JavaScriptCore/bindings/jni/jni_runtime.h
index 3e3985e..2a19e10 100644
--- a/JavaScriptCore/bindings/jni/jni_runtime.h
+++ b/JavaScriptCore/bindings/jni/jni_runtime.h
@@ -22,9 +22,13 @@
  * (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_RUNTIME_H_
+#define _JNI_RUNTIME_H_
+
 #include <CoreFoundation/CoreFoundation.h>
 
-#include "../runtime.h"
+#include <jni_utility.h>
+#include <runtime.h>
 
 namespace KJS
 {
@@ -40,16 +44,16 @@ public:
     JavaString () : _env(0), _characters(0), _jString(0) {};
     
     JavaString (JNIEnv *e, jstring s) : _env(e), _jString(s) {
-        _characters = getCharactersFromJString (_env, s);
+        _characters = getCharactersFromJStringInEnv (_env, s);
     }
     
     ~JavaString () {
-        releaseCharactersForJString (_env, _jString, _characters);
+        releaseCharactersForJStringInEnv (_env, _jString, _characters);
     }
 
     JavaString(const JavaString &other) : _env(other._env), _jString (other._jString)
     {
-        _characters = getCharactersFromJString (_env, _jString);
+        _characters = getCharactersFromJStringInEnv (_env, _jString);
     }
 
     JavaString &operator=(const JavaString &other)
@@ -57,11 +61,11 @@ public:
         if (this == &other)
             return *this;
             
-        releaseCharactersForJString (_env, _jString, _characters);
+        releaseCharactersForJStringInEnv (_env, _jString, _characters);
         
         _env = other._env;
         _jString = other._jString;
-        _characters = getCharactersFromJString (_env, _jString);
+        _characters = getCharactersFromJStringInEnv (_env, _jString);
         
         return *this;
     }
@@ -250,94 +254,6 @@ private:
     JavaString *_returnType;
 };
 
-class JavaClass : public Class
-{
-public:
-    JavaClass (JNIEnv *env, const char *name);
-    
-    void _commonDelete() {
-        free((void *)_name);
-        CFRelease (_fields);
-        CFRelease (_methods);
-        delete _constructors;
-    }
-    
-    ~JavaClass () {
-        _commonDelete();
-    }
-
-    void _commonCopy(const JavaClass &other) {
-        long i;
-
-        _name = strdup (other._name);
-
-        _methods = CFDictionaryCreateCopy (NULL, other._methods);
-        _fields = CFDictionaryCreateCopy (NULL, other._fields);
-        
-        _numConstructors = other._numConstructors;
-        _constructors = new JavaConstructor[_numConstructors];
-        for (i = 0; i < _numConstructors; i++) {
-            _constructors[i] = other._constructors[i];
-        }
-    }
-    
-    JavaClass (const JavaClass &other) 
-            : Class() {
-        _commonCopy (other);
-    };
-
-    JavaClass &operator=(const JavaClass &other)
-    {
-        if (this == &other)
-            return *this;
-            
-        _commonDelete();
-        _commonCopy (other);
-        
-        return *this;
-    }
-
-    virtual const char *name() const { return _name; };
-    
-    virtual Method *methodNamed(const char *name) const {
-        Method *aMethod = (Method *)CFDictionaryGetValue(_methods, name);
-        return aMethod;
-    };
-    
-    virtual Constructor *constructorAt(long i) const {
-        return &_constructors[i]; 
-    };
-    
-    virtual long numConstructors() const { return _numConstructors; };
-    
-    virtual Field *fieldNamed(const char *name) const {
-        Field *aField = (Field *)CFDictionaryGetValue(_fields, name);
-        return aField;
-    };
-
-private:
-    const char *_name;
-    CFDictionaryRef _fields;
-    CFDictionaryRef _methods;
-    JavaConstructor *_constructors;
-    long _numConstructors;
-};
-
-class JavaInstance : public Instance
-{
-public:
-    JavaInstance (JNIEnv *env, jobject instance, JavaClass *aClass);
-        
-    ~JavaInstance ();
-    
-    virtual Class *getClass() const {
-        return _class;
-    }
-    
-private:
-    JNIEnv *_env;
-    jobject _instance;
-    JavaClass *_class;
-};
+}
 
-}
\ No newline at end of file
+#endif
diff --git a/JavaScriptCore/bindings/jni/jni_utility.cpp b/JavaScriptCore/bindings/jni/jni_utility.cpp
index 367ddc5..142c66d 100644
--- a/JavaScriptCore/bindings/jni/jni_utility.cpp
+++ b/JavaScriptCore/bindings/jni/jni_utility.cpp
@@ -25,6 +25,42 @@
  
 #include "jni_utility.h"
 
+static JavaVM *jvm;
+
+JavaVM *getJavaVM()
+{
+    if (jvm)
+        return jvm;
+
+    JavaVM *jvmArray[1];
+    jsize bufLen = 1;
+    jsize nJVMs = 0;
+    jint jniError = 0;
+
+    // Assumes JVM is already running ..., one per process
+    jniError = JNI_GetCreatedJavaVMs(jvmArray, bufLen, &nJVMs);
+    if ( jniError == JNI_OK && nJVMs > 0 ) {
+        jvm = jvmArray[0];
+    }
+    else 
+        fprintf(stderr, "%s: JNI_GetCreatedJavaVMs failed, returned %d", __PRETTY_FUNCTION__, jniError);
+        
+    return jvm;
+}
+
+JNIEnv *getJNIEnv()
+{
+    JNIEnv *env;
+    jint jniError = 0;
+
+    jniError = (jvm)->AttachCurrentThread((void**)&env, (void *)NULL);
+    if ( jniError == JNI_OK )
+        return env;
+    else
+        fprintf(stderr, "%s: AttachCurrentThread failed, returned %d", __PRETTY_FUNCTION__, jniError);
+    return NULL;
+}
+
 
 static bool attachToJavaVM(JavaVM **jvm, JNIEnv **env)
 {
@@ -323,7 +359,17 @@ jdouble callJNIDoubleMethodA (jobject obj, const char *name, const char *sig, jv
     return result.d;
 }
 
-const char *getCharactersFromJString (JNIEnv *env, jstring aJString)
+const char *getCharactersFromJString (jstring aJString)
+{
+    return getCharactersFromJStringInEnv (getJNIEnv(), aJString);
+}
+
+void releaseCharactersForJString (jstring aJString, const char *s)
+{
+    releaseCharactersForJStringInEnv (getJNIEnv(), aJString, s);
+}
+
+const char *getCharactersFromJStringInEnv (JNIEnv *env, jstring aJString)
 {
     jboolean isCopy;
     const char *s = env->GetStringUTFChars((jstring)aJString, &isCopy);
@@ -334,7 +380,8 @@ const char *getCharactersFromJString (JNIEnv *env, jstring aJString)
     return s;
 }
 
-void releaseCharactersForJString (JNIEnv *env, jstring aJString, const char *s)
+void releaseCharactersForJStringInEnv (JNIEnv *env, jstring aJString, const char *s)
 {
     env->ReleaseStringUTFChars (aJString, s);
 }
+
diff --git a/JavaScriptCore/bindings/jni/jni_utility.h b/JavaScriptCore/bindings/jni/jni_utility.h
index 92bb357..492415e 100644
--- a/JavaScriptCore/bindings/jni/jni_utility.h
+++ b/JavaScriptCore/bindings/jni/jni_utility.h
@@ -22,10 +22,16 @@
  * (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_UTILITY_H_
+#define _JNI_UTILITY_H_
+
 #include <JavaVM/jni.h>
 
-const char *getCharactersFromJString (JNIEnv *env, jstring aJString);
-void releaseCharactersForJString (JNIEnv *env, jstring aJString, const char *s);
+const char *getCharactersFromJString (jstring aJString);
+void releaseCharactersForJString (jstring aJString, const char *s);
+
+const char *getCharactersFromJStringInEnv (JNIEnv *env, jstring aJString);
+void releaseCharactersForJStringInEnv (JNIEnv *env, jstring aJString, const char *s);
 
 jobject callJNIObjectMethod( jobject obj, const char *name, const char *sig, ... );
 void callJNIVoidMethod( jobject obj, const char *name, const char *sig, ... );
@@ -48,3 +54,8 @@ jint callJNIIntMethodA( jobject obj, const char *name, const char *sig, jvalue *
 jlong callJNILongMethodA( jobject obj, const char *name, const char *sig, jvalue *args);
 jfloat callJNIFloatMethodA( jobject obj, const char *name, const char *sig, jvalue *args);
 jdouble callJNIDoubleMethodA( jobject obj, const char *name, const char *sig, jvalue *args);
+
+JavaVM *getJavaVM();
+JNIEnv *getJNIEnv();
+
+#endif
\ No newline at end of file
diff --git a/JavaScriptCore/bindings/runtime.cpp b/JavaScriptCore/bindings/runtime.cpp
index 8614165..2085757 100644
--- a/JavaScriptCore/bindings/runtime.cpp
+++ b/JavaScriptCore/bindings/runtime.cpp
@@ -22,7 +22,15 @@
  * (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 "runtime.h"
+#include <runtime.h>
+#include <jni_instance.h>
 
 using namespace KJS;
 using namespace Bindings;
+
+Instance *Instance::createBindingForLanguageInstance (BindingLanguage language, void *instance)
+{
+    if (language == Instance::JavaLanguage)
+        return new Bindings::JavaInstance ((jobject)instance);
+    return 0;
+}
diff --git a/JavaScriptCore/bindings/runtime.h b/JavaScriptCore/bindings/runtime.h
index 20bfc05..a537654 100644
--- a/JavaScriptCore/bindings/runtime.h
+++ b/JavaScriptCore/bindings/runtime.h
@@ -93,6 +93,13 @@ public:
 class Instance
 {
 public:
+    typedef enum {
+        JavaLanguage,
+        ObjectiveCLanguage
+    } BindingLanguage;
+
+    static Instance *createBindingForLanguageInstance (BindingLanguage language, void *instance);
+
     virtual Class *getClass() const = 0;
     virtual ~Instance() {};
 };
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 3acfe79..d3f7929 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,22 @@
+2003-11-19  Richard Williamson   <rjw at apple.com>
+
+	More LiveConnect stuff.  With that patch we make the applet
+	visible to JavaScript in an Bindings::Instance.  Next step
+	it to flush out implementation of RuntimeObjectImp and
+	RuntimeFunctionImp.
+
+        Reviewed by Ken.
+
+        * khtml/html/html_objectimpl.cpp:
+        (HTMLAppletElementImpl::HTMLAppletElementImpl):
+        (HTMLAppletElementImpl::~HTMLAppletElementImpl):
+        (HTMLAppletElementImpl::getAppletInstance):
+        * khtml/html/html_objectimpl.h:
+        * kwq/KWQKHTMLPart.h:
+        * kwq/KWQKHTMLPart.mm:
+        (KWQKHTMLPart::getAppletInstanceForView):
+        * kwq/WebCoreBridge.h:
+
 2003-11-19  David Hyatt  <hyatt at apple.com>
 
 	Fix for 3488888, about:blank in iframes doesn't repaint properly.  Fix for 3485478, refreshing a remote
diff --git a/WebCore/khtml/html/html_objectimpl.cpp b/WebCore/khtml/html/html_objectimpl.cpp
index b386f6b..9e8b068 100644
--- a/WebCore/khtml/html/html_objectimpl.cpp
+++ b/WebCore/khtml/html/html_objectimpl.cpp
@@ -46,6 +46,10 @@
 #include "java/kjavaappletcontext.h"
 #endif
 
+#if APPLE_CHANGES
+#include "KWQKHTMLPart.h"
+#endif
+
 using namespace DOM;
 using namespace khtml;
 
@@ -54,10 +58,12 @@ using namespace khtml;
 HTMLAppletElementImpl::HTMLAppletElementImpl(DocumentPtr *doc)
   : HTMLElementImpl(doc)
 {
+    appletInstance = 0;
 }
 
 HTMLAppletElementImpl::~HTMLAppletElementImpl()
 {
+    delete appletInstance;
 }
 
 NodeImpl::Id HTMLAppletElementImpl::id() const
@@ -162,10 +168,21 @@ bool HTMLAppletElementImpl::callMember(const QString & name, const QStringList &
 #if APPLE_CHANGES
 Bindings::Instance *HTMLAppletElementImpl::getAppletInstance() const
 {
+    if (appletInstance)
+        return appletInstance;
+    
     // Actually get instance point for corresponding jobject and create
     // a Instance with it.
-    printf ("%s: NOT YET IMPLEMENTED return fake reference\n", __PRETTY_FUNCTION__);
-    return (Bindings::Instance *)0xfeadface;
+    if (renderer()){
+        RenderApplet *r = static_cast<RenderApplet*>(m_render);
+        
+        if (r->widget()){
+            void *_view = r->widget()->getView();
+            KHTMLView* w = getDocument()->view();
+            appletInstance = KWQ(w->part())->getAppletInstanceForView((NSView *)_view);
+        }
+    }
+    return appletInstance;
 }
 #endif
 
diff --git a/WebCore/khtml/html/html_objectimpl.h b/WebCore/khtml/html/html_objectimpl.h
index 027dbe1..eb0bc00 100644
--- a/WebCore/khtml/html/html_objectimpl.h
+++ b/WebCore/khtml/html/html_objectimpl.h
@@ -64,8 +64,10 @@ public:
 
 protected:
     khtml::VAlign valign;
+    
+private:
 #if APPLE_CHANGES
-    //jobject _appletInstance;
+    mutable Bindings::Instance *appletInstance;
 #endif
 };
 
diff --git a/WebCore/kwq/KWQKHTMLPart.h b/WebCore/kwq/KWQKHTMLPart.h
index 8cd0e66..2c940ca 100644
--- a/WebCore/kwq/KWQKHTMLPart.h
+++ b/WebCore/kwq/KWQKHTMLPart.h
@@ -35,6 +35,10 @@
 #import "WebCoreKeyboardAccess.h"
 
 #include <CoreFoundation/CoreFoundation.h>
+
+#include <JavaVM/jni.h>
+#include <JavaScriptCore/runtime.h>
+
 #include "KWQDict.h"
 
 class KHTMLPartPrivate;
@@ -248,6 +252,8 @@ public:
     bool haveToldBridgeAboutLoad(const QString &urlString);
     void print();
 
+    Bindings::Instance *getAppletInstanceForView (NSView *aView);
+    
 private:
     virtual void khtmlMousePressEvent(khtml::MousePressEvent *);
     virtual void khtmlMouseDoubleClickEvent(khtml::MouseDoubleClickEvent *);
diff --git a/WebCore/kwq/KWQKHTMLPart.mm b/WebCore/kwq/KWQKHTMLPart.mm
index 22fcf23..4042685 100644
--- a/WebCore/kwq/KWQKHTMLPart.mm
+++ b/WebCore/kwq/KWQKHTMLPart.mm
@@ -2750,3 +2750,18 @@ void KWQKHTMLPart::print()
 {
     [_bridge print];
 }
+
+Bindings::Instance *KWQKHTMLPart::getAppletInstanceForView (NSView *aView)
+{
+    // Unfortunately we have to do a layout here to guarantee that 'real'
+    // applet view is correctly set on the RenderApplet's widget.
+    forceLayout();
+    
+    // Get a pointer to the actual Java applet instance.
+    jobject applet = [_bridge pollForAppletInView:aView];
+    
+    // Wrap the Java instance in a language neutral binding and hand
+    // off ownership to the APPLET element.
+    return Bindings::Instance::createBindingForLanguageInstance (Bindings::Instance::JavaLanguage, applet);
+}
+
diff --git a/WebCore/kwq/WebCoreBridge.h b/WebCore/kwq/WebCoreBridge.h
index c676f7b..3a85116 100644
--- a/WebCore/kwq/WebCoreBridge.h
+++ b/WebCore/kwq/WebCoreBridge.h
@@ -27,6 +27,8 @@
 
 #import <WebCore/WebCoreKeyboardAccess.h>
 
+#import <JavaVM/jni.h>
+
 #ifdef __cplusplus
 
 class KWQKHTMLPart;
@@ -362,6 +364,8 @@ typedef enum {
 
 - (void)print;
 
+- (jobject)pollForAppletInView: (NSView *)view;
+
 @end
 
 // This interface definition allows those who hold a WebCoreBridge * to call all the methods

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list