Skip to main content

JDIC WebBrowser crashes on the Mac with Safari 4 Beta

32 replies [Last post]
davidson1
Offline
Joined: 2003-06-25

We are investigating a new issue in which the JDIC WebBrowser component will crash on the Mac when attempting to create the CC_DMWebKitView. This crash will occur if the end user has installed Safari 4 beta (AppleWebKit version 528.18.1). This is fine with Safari 3.2.3 (AppleWebKit 525.28.3).

Current thread (0x0482e000): JavaThread "AWT-EventQueue-0" [_thread_in_native, id=-1328398336, stack(0xb0c24000,0xb0d24000)]
Stack: [0xb0c24000,0xb0d24000]
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j org.jdesktop.jdic.browser.WebKitWebBrowser.createNSView1()I+0
j org.jdesktop.jdic.browser.WebKitWebBrowser.createNSView()I+2
j com.apple.eawt.CocoaComponent.createNSViewLong()J+1
j apple.awt.CToolkit.createCanvas(Ljava/awt/Canvas;)Ljava/awt/peer/CanvasPeer;+33
j java.awt.Canvas.addNotify()V+20
j org.jdesktop.jdic.browser.WebKitWebBrowser.addNotify()V+1

Thread 21 Crashed:
0 ??? 0000000000 0 + 0
1 com.apple.Foundation 0x94e08b2d _NSRemoveHandler2 + 33
2 libjdic.jnilib 0x1bafb3b5 Java_org_jdesktop_jdic_browser_WebKitWebBrowser_createNSView1 + 587

We have done some minor fixes to our JDIC implementation. I was wondering if anyone else out there has experienced this problem.

Also, does anyone know how to get the deltas between AppleWebKit versions to help me diagnose this problem?

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
acircus
Offline
Joined: 2009-01-17

Hi emallin,
What version of mac os are you using?
I use Snow Leopard and I encountered problems in building the jnilib-s.

below is the error that I get:

buildmacjni:
[exec] rm -f *.jnilib
[exec] rm -f *.o
[exec] g++ -Wno-protocol -Wundeclared-selector -W -Wall -c -I/System/Library/Frameworks/JavaVM.framework/Headers -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc MacBrowserService.mm
[exec] In file included from /System/Library/Frameworks/JavaVM.framework/Headers/jni.h:22,
[exec] from MacBrowserService.mm:21:
[exec] /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory
[exec] In file included from /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:16,
[exec] from /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:6,
[exec] from /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h:12,
[exec] from MacBrowserService.mm:22:
[exec] /Developer/SDKs/MacOSX10.4u.sdk/usr/include/float.h:8:24: error: float.h: No such file or directory

I checked and the stdarg.h and float.h and all the headers are in /Developer/SDKs/MacOSX10.4u.sdk/usr/include/

I have no c/objective-c knowledge and it's hard for me to manage this.

nameel
Offline
Joined: 2009-07-14

Hi,

I think this fix is breaking in Safari 3.2.3. This is happening if we have more than one instance of browser in separate containers. I have tested this with old version and it is working fine. Is there any way to make it work in both Safari 3 and 4?

Thanks

mrsteve
Offline
Joined: 2005-07-26

Thanks for posting the ZIP. I can't get to work, though - is anyone else having difficulty?

After updating my app to have the new jdic_stub.jar and the new libjdic.jnilib, when I attempt to show a browser, I get:

Invalid memory access of location 00000021 eip=90a594c0

