[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:17:50 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 7389d4e8f7fa16525c387929068f55a9047a88e2
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Dec 11 02:20:43 2003 +0000

    WebKit:
    	Added method to get to the bridge from a view.  This is
    	used to ultimately get the part and KJS::Window for a
    	particular applet.
    
            Reviewed by Hyatt.
    
            * WebCoreSupport.subproj/WebViewFactory.m:
            (-[WebViewFactory refreshPlugins:]):
            (-[WebViewFactory bridgeForView:]):
    
    WebCore:
    	Added method to get to the bridge from a view.  This is
    	used to ultimately get the part and KJS::Window for a
    	particular applet.
    
            Reviewed by Hyatt.
    
            * kwq/WebCoreBridge.h:
            * kwq/WebCoreBridge.mm:
            (rootForView):
            (-[WebCoreBridge init]):
            * kwq/WebCoreViewFactory.h:
            * kwq/WebCoreViewFactory.m:
    
    JavaScriptCore:
    	Added code to manage reference counting of JavaScript
    	objects passed to Java.   Also added implementation of
    	KJS_JSCreateNativeJSObject.  This is the function that
    	provides the root object to Java (KJS::Window).
    
            Reviewed by Hyatt.
    
            * JavaScriptCore.pbproj/project.pbxproj:
            * bindings/jni_jsobject.cpp:
            (KJS_setFindObjectForNativeHandleFunction):
            (KJS_findObjectForNativeHandleFunction):
            (getReferencesByOwnerDictionary):
            (getReferencesDictionary):
            (findReferenceDictionary):
            (addJavaReference):
            (removeJavaReference):
            (removeAllJavaReferencesForOwner):
            * bindings/jni_jsobject.h:
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5750 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 7725874..60d72c8 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,24 @@
+2003-12-10  Richard Williamson   <rjw at apple.com>
+
+	Added code to manage reference counting of JavaScript
+	objects passed to Java.   Also added implementation of
+	KJS_JSCreateNativeJSObject.  This is the function that
+	provides the root object to Java (KJS::Window).
+
+        Reviewed by Hyatt.
+
+        * JavaScriptCore.pbproj/project.pbxproj:
+        * bindings/jni_jsobject.cpp:
+        (KJS_setFindObjectForNativeHandleFunction):
+        (KJS_findObjectForNativeHandleFunction):
+        (getReferencesByOwnerDictionary):
+        (getReferencesDictionary):
+        (findReferenceDictionary):
+        (addJavaReference):
+        (removeJavaReference):
+        (removeAllJavaReferencesForOwner):
+        * bindings/jni_jsobject.h:
+
 2003-12-09  Richard Williamson   <rjw at apple.com>
 
 	LiveConnect stubs that correspond to the native methods
diff --git a/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj b/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
index ef88e02..db0d88e 100644
--- a/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
+++ b/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
@@ -514,6 +514,9 @@
 			fileRef = 513589EE0586989000813311;
 			isa = PBXBuildFile;
 			settings = {
+				ATTRIBUTES = (
+					Private,
+				);
 			};
 		};
 		517D52DC056BF2F5003851BD = {
diff --git a/JavaScriptCore/bindings/jni_jsobject.cpp b/JavaScriptCore/bindings/jni_jsobject.cpp
index 45c28e1..68b0a7f 100644
--- a/JavaScriptCore/bindings/jni_jsobject.cpp
+++ b/JavaScriptCore/bindings/jni_jsobject.cpp
@@ -22,16 +22,162 @@
  * (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 <CoreFoundation/CoreFoundation.h>
+
 #include <jni_jsobject.h>
- 
-jlong KJS_JSCreateNativeJSObject (JNIEnv *env, jclass clazz, jstring jurl, jboolean ctx)
+
+static KJSFindObjectForNativeHandleFunctionPtr findObjectForNativeHandleFunctionPtr = 0;
+
+void KJS_setFindObjectForNativeHandleFunction(KJSFindObjectForNativeHandleFunctionPtr aFunc)
 {
-    fprintf (stderr, "%s:\n", __PRETTY_FUNCTION__);
-    return POINTER_JNI_JLONG(0);
+    findObjectForNativeHandleFunctionPtr = aFunc;
+}
+
+KJSFindObjectForNativeHandleFunctionPtr KJS_findObjectForNativeHandleFunction()
+{
+    return findObjectForNativeHandleFunctionPtr;
+}
+
+// Java does NOT always call finalize (and thus KJS_JSObject_JSFinalize) when
+// it collects an objects.  This presents some difficulties.  We must ensure
+// the a JSObject's corresponding JavaScript object doesn't get collected.  We
+// do this by incrementing the JavaScript's reference count the first time we
+// create a JSObject for it, and decrementing the JavaScript reference count when
+// the last JSObject that refers to it is finalized, or when the applet is
+// shutdown.
+//
+// To do this we keep a dictionary that maps each applet instance
+// to the JavaScript objects it is referencing.  For each JavaScript instance
+// we also maintain a secondary reference count.  When that reference count reaches
+// 1 OR the applet is shutdown we deref the JavaScript instance.  Applet instances
+// are represented by a jlong.
+
+static CFMutableDictionaryRef referencesByOwnerDictionary = 0;
+
+static CFMutableDictionaryRef getReferencesByOwnerDictionary()
+{
+    if (!referencesByOwnerDictionary)
+        referencesByOwnerDictionary = CFDictionaryCreateMutable(NULL, 0, NULL, &kCFTypeDictionaryValueCallBacks);
+    return referencesByOwnerDictionary;
+}
+
+static CFMutableDictionaryRef getReferencesDictionary(const void *owner)
+{
+    CFMutableDictionaryRef refsByOwner = getReferencesByOwnerDictionary();
+    CFMutableDictionaryRef referencesDictionary = 0;
+    
+    referencesDictionary = (CFMutableDictionaryRef)CFDictionaryGetValue (refsByOwner, owner);
+    if (!referencesDictionary) {
+        referencesDictionary = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);
+        CFDictionaryAddValue (refsByOwner, owner, referencesDictionary);
+        CFRelease (referencesDictionary);
+    }
+    return referencesDictionary;
+}
+
+// Scan all the dictionary for all the owners 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)
+{
+    CFMutableDictionaryRef refsByOwner = getReferencesByOwnerDictionary ();
+    CFMutableDictionaryRef referencesDictionary, foundDictionary = 0;
+    
+    if (refsByOwner) {
+        const void **allValues;
+        CFIndex count, i;
+        
+        count = CFDictionaryGetCount(referencesDictionary);
+        CFDictionaryGetKeysAndValues (referencesDictionary, NULL, allValues);
+        allValues = (const void **)malloc (sizeof(void *) * count);
+        for(i = 0; i < count; i++) {
+            CFMutableDictionaryRef referencesDictionary = (CFMutableDictionaryRef)allValues[i];
+            if (CFDictionaryGetValue(referencesDictionary, imp) != 0) {
+                foundDictionary = referencesDictionary;
+                break;
+            }
+        }
+        
+        free ((void *)allValues);
+    }
+    return foundDictionary;
+}
+
+static void addJavaReference (const void *owner, KJS::ValueImp *imp)
+{
+    CFMutableDictionaryRef referencesDictionary = getReferencesDictionary (owner);
+    
+    unsigned int numReferences = (unsigned int)CFDictionaryGetValue (referencesDictionary, imp);
+    if (numReferences == 0) {
+        imp->ref();
+        CFDictionaryAddValue (referencesDictionary, imp,  (const void *)1);
+    }
+    else {
+        CFDictionaryReplaceValue (referencesDictionary, imp, (const void *)(numReferences+1));
+    }
+}
+
+static void removeJavaReference (KJS::ValueImp *imp)
+{
+    CFMutableDictionaryRef referencesDictionary = findReferenceDictionary (imp);
+    
+    unsigned int numReferences = (unsigned int)CFDictionaryGetValue (referencesDictionary, imp);
+    if (numReferences == 1) {
+        imp->deref();
+        CFDictionaryRemoveValue (referencesDictionary, imp);
+    }
+    else {
+        CFDictionaryReplaceValue (referencesDictionary, imp, (const void *)(numReferences-1));
+    }
+}
+
+// Must be called when the applet is shutdown.
+void removeAllJavaReferencesForOwner (const void *owner)
+{
+    CFMutableDictionaryRef referencesDictionary = getReferencesDictionary (owner);
+    
+    if (referencesDictionary) {
+        void **allImps;
+        CFIndex count, i;
+        
+        count = CFDictionaryGetCount(referencesDictionary);
+        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]);
+            anImp->deref();
+        }
+        free ((void *)allImps);
+        CFDictionaryRemoveAllValues (referencesDictionary);
+
+        CFMutableDictionaryRef refsByOwner = getReferencesByOwnerDictionary();
+        CFDictionaryRemoveValue (refsByOwner, owner);
+    }
+}
+
+
+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();
+    if (aFunc) {
+        KJS::ObjectImp *imp = aFunc(jlong_to_ptr(nativeHandle));
+        addJavaReference (jlong_to_ptr(nativeHandle), imp);        
+        return ptr_to_jlong(imp);
+    }
+    
+    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__);
 }
 
