Embedded browser inside Eclipse – how? what? why?

Eclipse is strong IDE and preferred choice for coding many languages. I have been using it for Java, JEE, PHP and recently started C, C++ using Eclipse. The strong plugin ecosystem has always proved of great help to get many things done at faster rate and in convenient way. Besides using Eclipse as IDE, I have also ventured into developing Plugins/Features/Product and you may notice few of my articles describing same. Few years back, I came across tools like Maqetta and online screen editors and off recently my encounter with Wix and Weebly made me think as how these technologies can be made available inside Eclipse. It was obvious that using SWT browser control, its quite easy to plug the tools described above. But to me, that’s mere hack and not delivering true Eclipse Plugin experience (experience similar to what Flash Builder provides with native component panels and clean editor area to design screens).

This lead to venturing into an undiscovered area of my technical experience but due to some reasons, I left the exploration mid way. Till that time, I had got fair understanding of SWT Browser and Browser Functions. Also I did cross ventured into embedded chromium but didn’t explore it any further and got occupied with my daily routines. Few weeks back, while playing with Wix, the long time sleeping dragon just woke up and hinted me to dig again as what options are available to deliver true experience of HTML editor inside Eclipse.

Chromium Embedded Framework (Lets stick to JCEF than CEF)
Chromium is a fantastic project for all those enthusiast who likes to get their hands dirty with C++ and want to roll out their own Browser. The project which is powering Google’s Chrome,

Chromium Embedded

Chromium Embedded

has been definitely helping others as well. With the capability to embed the browser into desktop technologies, Chromium embedded framework has been helping to deliver true web experience inside Desktop application. The JCEF fork has extended the reach of CEF further by enabling embedded support inside Java. This helps Java Developers to use feature rich Browser (compliant with bleeding edge technologies) right inside application.

After exploring the JCEF (Java Chromium Embedded Framework), I realized that the primary support has been exposed via AWT. This limits using JCEF inside Eclipse SWT. Though there is SWT AWT bridge is available, the application stops working inside MAC due to restriction on using SWT AWT at the same time. Well the approach works just fine under Windows.

But that’s not all, the JCEF port also lacks support for Java to JS communication (Browser Function support available in Eclipse SWT). Though the underlying CEF allows the integration, there is no interfacing API developed in JNI for Java. This limits the adoption of JCEF inside Eclipse and makes it more suitable as HTML renderer (Though there is no Browser Function support, I guess Message passing should be able to solve the problem to an extent, but that will make the code bit complex).

Webkit
Eclipse does provide an option to specify which browser technology should be used while using SWT browser control and one of the option is using Webkit.

WebKit

WebKit

This seems to be much reliable and easy to get started approach, with the only requirement to install Apple Safari on OS. But recently Apple stopped supporting Safari on Microsoft Windows, which is determinant for this approach.

Mozilla
Mozilla is yet another option available out of box inside Eclipse SWT Browser, but it requires installation of XULRunner. While I tried this approach many a times, I could never able to settle the code to use XULRunner successfully. Besides recent move by Mozilla to stop automated builds of XULRunner seems to be concerning.

New kid on the block – JavaFX
Okay, it isn’t that new. But it seems to be Oracle’s desperate attempt to bring Java UI back into the game.

JavaFX

JavaFX

JavaFX is much faster and provides rich controls and works pretty well on mobile as well. With FML, the development of UI is much easier task (plus the styling support using CSS is quite attractive). Besides all the general components, JavaFx also comes with WebView – a webkit version of embedded browser.

This is much reliable option as it heavily relies from the burden of relying on OS’s native browser (in case of SWT.None as choice for SWT.Browser). Additionally, the designers of JavaFX have already thought of bridge code for SWT, which enables plugging any JavaFX control right inside Eclipse. Using FXCanvas, its quite easy to bring JavaFX experience to Eclipse SWT platform. But, its not that easy to get JavaFX directly in Eclipse as the underlying library in Oracle JDK is delivered as a part of ‘ext’. Meaning its not yet easily portable solution across JVM vendors. But not to worry much, the much popular Java 8 provides open source implementation of JavaFX, which should lead to adoption by others.

Also to overcome ‘Access restriction warning’ displayed in Eclipse plugin project for JavaFX, use e(fx)clipse plugin. It provides easy approach to use JavaFX inside Eclipse Plugin project.

After fiddling with the project, I could easily able to build my own version of mini HTML editor allowing cross communication between Eclipse and Webkit (Won’t talk much about it in this article as there is lot more to do, to make it framework agnostic). The problem, I noticed with WebView was not being able to select the text. This may be caused due to silhouette canvas (I guess it uses shadow technique to render browser) being used inside WebView to render the browser. Few forums suggested that FX 8 has fixed the issue, but I couldn’t able to locate the download for same.

All of these options enable opportunity to deliver rich experience to user within desktop application. Users can interact with Web UI without having a need to leave your Eclipse project. I will be digging more in this area but with all the resources I have shared above, I hope you find something interesting or useful.

Note: Of Late, there seems to be shift from Eclipse to IntelliJ IDEA. Given that Google has now stopped future developments of Android Studio on Eclipse and ported its tooling to IntelliJ IDEA, the developers using eclipse have eroded. After using IntelliJ for Android development, I feel Eclipse has finally got a tough contender to beat down.

Be Sociable, Share!

Leave a Comment.