|
|
|
Re: How to make Browser.setText to show the XHTML? [message #490427 is a reply to message #490215] |
Thu, 08 October 2009 15:43 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
I see, it looks like a JavaXPCOM bug in xulrunner-1.8.1.3. The snippet in
the bug report works for me with xulrunner 1.9.0 and 1.9.1, but I see
problems with 1.8.1.3 as well. I can make it work with 1.8.1.3 by changing
the progress listener to the code below, its only problem is that it could
have a problem on 64-bit. If you don't care about running on 64-bit then
this should work for you. Alternatively, if you don't mind using xulrunner
1.9.x instead of 1.8.1.3 then you can revert to the JavaXPCOM-only solution
in the bug report. If neither of these apply then pick one ;-).
browser.addProgressListener(new ProgressAdapter() {
public void completed(ProgressEvent event) {
nsIServiceManager serviceManager =
Mozilla.getInstance().getServiceManager();
nsIIOService ioService =
(nsIIOService)serviceManager.getService("9ac9e770-18bc-11d3-9337-00104ba0fd4
0", nsIIOService.NS_IIOSERVICE_IID);
nsIURI uri = ioService.newURI("file:///", null, null);
nsIWebBrowser webBrowser = (nsIWebBrowser)browser.getWebBrowser();
nsIWebBrowserStream stream =
(nsIWebBrowserStream)webBrowser.queryInterface(nsIWebBrowser Stream.NS_IWEBBR
OWSERSTREAM_IID);
stream.openStream(uri, "application/xhtml+xml");
byte[] data = null;
try {
data = content.getBytes ("UTF-8"); //$NON-NLS-1$
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
/*
* JavaXPCOM in xulrunner 1.8.1.3 is not converting the byte[]
properly in the
* nsIWebBrowserStream.appendToStream() call. The workaround is to
revert to
* C++-level XPCOM for this call. JavaXPCOM converts this call
properly as of
* xulrunner 1.9.
*/
int /*long*/ ptr = C.malloc (data.length);
XPCOM.memmove (ptr, data, data.length);
int pageSize = 8192;
int pageCount = data.length / pageSize + 1;
int /*long*/ current = ptr;
long streamHandle = Mozilla.getInstance().wrapJavaObject(stream,
nsIWebBrowserStream.NS_IWEBBROWSERSTREAM_IID);
/*
* Note: the following line casts streamHandle to (int), which can
cause a
* pointer truncation on 64-bit.
*/
org.eclipse.swt.internal.mozilla.nsIWebBrowserStream
xpcomWebBrowserStream = new
org.eclipse.swt.internal.mozilla.nsIWebBrowserStream((int)/* 64*/streamHandle
);
for (int i = 0; i < pageCount; i++) {
int length = i == pageCount - 1 ? data.length % pageSize :
pageSize;
if (length > 0) {
int rc = xpcomWebBrowserStream.AppendToStream (current,
length);
if (rc != XPCOM.NS_OK) {
System.out.println("XPCOM Error: " +
Integer.toHexString(rc));
break;
}
}
current += pageSize;
}
stream.closeStream ();
C.free (ptr);
}
});
HTH,
Grant
"Alexander Ilyin" <a_ilyin@yahoo.com> wrote in message
news:haj1eo$71h$1@build.eclipse.org...
> Thank you for your answers.
>
> Its really should satisfy my needs. Something what I looking for. Thank
you.
>
> Just one problem. Your snippet does not work for me. :(
>
> Some problems with a stream. Mozilla gets data somewhere else. So I see
just a garbage or application even unexpectedly terminates.
>
> I just copy-past your snippet (Use another class name and package). Setup
the build path and add at the start of the main:
> System.setProperty("org.eclipse.swt.browser.XULRunnerPath", "path to the
xulrunner");
>
> XUL stuff(xullrunner and java xpcom plug-ins) I got from:
>
http://releases.mozilla.org/pub/mozilla.org/xulrunner/releas es/1.8.1.3/contrib/eclipse/
>
> Using Eclipse 3.5
>
> What I did miss?
>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03312 seconds