If you’ve developed applications or extensions using the Mozilla platform, you know that there are tons of services and APIs available. We use those same capabilities when building Fennec. However, there are times when the default platform behavior is not desirable on mobile devices. When that happens, we could hack up our own system, or we could re-implement the platform APIs to suit our needs. We try to do the latter.
Here are some APIs that have been reimplemented in Fennec: nsIAlertsService, nsIPromptService, nsIDownloadManagerUI, and window.openDialog(). The primary reason all of these APIs have been reimplemented is that they open new XUL windows. We don’t like doing that in Fennec. Mostly because opening a XUL window is slow. But also because we love having tighter control over the look, feel and behavior of the UI elements.
Since we re-implement the interfaces,
nsIDownloadManagerUI can be used just as they are on the desktop. The big difference is that none of them open new windows. The UI is embedded into the main window itself. It’s faster to display and easier to control and style the UI elements. In the case of the download manager, it’s designed to be embedded in the main window.
On the other hand, we couldn’t exactly match the way
window.openDialog() worked, so we created a slightly different API:
importDialog(). The big difference is that
importDialog() actually merges the XUL dialog into the main window. It does not open a new XUL window.
aSrc: The chrome URL of the XUL dialog
The XUL passed to
importDialog() is very similar to XUL passed to
window.openDialog(), with some limitations and caveats:
<dialog>top level elements are permitted
- Scripts are loaded via an attribute on the
<dialog>element, not via the
Here is an example:
<?xml version="1.0"?> <!DOCTYPE mydialog SYSTEM "chrome://myextension/locale/mydialog.dtd"> <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" script="chrome://myextension/content/mydialog.js"> <label id="mydialog-title" crop="center"/> ... some other widgets ... <hbox pack="center"> <button label="&ok.label;" oncommand="myDialog.doSomething();"/> </hbox> </dialog>
Obviously, add-on developers should use these features. We are looking for feedback as well. Perhaps we could get
importDialog() working more like
A big thank you goes out to Fabrice Desré for working on reimplementing nsIPromptService. He created some great building blocks for Fennec.