Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » swt browser widget/xpcom integration question
swt browser widget/xpcom integration question [message #893267] Tue, 03 July 2012 12:24 Go to next message
Mark Fishman is currently offline Mark FishmanFriend
Messages: 27
Registered: March 2011
Junior Member
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 #893417 is a reply to message #893267] Wed, 04 July 2012 04:09 Go to previous messageGo to next message
Lakshmi P ShanmugamFriend
Messages: 279
Registered: July 2009
Location: India
Senior Member
Hi,

May be you could try SWT BrowserFunction and see if it works...
BrowserFunction provides a way to call a Java function from JavaScript and pass values between Java and JavaScript. See snippet --> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet307.java

Other Browser snippets: http://eclipse.org/swt/snippets/#browser


Lakshmi P Shanmugam
Re: swt browser widget/xpcom integration question [message #893714 is a reply to message #893417] Thu, 05 July 2012 10:51 Go to previous messageGo to next message
Mark Fishman is currently offline Mark FishmanFriend
Messages: 27
Registered: March 2011
Junior Member
Hi Lakshmi,

Thanks for your response. Can you give me a little more information on what you are thinking here?

I have used BrowserFunctions in the past but I just don't quite see how it will solve my problem. The only idea I can come up with is to write a Java method that returns "browser.getWebBrowser();" which, I guess, would give me a handle that I could use in javascript but since the getWebBrowser() will only return the nsIWebBrowser object if I am talking to a xulrunner that has javaxpcom it does not really meet my goal of taking javaxpcom out of the equation.

Were you thinking along these same lines as well or am I just being dense and missing something?

Thanks again.

-- Mark
Re: swt browser widget/xpcom integration question [message #894089 is a reply to message #893714] Fri, 06 July 2012 15:10 Go to previous message
Mark Fishman is currently offline Mark FishmanFriend
Messages: 27
Registered: March 2011
Junior Member
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 = .... ; 
}
Previous Topic:OLE SWT Excel macros
Next Topic:Listener on all Eclipse operations
Goto Forum:
  


Current Time: Tue Apr 23 08:03:35 GMT 2024

Powered by FUDForum. Page generated in 0.03398 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top