Using OOPHM to develop XUL applications
Posted in GWT on October 30th, 2009 – 4 CommentsGWT bootstrap script
This post shows how we can use OOPHM to develop XUL applications in GWT. In this post, we will develop a Firefox extension and you can try yourself on Thunderbird and XulRunner.
In previous versions, GWT uses Hosted Browser and it is the only the supported browser during development cycles.
With new version, GWT 2.0 milestone 2, developers are free to choose their favorite browser, and they can develop applications from multiple browsers with OOPHM – Out Of Process Hosted Mode.
GWT has several linkers which generate the bootstrap scripts for your application.
The default IFrameLinker’s script uses document.write to inject other required scripts. However, because document.write is not available in XUL, the normal GWT bootstrap process does not work for XUL.
In addition, this bootstraps script creates a iframe element to load other scripts. Because for security reasons, content in this iframe can not access its parent chrome. See https://developer.mozilla.org/en/XUL/iframe.
XulLinker
Thus, we created another specific linker XulLinker for XUL applications. XulLinker uses Mozilla’s specific function document.loadOverlay to securely load the other scripts. XulLinker is test to run on Windows and Linux. Its source code is included in the download file.
For the purpose of this demonstration, we write a Hello application. The screenshots is as below:

Normal xul application e.g unprivileged mode

Chrome mode e.g privileged mode

GWT-Development-Mode
The example is simple, and you can discover its source code yourself. However, some key points you need to know:
- In TestXulLink.gwt.xml we added a new linker: <add-linker name=”xul” />
- The .xul file and .nocache.js must be in same directory
- You have to create a Firefox extension stub and install it before writing GWT code. For this example, copy file xullinker@gdevelop.com to your Firefox extension directory and edit it to point to the war directory of this example.
Run the example in Development Mode and then type chrome://xullinker/content/XulLinker.xul?gwt.hosted=localhost:9997 in Firefox’s address bar
After compiling the example, you can run in Web mode using chrome://xullinker/content/XulLinker.xul instead.
Summary
We use XulLinker to load required scripts for GWT application. XulLinker help us to develop Firefox, Thunderbird extensions and XUL applications using Java and GWT.
Source Code: XulLinker.tgz
See the LICENSE.txt in the download file for license details.


