1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
---
title: Chrome Registration
slug: Mozilla/Chrome_Registration
tags:
- NeedsEditorialReview
- Toolkit API
translation_of: Mozilla/Chrome_Registration
---
<p> </p>
<h3 id="What_is_Chrome.3F" name="What_is_Chrome.3F">Chrome是什么?</h3>
<p><a href="cn/Chrome">Chrome</a> 是应用程序内容窗口以外一系列用户接口元素。工具栏,如菜单栏,进度栏和标题栏这些都是chrome典型的元件。</p>
<h3 id="Chrome_Providers" name="Chrome_Providers">Chrome Providers</h3>
<p>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.</p>
<p>There are three basic types of chrome providers:</p>
<h4 id="Content" name="Content">Content</h4>
<p>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.</p>
<h4 id="Locale" name="Locale">Locale</h4>
<p>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.</p>
<h4 id="Skin" name="Skin">Skin</h4>
<p>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.</p>
<p><em>Note</em>: Scripts (including those found in <a href="cn/XBL">XBL</a>) loaded from skin packages will not execute.</p>
<h3 id="The_Chrome_Registry" name="The_Chrome_Registry">The Chrome Registry</h3>
<p>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.</p>
<p>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.</p>
<p>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, and chrome/*.manifest in a XULRunner application.</p>
<p>The plaintext chrome manifests are in a simple line-based format. Each line is parsed individually; if the line is parseable 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).</p>
<pre class="eval">locale packagename localename path/to/files
skin packagename skinname path/to/files
</pre>
<h3 id="Manifest_Instructions" name="Manifest_Instructions">Manifest Instructions</h3>
<h4 id="comments" name="comments">comments</h4>
<p>A line is a comment if it begins with the character '#'; any other characters on the line are ignored.</p>
<pre class="eval"># this line is a comment - you can put whatever you want here
</pre>
<h4 id="content" name="content">content</h4>
<p>A content package is registered with the line</p>
<pre class="eval">content<em>packagename</em><em>uri/to/files/</em><em>[flags]</em>
</pre>
<p>This will register a location to use when resolving the URI <a class="external" rel="freelink">chrome://</a><em>packagename</em> /content/.... The URI may be absolute or relative to the location of the manifest file. Note, that it must end with an '/'.</p>
<h4 id="locale" name="locale">locale</h4>
<p>A locale package is registered with the line</p>
<pre class="eval">locale<em>packagename</em><em>localename</em><em>uri/to/files/</em><em>[flags]</em>
</pre>
<p>This will register a locale package when resolving the URI <a class="external" rel="freelink">chrome://</a><em>packagename</em> /locale/... . The<em>localename</em> 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.</p>
<h4 id="skin" name="skin">skin</h4>
<p>A skin package is registered with the line</p>
<pre class="eval">skin<em>packagename</em><em>skinname</em><em>uri/to/files/</em><em>[flags]</em>
</pre>
<p>This will register a skin package when resolving the URI <a class="external" rel="freelink">chrome://packagename/skin/</a>... . The<em>skinname</em> 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.</p>
<h4 id="style" name="style">style</h4>
<p>Style overlays (custom CSS which will be applied to a chrome page) are registered with the following syntax:</p>
<pre class="eval">style <a class="external" rel="freelink">chrome://</a><em>URI-to-style</em> <a class="external" rel="freelink">chrome://</a><em>stylesheet-URI</em><em>[flags]</em>
</pre>
<div class="note">Note that only stylesheets at chrome URIs can be applied in this way.</div>
<h4 id="override" name="override">override</h4>
<p>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:</p>
<pre class="eval">override <a class="external" rel="freelink">chrome://</a><em>package</em>/<em>type</em>/<em>original-uri.whatever</em><em>new-resolved-URI</em><em>[flags]</em>
</pre>
<p>Note: overrides are not recursive (so overriding <a class="external" rel="freelink">chrome://foo/content/bar/</a> with <a class="external" rel="freelink">file:///home/john/blah/</a> will not usually do what you want or expect it to do).</p>
<div class="note">
<p>There is a currently a bug in the Firefox 2.0.0.* series, as well as previous builds, where if you use a relative URL for the<em>new-resolved-URI</em> parameter, the override will not work. You need to provide a fully qualified URL (ie, one that is resolvable anywhere, not just in the directory the chrome manifest resides in). Given that the extension or application developer usually is unable to predict what the full path to such a file might be, currently one would normally only use this directive using another <a class="external" rel="freelink">chrome://</a> URL as the<em>new-resolved-URI</em> parameter. See {{ Bug(323455) }}.</p>
</div>
<h4 id="resource" name="resource">resource</h4>
<p>{{ Fx_minversion_inline(3) }}</p>
<p>When using <a href="cn/Using_JavaScript_code_modules">JavaScript code modules</a> it may be necessary to create resource protocol aliases so extensions and applications can load modules using <a href="cn/Components.utils.import">Components.utils.import</a>. Aliases can be created using the <code>resource</code> instruction:</p>
<pre class="eval">resource<em>aliasname</em><em>uri/to/files/</em><em>[flags]</em>
</pre>
<p>This will create an mapping for the <code><a class="external" rel="freelink">res://</a><aliasname>/</code> to the path given.</p>
<div class="note">
<p>Note that there are no security restrictions preventing web content from including content at resource uris so take care with what you make visible there.</p>
</div>
<h3 id="Manifest_Flags" name="Manifest_Flags">Manifest Flags</h3>
<p>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.</p>
<h4 id="application" name="application">application</h4>
<p>Extensions may install into multiple applications. There may be chrome registration lines which only apply to one particular application. The flag</p>
<pre class="eval">application=<em>app-ID</em>
</pre>
<p>indicates that the instruction should only be applied if the extension is installed into the application identified by<em>app-ID</em> is running. Multiple application flags may be included on a single line, in which case the line is applied if any of the flags match.</p>
<h4 id="appversion" name="appversion">appversion</h4>
<p>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</p>
<pre class="eval">appversion=<em>version</em>
appversion<<em>version</em>
appversion<=<em>version</em>
appversion><em>version</em>
appversion>=<em>version</em>
</pre>
<p>indicates that the instruction should only be applied if the extension is installed into the application version identified. Multiple <code>appversion</code> 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 <a href="cn/Toolkit_version_format">Toolkit version format</a>.</p>
<div class="note">
<p>Versions of Gecko before 1.8.0.13 and 1.8.1.5 contained a bug where if you use the comparisons <, > or = then the version string had be 2 characters or more long. If not you would get a message in the error console that the <code>appversion</code> flag was not recognized. See {{ Bug(380398) }}.</p>
</div>
<h4 id="contentaccessible" name="contentaccessible">contentaccessible</h4>
<p>{{ Fx_minversion_inline(3) }} Untrusted content is no longer allowed to reference resources in chrome packages. If this needs to be explicitly allowed, set the contentaccessible flag to yes for behavior as found in older versions.</p>
<p>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. <span class="comment">Changed for Firefox 3 RC 1 for {{ bug(292789) }}.</span></p>
<h4 id="os" name="os">os</h4>
<p>{{ Fx_minversion_inline(3) }} 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 <a href="cn/OS_TARGET">OS_TARGET</a> for the platform.</p>
<pre class="eval">os=WINNT
os=Darwin
</pre>
<p>See <a href="cn/OS_TARGET">OS_TARGET</a> for a more complete list of os names. The os name is case insensitive.</p>
<h4 id="osversion" name="osversion">osversion</h4>
<p>{{ Fx_minversion_inline(3) }} 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:</p>
<pre class="eval">osversion>=10.5
</pre>
<h4 id="platform_.28Platform-specific_packages.29" name="platform_.28Platform-specific_packages.29">platform (Platform-specific packages)</h4>
<p>Some packages are marked with a special flag indicating that they are platform specific. Some parts of content, skin, 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.</p>
<p>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.</p>
<p>To indicate that a package is platform-specific, add the "platform" modifier to the "content" line after the path, for example:</p>
<pre class="eval">content global-platform jar:toolkit.jar!/toolkit/content/global-platform/ platform
</pre>
<p>Once that is specified in your manifest you then ensure that under the directory global-platform are subdirectories <code>win</code> (Windows/OS2), <code>mac</code> (OS9/OSX), or <code>unix</code> (Everything Else). Anything residing outside of these subdirectories will be ignored.</p>
<h4 id="xpcnativewrappers" name="xpcnativewrappers">xpcnativewrappers</h4>
<p>Chrome packages can decide whether to use the xpcnativewrappers security mechanism to protect their code against malicious content that they might access. See <a href="cn/Safely_accessing_content_DOM_from_chrome">Safely accessing content DOM from chrome</a> for details.</p>
<p>As of Firefox 1.5 alpha releases (Deer Park alphas), this flag is *off* by default, and must be explicitly enabled by specifying xpcnativewrappers=yes.</p>
<p>As of the first Firefox 1.5 beta release, this flag will be enabled by default, and extensions that need insecure access to the content objects will be required to specify xpcnativewrappers=no.</p>
<p>The xpcnativewrappers flag applies only to content packages: it is not recognized for locale or skin registration.</p>
<p> </p>
<h3 id="Example_Chrome_Manifest" name="Example_Chrome_Manifest">Example Chrome Manifest</h3>
<pre class="eval">content necko jar:comm.jar!/content/necko/ xpcnativewrappers=yes
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 <a class="external" rel="freelink">chrome://browser/content/pageInfo.xul</a> <a class="external" rel="freelink">chrome://pippki/content/PageInfoOverlay.xul</a> application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
overlay <a class="external" rel="freelink">chrome://communicator/content/pref/preftree.xul</a> <a class="external" rel="freelink">chrome://pippki/content/PrefOverlay.xul</a>
overlay <a class="external" rel="freelink">chrome://navigator/content/pageInfo.xul</a> <a class="external" rel="freelink">chrome://pippki/content/PageInfoOverlay.xul</a> <a class="link-mailto" href="mailto:application=seamonkey@applications.mozilla.org" rel="freelink">application=seamonkey@applications.mozilla.org</a>
content pippki jar:pippki.jar!/content/pippki/ xpcnativewrappers=yes
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 <a class="external" rel="freelink">chrome://global/content/netError.xhtml</a> jar:embedder.jar!/global/content/netError.xhtml
content inspector jar:inspector.jar!/content/inspector/ xpcnativewrappers=no
</pre>
<h3 id="Debugging_a_Chrome_Manifest_file" name="Debugging_a_Chrome_Manifest_file">Debugging a Chrome Manifest file</h3>
<p>The <a class="link-https" href="https://addons.mozilla.org/firefox/4453">Chrome List</a> extension shows all registered chrome. This is very helpful when trying to write a <code>chrome.manifest</code> file as you can inspect where the files are being mapped from (jar files, local directory, etc.)</p>
<h3 id="Old-style_contents.rdf_manifests" name="Old-style_contents.rdf_manifests">Old-style contents.rdf manifests</h3>
<p>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, the Mozilla Suite (SeaMonkey) does 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.</p>
<h3 id="Official_References_for_Toolkit_API" name="Official_References_for_Toolkit_API">Official References for <a href="cn/Toolkit_API">Toolkit API</a></h3>
<p>{{ page("zh-CN/docs/Toolkit_API/Official_References") }}</p>
|