This happens using the Browser demo against the Mac JARs and nothing else. If you run the Browser demo totally unmodified, it seems to work. But if you launch two or three Browser frames in the same VM, it crashes the VM. Sometimes it takes 3 times to crash, sometimes 2. I adapted Browser to use the event dispatch (which it doesn't do in main) but this had no effect.

(Mac OS 10.4, Java 5, Safari 4 - not the beta, but the version automatically updated to by my system)

I also tried recompiling the jnilib on my system with no effect. Has anyone else got this working using the above machine spec?

Message was edited by: mrsteve

taylans
Offline
Joined: 2008-08-18

code provided by jroar works fine. i had done some modifications but the code given should also work.i use multiple instances at same time. no problems so far. used the browser many times. i have 3 instances at the same time and change the content
very often. it is used as a mail client like outlook. users can do a lot of editing. i added a mail editor, not javascript based. editing commands such as italic, bold. etc are sent from java side.

my specs are:

safari: Version 4.0.2 (5530.19)
jdic: many modifications to java and c side + modifications by jroar
os: 10.5.7
java: 1.6.0_13

jroar
Offline
Joined: 2005-03-01

davidson, many thanks for your fix, I got it compiled and running, but there's one problem: you apparantly cannot create more than one instance of the web browser. In my application I need 3 instances of the web browser, but only the last created is working and showing. Is there a solution to this or do I have to rewrite my java app to share one instance?

thanks!

EDIT: well I've temporarily fixed that with using an NSMutableArray which holds the WebKitWebBrowser instances but it'd be good to know if there was a clean solution to this (:

emallin
Offline
Joined: 2007-08-29

Hi all,
firstly, thanks for all the fixes that have been provided so far. I've tried applying the fix that's been provided by jroar, and the browser now displays the content successfully, however the Swing application and embedded browser now just hang. Can you confirm which version of JDIC the changes have been applied to? I've been using a version released on 20061102 as I haven't found any later versions that are compatible with MAC. Can anyone confirm if there are any newer MAC versions available?

I also attempted to apply all fixes provided by davidson1, however as I'm not an Objective-C developer, had little success. Can you post the updated source code and confirm to which version of JDIC these changes were applied. Alternatively, can you provide the source code for WebKitWebBrowser.mm as there's a few areas I'm unsure about from the diffs.

Java version: 1.5.0 Update 19
MAC version: 10.4.11
Safari version: 4.0.3

Many thanks,
Eoin

Message was edited by: emallin

venkat1225
Offline
Joined: 2009-09-09

Hi
Davidson,
I am using jdk1.5 and safari 4.0.3 I am modifying all files what you gave the files in this thread but after changeing all files i got [b] ERROR : Failed to create WebKitView Invalid memory access of location 00000000 eip=00000000[/b] Could you post me if u have modified(working jdic .jar)either mac or crossplatform.
Thanks,
Venkat

jcd
Offline
Joined: 2005-06-06

Hello jdic Mac developers,

My application is using jdic WebKitWebBrowser+WebKitEngine and was running fine with Safari 3.2.3 but now is crashing since I updated to Safari 4.02

I tried to set

-Dcom.apple.eawt.CocoaCopmponent.CompatibilityMode=false

But the application continues to crash.

Does anybody found a solution to solve this issue???

Thank you in advance

Best,

JCD

Message was edited by: jcd

muhammadhassan
Offline
Joined: 2006-08-24

Hi All,

I am trying to run Demo JDIC Browser on Mac Snow Leopard. I have latest version of Safari and Java. I am using jdic_mac_new.jar and libjdic.jnilib downloaded from this link (provided by jroar) http://www.u-mass.de/software/jdic_mac_fix.zip

I am getting following exception:

Exception in thread "main" java.lang.UnsatisfiedLinkError: /Users/readerlite1/Desktop/JavaBrowser/lib/libjdic.jnilib: no suitable image found. Did find: /Users/readerlite1/Desktop/JavaBrowser/lib/libjdic.jnilib: no matching architecture in universal wrapper
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1861)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1778)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1045)
at org.jdesktop.jdic.browser.internal.WebBrowserUtil$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at org.jdesktop.jdic.browser.internal.WebBrowserUtil.loadLibrary(Unknown Source)
at org.jdesktop.jdic.browser.internal.WebBrowserUtil.getDefaultBrowserPath(Unknown Source)
at org.jdesktop.jdic.browser.BrowserEngineManager.selectEngine(Unknown Source)
at org.jdesktop.jdic.browser.BrowserEngineManager.getActiveEngine(Unknown Source)
at Browser.jbInit(Browser.java:174)
at Browser.(Browser.java:69)
at Browser.main(Browser.java:85)

Any one having same exception or have found solution to this.. Please reply.

Thank you
BR
Faisal[b][/b][b][/b][b][/b][i][/i][i][/i][i][/i][i][/i]

Message was edited by: muhammadhassan

Message was edited by: muhammadhassan

muhammadhassan
Offline
Joined: 2006-08-24

Can some give me the latest jdic.jar and libjdic.jnilib build on Mac Snow Leopard?

davetron
Offline
Joined: 2009-07-30

Hi folks,

Apologies if this is a redundant question but has this problem been raised with a specific Issue # ?
We have an application that is affected by this problem and would like to keep an eye on if/when a fix is available.

Thanks,
David

venkat1225
Offline
Joined: 2009-09-09

Hi David
I am using safari 4.0.3 and latest jdic jar even that jar also i am faceing same issue. I mean when trying to open awt component safari crashes and it throws some exceptions
is there any solution for this issue.
Thanks,
Venkat.

taylans
Offline
Joined: 2008-08-18

i have a running system of

safari: Version 4.0.2 (5530.19)
jdic: many modifications to java and c side + modifications by jroar
os: 10.5.7
java: 1.6.0_13

with no problems.

i did not try jdic with safari 4.0.3 yet. But there is a big problem
when os upgraded to snow leopard (10.6) the native library functions can not
be reached from java. i am trying to solve this.

venkat1225
Offline
Joined: 2009-09-09

Hi All,

