Hi all,
I'm running into some problems trying to run my java code using the
embedded Browser with XULRunner
The App I'm calling my static java function from has the possibility to
specify whether the java call should be made on a new thread. The app
puts itself in a "modal mode" in this case effectively preventing any
window switching.
The other possibility is to execute the java call in the current thread
and not blocking the UI of the app, which I can't do in my case.
Now my problem is this:
- if I use the current thread method everything works as expected, but
the user can switch to other windows of the calling app, which must be
prevented.
- if I use the new thread method, the first call to openFromURL
succeeds, but any subsequent calls (even with the same url) fail with
ERROR: Open URL 'chrome://URL' failed.
org.mozilla.xpcom.XPCOMException: The function "loadURI" returned an
error condition (0x80040111)
at org.mozilla.xpcom.internal.XPCOMJavaProxy.callXPCOMMethod(Native
Method)
at
org.mozilla.xpcom.internal.XPCOMJavaProxy.invoke(XPCOMJavaProxy.java:140)
at $Proxy7.loadURI(Unknown Source)
at
org.eclipse.swt.browser.AbstractMozillaBrowser.setUrl(AbstractMozillaBrowser.java:1153)
at tanner.xul.TAGXULRunner.setURL(TAGXULRunner.java:63)
at tanner.xul.TAGXULRunner.<init>(TAGXULRunner.java:33)
at tanner.xul.TAGXULRunner.openFromURL(TAGXULRunner.java:100)
Has anybody any ideas what might go wrong here ?
I suspect, that when my code is called on a new thread, upon termination
of that thread, something gets pulled down that is not recreated on the
second call, but I have no idea what this could be.
Any pointers are appreciated.
Below is the java class I'm using.
package tag.xul;
import java.io.*;
import java.net.MalformedURLException;
import org.eclipse.swt.*;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class TAGXULRunner {
public static String DEFAULT_TITLE = "MyMozilla";
public static String OPEN_FROM_URL_OPTION = "-url";
public static String OPEN_FROM_FILE_OPTION = "-file";
Display display;
Shell shell;
MozillaBrowser browser;
TAGXULRunnerDOMObjectAccess objValue;
public TAGXULRunner() {
initialize();
}
TAGXULRunner(Display display) {
initialize(display);
}
public TAGXULRunner(String url) {
initialize();
setURL(url);
}
void initialize() {
initialize( new Display() );
}
void initialize(Display display) {
this.display = display;
shell = new Shell(display);
shell.setText(DEFAULT_TITLE);
shell.setLayout(new FillLayout());
browser = new MozillaBrowser(shell, SWT.NONE);
objValue = new TAGXULRunnerDOMObjectAccess(browser);
TAGXULRunnerListener listener = new TAGXULRunnerListener(this);
browser.addOpenWindowListener(listener);
browser.addCloseWindowListener(listener);
browser.addTitleListener(listener);
browser.addVisibilityWindowListener(listener);
shell.addShellListener(listener);
}
public void setURL(String url) {
try {
System.out.println("Set URL: " + url);
browser.setUrl(url);
} catch(RuntimeException err) {
display.dispose();
throw err;
}
}
void doModal() {
try {
while(!shell.isDisposed()) {
if(!display.readAndDispatch()) {
display.sleep();
}
}
} catch(Exception err) {
err.printStackTrace();
} finally {
display.dispose();
}
}
public synchronized void start() {
shell.open();
doModal();
}
public MozillaBrowser getBrowser() {
return browser;
}
public TAGXULRunnerDOMObjectAccess getDOMObjectAccess() {
return objValue;
}
public static TAGXULRunner openFromURL(String url) {
TAGXULRunner xulRunner = null;
try {
xulRunner = new TAGXULRunner(url);
xulRunner.start();
return xulRunner;
} catch(RuntimeException err) {
System.err.println("ERROR: Open URL '" + url + "' failed.");
throw err;
}
}
public static TAGXULRunner openFromFile(String filePath) throws
MalformedURLException {
try {
File file = new File(filePath);
String url;
url = file.toURL().toExternalForm();
return openFromURL(url);
} catch(RuntimeException err) {
System.err.println("ERROR: Open file '" + filePath + "'
failed.");
throw err;
}
}
}
_______________________________________________
dev-embedding mailing list
[EMAIL PROTECTED]
https://lists.mozilla.org/listinfo/dev-embedding