[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:18:29 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit f1078860337b0411a05e975c3ee999d1d824f518
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Dec 12 00:48:31 2003 +0000

    JavaScriptCore:
    	Added support for calling a JavaScript function from
    	Java.  Right now this only works for void func(void)
    	functions, but the conversion of args and return values
    	will come shortly.
    
    	Cleaned up and verified reference counting scheme, and
    	dereferencing of vended JavaScript objects when applet is
    	destroyed (actually when part is destroyed).
    
    	Removed link hack for testkjs now that the Java folks think
    	they have a solution for the 1.4.2 JavaVM link problem.  Although
    	Greg B. thinks his solution may cause problems for the 1.3.1
    	version of the VM!?!
    
            Reviewed by Ken.
    
            * Makefile.am:
            * bindings/jni/jni_runtime.h:
            (Bindings::JavaString::JavaString):
            * bindings/jni/jni_utility.cpp:
            (convertValueToJValue):
            (convertValueToJObject):
            (listFromJArray):
            * bindings/jni/jni_utility.h:
            * bindings/jni_jsobject.cpp:
            (KJS_setFindRootObjectForNativeHandleFunction):
            (KJS_findRootObjectForNativeHandleFunction):
            (getReferencesByRootDictionary):
            (getReferencesDictionary):
            (findReferenceDictionary):
            (rootForImp):
            (addJavaReference):
            (removeJavaReference):
            * bindings/jni_jsobject.h:
            (Bindings::RootObject::RootObject):
            (Bindings::RootObject::~RootObject):
            (Bindings::RootObject::setRootObjectImp):
            (Bindings::RootObject::rootObjectImp):
            (Bindings::RootObject::setInterpreter):
            (Bindings::RootObject::interpreter):
    
    WebCore:
    	Cleaned up and verified reference counting scheme, and
    	dereferencing of vended JavaScript objects when applet is
    	destroyed (actually when part is destroyed).
    
            Reviewed by Ken.
    
            * kwq/KWQKHTMLPart.h:
            * kwq/KWQKHTMLPart.mm:
            (KWQKHTMLPart::~KWQKHTMLPart):
            (KWQKHTMLPart::getAppletInstanceForView):
            (KWQKHTMLPart::addPluginRootObject):
            (KWQKHTMLPart::cleanupPluginRootObjects):
            * kwq/WebCoreBridge.h:
            * kwq/WebCoreBridge.mm:
            (rootForView):
            (-[WebCoreBridge init]):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5774 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index c321dc6..a93dae1 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,46 @@
+2003-12-11  Richard Williamson   <rjw at apple.com>
+
+	Added support for calling a JavaScript function from
+	Java.  Right now this only works for void func(void)
+	functions, but the conversion of args and return values
+	will come shortly.
+
+	Cleaned up and verified reference counting scheme, and
+	dereferencing of vended JavaScript objects when applet is
+	destroyed (actually when part is destroyed).
+	
+	Removed link hack for testkjs now that the Java folks think
+	they have a solution for the 1.4.2 JavaVM link problem.  Although
+	Greg B. thinks his solution may cause problems for the 1.3.1
+	version of the VM!?!
+
+        Reviewed by Ken.
+
+        * Makefile.am:
+        * bindings/jni/jni_runtime.h:
+        (Bindings::JavaString::JavaString):
+        * bindings/jni/jni_utility.cpp:
+        (convertValueToJValue):
+        (convertValueToJObject):
+        (listFromJArray):
+        * bindings/jni/jni_utility.h:
+        * bindings/jni_jsobject.cpp:
+        (KJS_setFindRootObjectForNativeHandleFunction):
+        (KJS_findRootObjectForNativeHandleFunction):
+        (getReferencesByRootDictionary):
+        (getReferencesDictionary):
+        (findReferenceDictionary):
+        (rootForImp):
+        (addJavaReference):
+        (removeJavaReference):
+        * bindings/jni_jsobject.h:
+        (Bindings::RootObject::RootObject):
+        (Bindings::RootObject::~RootObject):
+        (Bindings::RootObject::setRootObjectImp):
+        (Bindings::RootObject::rootObjectImp):
+        (Bindings::RootObject::setInterpreter):
+        (Bindings::RootObject::interpreter):
+
 === Safari-117 ===
 
 2003-12-10  Darin Adler  <darin at apple.com>
diff --git a/JavaScriptCore/Makefile.am b/JavaScriptCore/Makefile.am
index 4ea7c0f..991cd6b 100644
--- a/JavaScriptCore/Makefile.am
+++ b/JavaScriptCore/Makefile.am
@@ -6,7 +6,7 @@ INCLUDES = -I $(top_srcdir)/JavaScriptCore/kjs
 noinst_PROGRAMS = kjs/testkjs
 kjs_testkjs_SOURCES = kjs/testkjs.cpp
 kjs_testkjs_DEPENDENCIES = JavaScriptCore-stamp
-kjs_testkjs_LDFLAGS = -F$(SYMROOTS) -framework JavaScriptCore -framework Cocoa
+kjs_testkjs_LDFLAGS = -F$(SYMROOTS) -framework JavaScriptCore
 
 all-am: JavaScriptCore-stamp
 JavaScriptCore-stamp: kjs/*.cpp kjs/*.h pcre/*.c pcre/*.h bindings/*.h bindings/*.cpp bindings/jni/*.cpp bindings/jni/*.h
diff --git a/JavaScriptCore/bindings/jni/jni_runtime.h b/JavaScriptCore/bindings/jni/jni_runtime.h
index 248ca21..76e574d 100644
--- a/JavaScriptCore/bindings/jni/jni_runtime.h
+++ b/JavaScriptCore/bindings/jni/jni_runtime.h
@@ -50,6 +50,13 @@ public:
         releaseCharactersForJStringInEnv (e, s, c);
     }
     
+    JavaString (jstring s) {
+        JNIEnv *e = getJNIEnv();
+        const char *c = getCharactersFromJStringInEnv (e, s);
+        _characters = strdup(c);
+        releaseCharactersForJStringInEnv (e, s, c);
+    }
+    
     ~JavaString () {
         free ((void *)_characters);
     }
diff --git a/JavaScriptCore/bindings/jni/jni_utility.cpp b/JavaScriptCore/bindings/jni/jni_utility.cpp
index dbc0b49..9209c0f 100644
--- a/JavaScriptCore/bindings/jni/jni_utility.cpp
+++ b/JavaScriptCore/bindings/jni/jni_utility.cpp
@@ -22,7 +22,8 @@
  * (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 "interpreter.h"
+#include <interpreter.h>
+#include <list.h>
 
 #include "jni_runtime.h"
 #include "jni_utility.h"
@@ -599,3 +600,15 @@ jvalue convertValueToJValue (KJS::ExecState *exec, KJS::Value value, JNIType _JN
     }
     return result;
 }
+
+jobject convertValueToJObject (KJS::ExecState *exec, KJS::Value value)
+{
+    // FIXME:  Implement!
+    return 0;
+}
+
+KJS::List listFromJArray(jobjectArray jArray)
+{
+    // FIXME:  Implement!
+    return KJS::List::empty();
+}
diff --git a/JavaScriptCore/bindings/jni/jni_utility.h b/JavaScriptCore/bindings/jni/jni_utility.h
index bceeaff..65a572e 100644
--- a/JavaScriptCore/bindings/jni/jni_utility.h
+++ b/JavaScriptCore/bindings/jni/jni_utility.h
@@ -25,6 +25,7 @@
 #ifndef _JNI_UTILITY_H_
 #define _JNI_UTILITY_H_
 
+#include <list.h>
 #include <value.h>
 
 #include <JavaVM/jni.h>
@@ -59,6 +60,7 @@ JNIType JNITypeFromPrimitiveType(char type);
 const char *signatureFromPrimitiveType(JNIType type);
 
 jvalue convertValueToJValue (KJS::ExecState *exec, KJS::Value value, JNIType _JNIType, const char *javaClassName);
+jobject convertValueToJObject (KJS::ExecState *exec, KJS::Value value);
 
 jvalue getJNIField( jobject obj, JNIType type, const char *name, const char *signature);
 
@@ -84,6 +86,8 @@ jlong callJNILongMethodA( jobject obj, const char *name, const char *sig, jvalue
 jfloat callJNIFloatMethodA( jobject obj, const char *name, const char *sig, jvalue *args);
 jdouble callJNIDoubleMethodA( jobject obj, const char *name, const char *sig, jvalue *args);
 
+KJS::List listFromJArray(jobjectArray jArray);
+
 JavaVM *getJavaVM();
 JNIEnv *getJNIEnv();
 
diff --git a/JavaScriptCore/bindings/jni_jsobject.cpp b/JavaScriptCore/bindings/jni_jsobject.cpp
index 6c0f65d..694e780 100644
--- a/JavaScriptCore/bindings/jni_jsobject.cpp
+++ b/JavaScriptCore/bindings/jni_jsobject.cpp
@@ -24,18 +24,27 @@
  */
 #include <CoreFoundation/CoreFoundation.h>
 
+#include <identifier.h>
+#include <internal.h>
+#include <interpreter.h>
+#include <list.h>
 #include <jni_jsobject.h>
+#include <jni_runtime.h>
+#include <jni_utility.h>
 
-static KJSFindObjectForNativeHandleFunctionPtr findObjectForNativeHandleFunctionPtr = 0;
+using namespace Bindings;
+using namespace KJS;
 
-void KJS_setFindObjectForNativeHandleFunction(KJSFindObjectForNativeHandleFunctionPtr aFunc)
+static KJSFindRootObjectForNativeHandleFunctionPtr findRootObjectForNativeHandleFunctionPtr = 0;
+
+void KJS_setFindRootObjectForNativeHandleFunction(KJSFindRootObjectForNativeHandleFunctionPtr aFunc)
 {
-    findObjectForNativeHandleFunctionPtr = aFunc;
+    findRootObjectForNativeHandleFunctionPtr = aFunc;
 }
 
-KJSFindObjectForNativeHandleFunctionPtr KJS_findObjectForNativeHandleFunction()
+KJSFindRootObjectForNativeHandleFunctionPtr KJS_findRootObjectForNativeHandleFunction()
 {
-    return findObjectForNativeHandleFunctionPtr;
+    return findRootObjectForNativeHandleFunctionPtr;
 }
 
 // Java does NOT always call finalize (and thus KJS_JSObject_JSFinalize) when
@@ -52,45 +61,46 @@ KJSFindObjectForNativeHandleFunctionPtr KJS_findObjectForNativeHandleFunction()
 // 1 OR the applet is shutdown we deref the JavaScript instance.  Applet instances
 // are represented by a jlong.
 
-static CFMutableDictionaryRef referencesByOwnerDictionary = 0;
+static CFMutableDictionaryRef referencesByRootDictionary = 0;
 
-static CFMutableDictionaryRef getReferencesByOwnerDictionary()
+static CFMutableDictionaryRef getReferencesByRootDictionary()
 {
-    if (!referencesByOwnerDictionary)
-        referencesByOwnerDictionary = CFDictionaryCreateMutable(NULL, 0, NULL, &kCFTypeDictionaryValueCallBacks);
-    return referencesByOwnerDictionary;
+    if (!referencesByRootDictionary)
+        referencesByRootDictionary = CFDictionaryCreateMutable(NULL, 0, NULL, &kCFTypeDictionaryValueCallBacks);
+    return referencesByRootDictionary;
 }
 
-static CFMutableDictionaryRef getReferencesDictionary(const void *owner)
+static CFMutableDictionaryRef getReferencesDictionary(const Bindings::RootObject *root)
 {
-    CFMutableDictionaryRef refsByOwner = getReferencesByOwnerDictionary();
+    CFMutableDictionaryRef refsByRoot = getReferencesByRootDictionary();
     CFMutableDictionaryRef referencesDictionary = 0;
     
-    referencesDictionary = (CFMutableDictionaryRef)CFDictionaryGetValue (refsByOwner, owner);
+    referencesDictionary = (CFMutableDictionaryRef)CFDictionaryGetValue (refsByRoot, (const void *)root);
     if (!referencesDictionary) {
         referencesDictionary = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);
-        CFDictionaryAddValue (refsByOwner, owner, referencesDictionary);
+        CFDictionaryAddValue (refsByRoot, root, referencesDictionary);
         CFRelease (referencesDictionary);
     }
     return referencesDictionary;
 }
 
