aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/xulrunner_tips/index.html
blob: f0f13843446836e680d52ef1a85f7c2d27c2baf0 (plain)
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
---
title: XULRunner tips
slug: XULRunner_tips
translation_of: Archive/Mozilla/XULRunner/Tips
---
<p>XULRunner常见问题,正在整理。</p>
<h2 id="Extension_Manager" name="Extension_Manager">扩展管理器</h2>
<p>要安装扩展,你首先要在<a href="/en/XUL_Application_Packaging#em" title="en/XUL_Application_Packaging#em">application.ini</a>中激活扩展管理器. XULRunner 1.8.0不会从程序目录载入扩展;只有XULRunner目录和用户配置目录会被检查。 然而,XULRunner 1.9在配置和程序目录检查后,XULRunner目录将被略过。要让XPInstall对话框、扩展管理器、皮肤管理器运行,下面的选项必须要进行设置:</p>
<pre class="eval">pref("xpinstall.dialog.confirm", "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul");
pref("xpinstall.dialog.progress.skin", "chrome://mozapps/content/extensions/extensions.xul?type=themes");
pref("xpinstall.dialog.progress.chrome", "chrome://mozapps/content/extensions/extensions.xul?type=extensions");
pref("xpinstall.dialog.progress.type.skin", "Extension:Manager-themes");
pref("xpinstall.dialog.progress.type.chrome", "Extension:Manager-extensions");
pref("extensions.update.enabled", true);
pref("extensions.update.interval", 86400);
pref("extensions.dss.enabled", false);
pref("extensions.dss.switchPending", false);
pref("extensions.ignoreMTimeChanges", false);
pref("extensions.logging.enabled", false);
pref("general.skins.selectedSkin", "classic/1.0");
// NB these point at AMO
pref("extensions.update.url", "chrome://mozapps/locale/extensions/extensions.properties");
pref("extensions.getMoreExtensionsURL", "chrome://mozapps/locale/extensions/extensions.properties");
pref("extensions.getMoreThemesURL", "chrome://mozapps/locale/extensions/extensions.properties");
</pre>
<p>If your application is based on Gecko 2.0, you need to register a component through the new component registration because the extension manager uses FUEL, namely <code>Application.restart()</code>, to restart your xulrunner-based application after any change (installation, removal, enabling, disabling) in the extensions' list:</p>
<ol>
  <li>copy files <code>fuelApplication.js</code> and <code>fuelApplication.manifest</code> from <a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/fuel/src/" title="http://mxr.mozilla.org/mozilla-central/source/browser/fuel/src/"><code>browser/fuel/src</code></a> for instance into your <code>components/</code> directory</li>
  <li>tweak the line <code>#include ../../../toolkit/components/exthelper/extApplication.js</code> in your copy of <code>fuelApplication.js</code> as needed</li>
  <li>make sure to declare the FUEL module and the two files in your <code>components/Makefile.in</code> as in <a class="external" href="http://mxr.mozilla.org/mozilla-central/source/browser/fuel/src/Makefile.in" title="http://mxr.mozilla.org/mozilla-central/source/browser/fuel/src/Makefile.in"><code>browser/fuel/src/Makefile.in</code></a></li>
  <li>rebuild...</li>
</ol>
<h2 id="Useful_Chrome_URLs">Useful Chrome URLs</h2>
<p>Most of these require <a href="#Branding"> branding</a>.</p>
<table class="standard-table">
  <tbody>
    <tr>
      <th>Window</th>
      <th>URL</th>
      <th>Window Type</th>
    </tr>
    <tr>
      <td>Extension Manager</td>
      <td>chrome://mozapps/content/extensions/extensions.xul?type=extensions</td>
      <td>Extension:Manager-extensions</td>
    </tr>
    <tr>
      <td>Theme Manager</td>
      <td>chrome://mozapps/content/extensions/extensions.xul?type=themes</td>
      <td>Extension:Manager-themes</td>
    </tr>
    <tr>
      <td>JavaScript Console</td>
      <td>chrome://global/content/console.xul</td>
      <td>global:console</td>
    </tr>
    <tr>
      <td>about:config</td>
      <td>chrome://global/content/config.xul</td>
      <td>  </td>
    </tr>
  </tbody>
