WebKit for SWT is an open-source embeddable Java(tm) WebKit browser component developed by Genuitec and contributed to the Eclipse Blinki Mobile DevKit project. WebKit for SWT can be used in the development of a wide range of Java SWT standalone and RCP applications that require integration of rich internet content, and services.
The WebKit browser engine is one of the hottest most interesting browser technologies. It can be found on both the desktop and smartphones. For example, implementations of WebKit serve as the rendering engine behind Google's Chrome browser and Android mobile web browser, Apple's Safari and iPhone Mobile Safari browsers, Nokia's smartphones and the list grows daily. Much of the positive community vibe around WebKit is due to its early support of HTML5 features such as offline data storage, video and audio elements, CSS3 animation, and a new generation of rip'n fast high performance JavaScript engines such as Google's V8 and WebKit's SquirrelFish.
WebKit for SWT provides the following browser integration and management services:
WebKit for SWT is a spin-off of the the new
MobiOne Mobile Web IDE
and contributed to Eclipse to serve as one of the core technologies
in the OSS mobile web initiative,
Eclipse Blinki Mobile
Web DevKit. We have worked to keep the programming model consistent
with SWT conventions and minimize configuration requirements. For
example WebKit for SWT requires loading of its own native DLLs. We
have eliminated the traditionally tedious and error prone setup of
these DLLs for your WebKit for SWT application's proper operation,
e.g., no need to setup PATH or java.library.path.
Following are 2 screenshots of Flash websites displayed in the
example SWTWebKitBrowser Java app. This Chrome-like example browser
application was developed using WebKit for SWT and demonstrates some
of the key API usage. See the
Example Resources section below for more
detail about this and other WebKit for SWT programming resources.
WebKit for SWT is released under the EPL 1.0 license. Additional open-source licenses apply to the core native WebKit code included in the distribution. Please see the README.html file included in the root folder of your distribution for more details.
No Mac or Linux Support Yet!
The lack of support for the Mac or Linux platforms is due to WebKit for SWT 's reliance on the Google Chromium framework. Chromium support for Mac and Linux platforms is being developed but not yet general available. Google has committed to Mac support in 2009. WebKit for SWT will support these platforms shortly after Chromium support is available.
WebKit for SWT is distributed in 2 forms: 1) a basic Java Zip archive
and 2) Eclipse plugins available from an Eclipse update site. The
basic Java Zip is best used for development of standalone Java SWT
applications. The Eclipse plugin distribution should be used for
creating Eclipse RCP applications or tools.
Getting started is a simple process of downloading the WebKit for SWT
distro zip file and unzipping in a location of your choice.
Step-1. Download WebKit for SWT here (9.52 Mb)
Step-2: Unzip the webit4swt-0.6.0.zip to your file system
There are several example Java applications that you may use to
assist with your use of WebKit for SWT.
SWTWebKitBrowser App - A simple browser application
modeled after Google's Chrome browser UI. To run this example use
either the Windows batch file in the Java Zip distro or the Java
commandline shown below. The commandlines assume that your current
directory is the WebKit for SWT root installation directory. Also the
Java6 JVM is assumed to be on your PATH.
bin/runExampleBrowser.batBrowser Snippets - a collection of small Java applications that demonstrate how to use various features of WebKit for SWT. The snippets are adapted versions of the original SWT Browser snippets. To run any of the snippets use the following commandline pattern:
or
java -cp lib/webkit4swt-0.6.0.jar;lib/webkit4swt-examples-0.6.0.jar;lib/swt.jar com.genuitec.blinki.webkit.swt.examples.browser.SWTWebKitBrowser
java -cp lib/webkit4swt-0.6.0.jar;lib/webkit4swt-examples-0.6.0.jar;lib/swt.jar com.genuitec.org.eclipse.swt.browser.<yourSnippetClassnameHere>
Source Code - The Java source code is available for
each of these examples. For users of the Java distro you can find the
examples source code in the examples directory. For RCP and
plugin developers see
Getting the Src.
The central class of WebKit for SWT is WebKitBrowser , an Eclipse SWT UI component based on Google's Chromium WebKit framework. In your application you use WebKitBrowser like any other SWT component, e.g.,
new WebKitBrowser(Composite parent, int swt-style-flags)
public class HelloWorld {
public static void main(String [] args) {
Display display = new Display();
Shell shell = new Shell(display); //create window
shell.setLayout(new
FillLayout());
WebKitBrowser browser= new WebKitBrowser(shell, SWT.NONE); //create browser
browser.setUrl("http://helloworld.org");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
getUserAgent()The cookie methods work with textual representation of the cookie, e.g., "cookieName=value". See the WebKitBrowser JavaDoc for more details on the proper use of each of these methods.
setUserAgent(aUserAgentString)
setProfileFolder(aFile)
getCookie(aCookieName,aURLString)
getCookieNames(aURLString)
setCookie(aCookieString,aURLString)
deleteCookie(aCookieName,aURLString)
setUrl(aUrlString)The back() and forward() methods are asynchronous operations and can be monitored using either a LocationListener or a ProgressListener, see Event Services below. The refresh() method reloads the browser's current page.
back()
isBackEnabled()
forward()
isForwardEnabled()
refresh()
In addition rendering web content loaded by a navigation service, WebKitBrowser can load HTML source code directly using the following method:
setText(htmlSrc)The method setText(htmlSrc) will parse and render the supplied htmlSrc string. This operation enables an application to generate custom HTML content and JavaScript functionality and manually render it in a custom manner.
Many of the the
WebKitBrowser
service execute asynchronously. For example, when you invoke
webKitBrowser.setUrl(aUrl)
, rather than lockup the UI waiting for the page to load, the browser
begins loading the page on a separate thread and returns control
almost immediately. For all asynchronous operations
WebKitBrowser
provides event details through a Java Listener callback framework.
Following are the event listener interfaces and their key methods that you can choose to monitor for asynchronous browser events:
OpenWindowListener - open(WebKitWindowEvent)
CloseWindowListener - close(WindowEvent)
LocationListener - changing(LocationEvent), changed(LocationEvent)
ProgressListener - changing(ProgressEvent), completed(ProgressEvent)
StatusTextListener - changed(StatusTextEvent)
TitleListener - changed(TitleEvent)
VisibilityWindowListener - show(WindowEvent), hide(WindowEvent)
Browser menu operations are not asynchronous and enable you to modify a menu before its display or process a menu item selection immediately.
See Known Issues to learn more about issues and limitations of the following events: WebkitWindowEvent, ProgressEvent, StatusTextEvent and VisibilityWindowEvent.BrowserMenuEventListener - beforeMenuShow(BrowserMenuEvent),
- menuItemAction(BrowserMenuItemActionEvent),
- menuItemName( BrowserMenuItemActionEvent )
A JavaScript API is provided to enable you to execute JavaScript functions or scriptlets on the current document. This is the primary mechanism for accessing and manipulating the DOM. To execute a JavaScript function use:
execute(theJavaScriptSrc)- returns boolean; true if success; false otherwise
evaluate(theJavaScriptSrc)- returns simple Object of type: String, boolean, int, double, void
API support for direct DOM access and update from Java is planned in
an upcoming release.
WebKitBrowser
also allows you to provide a handler for JavaScript alerts.
While WebKit for SWT supports most of the Chromium plugins such as
Flash there are no APIs yet available for plugin development or
management from Java. We would like
community feedback on their plugin
management needs.
A Java Native Interface (JNI) bridge enables WebKitBrowser to control
the Chromium framework and receive asynchronous events. We use a
customized version of the C++ Chromium Embedded Framework (see
Credits) to simplify embedding and use of the
Chromium WebKit engine. The C++ integration is provided by the 2
dynamic link libraries (DLL),
webkit4swt-x.y.z.dll and
icudt38.dll. These DLLs are loaded
from either the path defined by the JVM system
java.library.path property or
explicitly unarchived and loaded from the
webkit4swt JAR. For the latter DLL
loading method we reused the SWT mechanism that automatically unzips
all DLLs from the
webkit4swt JAR to your tmp folder.
Then these DLLs are loaded using the system DLL loading mechanism. On
Vista the default user temp location is
<user_home>/appdata/local/temp.
The WebKit for SWT source code is available via anonymous CVS access.
pserver:anonymous@opensource.genuitec.com:/home/cvs/public/eclipse/blinki
The code is organized into the following projects:
com.genuitec.blinki.webkit4swt
- Eclipse feature project
com.genuitec.blinki.webkit.swt
- Eclipse Java plugin project
com.genuitec.blinki.webkit.swt.win32 - Eclipse Java plugin fragment
project