@@ -80,3 +226,4 @@ jstring KJS_JSObject_JSObjectToString (JNIEnv *env, jclass clazz, jlong nativeJS
     return 0;
 }
 
+}
diff --git a/JavaScriptCore/bindings/jni_jsobject.h b/JavaScriptCore/bindings/jni_jsobject.h
index 0fd1bd6..13e21cb 100644
--- a/JavaScriptCore/bindings/jni_jsobject.h
+++ b/JavaScriptCore/bindings/jni_jsobject.h
@@ -25,12 +25,23 @@
 #ifndef _JNI_JS_H_
 #define _JNI_JS_H_
 
+#include <JavaScriptCore/object.h>
+
 #include <JavaVM/jni.h>
 
-#define POINTER_JNI_JLONG(ptr) ((jlong)ptr)
+#define jlong_to_ptr(a) ((void*)(uintptr_t)(a))
+#define jlong_to_impptr(a) (static_cast<KJS::ValueImp*>(((void*)(uintptr_t)(a))))
+#define ptr_to_jlong(a) ((jlong)(uintptr_t)(a))
+
+typedef KJS::ObjectImp *(*KJSFindObjectForNativeHandleFunctionPtr)(void *);
+
+void KJS_setFindObjectForNativeHandleFunction(KJSFindObjectForNativeHandleFunctionPtr aFunc);
+KJSFindObjectForNativeHandleFunctionPtr KJS_findObjectForNativeHandleFunction();
+
+extern "C" {
 
 // Functions called from the Java VM when making class to the JSObject class.
-jlong KJS_JSCreateNativeJSObject (JNIEnv *env, jclass clazz, jstring jurl, jboolean ctx);
+jlong KJS_JSCreateNativeJSObject (JNIEnv *env, jclass clazz, jstring jurl, jlong nativeHandle, jboolean ctx);
 void KJS_JSObject_JSFinalize (JNIEnv *env, jclass jsClass, jlong nativeJSObject);
 jobject KJS_JSObject_JSObjectCall (JNIEnv *env, jclass jsClass, jlong nativeJSObject, jstring jurl, jstring methodName, jobjectArray args, jboolean ctx);
 jobject KJS_JSObject_JSObjectEval (JNIEnv *env, jclass jsClass, jlong nativeJSObject, jstring jurl, jstring jscript, jboolean ctx);
@@ -41,4 +52,6 @@ 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);
 