</table>
<h2 id="Developer_Extensions" name="Developer_Extensions">Developer Extensions</h2>
<h3 id="Venkman"><a href="/en/Venkman" title="en/Venkman">Venkman</a></h3>
<ul>
  <li>Need a custom build or a compatible extension</li>
  <li>Need to edit compatibility in</li>
  <li>Needs a method to start venkman (usually by overlaying the main XUL file, similar to existing code for Firefox, Suite, etc.)</li>
  <li>The function toOpenWindowByType() needs to be defined. There is a <a class="external" href="http://www.rcode.net/blog/tlaurenzo/2006/03/17/getting-dev-tools-working-with-xulrunner/" title="http://www.rcode.net/blog/tlaurenzo/2006/03/17/getting-dev-tools-working-with-xulrunner/">working stub</a>. Any better suggestion?</li>
  <li>Venkman uses "chrome://communicator/skin/" as an alias for "chrome://global/skin/" and this alias was maintained in the XULRunner toolkit until XULRunner 1.9 was released. When using XULRunner 1.9 or greater, you can create your own alias
    <ul>
      <li>in your chrome manifest add a "skin" line:
        <pre>skin communicator classic/1.0 skin/communicator/</pre>
      </li>
      <li>add a skin folder named "communicator" and add a single CSS file named "communicator.css" with this content:
        <pre>@import url("chrome://global/skin");</pre>
      </li>
    </ul>
  </li>
</ul>
<h3 id="DOM_Inspector" name="DOM_Inspector"><a href="/en/DOM_Inspector" title="en/DOM_Inspector">DOM Inspector</a></h3>
<p>To add DOM Inspector 2.0.* to your XULRunner 1.9.0.* application follow these steps:</p>
<ul>
  <li>Download the <a class="link-https" href="https://addons.mozilla.org/en-US/firefox/addon/6622" title="https://addons.mozilla.org/en-US/firefox/addon/6622">Dom Inspector</a> (instead of clicking the "Add to..." button, right-click and select "Save Link As...").</li>
  <li>Save the <em>dom_inspector-*.xpi</em> package to a temporary directory</li>
  <li>Unzip the package</li>
  <li>Copy the following files:<br>
    <em>chrome/inspector.jar</em> to the chrome directory of your XULRunner application<br>
    <em>components/inspector-cmdline.js</em> to your components directory<br>
    <em>defaults/preferences/inspector.js</em> to your preferences directory</li>
  <li>Open your chrome.manifest file and add these lines:</li>
</ul>
<pre>content  inspector                       jar:inspector.jar!/content/inspector/ xpcnativewrappers=no
locale   inspector           en-US       jar:inspector.jar!/locale/en-US/inspector/
skin     inspector           modern/1.0  jar:inspector.jar!/skin/modern/inspector/
skin     inspector           classic/1.0 jar:inspector.jar!/skin/classic/inspector/

overlay  chrome://inspector/content/popupOverlay.xul   chrome://inspector/content/viewers/dom/popupOverlay.xul
overlay  chrome://inspector/content/commandOverlay.xul chrome://inspector/content/viewers/styleRules/commandOverlay.xul
overlay  chrome://inspector/content/keysetOverlay.xul  chrome://inspector/content/viewers/dom/keysetOverlay.xul
overlay  chrome://inspector/content/popupOverlay.xul   chrome://inspector/content/viewers/styleRules/popupOverlay.xul
overlay  chrome://inspector/content/commandOverlay.xul chrome://inspector/content/viewers/dom/commandOverlay.xul
</pre>
<p>To launch DOM Inspector in your application, you need to open its main window, with a command like this:</p>
<pre>window.open("chrome://inspector/content/inspector.xul", "", "chrome");
</pre>
<p><strong>Alternatively, the DOM Inspector may also be added as an extension:</strong></p>
<ol>
  <li>(if you already have inspector installed for another application you can skip to the next step)<br>
    Follow the instructions above through "Unzip the package."</li>
  <li>Create a file in the extensions directory of your application with the same name as the DOM Inspector ID (<a class="link-mailto" href="mailto:inspector@mozilla.org" rel="freelink">inspector@mozilla.org</a>) containing one line of text -- the exact path to the root directory of DOM inspector (where the install.rdf is) like this one:
    <pre>/home/username/.mozilla/firefox/numbersandletters/extensions/inspector@mozilla.org/</pre>
  </li>
  <li>Now create a javascript file with the following code and include it in the main window of your application:
    <pre>function startDOMi()
{
  // Load the Window DataSource so that browser windows opened subsequent to DOM
  // Inspector show up in the DOM Inspector's window list.
  var windowDS = Components.classes["@mozilla.org/rdf/datasource;1?name=window-mediator"]
                                   .getService(Components.interfaces.nsIWindowDataSource);
  var tmpNameSpace = {};
  var sl = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
    .createInstance(Components.interfaces.mozIJSSubScriptLoader);
  sl.loadSubScript("chrome://inspector/content/hooks.js", tmpNameSpace);
  tmpNameSpace.inspectDOMDocument(document);
}
</pre>
  </li>
  <li>Now create a hook in your application window to start DOM Inspector, like this one:
    <pre>&lt;button label="Start Inpector" oncommand="startDOMi()"/&gt;</pre>
  </li>
  <li>Start your application and DOM Inspector will be installed.</li>
