Chrome registration 编辑
What is chrome?
Chrome is the set of user interface elements of the application window that are outside the window's content area. Toolbars, menu bars, progress bars, and window title bars are all examples of elements that are typically part of the chrome.
Mozilla locates and reads the root chrome.manifest
file for extensions and themes.
Note: With Gecko 1.9.2 and older, Mozilla reads chrome/*.manifest
files from applications. Starting with Gecko 2.0, the root chrome.manifest
is the only manifest used; you can add manifest
commands to that file to load secondary manifests.
Chrome providers
A supplier of chrome for a given window type (e.g., for the browser window) is called a chrome provider. The providers work together to supply a complete set of chrome for a particular window, from the images on the toolbar buttons to the files that describe the text, content, and appearance of the window itself.
There are three basic types of chrome providers:
- Content
- The main source file for a window description comes from the content provider, and it can be any file type viewable from within Mozilla. It will typically be a XUL file, since XUL is designed for describing the contents of windows and dialogs. The JavaScript files that define the user interface are also contained within the content packages, as well as most XBL binding files.
- Locale
- Localizable applications keep all their localized information in locale providers. This allows translators to plug in a different chrome package to translate an application without altering the rest of the source code. The two main types of localizable files are DTD files and Java-style properties files.
- Skin
- A skin provider is responsible for providing a complete set of files that describe the visual appearance of the chrome. Typically a skin provider will provide CSS files and images.
Note: Scripts (including those found in XBL) loaded from skin packages will not execute.
The chrome registry
The Gecko runtime maintains a service known as the chrome registry that provides mappings from chrome package names to the physical location of chrome packages on disk.
This chrome registry is configurable and persistent, and thus a user can install different chrome providers, and select a preferred skin and locale. This is accomplished through xpinstall and the extension manager.
In order to inform the chrome registry of the available chrome, a text manifest is used: this manifest is "chrome.manifest" in the root of an extension, or theme, or XULRunner application.
The plaintext chrome manifests are in a simple line-based format. Each line is parsed individually; if the line is parsable the chrome registry takes the action identified by that line, otherwise the chrome registry ignores that line (and prints a warning message in the runtime error console).
locale packagename localename path/to/files skin packagename skinname path/to/files
Note: The characters @ # ; : ? / are not allowed in the packagename.
Firefox 2, Thunderbird 2, and SeaMonkey 1.1 will not find the chrome whenpackagename
is mixed case. If the above example had a packagename
of CamelCasePackage, you would get an error message similar to "No chrome registered for chrome://camelcasepackage/path/to/files". Firefox 3, Thunderbird 3, and SeaMonkey 2 support mixed case. Bug resolved in Mozilla 1.9; see bug 132183.Manifest instructions
comments
# this line is a comment - you can put here whatever you want
A line is a comment if it begins with the character '#'. Any following character in the same line is ignored.
manifest
manifest subdirectory/foo.manifest [flags]
This will load a secondary manifest file. This can be useful for separating component and chrome registration instructions, or separate platform-specific registration data.
binary-component
binary-component components/mycomponent.dll [flags]
Instructs Mozilla to register and use a binary component. It should be combined with the abi flag, since binary components are ABI-specific. Prior to Firefox 4, files in the components directory were registered automatically.
interfaces
interfaces component/mycomponent.xpt [flags]
Instructs Mozilla to load interface information from a typelib file produced by XPIDL. Prior to Firefox 4, files in the components directory were registered automatically.
component
component {00000000-0000-0000-0000-000000000000} components/mycomponent.js [flags]
Informs Mozilla about a component CID implemented by an XPCOM component implemented in JavaScript (or another scripting language, if applicable). The ClassID {0000...} must match the ClassID implemented by the component. To generate a unique ClassID, use a UUID generator program or site.
contract
contract @foobar/mycontract;1 {00000000-0000-0000-0000-000000000000} [flags]
Maps a contract ID (a readable string) to the ClassID for a specific implementation. Typically a contract ID will be paired with a component entry immediately preceding.
category
category category entry-name value [flags]
Registers an entry in the category manager. The specific format and meaning of category entries depend on the category.
content
A content package is registered with the line:
content packagename uri/to/files/ [flags]
This will register a location to use when resolving the URI chrome://packagename/content/...
. The URI may be absolute or relative to the location of the manifest file. Note: it must end with a '/'.
locale
A locale package is registered with the line:
locale packagename localename uri/to/files/ [flags]
This will register a locale package when resolving the URI chrome://packagename/locale/... . The localename is usually a plain language identifier "en" or a language-country identifier "en-US". If more than one locale is registered for a package, the chrome registry will select the best-fit locale using the user's preferences.
skin
A skin package is registered with the line:
skin packagename skinname uri/to/files/ [flags]
This will register a skin package when resolving the URI chrome://packagename/skin/... . The skinname is an opaque string identifying an installed skin. If more than one skin is registered for a package, the chrome registry will select the best-fit skin using the user's preferences.
style
Style overlays (custom CSS which will be applied to a chrome page) are registered with the following syntax:
style chrome://URI-to-style chrome://stylesheet-URI [flags]Note: Only stylesheets at chrome URIs can be applied in this way.
override
In some cases an extension or embedder may wish to override a chrome file provided by the application or XULRunner. In order to allow for this, the chrome registration manifest allows for "override" instructions:
override chrome://package/type/original-uri.whatever new-resolved-URI [flags]
Note: overrides are not recursive (so overriding chrome://foo/content/bar/ with file:///home/john/blah/ will not usually do what you want or expect it to do). Also, the path inside overridden files is relative to the overridden path, not the original one (this can be annoying and/or useful in CSS files, for example).
Note: There was a bug in Gecko 1.8.1.5 (Firefox 2.0.0.5) and earlier where you could not use a relative URL for the new-resolved-URI parameter. You needed to provide an absolute URL. See bug 323455.
resource
Aliases can be created using the resource
instruction:
resource aliasname uri/to/files/ [flags]
This will create a mapping for resource://<aliasname>/
URIs to the path given.
Note: There are no security restrictions preventing web content from including content at resource: URIs, so take care what you make visible there.
Manifest flags
Manifest lines can have multiple, space-delimited flags added at the end of the registration line. These flags mark special attributes of chrome in that package, or limit the conditions under which the line is used.
application
Extensions may install into multiple applications. There may be chrome registration lines which only apply to one particular application. The flag
application=app-ID
indicates that the instruction should only be applied if the extension is installed into the application identified by app-ID. Multiple application flags may be included on a single line, in which case the line is applied if any of the flags match.
This example shows how a different overlay can be used for different applications:
overlay chrome://browser/content/browser.xul chrome://myaddon/content/ffOverlay.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} overlay chrome://messenger/content/mailWindowOverlay.xul chrome://myaddon/content/tbOverlay.xul application={3550f703-e582-4d05-9a08-453d09bdfdc6} overlay chrome://songbird/content/xul/layoutBaseOverlay.xul chrome://myaddon/content/sbOverlay.xul application=songbird@songbirdnest.com
appversion
Extensions may install into multiple versions of an application. There may be chrome registration lines which only apply to a particular application version. The flag
appversion=version appversion<version appversion<=version appversion>version appversion>=version
indicates that the instruction should only be applied if the extension is installed into the application version identified. Multiple appversion
flags may be included on a single line, in which case the line is applied if any of the flags match. The version string must conform to the Toolkit version format.
Note: Versions of Gecko before Gecko 1.8.0.13 and Gecko 1.8.1.5 contained a bug where if you use the comparisons <, > or =, the version string had be two or more characters long. If not, you would get a message in the error console that the appversion
flag was not recognized. See bug 380398.
platformversion
When supporting more then one application, it is often more convenient for an extension to specify which Gecko version it is compatible with. This is particularly true for binary components. If there are chrome registration lines which only apply to a particular Gecko version, the flag
platformversion=version platformversion<version platformversion<=version platformversion>version platformversion>=version
indicates that the instruction should only be applied if the extension is installed into an application using the Gecko version identified. Multiple platformversion
flags may be included on a single line, in which case the line is applied if any of the flags match.
contentaccessible
Chrome resources can no longer be referenced from within <img>, <script>, or other elements contained in, or added to, content that was loaded from an untrusted source. This restriction applies to both elements defined by the untrusted source and to elements added by trusted extensions. If such references need to be explicitly allowed, set the contentaccessible
flag to yes
to obtain the behavior found in older versions of Firefox. See bug 436989.
The contentaccessible
flag applies only to content packages: it is not recognized for locale or skin registration. However, the matching locale and skin packages will also be exposed to content.
n.b.: Because older versions of Firefox do not understand the contentaccessible
flag, any extension designed to work with both Firefox 3 and older versions of Firefox will need to provide a fallback. For example:
content packagename chrome/path/ content packagename chrome/path/ contentaccessible=yes
os
Extensions (or themes) may offer different features depending on the operating system on which Firefox is running. The value is compared to the value of OS_TARGET for the platform.
os=WINNT os=Darwin
See OS_TARGET for a more complete list of os names. The os name is case insensitive.
osversion
An extension or theme may need to operate differently depending on which version of an operating system is running. For example, a theme may wish to adopt a different look on Mac OS X 10.5 than 10.4:
osversion>=10.5
abi
If a component is only compatible with a particular ABI, it can specify which ABI/OS by using this directive. The value is taken from the nsIXULRuntime OS and XPCOMABI values (concatenated with an underscore). For example:
binary-component component/myLib.dll abi=WINNT_x86-MSVC
binary-component component/myLib.so abi=Linux_x86-gcc3
See XPCOM ABI for more details.
platform (Platform-specific packages)
Some packages are marked with a special flag indicating that they are platform specific. Some parts of content, skin, and locales may be different based on the platform being run. These packages contain three different sets of files, for Windows and OS/2, Macintosh, and Unix-like platforms. For example, the order of the "OK" and "Cancel" buttons in a dialog is different, as well as the names of some items.
The "platform" modifier is only parsed for content registration; it is not recognized for locale or skin registration. However, it applies to content, locale, and skin parts of the package, when specified.
To indicate that a package is platform-specific, add the "platform" modifier to the "content" line after the path, for example:
content global-platform jar:toolkit.jar!/toolkit/content/global-platform/ platform
Once that is specified in your manifest you then ensure that under the directory global-platform are subdirectories win
(Windows/OS2), mac
(OS9/OSX), or unix
(Everything Else). Anything residing outside of these subdirectories will be ignored.
process
In electrolysis registrations can be set to only apply in either the main process or any content processes. The "process" flag selects between these two. This can allow you to register different components for the same contract ID or ensure a component can only be loaded in the main process.
Note: Extensions can't currently (bug 1131065) register components to load in the content process using the manifest file so this flag is largely useless to extension developers.
component {09543782-22b1-4a0b-ba07-9134365776ee} maincomponent.js process=main component {98309951-ac89-4642-afea-7b2b6216bcef} contentcomponent.js process=content
xpcnativewrappers
Chrome packages can decide whether to use the XPCNativeWrapper security mechanism to automatically protect their code against malicious content that they might access. See Safely accessing content DOM from chrome for details.
This flag is enabled by default since Firefox 1.5. Disabling it manually was possible by specifying xpcnativewrappers=no
until Firefox 4.
Note: Support for this flag has been removed in Gecko 2.0. You can no longer disable XPCNativeWrapper
s. To update your add-on to work without this flag:
- If your add-on depends upon XBL bindings attached to content objects (that is, it needs to be able to call functions or get and set properties created by the XBL binding), you'll need to use the object's
wrappedJSObject
property to obtain a wrapped object. - If you need to call functions or access properties defined by the content -- for example, if your add-on wants to add a button to the page that calls a JavaScript function defined by the page.
The xpcnativewrappers
flag applies only to content packages; it is not recognized for locale or skin registration.
remoteenabled
In multiprocess Firefox, the default is that a given chrome: URI will always be loaded into the chrome process. If you set the "remoteenabled" flag, then the page will be loaded in the same process as the browser
that loaded it:
content packagename chrome/path/ remoteenabled=yes
remoterequired
In multiprocess Firefox, the default is that a given chrome: URI will always be loaded into the chrome process. If you set the "remoterequired" flag, then the page will always be loaded into a child process:
content packagename chrome/path/ remoterequired=yes
Example chrome manifest
content necko jar:comm.jar!/content/necko/ locale necko en-US jar:en-US.jar!/locale/en-US/necko/ content xbl-marquee jar:comm.jar!/content/xbl-marquee/ content pipnss jar:pipnss.jar!/content/pipnss/ locale pipnss en-US jar:en-US.jar!/locale/en-US/pipnss/ # Firefox-only overlay chrome://browser/content/pageInfo.xul chrome://pippki/content/PageInfoOverlay.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} # SeaMonkey-only overlay chrome://navigator/content/pageInfo.xul chrome://pippki/content/PageInfoOverlay.xul application={92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a} overlay chrome://communicator/content/pref/preftree.xul chrome://pippki/content/PrefOverlay.xul content pippki jar:pippki.jar!/content/pippki/ locale pippki en-US jar:en-US.jar!/locale/en-US/pippki/ content global-platform jar:toolkit.jar!/content/global-platform/ platform skin global classic/1.0 jar:classic.jar!/skin/classic/global/ override chrome://global/content/netError.xhtml jar:embedder.jar!/global/content/netError.xhtml content inspector jar:inspector.jar!/content/inspector/
Instructions supported in bootstrapped add-ons
The following instructions are supported in Bootstrapped extensions:
manifest
content
locale
skin
override
Debugging a chrome manifest file
The Chrome List extension shows all registered chrome. This is very helpful when trying to write a chrome.manifest
file as you can inspect where the files are being mapped from (jar files, local directory, etc.)
Old-style contents.rdf manifests
Before the plaintext manifests were introduced (which happened in Firefox 1.5, Toolkit 1.8), RDF manifests named "contents.rdf" were used to register chrome. This format is deprecated; however, SeaMonkey versions before version 2 do not support the plaintext manifest format yet, so contents.rdf
manifests are required for extensions that wish to maintain backwards compatibility with Firefox 1.0 or the suite.
contents.rdf
manifest format is no longer supported at all starting with Gecko 1.9.2; add-ons already installed using this format will continue to work but can no longer be installed. Be sure to remove your add-on and reinstall it to ensure that it installs correctly after updating it to use a plaintext manifest.Official references for Toolkit API
Official References. Do not add to this list without contacting Benjamin Smedberg. Note that this page is included from the pages listed below. So: Don't Add Breadcrumbs!
- Structure of an Installable Bundle: describes the common structure of installable bundles, including extensions, themes, and XULRunner applications
- Extension Packaging: specific information about how to package extensions
- Theme Packaging: specific information about how to package themes
- Multiple-item Extension Packaging: specific information about multiple-item extension XPIs
- XUL Application Packaging: specific information about how to package XULRunner applications
- Chrome Registration
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论