XUL Tutorial - 1.3 - The Chrome URL
Previous Contents Reference Next

XUL Tutorial - The Chrome URL

The following section will describe how to refer to XUL documents and other chrome files.

The Chrome URL

XUL files can be referred to with a regular HTTP URL just like HTML files can be (or any type of URL). However, packages that are installed into Mozilla's chrome system can be refered to with special chrome URLs. Files in the chrome directory will be installed already but you can register your own.

Installed packages have the advantage that they don't have security restrictions placed on them, which is necessary for many applications. The chrome URL has the advantage over URL types because they automatically handle mulitple skins and locales.

The basic syntax of a chrome URL is as follows:

chrome://<component>/content/<file.xul>

where <component> is the component name, such as messenger or editor.

Example: chrome://messenger/content/messenger.xul

The example here refers to the messenger window. You could point to a file that is part of a skin by replacing 'content' with 'skin' and changing the filename. Similarly, you can point to a file that is part of a locale by using 'locale' instead of 'content'.

You could think of the chrome URL as a special type of file URL (that is, file:// URLs) but where the root directory is the Mozilla chrome directory. However, there is one additional feature. The skin and locale part of the chrome URL maps to the current setting. If the user changes the default skin, the chrome URL does not change, but what it points to changes.

Mozilla is able to figure out which is the current skin and current language and map the appropriate directories into chrome URLs. Those RDF files in the chrome directory and the contents.rdf files are there to tell Mozilla how to do this. That way the user can use any skin or language but the URLs that refer to chrome files do not have to be changed. For example, the default navigator.css can be refered to with:

chrome://navigator/skin/navigator.css

If you change the browser skin to one located somewhere else, the chrome URL does not change, even through its real location changes.

The chrome system takes the navigator portion of the content, the navigator section of the current skin and the navigator section of the current locale and groups them together to form a user interface. Here are some more examples, this time for messenger:

chrome://messenger/content/messenger.xul
chrome://messenger/content/mime.js
chrome://messenger/skin/images/reply.jpg
chrome://messenger/locale/messenger.dtd

For subpackages, the same structure can be used. The following URL will refer to the bookmarks window:

chrome://communicator/content/bookmarks/bookmarks.xul

You can enter chrome URLs anywhere normal URLs can be used. You can even enter them directly into the URL bar in a Mozilla browser window.

Remember too, that you can also refer to XUL files with regular file URLs also. You might do this to test a file without having to install a package.

You might also see chrome URLs without specified filenames, such as:

chrome://global/skin/

This type of reference will automatically select an appropriate file from that directory. For skins, a file with the name of the package and a css extension is selected. In the above example, the file global.css is selected.

For content files, a file package.xul is selected and for locale files, a file package.dtd is selected, where package is the name of the package. This is a convenient shorthand syntax.


(Next) In the next section, we will look at how to create manifest files and install packages.

XUL Tutorial - 1.3 - The Chrome URL
Previous Contents Reference Next