</ol>
<p>Note: I use this method of installing extensions into all of my Mozilla applications. This way I have one directory where I keep all my Mozilla extensions, and each application (Firefox, Thunderbird) simply contains a few small, one line files pointing to the location of the extensions. (I keep them in source control to be sure I can maintain compatibility)</p>
<h3 id="Component_Viewer" name="Component_Viewer">Component Viewer</h3>
<p>Need custom build, first of all. What else?</p>
<h3 id="Extension_Developer.27s_Extension" name="Extension_Developer.27s_Extension">Extension Developer's Extension</h3>
<p><a class="external" href="http://ted.mielczarek.org/code/mozilla/extensiondev/">Extension Developer's Extension</a> is a useful tool, featuring Live XUL Editor and JavaScript Shell. To install the extension into your application you'll need to hack its install.rdf (see above). You'll probably also want to create menuitems that let you open the JS Shell and other tools provided by the extension.</p>
<h2 id="Branding" name="Branding">Branding</h2>
<p>Branding is a <a href="/en/Chrome_Registration" title="en/Chrome_Registration">chrome package</a> containing product-specific information (e.g. the product name, vendor, and logo). Some XULRunner components (in particular, the <a href="#Extension_Manager"> Extension Manager</a>) depend on branding, in the sense that they expect to find certain strings in <code><a class="external" rel="freelink">chrome://branding/locale/brand.dtd</a></code> and <code><a class="external" rel="freelink">chrome://branding/locale/brand.properties</a></code>. In order to satisfy these dependencies, you can save Firefox's <code>brand.dtd</code>/<code>brand.properties</code> to <code>chrome/locale/branding</code> folder, modify them appropriately, and <a href="/en/Chrome_Registration#locale" title="en/Chrome_Registration#locale">register a locale provider</a> for <code>branding</code> by adding the following line to your chrome manifest:</p>
<pre class="eval">locale branding en-US chrome/locale/branding/
</pre>
<p>The location you put the branding files in doesn't matter, as long as you register it appropriately in the manifest. In addition, a branding content package <a href="/en/Chrome_Registration#content" title="en/Chrome_Registration#content">must be registered</a> to include the application logos:</p>
<pre class="eval">content branding chrome/branding/
</pre>
<p>3 files should be provided in this folder: <em>about.png</em>, <em>icon48.png</em> and <em>icon64.png</em>. See <a class="external" href="http://mxr.mozilla.org/mozilla/source/other-licenses/branding/firefox/content/">Firefox</a> for example.</p>
<h3 id="Making_Windows_display_correct_application_name_and_icon_when_buttons_are_grouped" name="Making_Windows_display_correct_application_name_and_icon_when_buttons_are_grouped">Making Windows display correct application name and icon when buttons are grouped</h3>
<p>By default, the task bar on Windows might group windows belonging to the same process into one button to save space. This button is usually called "xulrunner.exe" and has XULRunner's icon. There are two approaches to display the branding of your application instead:</p>
<ul>
  <li>When compiling XULRunner yourself: create a file module.ver in the directory mozilla/xulrunner/app with the contents:
    <pre>WIN32_MODULE_DESCRIPTION=MyApplication</pre>
    <p>MyApplication should be replaced by whatever you want to see as title of the button. You can also replace xulrunner.ico in the same directory to change XULRunner's icon to the icon of your application.</p>
  </li>
  <li>With a precompiled XULRunner: use xulrunner-stub.exe to start your application but rename it into MyApplication.exe. With XULRunner 1.9 this will make the desired name appear in the task bar (not with XULRunner 1.8 however). Your application's icon can also be added to this executable with a tool like</li>
  <li><a class="external" href="http://www.angusj.com/resourcehacker/">Resource Hacker</a>. To change icon of specific window, see <a class="internal" href="/en/Window_icons" title="En/Window icons">Window icons</a>.</li>