I am using jdk1.5 and safari 4.0.3 I am modifying all files what you gave the files in this thread but after changeing all files i got ERROR : Failed to create WebKitView Invalid memory access of location 00000000 eip=00000000 Could you post me if u have modified(working jdic .jar)either mac or crossplatform.
Thanks,
Venkat

emallin
Offline
Joined: 2007-08-29

Hi,
I've managed to implement most of the fixes suggested, but I now run into a problem when trying to access any Swing components in my application. The application simply hangs.

A thread dump suggests that there's a deadlock between Swing and WebKit components in the AWT-EventQueue.

"AWT-EventQueue-0" prio=6 tid=0x00519e70 nid=0x1823200 runnable
[0xb0e8d000..0xb0e8dd10]
at apple.awt.CWindow._setVisible(Native Method)
at apple.awt.CFrame.setVisible(CFrame.java:85)
at apple.awt.CComponent.show(CComponent.java:230)
at java.awt.Dialog.conditionalShow(Dialog.java:461)
- locked <0x26ab39c8> (a java.awt.Component$AWTTreeLock)
at java.awt.Dialog.show(Dialog.java:526)
at java.awt.Component.show(Component.java:1302)
at java.awt.Component.setVisible(Component.java:1255)

Has anyone come across or come across any solutions. Unfortunately I have no experience with Objective-C?

Thanks,
Eoin

emallin
Offline
Joined: 2007-08-29

Hi all,
this was resolved by setting
-Dcom.apple.eawt.CocoaComponent.CompatibilityMode=false

Eoin

acircus
Offline
Joined: 2009-01-17

Hi taylans,
Can you upload a zip with the sources or with your build?
I use snow leopard and I urgently need a functional build for my app.
With sources from jroar i encountered the multiple instance problem and I've seen that you manage to fix this.

Appreciate,
Alex.

muhammadhassan
Offline
Joined: 2006-08-24

Hi acircus

Have you got any build that works fine on snow leopard? Can you please upload it somewhere?

Thank you
Faisal

Message was edited by: muhammadhassan

jroar
Offline
Joined: 2005-03-01

I'm running into this as well. Has anybody found a working solution you can share, yet? I myself am no (obj-)c develper, can't fix it :/

bterbushet
Offline
Joined: 2009-06-19

I have the same issue. Can someone post or checkin the solution to a repository?

jroar
Offline
Joined: 2005-03-01

I've uploaded a zip with the changed files and if you don't want to build it yourself I included the new version of libjdic and the jar file. Note that it doesn't include all changes by davidson, but it works fine, as far as I've tested, and if you needed this as urgent as I did this fix should serve you well until there's an official fix. Download link here: http://www.u-mass.de/software/jdic_mac_fix.zip

andreashenle
Offline
Joined: 2007-09-19

Thank you very much for the given solution.
In a first try this solution worked very well, but after started my application (inside eclipse) a second time the browser didn't appeared.
Do you know a solution for this?
Contains the code provided by you the earlier described solution for the multiple instance problem?

Thanks for the help - Regards

Andreas Henle

bterbushet
Offline
Joined: 2009-06-19

Thanks again for uploading your code. It works for me sporadically though. Is anyone else sometimes seeing a blank white area where the browser should be? Thanks.

Brian.

jroar
Offline
Joined: 2005-03-01

It seems to work very well for me, so I can't help you with your specific problems. Yes it contains the code supposed to fix that multiple instance problem. I just hope JWebPane will be released soon...

davidson1
Offline
Joined: 2003-06-25

We found a couple of minor issues in the JDIC web browser code during our testing of the new WebKit bug fix. I made some changes to fix these issues and the Safari 4 WebKit crash. Here is a description of my changes. The diffs follow.

* WebKitWebBrowser.java:
- Overridden createNSViewLong() and wrote createNSView() to call createNSViewLong(). This is the implementation of a the recommendation suggested in Apple technical note TN2147.
- Removed native method createNSView1() and created native method callbacks for createNSVLong1() and createWebKitView() - which pre-creates the WebKit component on the correct thread
- Constructor will call crateWebKitView() - which will preallocate the native WebView on the correct thread

* NativeEventThread.java:
- Fixed AOOBE by checking the Vector for elements before accessing element 0.

* WebBrowserUtil.java
- Changed trace method prefix.

* GNUmakefile
- Added compiler flags to support Leopard on 64-bit (commented out)

* CC_DMWebKitView.mm:
- Fixed string conversion bug in the handler for NSWebKitView_loadURL in the awtMessage method.
- Fixed a minor bug in decidePolicyForNavigationAction in call to NSLog with a path URL string. If the string contains a '%' symbol - like encoded html - then NSLog will do incorrect string substitution.
- Also contains the fix related to http://forums.java.net/jive/message.jspa?messageID=265510

