Firefox Hacks [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Firefox Hacks [Electronic resources] - نسخه متنی

Nigel McFarlane

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید






Hack 84. Do Groundwork for Extension Development

Understand how extensions, themes, and locales
fit into the Firefox architecture.

Chapter 7 introduced the key ideas of chrome,
chrome: URLs, JAR files, and packages [Hack #75] . Those concepts also apply to
more formal chrome enhancement projects. Such projects also require
the concepts of extensions, themes, locales, XPIs, and XPInstall.
This hack describes those concepts in more detail.
It's all about collecting together the jigsaw pieces
in preparation for solving the puzzle.

There are some basic differences between quick hacks to the chrome
and fully prepared extensions. These are the main advantages of
extensions:

They have a formal concept of version.

They can be updated after they are installed.

They can be updated across the Web from a web site.

If Firefox is upgraded, installed extensions are not lost.

Registration information exposes details of extensions to scripts.

Extensions are, by default, stored per-profile in the profile area.

Firefox's -safe-mode option
allows extensions to be disabled easily.



8.2.1. Spot Extension Files


All installed extensions live in the
extensions
directory, either in the profile area or in the install area. In that
directory are two important files.
Extensions.rdf is a small database of all the
currently installed extensions. The other file, usually named
something like installed-extensions.txt, lists
the extensions that were discovered the last time Firefox did a big
audit of all the extensions in the extensions
directory. This happens when the
installed-extensions.txt file is updated,
through the same approach used for the install
area's installed-chrome.txt
file [Hack #75] .

Separate from these two files are the actual extensions. Directories
with names like this contain one extension each:

{972ce4c6-7e08-4474-a285-3208198ce6fd}

The name exactly matches the UUID that uniquely identifies the
extension. Generation of UUIDs is done the same way as for XPCOM
components [Hack #82] . The
contents of these directories are the unpacked contents of the
.xpi file in which the extension was delivered.
Subdirectories named chrome,
components, defaults, and
uninstall inside each extension directory
perform the same roles as those directories in the install area. For
example, the .jar content files for the
extension can be found in the extension's
chrome subdirectory.

Firefox must scan all of these directories at startup (although the
XUL FastLoad cache can reduce this burden to zero), so installing
many extensions can affect startup performance a little. Then there
is the matter of what the extensions do once they start up.


8.2.2. Spot Extension Installers


Extensions are
delivered
as .xpi (XPI stands for cross
(X) platform
install) files. They're usually
delivered by clicking a link in an HTML page and require a special
web server setting [Hack #27] . At
the Mozilla Update web site (http://update.mozilla.org), you can see many
of these files behind the download links, and if you context-click on
one such link, you can save the .xpi file to
disk and open it up instead of installing it. These files are
ordinary ZIP files, except that they have a special directory layout
that includes an optional install script named
install.js and an install manifest named
install.rdf. They can also be digitally signed.


8.2.3. Three Kinds of RDF Files


Here's a summary of the preceding remarks from a
Resource Description Framework (RDF) perspective. RDF is used to
provide all the management information about extensions, locales,
themes, and packages.

Since extension content is typically delivered as one or more JAR
files, extensions contain (inside those JAR files) one or more
contents.rdf files. These files provide package
registration and overlay registration information for the
extension's chrome content. They're
all about the lowest-level detailpackages and
contentand they know nothing about extensions.

Extension JAR files are put into an XPI file along
with an install.rdf file. This second RDF file
contains all the registration information about the extension. The
content of this file allows Firefox to manage the extension across
versions, update it when required, and display its details in the
Extension Manager dialog box.

Finally, the Extensions.rdf file in the profile
area is the place where all of the information about extensions is
aggregated. It contains all of the important information from all of
the install.rdf files supplied by all of the
extensions.


8.2.4. Compare Locales, Themes, Applications, and Extensions


Locales, themes, applications, and extensions are four types of
downloadable enhancements that have a great deal in common. They all
use some combination of content hierarchy that combines a
package directory with one or more
skin, locale, or
content directories.

They differ in the registration information that's
stored in RDF. Pieces of data for each kind of enhancement are
recorded with different kinds of Uniform Resource Names (URNs). A
URL can be either a URL or a URN; see the IETF RFC 2396 technical
note for a definition (http://www.ietf.org). Once you understand the
basic URN naming scheme, browsing through the complex syntax of RDF
files is a little easier.

These are the URN registration prefixes for themes and extensions:

urn:mozilla:theme:...details...
urn:mozilla:extension:...details...

These URNs are downloaded during extension or theme install. At the
same time additional URNs that record the install bundle are also
saved. Here's an example:

urn:mozilla:install-manifest:...details...

By comparison, locales are generally bundled with a localized Firefox
install and are not installed via extensions. If they are delivered
as extensions, they acquire the same registration prefixes as
ordinary extensions do.

For install-bundled locales and install-bundled applications (like
Firefox), the only registration URNs that appear are the traditional
package ones:

urn:mozilla:locale:...
urn:mozilla:package:...
urn:mozilla:skin:...

This package configuration information is present in all cases, not
just for bundled items.


8.2.5. Find the XPInstall Missing Link


When an extension is downloaded, it doesn't appear
in the browser window as content and it doesn't get
saved to disk (unless you choose that option). So how is it delivered
to the Firefox profile area or install area?

The answer is
XPInstall (Cross
(X) Platform
Install), a small piece of Firefox that offers a
JavaScript hook in web pages and that can also recognize XPI content
types. When an extension is installed, the XPI file is sucked
directly into XPInstall (that is, into the Firefox
executable's memory), where it is pulled apart. Each
piece of the extension is then placed in the right spot.
It's a system similar to InstallShield, but much
less complex and entirely embedded inside the Firefox executable.
XPInstall is close to fully automatic in its processing, so
there's nothing much to do other than benefit from
it.


/ 164