-// Scan all the dictionary for all the owners to see if any have a 
+// Scan all the dictionary for all the roots to see if any have a 
 // reference to the imp, and if so, return it's reference count
 // dictionary.
-// FIXME:  This is a potential performance bottleneck.
-static CFMutableDictionaryRef findReferenceDictionary(KJS::ValueImp *imp)
+// FIXME:  This is a potential performance bottleneck with many applets.  We could fix be adding a
+// imp to root dictionary.
+static CFMutableDictionaryRef findReferenceDictionary(ObjectImp *imp)
 {
-    CFMutableDictionaryRef refsByOwner = getReferencesByOwnerDictionary ();
-    CFMutableDictionaryRef referencesDictionary = 0, foundDictionary = 0;
+    CFMutableDictionaryRef refsByRoot = getReferencesByRootDictionary ();
+    CFMutableDictionaryRef foundDictionary = 0;
     
-    if (refsByOwner) {
+    if (refsByRoot) {
         const void **allValues = 0;
         CFIndex count, i;
         
-        count = CFDictionaryGetCount(referencesDictionary);
-        CFDictionaryGetKeysAndValues (referencesDictionary, NULL, allValues);
+        count = CFDictionaryGetCount(refsByRoot);
         allValues = (const void **)malloc (sizeof(void *) * count);
+        CFDictionaryGetKeysAndValues (refsByRoot, NULL, allValues);
         for(i = 0; i < count; i++) {
             CFMutableDictionaryRef referencesDictionary = (CFMutableDictionaryRef)allValues[i];
             if (CFDictionaryGetValue(referencesDictionary, imp) != 0) {
@@ -104,9 +114,39 @@ static CFMutableDictionaryRef findReferenceDictionary(KJS::ValueImp *imp)
     return foundDictionary;
 }
 
-static void addJavaReference (const void *owner, KJS::ValueImp *imp)
+// FIXME:  This is a potential performance bottleneck with many applets.  We could fix be adding a
+// imp to root dictionary.
+const Bindings::RootObject *rootForImp (ObjectImp *imp)
 {
-    CFMutableDictionaryRef referencesDictionary = getReferencesDictionary (owner);
+    CFMutableDictionaryRef refsByRoot = getReferencesByRootDictionary ();
+    const Bindings::RootObject *rootObject = 0;
+    
+    if (refsByRoot) {
+        const void **allValues = 0;
+        const void **allKeys = 0;
+        CFIndex count, i;
+        
+        count = CFDictionaryGetCount(refsByRoot);
+        allKeys = (const void **)malloc (sizeof(void *) * count);
+        allValues = (const void **)malloc (sizeof(void *) * count);
+        CFDictionaryGetKeysAndValues (refsByRoot, allKeys, allValues);
+        for(i = 0; i < count; i++) {
+            CFMutableDictionaryRef referencesDictionary = (CFMutableDictionaryRef)allValues[i];
+            if (CFDictionaryGetValue(referencesDictionary, imp) != 0) {
+                rootObject = (const Bindings::RootObject *)allKeys[0];
+                break;
+            }
+        }
+        
+        free ((void *)allKeys);
+        free ((void *)allValues);
+    }
+    return rootObject;
+}
+
+static void addJavaReference (const Bindings::RootObject *root, ObjectImp *imp)
+{
+    CFMutableDictionaryRef referencesDictionary = getReferencesDictionary (root);
     
     unsigned int numReferences = (unsigned int)CFDictionaryGetValue (referencesDictionary, imp);
     if (numReferences == 0) {
@@ -118,7 +158,7 @@ static void addJavaReference (const void *owner, KJS::ValueImp *imp)
     }
 }
 
-static void removeJavaReference (KJS::ValueImp *imp)
+static void removeJavaReference (ObjectImp *imp)
 {
     CFMutableDictionaryRef referencesDictionary = findReferenceDictionary (imp);
     
@@ -132,10 +172,12 @@ static void removeJavaReference (KJS::ValueImp *imp)
     }
 }
 
+extern "C" {
+
 // Must be called when the applet is shutdown.
-void removeAllJavaReferencesForOwner (const void *owner)
+void KJS_removeAllJavaReferencesForRoot (Bindings::RootObject *root)
 {
-    CFMutableDictionaryRef referencesDictionary = getReferencesDictionary (owner);
+    CFMutableDictionaryRef referencesDictionary = getReferencesDictionary (root);
     
     if (referencesDictionary) {
         void **allImps = 0;
@@ -145,46 +187,62 @@ void removeAllJavaReferencesForOwner (const void *owner)
         CFDictionaryGetKeysAndValues (referencesDictionary, (const void **)allImps, NULL);
         allImps = (void **)malloc (sizeof(void *) * count);
         for(i = 0; i < count; i++) {
-            KJS::ValueImp *anImp = static_cast<KJS::ValueImp*>(allImps[i]);
+            ObjectImp *anImp = static_cast<ObjectImp*>(allImps[i]);
             anImp->deref();
         }
         free ((void *)allImps);
         CFDictionaryRemoveAllValues (referencesDictionary);
 
-        CFMutableDictionaryRef refsByOwner = getReferencesByOwnerDictionary();
-        CFDictionaryRemoveValue (refsByOwner, owner);
+        CFMutableDictionaryRef refsByRoot = getReferencesByRootDictionary();
+        CFDictionaryRemoveValue (refsByRoot, (const void *)root);
+        delete root;
     }
 }
 
-
-extern "C" {
-
 jlong KJS_JSCreateNativeJSObject (JNIEnv *env, jclass clazz, jstring jurl, jlong nativeHandle, jboolean ctx)
 {
-    fprintf (stderr, "%s: nativeHandle = %p\n", __PRETTY_FUNCTION__, jlong_to_ptr(nativeHandle));
-    
-    KJSFindObjectForNativeHandleFunctionPtr aFunc = KJS_findObjectForNativeHandleFunction();
+    KJSFindRootObjectForNativeHandleFunctionPtr aFunc = KJS_findRootObjectForNativeHandleFunction();
     if (aFunc) {
-        KJS::ObjectImp *imp = aFunc(jlong_to_ptr(nativeHandle));
-        addJavaReference (jlong_to_ptr(nativeHandle), imp);        
-        return ptr_to_jlong(imp);
+        Bindings::RootObject *root = aFunc(jlong_to_ptr(nativeHandle));
+        addJavaReference (root, root->rootObjectImp());        
+        return ptr_to_jlong(root->rootObjectImp());
     }
     
-    fprintf (stderr, "%s: unable to find window for nativeHandle = %p\n", __PRETTY_FUNCTION__, jlong_to_ptr(nativeHandle));
-
     return ptr_to_jlong(0);
 }
 
 void KJS_JSObject_JSFinalize (JNIEnv *env, jclass jsClass, jlong nativeJSObject)
 {
     removeJavaReference (jlong_to_impptr(nativeJSObject));
-    fprintf (stderr, "%s:\n", __PRETTY_FUNCTION__);
 }
 
-jobject KJS_JSObject_JSObjectCall (JNIEnv *env, jclass jsClass, jlong nativeJSObject, jstring jurl, jstring methodName, jobjectArray args, jboolean ctx)
+jobject KJS_JSObject_JSObjectCall (JNIEnv *env, jclass jsClass, jlong nativeJSObject, jstring jurl, jstring mName, jobjectArray args, jboolean ctx)
 {
-    fprintf (stderr, "%s:\n", __PRETTY_FUNCTION__);
-    return 0;
+    ObjectImp *imp = jlong_to_impptr(nativeJSObject);
+    const Bindings::RootObject *root = rootForImp (imp);
+    
+    // Change to assert.
+    if (!root) {
+        return 0;
+    }
+    
+    // Lookup the function object.
+    ExecState *exec = root->interpreter()->globalExec();
+    const char *methodName = JavaString(mName).characters();
+    Value func = imp->get (exec, Identifier (methodName));
+    if (func.isNull() || func.type() == UndefinedType) {
+        // Maybe throw an exception here?
+        return 0;
+    }
+
+    // Call the function object.
+    ObjectImp *funcImp = static_cast<ObjectImp*>(func.imp());
+    Object thisObj = Object(const_cast<ObjectImp*>(imp));
+    List argList = listFromJArray(args);
+    Value result = funcImp->call (exec, thisObj, argList);
+
+    // Convert and return the result of the function call.
+    return convertValueToJObject (exec, result);
 }
 
 jobject KJS_JSObject_JSObjectEval (JNIEnv *env, jclass jsClass, jlong nativeJSObject, jstring jurl, jstring jscript, jboolean ctx)
diff --git a/JavaScriptCore/bindings/jni_jsobject.h b/JavaScriptCore/bindings/jni_jsobject.h
index 13e21cb..2ebca42 100644
--- a/JavaScriptCore/bindings/jni_jsobject.h
+++ b/JavaScriptCore/bindings/jni_jsobject.h
@@ -25,18 +25,48 @@
 #ifndef _JNI_JS_H_
 #define _JNI_JS_H_
 
+#include <JavaScriptCore/interpreter.h>
 #include <JavaScriptCore/object.h>
 
 #include <JavaVM/jni.h>
 
 #define jlong_to_ptr(a) ((void*)(uintptr_t)(a))
-#define jlong_to_impptr(a) (static_cast<KJS::ValueImp*>(((void*)(uintptr_t)(a))))
+#define jlong_to_impptr(a) (static_cast<KJS::ObjectImp*>(((void*)(uintptr_t)(a))))
 #define ptr_to_jlong(a) ((jlong)(uintptr_t)(a))
 
-typedef KJS::ObjectImp *(*KJSFindObjectForNativeHandleFunctionPtr)(void *);
+namespace Bindings {
+
+class RootObject
+{
+public:
+    RootObject (const void *nativeHandle) : _nativeHandle(nativeHandle), _imp(0), _interpreter(0) {}
+    ~RootObject (){
+        _imp->deref();
+    }
+    
+    void setRootObjectImp (KJS::ObjectImp *i) { 
+        _imp = i;
+        _imp->ref();
+    }
+    
+    KJS::ObjectImp *rootObjectImp() const { return _imp; }
+    
+    void setInterpreter (KJS::Interpreter *i) { _interpreter = i; }
+    KJS::Interpreter *interpreter() const { return _interpreter; }
+    
+private:
+    const void *_nativeHandle;
+    KJS::ObjectImp *_imp;
+    KJS::Interpreter *_interpreter;
+};
+
+}
+
+typedef Bindings::RootObject *(*KJSFindRootObjectForNativeHandleFunctionPtr)(void *);
+
+void KJS_setFindRootObjectForNativeHandleFunction(KJSFindRootObjectForNativeHandleFunctionPtr aFunc);
+KJSFindRootObjectForNativeHandleFunctionPtr KJS_findRootObjectForNativeHandleFunction();
 
-void KJS_setFindObjectForNativeHandleFunction(KJSFindObjectForNativeHandleFunctionPtr aFunc);
-KJSFindObjectForNativeHandleFunctionPtr KJS_findObjectForNativeHandleFunction();
 
 extern "C" {
 
@@ -52,6 +82,8 @@ jobject KJS_JSObject_JSObjectGetSlot (JNIEnv *env, jclass jsClass, jlong nativeJ
 void KJS_JSObject_JSObjectSetSlot (JNIEnv *env, jclass jsClass, jlong nativeJSObject, jstring jurl, jint jindex, jobject value, jboolean ctx);
 jstring KJS_JSObject_JSObjectToString (JNIEnv *env, jclass clazz, jlong nativeJSObject);
 
+void KJS_removeAllJavaReferencesForRoot (Bindings::RootObject *root);
+
 }
 
 #endif
\ No newline at end of file
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 3f1bd6d..36f6b69 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,22 @@
+2003-12-11  Richard Williamson   <rjw at apple.com>
+
+	Cleaned up and verified reference counting scheme, and
+	dereferencing of vended JavaScript objects when applet is
+	destroyed (actually when part is destroyed).
+
+        Reviewed by Ken.
+
+        * kwq/KWQKHTMLPart.h:
+        * kwq/KWQKHTMLPart.mm:
+        (KWQKHTMLPart::~KWQKHTMLPart):
+        (KWQKHTMLPart::getAppletInstanceForView):
+        (KWQKHTMLPart::addPluginRootObject):
+        (KWQKHTMLPart::cleanupPluginRootObjects):
+        * kwq/WebCoreBridge.h:
+        * kwq/WebCoreBridge.mm:
+        (rootForView):
+        (-[WebCoreBridge init]):
+
 2003-12-11  Maciej Stachowiak  <mjs at apple.com>
 
         Reviewed by John.
diff --git a/WebCore/kwq/KWQKHTMLPart.h b/WebCore/kwq/KWQKHTMLPart.h
index 5364cd0..cdc297f 100644
--- a/WebCore/kwq/KWQKHTMLPart.h
+++ b/WebCore/kwq/KWQKHTMLPart.h
@@ -37,6 +37,7 @@
 #include <CoreFoundation/CoreFoundation.h>
 
 #include <JavaVM/jni.h>
+#include <JavaScriptCore/jni_jsobject.h>
 #include <JavaScriptCore/runtime.h>
 
 #include "KWQDict.h"
@@ -253,6 +254,8 @@ public:
     void print();
 
     Bindings::Instance *getAppletInstanceForView (NSView *aView);
+    void addPluginRootObject(const Bindings::RootObject *root);
+    void cleanupPluginRootObjects();
     
 private:
     virtual void khtmlMousePressEvent(khtml::MousePressEvent *);
@@ -305,6 +308,8 @@ private:
     QDict<char> urlsBridgeKnowsAbout;
 
     friend class KHTMLPart;
+
+    QPtrList<Bindings::RootObject> rootObjects;
 };
 
 inline KWQKHTMLPart *KWQ(KHTMLPart *part) { return static_cast<KWQKHTMLPart *>(part); }
diff --git a/WebCore/kwq/KWQKHTMLPart.mm b/WebCore/kwq/KWQKHTMLPart.mm
index 49e11ab..11f6f92 100644
--- a/WebCore/kwq/KWQKHTMLPart.mm
+++ b/WebCore/kwq/KWQKHTMLPart.mm
@@ -166,6 +166,8 @@ KWQKHTMLPart::KWQKHTMLPart()
 
 KWQKHTMLPart::~KWQKHTMLPart()
 {
+    cleanupPluginRootObjects();
+    
     mutableInstances().remove(this);
     if (d->m_view) {
 	d->m_view->deref();
@@ -2776,3 +2778,17 @@ Bindings::Instance *KWQKHTMLPart::getAppletInstanceForView (NSView *aView)
     return 0;
 }
 
+void KWQKHTMLPart::addPluginRootObject(const Bindings::RootObject *root)
+{
+    rootObjects.append (root);
+}
+
+void KWQKHTMLPart::cleanupPluginRootObjects()
+{
+    Bindings::RootObject *root;
+    while ((root = rootObjects.getLast())) {
+        KJS_removeAllJavaReferencesForRoot (root);
+        rootObjects.removeLast();
+    }
+}
+
diff --git a/WebCore/kwq/WebCoreBridge.h b/WebCore/kwq/WebCoreBridge.h
index 7f76012..95cc605 100644
--- a/WebCore/kwq/WebCoreBridge.h
+++ b/WebCore/kwq/WebCoreBridge.h
@@ -40,9 +40,6 @@ namespace khtml {
     class RenderObject;
 }
 
-namespace KJS {
-    class Window;
-}
 
 typedef khtml::RenderPart KHTMLRenderPart;
 
@@ -52,7 +49,6 @@ typedef khtml::RenderPart KHTMLRenderPart;
 @class KHTMLView;
 @class KHTMLRenderPart;
 @class RenderArena;
- at class Window;
 
 #endif
 
diff --git a/WebCore/kwq/WebCoreBridge.mm b/WebCore/kwq/WebCoreBridge.mm
index f1f94d2..803d514 100644
--- a/WebCore/kwq/WebCoreBridge.mm
+++ b/WebCore/kwq/WebCoreBridge.mm
@@ -36,6 +36,7 @@
 #import "htmltags.h"
 #import "khtml_part.h"
 #import "khtmlview.h"
+#import "kjs_proxy.h"
 #import "kjs_window.h"
 #import "loader.h"
 #import "render_frames.h"
@@ -87,6 +88,8 @@ using KJS::SavedBuiltins;
 
 using KParts::URLArgs;
 
+using Bindings::RootObject;
+
 NSString *WebCoreElementFrameKey = 		@"WebElementFrame";
 NSString *WebCoreElementImageAltStringKey = 	@"WebElementImageAltString";
 NSString *WebCoreElementImageKey = 		@"WebElementImage";
@@ -102,13 +105,18 @@ NSString *WebCoreElementTitleKey = 		@"WebCoreElementTitle"; // not in WebKit AP
 
 NSString *WebCorePageCacheStateKey =            @"WebCorePageCacheState";
 
-static KJS::ObjectImp *rootForView(void *v)
+static RootObject *rootForView(void *v)
 {
     NSView *aView = (NSView *)v;
-    
     WebCoreBridge *aBridge = [[WebCoreViewFactory sharedFactory] bridgeForView:aView];
-
-    return static_cast<KJS::ObjectImp *>(KJS::Window::retrieveWindow([aBridge part]));
+    KWQKHTMLPart *part = [aBridge part];
+    RootObject *root = new RootObject(v);
+    
+    root->setRootObjectImp (static_cast<KJS::ObjectImp *>(KJS::Window::retrieveWindow(part)));
+    root->setInterpreter (KJSProxy::proxy(part)->interpreter());
+    part->addPluginRootObject (root);
+    
+    return root;
 }
 
 @implementation WebCoreBridge
@@ -129,7 +137,7 @@ static bool initializedKJS = FALSE;
     }
     
     if (!initializedKJS) {
-        KJS_setFindObjectForNativeHandleFunction (rootForView);
+        KJS_setFindRootObjectForNativeHandleFunction (rootForView);
         initializedKJS = TRUE;
     }
     
@@ -1103,4 +1111,5 @@ static HTMLFormElementImpl *formElementFromDOMElement(id <WebDOMElement>element)
     return _part->xmlDocImpl()->getOrCreateAccObjectCache()->accObject(root);
 }
 
+
 @end

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list