+}
+
 #endif
\ No newline at end of file
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 73bfee4..4f29d51 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,18 @@
+2003-12-10  Richard Williamson   <rjw at apple.com>
+
+	Added method to get to the bridge from a view.  This is
+	used to ultimately get the part and KJS::Window for a
+	particular applet.
+
+        Reviewed by Hyatt.
+
+        * kwq/WebCoreBridge.h:
+        * kwq/WebCoreBridge.mm:
+        (rootForView):
+        (-[WebCoreBridge init]):
+        * kwq/WebCoreViewFactory.h:
+        * kwq/WebCoreViewFactory.m:
+
 2003-12-10  John Sullivan  <sullivan at apple.com>
 
         - WebCore part of fix for:
diff --git a/WebCore/kwq/WebCoreBridge.h b/WebCore/kwq/WebCoreBridge.h
index 972a70b..10836d5 100644
--- a/WebCore/kwq/WebCoreBridge.h
+++ b/WebCore/kwq/WebCoreBridge.h
@@ -40,6 +40,10 @@ namespace khtml {
     class RenderObject;
 }
 
+namespace KJS {
+    class Window;
+}
+
 typedef khtml::RenderPart KHTMLRenderPart;
 
 #else
@@ -48,6 +52,7 @@ typedef khtml::RenderPart KHTMLRenderPart;
 @class KHTMLView;
 @class KHTMLRenderPart;
 @class RenderArena;
+ at class Window;
 
 #endif
 