* WebKitWebBrowser.mm: This is where the real solution resides
- removed native implementation of createNSView1 and added createNSViewLong1, createWebKitView implementations
- createWebKitView: will create the WebKit component on the correct thread (calls initializeWebKitView)
- createNSViewLong1: will return the WebKit instance that was previously created.
- Introduced WebKitWebBrowser method as a convenience.

* org_jdesktop_jdic_browser_WebKitWebBrowser.h
- changes to support WebKitWebBrowser implementation

Index: build.xml
===================================================================
RCS file: /cvs/jdic/src/jdic/build.xml,v
retrieving revision 1.50
diff -r1.50 build.xml
68a69
>
245a247,249
>
> > includes="jdic.dll"/>
400c404
<
---
>

411c416,420
<
---
>

>
> > includes="libjdic.jnilib"/>
699a709,714
>
>

>
>
>

>
Index: demo/Browser/Browser.java
===================================================================
RCS file: /cvs/jdic/src/jdic/demo/Browser/Browser.java,v
retrieving revision 1.13
diff -r1.13 Browser.java
224,226d223
< jBrowserPanel.setLayout(new BorderLayout());
< jBrowserPanel.add(webBrowser.asComponent(), BorderLayout.CENTER);
<
229c226
< this.add(jBrowserPanel, BorderLayout.CENTER);
---
> this.add(webBrowser.asComponent(), BorderLayout.CENTER);
Index: src/mac_os_x/classes/org/jdesktop/jdic/browser/WebKitWebBrowser.java
===================================================================
RCS file: /cvs/jdic/src/jdic/src/mac_os_x/classes/org/jdesktop/jdic/browser/WebKitWebBrowser.java,v
retrieving revision 1.6
diff -r1.6 WebKitWebBrowser.java
23,26c23,25
< import java.awt.*;
< import java.awt.event.*;
< import java.util.Hashtable;
< import java.util.Vector;
---
> import java.awt.Component;
> import java.awt.Container;
> import java.awt.Dimension;
28,29c27
< import javax.swing.event.HyperlinkListener;
< import javax.swing.event.HyperlinkEvent;
---
>
32d29
< import org.jdesktop.jdic.browser.internal.NativeEventThread;
34,35d30
< import org.jdesktop.jdic.init.JdicInitException;
< import org.jdesktop.jdic.init.JdicManager;
39d33
<
46,71c40,63
< public static final int storeJavaObject = 1;
< public static final int loadURL = 2;
< public static final int resizeFrame = 3;
< public static final int stopLoading = 4;
< public static final int goBack = 5;
< public static final int goForward = 6;
< public static final int updateCursor = 7;
< public static final int runJS = 8;
< public static final int textLarger = 9;
< public static final int textSmaller = 10;
< public static final int search = 11;
< public static final int dispose = 12;
< public static final int ordercallback = 13;
< public static final int loadURLFromString = 14;
< public static final int reload = 15;
<
< public static final int INIT_WIDTH = 500;
< public static final int INIT_HEIGHT = 420;
<
<
< public static final int WEB_VIEW_POLICY_NONE = 0;
< public static final int WEB_VIEW_POLICY_IN_OLD_WINDOW = 1;
< public static final int WEB_VIEW_POLICY_IN_NEW_WINDOW = 2;
<
<
< protected boolean needResize = false;
---
> public static final int storeJavaObject = 1;
> public static final int loadURL = 2;
> public static final int resizeFrame = 3;
> public static final int stopLoading = 4;
> public static final int goBack = 5;
> public static final int goForward = 6;
> public static final int updateCursor = 7;
> public static final int runJS = 8;
> public static final int textLarger = 9;
> public static final int textSmaller = 10;
> public static final int search = 11;
> public static final int dispose = 12;
> public static final int ordercallback = 13;
> public static final int loadURLFromString = 14;
> public static final int reload = 15;
>
> public static final int INIT_WIDTH = 500;
> public static final int INIT_HEIGHT = 420;
>
> public static final int WEB_VIEW_POLICY_NONE = 0;
> public static final int WEB_VIEW_POLICY_IN_OLD_WINDOW = 1;
> public static final int WEB_VIEW_POLICY_IN_NEW_WINDOW = 2;
>
> protected boolean needResize = false;
74,75c66,70
< public native int createNSView1();
< int nsObject = 0;
---
> // public native int createNSView1();
> public native long createNSViewLong1();
> public native void createWebKitView();
>
> long nsObject = 0;
113c108,110
< BrowserEngineManager.WEBKIT);// set it as the default engine
---
> BrowserEngineManager.WEBKIT);// set it as the default engine
>
> createWebKitView();
146,147d142
< sendMsg(resizeFrame, this);
<
149c144,146
< if (c != null)
---
> if (c != null) {
> validate();
> c.validate();
151,160d147
< if (needResize) {
< Dimension cd = getSize();
< //System.out.println("cd "+cd);
< cd.width++;
< cd.height++;
< setSize(cd);
< cd.width--;
< cd.height--;
< setSize(cd);
< needResize = false;
162d148
<
166,168c152
< // send Message only if webkit has init
< if (nsObject != 0)
< sendMessage(messageID, null);
---
> sendMsg(messageID, null);
173c157
< if (nsObject != 0)
---
> if (nsObject != 0) {
174a159,161
> } else {
> WebBrowserUtil.trace("sendMsg: nsObject not initialized. messageID: " + messageID);
> }
230,231c217
< System.out
< .println("Java runJavaScriptAlertPanelWithMessage " + message);
---
> WebBrowserUtil.trace("Java runJavaScriptAlertPanelWithMessage " + message);
335,336c321
< nsObject = createNSView1();
< return nsObject;
---
> return (int)createNSViewLong();
339,342c324,332
< public int getNativeWindow() {
< return nsObject;
< }
<
---
> public long createNSViewLong() {
> nsObject = createNSViewLong1();
> return nsObject;
> }
>
> public int getNativeWindow() {
> return (int)nsObject;
> }
>
Index: src/mac_os_x/native/jni/CC_DMWebKitView.mm
===================================================================
RCS file: /cvs/jdic/src/jdic/src/mac_os_x/native/jni/CC_DMWebKitView.mm,v
retrieving revision 1.2
diff -r1.2 CC_DMWebKitView.mm
312c312,313
< //fprintf(stderr,"NSWebKitView_loadURLFromString\n");
---
> if (debug)
> fprintf(stderr,"NSWebKitView_loadURLFromString\n");
321c322
< NSURL *url = [NSURL URLWithString : [NSString stringWithCString : urlString]];
---
> NSURL *url = [NSURL URLWithString : [NSString stringWithUTF8String : urlString]];
322a324,326
> if (debug)
> NSLog(@"NSWebKitView_loadURL calling loadRequest:request %@\n", request);
>
325d328
< //fprintf(stderr,"NSWebKitView_loadURL\n");
565,568c568,571
< if (debug)
< NSLog(@"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!-----\nwebView:%@ decidePolicyForNavigationAction:request:%@ actionInformation %@\n-----\n", sender, request,actionInformation);
< NSString *path = [[request URL] absoluteString];
< NSLog(path);
---
> NSString *path = [[request URL] absoluteString];
> if (debug) {
> NSLog(@"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!-----\nwebView:%@ decidePolicyForNavigationAction:request:%@ actionInformation %@\n-----\n", sender, request,actionInformation);
> }
612a616
> /*
621,626c625,630
< /*
< if(![responder isKindOfClass : [NSTextField class]]){
< responder = [self window];
< }
< [[self window] makeFirstResponder : responder];
< */
---
>
> // if(![responder isKindOfClass : [NSTextField class]]){
> // responder = [self window];
> // }
> // [[self window] makeFirstResponder : responder];
>
628a633
> */
Index: src/mac_os_x/native/jni/GNUmakefile
===================================================================
RCS file: /cvs/jdic/src/jdic/src/mac_os_x/native/jni/GNUmakefile,v
retrieving revision 1.4
diff -r1.4 GNUmakefile
21a22,28
> SDKROOT = -isysroot /Developer/SDKs/MacOSX10.4u.sdk
> ARCHES = -arch i386 -arch ppc
>
> # Use this to support Leopard and 64-bit Java
> # SDKROOT = -isysroot /Developer/SDKs/MacOSX10.5.sdk
> # ARCHES = -arch i386 -arch ppc -arch x86_64
>
23c30
< CXXFLAGS = -W -Wall -c -I/System/Library/Frameworks/JavaVM.framework/Headers -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc
---
> CXXFLAGS = -W -Wall -c -I/System/Library/Frameworks/JavaVM.framework/Headers $(SDKROOT) $(ARCHES)
25c32
< LDFLAGS = -dynamiclib -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc
---
> LDFLAGS = -mmacosx-version-min=10.4 -dynamiclib $(SDKROOT) $(ARCHES)
Index: src/mac_os_x/native/jni/WebKitWebBrowser.mm
===================================================================
RCS file: /cvs/jdic/src/jdic/src/mac_os_x/native/jni/WebKitWebBrowser.mm,v
retrieving revision 1.2
diff -r1.2 WebKitWebBrowser.mm
24,25c24
<
< #include "CC_DMWebKitView.h"
---
>
28d26
< JavaVM *JVM = NULL;
29a28,29
> JavaVM *JVM = NULL;
> WebKitWebBrowser* wb = nil;
44,47c44,46
< /*
< * Class:
< * Method: createNSView1
< * Signature: ()J
---
> /**
> * Return the allocated instance to the calling method.
> *
49,50c48,49
< JNIEXPORT jint JNICALL Java_org_jdesktop_jdic_browser_WebKitWebBrowser_createNSView1
< (JNIEnv *env, jobject nsWebKitViewView)
---
> JNIEXPORT jlong JNICALL Java_org_jdesktop_jdic_browser_WebKitWebBrowser_createNSViewLong1
> (JNIEnv *env, jobject caller)
52,77c51
< CC_DMWebKitView *webKitView = nil;
< NS_DURING;
< // Here we create our custom NSView
< int initWidth = 200;
< int initHeight = 200;
<
< jclass clazz = env->FindClass(JRISigClass("org/jdesktop/jdic/browser/WebKitWebBrowser"));
< if(clazz != 0){
< jfieldID fID = env->GetStaticFieldID(clazz,"INIT_WIDTH",JRISigInt);
< if(fID != 0){
< initWidth = env->GetStaticIntField(clazz,fID);
< }
< fID = env->GetStaticFieldID(clazz,"INIT_HEIGHT",JRISigInt);
< if(fID != 0){
< initHeight = env->GetStaticIntField(clazz,fID);
< }
< }
< webKitView = [[CC_DMWebKitView alloc] initWithFrame : NSMakeRect(0,0,initWidth,initHeight)];
< //fprintf(stderr,"OK : WebKitView\n");
< [webKitView setJVM : JVM];
< NS_HANDLER;
< fprintf(stderr,"ERROR : Failed to create WebKitView\n");
< NS_VALUERETURN(0, jlong);
< NS_ENDHANDLER;
<
< return (jint) webKitView;
---
> return (jlong)[wb getWebKitView];
79a54,60
> // WebKit instances must be allocated on the AppKit thread
> JNIEXPORT void JNICALL Java_org_jdesktop_jdic_browser_WebKitWebBrowser_createWebKitView
> (JNIEnv *env, jobject caller)
> {
> wb = [[WebKitWebBrowser alloc] init];
> [wb performSelectorOnMainThread:@selector(initializeWebKitView) withObject:nil waitUntilDone:NO];
> }
88c69
< (JNIEnv *env, jclass) {
---
> (JNIEnv *env, jclass) {
100c81
< (JNIEnv *env, jclass) {
---
> (JNIEnv *env, jclass) {
111,112c92,124
< (JNIEnv *env, jclass) {
<
---
> (JNIEnv *env, jclass) {
>
> }
>
> @implementation WebKitWebBrowser
>
> - (void) initializeWebKitView {
> NS_DURING;
> int initWidth = 200;
> int initHeight = 200;
>
> /* jclass clazz = env->FindClass(JRISigClass("org/jdesktop/jdic/browser/WebKitWebBrowser"));
> if(clazz != 0){
> jfieldID fID = env->GetStaticFieldID(clazz,"INIT_WIDTH",JRISigInt);
> if(fID != 0){
> initWidth = env->GetStaticIntField(clazz,fID);
> }
> fID = env->GetStaticFieldID(clazz,"INIT_HEIGHT",JRISigInt);
> if(fID != 0){
> initHeight = env->GetStaticIntField(clazz,fID);
> }
> }
> */
> webKitView = [[CC_DMWebKitView alloc] initWithFrame : NSMakeRect(0,0,initWidth,initHeight)];
> fprintf(stderr,"OK : WebKitView\n");
> [webKitView setJVM : JVM];
> NS_HANDLER;
> fprintf(stderr,"ERROR : Failed to create WebKitView\n");
> NS_ENDHANDLER;
> }
>
> - (CC_DMWebKitView*) getWebKitView {
> return webKitView;
113a126
> @end
Index: src/mac_os_x/native/jni/libjdic.jnilib
===================================================================
RCS file: /cvs/jdic/src/jdic/src/mac_os_x/native/jni/libjdic.jnilib,v
retrieving revision 1.1
diff -r1.1 libjdic.jnilib
Binary files /tmp/cvss8ayjw and libjdic.jnilib differ
Index: src/mac_os_x/native/jni/org_jdesktop_jdic_browser_WebKitWebBrowser.h
===================================================================
RCS file: /cvs/jdic/src/jdic/src/mac_os_x/native/jni/org_jdesktop_jdic_browser_WebKitWebBrowser.h,v
retrieving revision 1.1
diff -r1.1 org_jdesktop_jdic_browser_WebKitWebBrowser.h
2a3
> #include "CC_DMWebKitView.h"
92c93
< * Method: createNSView1
---
> * Method: createNSViewLong
95,97c96,98
< JNIEXPORT jint JNICALL Java_org_jdesktop_jdic_browser_WebKitWebBrowser_createNSView1
< (JNIEnv *, jobject);
<
---
> JNIEXPORT jlong JNICALL Java_org_jdesktop_jdic_browser_WebKitWebBrowser_createNSViewLong1(JNIEnv *, jobject);
> JNIEXPORT void JNICALL Java_org_jdesktop_jdic_browser_WebKitWebBrowser_createWebKitView(JNIEnv *, jobject);
>
99a101,109
>
> @interface WebKitWebBrowser : NSObject {
> CC_DMWebKitView *webKitView;
> }
>
> - (void) initializeWebKitView;
> - (CC_DMWebKitView*) getWebKitView;
>
> @end
Index: src/share/classes/org/jdesktop/jdic/browser/internal/NativeEventThread.java
===================================================================
RCS file: /cvs/jdic/src/jdic/src/share/classes/org/jdesktop/jdic/browser/internal/NativeEventThread.java,v
retrieving revision 1.10
diff -r1.10 NativeEventThread.java
101c101
< public void run() {
---
> public void run() {
184c184,186
< ((IWebBrowser) webBrowsers.elementAt(0)).setInitFailureMessage(msg);
---
> if (webBrowsers.size() > 0) {
> ((IWebBrowser) webBrowsers.elementAt(0)).setInitFailureMessage(msg);
> }
Index: src/share/classes/org/jdesktop/jdic/browser/internal/WebBrowserUtil.java
===================================================================
RCS file: /cvs/jdic/src/jdic/src/share/classes/org/jdesktop/jdic/browser/internal/WebBrowserUtil.java,v
retrieving revision 1.8
diff -r1.8 WebBrowserUtil.java
147c147
< System.out.println("*** Jtrace: " + msg);
---
> System.out.println("*** WebBrowserUtil.trace: " + msg);

mcostest
Offline
Joined: 2009-05-29

I'm searching for a solution to embed a web browser in a java swing application running on mac os 10.5, more advanced that JEditorPane.
I tried your fixes and I got an error when trying to run demo/Browser sample - it seems to enter in a recursive call, ie, the following lines are endlessly repetead in the console:

at com.apple.eawt.CocoaComponent.createNSViewLong(CocoaComponent.java:92)
at org.jdesktop.jdic.browser.WebKitWebBrowser.createNSView(Unknown Source)

Other samples (FileExplorer, FileChooser) run ok with the jdic I built.

I think that some text is broken in the cvs patch you posted, for
src/jdic/src/mac_os_x/classes/org/jdesktop/jdic/browser/WebKitWebBrowser.java file
.....
151,160d147
< if (needResize) {
< Dimension cd = getSize();
< // if (debug)
> fprintf(stderr,"NSWebKitView_loadURLFromString\n");
321c322
< NSURL
....

it seems that it contains also the patch for some native code
(seems to be from src/jdic/src/mac_os_x/native/jni/CC_DMWebKitView.mm file)

Can you please re-post the patch?
Thanks

davidson1
Offline
Joined: 2003-06-25

Ah yes, It seems that the cut and paste from my terminal is incorrect. The major changes to WebKitWebBrowser is to call the new native methods. Here is the relevant sections of WebKitWebBrowser that you need to change:

// public native int createNSView1();
public native long createNSViewLong1();
public native void createWebKitView();

long nsObject = 0;

public WebKitWebBrowser() {
super();
BrowserEngineManager.instance().setActiveEngine(
BrowserEngineManager.WEBKIT);// set it as the default engine

createWebKitView();
}

public int createNSView() {
return (int)createNSViewLong();
}

public long createNSViewLong() {
nsObject = createNSViewLong1();
return nsObject;
}

public int getNativeWindow() {
return (int)nsObject;
}

mcostest
Offline
Joined: 2009-05-29

after rebuilding (with the correction in your previous post) I am stuck with another error. When launching Browser, it displays
OK : WebKitView
Invalid memory access of location 00000000 rip=84347ad9

and crashes in one of the threads:
Thread 1 Crashed:
0 libobjc.A.dylib 0x00007fff84347ad9 objc_msgSend + 41
1 ??? 0x000000010200e878 0 + 4328581240
2 ??? 0x0000000102003009 0 + 4328534025
3 ??? 0x0000000102003009 0 + 4328534025
4 ??? 0x0000000102002f3a 0 + 4328533818
...

I used java 1.6_07 (64 bit) on macos 10.5.6

davidson1
Offline
Joined: 2003-06-25

Did you recompile the native libs to support 64-bit? Take a look at my diffs for GNUmakefile.

Also, you may want to change your default JVM to 32-bit Java 5 in your Java Preferences. Once you change your default Java for applications then you will have to flush your Java cache.

Also, my solution may not be complete. There seems to be a memory leak. I'm not sure if it's in the jdic component or our code so I'm still investigating.

andreashenle
Offline
Joined: 2007-09-19

hi davidson,

I also already worked on problems with the browser component integration in jdic - your solution looks quite promising.

Have you checked in your changes to any repository?
Is your solution working with 64-bit Java and 32-bit Java at the same time or is it necessary to provide two different libs?

Thank you for the answers - Regards

Andreas

davidson1
Offline
Joined: 2003-06-25

I seemed to have found a proper and workable solution. The problem is that the JDIC WebKitWebBrowser.mm will construct the WebView (CC_DMWebKitView) on the calling thread.

Doug Zwick has outlined the correct solution:
http://lists.apple.com/archives/java-dev/2009/Mar/msg00151.html

We have to create the WebKit on the AppKit thread. My solution uses TN2147 for guidance:
http://developer.apple.com/technotes/tn2005/tn2147.html

I'll post the diffs once QA finishes testing the solution. I have commit status on this project and I would be willing to check in these fixes if someone wants to review them.

davidson1
Offline
Joined: 2003-06-25

Quick update....

I'm diagnosing this problem with the Browser demo app as part of the JDIC distribution.

The crash is in the exception handler (_NSRemoveHandler2) in the Mac OS 10.4 SDK so I linked against the 10.5 SDK in the makefile to so that I can get the root cause of the exception. I also removed the exception handling macros in WebKitWebBrowser ... createNSView1.

The root exception is a WebKitThreadingException resulting from initializing WebView from a secondary thread:

Application Specific Information:
*** Terminating app due to uncaught exception 'WebKitThreadingException', reason: 'objc_object* -[WebView initWithFrame:frameName:groupName:](WebView*, objc_selector*, NSRect, NSString*, NSString*) was called from a secondary thread'

Thread 0:
0 libSystem.B.dylib 0x96577286 mach_msg_trap + 10
1 libSystem.B.dylib 0x9657ea7c mach_msg + 72
2 com.apple.CoreFoundation 0x939cc04e CFRunLoopRunSpecific + 1790
3 com.apple.CoreFoundation 0x939ccc78 CFRunLoopRunInMode + 88
4 com.apple.HIToolbox 0x927c628c RunCurrentEventLoopInMode + 283
5 com.apple.HIToolbox 0x927c60a5 ReceiveNextEventCommon + 374
6 com.apple.HIToolbox 0x927c5f19 BlockUntilNextEventMatchingListInMode + 106
7 com.apple.AppKit 0x96cbbd0d _DPSNextEvent + 657
8 com.apple.AppKit 0x96cbb5c0 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
9 com.apple.AppKit 0x96cb45fb -[NSApplication run] + 795
10 libawt.jnilib 0x0e0a7f09 +[AWTStarter startAWT:] + 1941
11 libawt.jnilib 0x0e0a7726 -[CPerformer perform] + 281
12 com.apple.Foundation 0x9472e9bc __NSThreadPerformPerform + 476
13 com.apple.CoreFoundation 0x939cc595 CFRunLoopRunSpecific + 3141
14 com.apple.CoreFoundation 0x939ccc78 CFRunLoopRunInMode + 88
15 java 0x00005169 0x1000 + 16745
16 java 0x000021fa 0x1000 + 4602

Thread 1 Crashed:
0 com.apple.CoreFoundation 0x93a45f54 ___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___ + 4
1 libobjc.A.dylib 0x93443e3b objc_exception_throw + 40
2 com.apple.CoreFoundation 0x93a45e8b +[NSException raise:format:arguments:] + 155
3 com.apple.CoreFoundation 0x93a45eca +[NSException raise:format:] + 58
4 com.apple.WebCore 0x2153b781 WebCoreReportThreadViolation + 257
5 com.apple.WebKit 0x20b039d6 -[WebView initWithFrame:frameName:groupName:] + 214
6 libjdic.jnilib 0x1e5a3534 -[CC_DMWebKitView initWithFrame:] + 176
7 libjdic.jnilib 0x1e5a32eb Java_org_jdesktop_jdic_browser_WebKitWebBrowser_createNSView1 + 433

2009-05-20 11:40:13.402 java[16759:1003] An uncaught exception was raised
2009-05-20 11:40:13.403 java[16759:1003] objc_object* -[WebView initWithFrame:frameName:groupName:](WebView*, objc_selector*, NSRect, NSString*, NSString*) was called from a secondary thread
2009-05-20 11:40:13.404 java[16759:1003] *** Terminating app due to uncaught exception 'WebKitThreadingException', reason: 'objc_object* -[WebView initWithFrame:frameName:groupName:](WebView*, objc_selector*, NSRect, NSString*, NSString*) was called from a secondary thread'
2009-05-20 11:40:13.404 java[16759:1003] Stack: (
2477023403,
2470723131,
2477022859,
2477022922,
559134593,
548420054,
509228340,
509227755,
56130823
)

It appears that the WebKit that ships with Safari 4 is much more strict in enforcing thread integrity. Hmmmmm....