Firefox extension development (i): the basic structure of the extension

Source: Internet
Author: User
Tags locale

People who have used Firefox are sure to install Firefox extensions so they can play the full power of Firefox. The general extension is a file with the suffix. Xpi, in fact, this file is the ZIP format of the compressed package, compressed an extension of all the necessary directories and files, the basic directory structure is as follows:

EXTENSION.XPI:
/install.rdf
/components/*
/components/cmdline.js
/defaults/
/defaults/preferences/*.js
/plugins/*
/chrome.manifest
/chrome/icons/default/*
/chrome/
/chrome/content/

Seemingly complex, let's begin by introducing the most important documents:

1. INSTALL.RDF

As you can see from the name, this file describes the information required for an extended installation, including the extended identity, version, applicable application, author, and so on. itself is an RDF file.

A basic INSTALL.RDF Example:

  1. <?xml version="1.0"?>
  2. <RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  3. Xmlns:em="http://www.mozilla.org/2004/em-rdf#">
  4. <!--logo and version ---
  5. <description about ="Urn:mozilla:install-manifest">
  6. <em:id> [Email protected] </em:id>
  7. <em:version>1.0</em:version>
  8. <em:type>2</em:type>
  9. <!--for Applications--
  10. <em:targetapplication>
  11. <description>
  12. <em:id> {ec8030f7-c20a-464f-9b0e-13a3a9e97384} </em:id>
  13. <em:minversion>1.5</em:minversion>
  14. <em:maxversion>2.0.0.*</em:maxversion>
  15. </description>
  16. </em:targetapplication>
  17. <!--name, description, author and website address--
  18. <em:name> Hello</em:name>

The 8~10 line is the identity information, and the <em:id> segment of line 8th is the unique identity of this package, which can be an email from the author, with the purpose of uniquely identifying the package. Line 9th is the current version. The <em:type> of line 10th, with a value of 2 for "I am an extension", 4 for "I am the subject", here is an extension, so the value is 2.

The <em:targetApplication> section of the 14~20 line describes the application that the package is targeting, and the odd <em:id> of 16 lines indicates that the extension is for Firefox, not Thunderbird, Sunbird , so that the value of this ID will not change as long as it is for Firefox extensions. The 17~18 line describes the version of Firefox that this extension applies to.

The 23~26 line describes the basic information of the extension, which can be seen from the name of the tag, and the extension information displayed in the Extension Manager is derived from here.

2. Chrome Catalog

Chrome is the most important directory for extensions, all files that describe the extension, called Chrome.

Chrome typically includes 3 types of files, content, Locale, skin:

content: Describes the extension interface, the appearance of the definition file, such as button layout, dialog box, through the Xul file and JS file to set, we can see the introduction of XUL later.

locale: A file that describes multilingual information, typically a DTD file of XML.

Skin: A CSS file that defines the interface style and the desired picture file.

A typical (not absolute) Chrome directory contains a few subdirectories:

/chrome
content/
locale/
skin/

Three subfolders contain files that extend the corresponding content, locale, and SKN types.

3.chrome.manifest file

Next, let Fierfox find out where the expanded content, locale, and skin files are, and chrome.manifest is the role.

This file lets Firefox know where the extended content, locale, skin, and other files are, such as:

content Hello chrome/content/

Simply stated, hello this extended content type file is in the content subdirectory of the chrome directory.

The definition of locale is slightly different:

locale Hello zh-cn chrome/locale/zh-cn/

Indicate hello, the extended ZH-CN, which is the locale of the Chinese, under the chrome/locale/zh-cn/directory.

The definition of skin is similar to the locale:

Skin Hello classic/1.0 chrome/skin/classv1/

Indicate hello this extension, called classic/1.0 's skin, under the chrome/skin/classv1/directory.

By specifying the Chrome.manifest file, Firefox can find the corresponding file. In Firefox, referring to the file on the Web server is the "http:/" prefix, referring to the file on the hard disk is the "file://" prefix, the reference extension of the file has a separate reference prefix, that is, "chrome://", such as:

Examples of fireftp:

from the address bar can be seen, open fireftp this extension, is actually open the FireFTP content type file in the Fireftp.xul file.

Chrome://hello/content/about.xul The About.xul file in the Hello extension content type file is referenced. This way, regardless of the content, locale, and skin on the hard drive, as long as the Chrome.manifest file is configured, Firefox will be able to refer to the specific file via "chrome://". Transferred from: http://www.cnblogs.com/jxsoft/archive/2011/04/07/2008177.html

Firefox extension development (i): the basic structure of the extension

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.