</ul>
<h2 id="Reading_command_line_arguments" name="Reading_command_line_arguments">Reading command line arguments</h2>
<p>See <a href="/en/Chrome/Command_Line" title="en/Chrome/Command_Line">Chrome: Command Line</a>. Command line arguments are handled via nsICommandLineHandler, as usual.</p>
<h2 id="Preferences_needed_for_file_download_dialogs" name="Preferences_needed_for_file_download_dialogs">Preferences needed for file download dialogs</h2>
<p>To use the unknown-content-type and file-downloads dialogs from a &lt;browser&gt; element, you need to add the following prefs:</p>
<pre class="eval">pref("browser.download.useDownloadDir", true);
pref("browser.download.folderList", 0);
pref("browser.download.manager.showAlertOnComplete", true);
pref("browser.download.manager.showAlertInterval", 2000);
pref("browser.download.manager.retention", 2);
pref("browser.download.manager.showWhenStarting", true);
pref("browser.download.manager.useWindow", true);
pref("browser.download.manager.closeWhenDone", true);
pref("browser.download.manager.openDelay", 0);
pref("browser.download.manager.focusWhenStarting", false);
pref("browser.download.manager.flashCount", 2);
//
pref("alerts.slideIncrement", 1);
pref("alerts.slideIncrementTime", 10);
pref("alerts.totalOpenTime", 4000);
pref("alerts.height", 50);
</pre>
<p>If you are missing preferences that a dialog requires, you will get the following errors:</p>
<pre class="eval">Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIPrefBranch.getBoolPref]

Error: dialog has no properties
Source File: <a class="external" rel="freelink">chrome://mozapps/content/downloads/u...ontentType.xul</a>
Line: 1
</pre>
<h2 id="Enabling_Password_Manager" name="Enabling_Password_Manager">Enabling Password Manager</h2>
<p>These preferences seem to be the default in Firefox, however, they are missing in XULRunner. Without these settings Password Manager will not store login details.</p>
<pre class="eval">pref("signon.rememberSignons", true);
pref("signon.expireMasterPassword", false);
pref("signon.SignonFileName", "signons.txt");
</pre>
<p>You also need to get an instance of the login manager service, which internally initializes the system:</p>
<pre class="eval">Components.classes["@mozilla.org/login-manager;1"].getService(Components.interfaces.nsILoginManager);
</pre>
<h2 id="Using_Firefox_3_to_run_XULRunner_applications" name="Using_Firefox_3_to_run_XULRunner_applications">Using Firefox 3 to run XULRunner applications</h2>
<p>Firefox 3 contains the XULRunner runtime. It has an <code>-app</code> command-line switch to run a specified XUL application instead of starting the browser.</p>
<p>On Windows:</p>
<pre class="eval">  firefox.exe -app <em>path\to\</em>application.ini
</pre>
<p>On Linux:</p>
<pre class="eval">  firefox -app <em>path/to/</em>application.ini</pre>
<p>On the Mac:</p>
<pre class="eval">  /Applications/Firefox.app/Contents/MacOS/firefox-bin -app <em>/path/to/</em>application.ini
</pre>
<p>Note that at least on the Mac, you need to use a full path. Partial paths don't seem to work.</p>
<h2 id="Troubleshooting" name="Troubleshooting">Troubleshooting</h2>
<h3 id="Window_title_missing" name="Window_title_missing">Window title missing</h3>
<p>If the title of your XUL <code>&lt;<a href="/en/XUL/window" title="en/XUL/window">window</a>&gt;</code> is blank, even though you specified a title attribute, make sure the extension on your XUL file is <code>.xul</code> rather than <code>.xml</code></p>
<h2 id="默认皮肤">默认皮肤</h2>
<p>To create a default theme you need to create a folder in the extensions folder with an <a class="external" href="/en/Install_Manifests" title="http://developer.mozilla.org/editor/fckeditor/core/editor/en/Install_Manifests">install.rdf</a> in it.  As of Oct. 2008, the folder needs to have the same name as the one in Firefox 3.0. </p>
<p><code>\MyApp\Extensions\{972ce4c6-7e08-4474-a285-3208198ce6fd}\</code>install.rdf</p>
<p>It should also have an &lt;em:internalName&gt;classic/1.0&lt;/em:internalName&gt; as that is the default theme in Firefox.</p>
<p>{{ languages( { "ja": "ja/XULRunner_tips", "fr": "fr/Astuces_XULRunner" } ) }}</p>