这是教程最后一部分, 我们将把所有的web所有的组件成分打包成可安装到其他应用中的形式 - the library itself, the type library, the header file, and the user interface resources. The first section, Component Installation Overview, describes the general installation process in Mozilla. The following sections describe the steps you can take to organize the WebLock component for distribution and installation.
请注意: 这个教程主要是关注组件开发本身, 所以这部分描述有关打包和安装到Gecko的过程是很简单的. 如果你希望了解详细的打包和安装组件到基于Gecko应用的信息，应该参考http://www.mozilla.org/projects/xpinstall.
Component Installation Overview
Like the Windows registry, the chrome registry is a database of information about applications, skins, and other extensions that have been installed in a Gecko application. Since Mozilla and other Gecko-based applications are cross-platform, this database is abstracted above the operating system or any particular platform's registry.
The chrome registry lives in a series of RDF/XML files in the application directory of Mozilla and other Gecko-based browsers, where new installs, user configurable data, skins, and other information are related to one another and the application itself.
Install 对象下载包含了安装文件的JAR并且调用注册方法来告诉 Mozilla 新的组件和用来调用WebLock组件的UI. WebLock Installation Script 是完整的
trigger installation script
, 可以从网页触发. 文件被存储在JAR file
Once you have compiled all the resources that make up the WebLock component and the files that make up the user interface that will be added to the browser, you can place these within a subdirectory called
Place the entire subdirectory into a ZIP archive and name the archive
weblock.xpi. The archive, its subdirectory structure, and its contents should look like this:
Note that the top level of the archive holds the
install.js installation file, an RDF manifest for the package as a whole, and the component files (
weblock4.dll). The component files are copied to the components directory of the Gecko application, and the weblock subdirectory gets copied over into the chrome subdirectory, where its UI resources can be added dynamically to the XUL-based Gecko application.
The next section shows how this process of downloading, copying and registering the necessary files from the XPI can be achieved with an XPInstall installation script.
The WebLock Installation Script
weblock.xpi) itself. 一旦触发 (see The WebLock Trigger Script), 安章脚本将:
- downloads the WebLock component and places it in the
- copies the
weblocksubdirectory in the Mozilla chrome application subdirectory
- registers both the component and the UI
The XPInstall API提供了一些核心方法[essential-methods]例如
addFile, and others.
// initialize the installation var err = initInstall("WebLock", "weblock", 1.0); var componentsDir = getFolder("Components"); var cf = getFolder("Chrome"); // add the DLL and say where it'll go addFile("weblock.dll", 1.0, "weblock.dll", componentsDir, ""); // add the typelib also addFile("weblock.xpt", "1.0", "weblock.xpt", componentsDir, ""); // add the weblock subdirectory of the XPI and specify that // it be installed in the chrome application directory err = addDirectory("weblock", "1.0", "", chromeDir, ""); // ? have to register component here or with regxpcom? // register the new UI with the mozilla chrome registry registerChrome(CONTENT, getFolder(cf,"weblock.xpi"),"weblock"); registerChrome(SKIN, getFolder(cf, "weblock.xpi"),"weblock"); // perform the installation if there are no errors if (err==SUCCESS) performInstall(); else cancelInstall(err);
The WebLock Trigger Script
installWebLock, that gets called when the user clicks the hyperlink.
Distributing Your Component
Once you have the component packaged properly and the necessary installation and trigger scripts, you are ready to distribute your component so others can install it in their Gecko applications.
In Mozilla and Netscape browsers, XPInstall makes this process especially easy by providing the file format (XPI) and the necessary installation scripts for doing a web-based installation. As WebLock Installation Script demonstrates, XPInstall uses special keywords to refer to common installation directories such as
components in a generalized, cross-platform way.
If you are installing WebLock in an Gecko-based application for which XPInstall is not available, then you will have to devise a separate installation scheme. We leave this as an exercise for the reader.
- Note: install-object-methodsThe methods are available on the main
Installobject, which is implied in the script below in the same way that the
initInstall()from the script is equivalent to
Copyright (c) 2003 by Doug Turner and Ian Oeschger. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.02 or later. Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder. Distribution of the work or derivative of the work in any standard (paper) book form is prohibited unless prior permission is obtained from the copyright holder.