@@ -233,7 +238,7 @@ typedef enum {
 
 + (void)updateAllViews;
 
--(id)accessibilityTree;
+- (id)accessibilityTree;
 
 @end
 
@@ -366,7 +371,7 @@ typedef enum {
 
 - (void)print;
 
-- (jobject)pollForAppletInView: (NSView *)view;
+- (jobject)pollForAppletInView:(NSView *)view;
 
 @end
 
diff --git a/WebCore/kwq/WebCoreBridge.mm b/WebCore/kwq/WebCoreBridge.mm
index 653c396..f1f94d2 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_window.h"
 #import "loader.h"
 #import "render_frames.h"
 #import "render_image.h"
@@ -44,6 +45,8 @@
 #import "render_style.h"
 #import "render_replaced.h"
 
+#import <JavaScriptCore/jni_jsobject.h>
+#import <JavaScriptCore/object.h>
 #import <JavaScriptCore/property_map.h>
 
 #import "KWQAssertions.h"
@@ -61,6 +64,7 @@
 #import "WebCoreDOMPrivate.h"
 #import "WebCoreImageRenderer.h"
 #import "WebCoreTextRendererFactory.h"
+#import "WebCoreViewFactory.h"
 #import "WebCoreSettings.h"
 
 #import <AppKit/NSView.h>
@@ -98,9 +102,19 @@ NSString *WebCoreElementTitleKey = 		@"WebCoreElementTitle"; // not in WebKit AP
 
 NSString *WebCorePageCacheStateKey =            @"WebCorePageCacheState";
 
+static KJS::ObjectImp *rootForView(void *v)
+{
+    NSView *aView = (NSView *)v;
+    
+    WebCoreBridge *aBridge = [[WebCoreViewFactory sharedFactory] bridgeForView:aView];
+
+    return static_cast<KJS::ObjectImp *>(KJS::Window::retrieveWindow([aBridge part]));
+}
+
 @implementation WebCoreBridge
 
 static bool initializedObjectCacheSize = FALSE;
+static bool initializedKJS = FALSE;
 
 - init
 {
@@ -114,6 +128,11 @@ static bool initializedObjectCacheSize = FALSE;
         initializedObjectCacheSize = TRUE;
     }
     
+    if (!initializedKJS) {
+        KJS_setFindObjectForNativeHandleFunction (rootForView);
+        initializedKJS = TRUE;
+    }
+    
     _shouldCreateRenderers = YES;
     
     return self;
@@ -1083,4 +1102,5 @@ static HTMLFormElementImpl *formElementFromDOMElement(id <WebDOMElement>element)
     if (!root) return nil;
     return _part->xmlDocImpl()->getOrCreateAccObjectCache()->accObject(root);
 }
+
 @end
diff --git a/WebCore/kwq/WebCoreViewFactory.h b/WebCore/kwq/WebCoreViewFactory.h
index e42c881..1ce6faa 100644
--- a/WebCore/kwq/WebCoreViewFactory.h
+++ b/WebCore/kwq/WebCoreViewFactory.h
@@ -27,6 +27,7 @@
 @class NSDictionary;
 @class NSString;
 @class NSView;
+ at class WebCoreBridge;
 
 @protocol WebCoreViewFactory
 
@@ -40,6 +41,8 @@
 
 - (NSString *)defaultLanguageCode;
 
+- (WebCoreBridge *)bridgeForView:(NSView *)aView;
+
 @end
 
 @interface WebCoreViewFactory : NSObject
diff --git a/WebCore/kwq/WebCoreViewFactory.m b/WebCore/kwq/WebCoreViewFactory.m
index 1be3e94..81becf6 100644
--- a/WebCore/kwq/WebCoreViewFactory.m
+++ b/WebCore/kwq/WebCoreViewFactory.m
@@ -22,7 +22,6 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
-
 #import "WebCoreViewFactory.h"
 #import "KWQAssertions.h"
 
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 636ac53..4124405 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,15 @@
+2003-12-10  Richard Williamson   <rjw at apple.com>
+
+	Added method to get to the bridge from a view.  This is
+	used to ultimately get the part and KJS::Window for a
+	particular applet.
+
+        Reviewed by Hyatt.
+
+        * WebCoreSupport.subproj/WebViewFactory.m:
+        (-[WebViewFactory refreshPlugins:]):
+        (-[WebViewFactory bridgeForView:]):
+
 2003-12-10  John Sullivan  <sullivan at apple.com>
 
         - WebKit part of fix for:
diff --git a/WebKit/WebCoreSupport.subproj/WebViewFactory.m b/WebKit/WebCoreSupport.subproj/WebViewFactory.m
index 1b4156e..fe2c215 100644
--- a/WebKit/WebCoreSupport.subproj/WebViewFactory.m
+++ b/WebKit/WebCoreSupport.subproj/WebViewFactory.m
@@ -9,7 +9,10 @@
 #import <WebKit/WebViewFactory.h>
 
 #import <WebKit/WebAssertions.h>
+#import <WebKit/WebBridge.h>
 #import <WebKit/WebControllerSets.h>
+#import <WebKit/WebFrameView.h>
+#import <WebKit/WebHTMLViewPrivate.h>
 #import <WebKit/WebLocalizableStrings.h>
 
 #import <WebKit/WebPluginDatabase.h>
@@ -37,6 +40,19 @@
     }
 }
 
+- (WebCoreBridge *)bridgeForView:(NSView *)v
+{
+    NSView *aView = [v superview];
+    
+    while (aView) {
+        if ([aView isKindOfClass:[WebHTMLView class]]) {
+            return [(WebHTMLView *)aView _bridge];
+        }
+        aView = [aView superview];
+    }
+    return nil;
+}
+
 - (NSString *)inputElementAltText
 {
     return UI_STRING_KEY("Submit", "Submit (input element)", "alt text for <input> elements with no alt, title, or value");

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list