swt browser widget/xpcom integration question [message #893267] |
Tue, 03 July 2012 08:24  |
Eclipse User |
|
|
|
Hi,
I am using a SWT Browser widget with XULRunner to provide some embedded web content in my application. I currently have some code that gets a hold of the nsIWebBrowser by doing a swtBrowser.getBrowser() call and then from there uses the javaxpcom interfaces to add the functionality that I need. Due to the fact that Mozilla is no longer actively supporting javaxpcom I would really like to convert my code to javascript and then just do a swtBrowser.execute(...); to invoke it. Unfortunately, I am stuck by the fact that I need to get a hold of the nsIWebBrowser widget that the SWT browser creates from my javascript and I can't figure out any good way to do so. Is this possible and, if so, can some one point me to a snippet of code that will do this?
Thanks.
-- Mark
|
|
|
|
|
Re: swt browser widget/xpcom integration question [message #894089 is a reply to message #893714] |
Fri, 06 July 2012 11:10  |
Eclipse User |
|
|
|
So I have a solution, if a rather poor one.
You can use the nsiWindowWatcher to get a hold of the nsIDomWindow and from that you can move up to the nsiWebBrowser or query for any of the interfaces like nsIWebNavigation, nsIDocShell, etc.
As a note, my first cut, was to get the nsiWindowWatcher and then interrogate it for the activeWindow. That worked on a Window's box talking to a XULRunner with JavaXPCOM support but not a linux box talking to a XULRunner without JavaXPCOM support.
My hacky solution was to pass in the url that the Java browser object was pointing at and search through all of the windows for the one whose location was equal to that url. There is almost definitely a better solution then this but that was the best I could come up with.
Below is an example snippet of code that I used to find the nsiMarkupDocumentViewer so I could provide zoom in/zoom out capabilities, again there is probably a more elegant solution:
var swtBrowserUrl = '....';
var winWatcher= Components.classes["@mozilla.org/embedcomp/window-watcher;1"].
getService(Components.interfaces.nsIWindowWatcher);
var enumerator = winWatcher.getWindowEnumerator();
var win = null;
while(enumerator.hasMoreElements())
{
var checkWin = enumerator.getNext();
if(checkWin.document.location == swtBrowserUrl)
{
win = checkWin;
break;
}
}
if(win != null)
{
var docViewer = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIWebNavigation).
QueryInterface(Components.interfaces.nsIDocShell).
containerViewer.QueryInterface(
Components.interfaces.nsIMarkupDocumentViewer);
docViewer.fullZoom = .... ;
}
|
|
|
Powered by
FUDForum. Page generated in 0.02821 seconds