aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/mozilla/firefox/releases/3/updating_extensions/index.html
blob: 1202baaa23605b1953392c544f35379b60afe0df (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
214
215
216
217
218
---
title: 为Firefox 3升级扩展
slug: Mozilla/Firefox/Releases/3/Updating_extensions
tags:
  - Firefox 3
translation_of: Mozilla/Firefox/Releases/3/Updating_extensions
original_slug: Updating_extensions_for_Firefox_3
---
<div><section class="Quick_links" id="Quick_Links">
  <ol>
    <li class="toggle">
        <details>
            <summary>Firefox developer 发布说明</summary>
            <ol>
              <li><a href="/zh-CN/docs/Mozilla/Firefox/Releases">Firefox developer 发布说明</a></li>
            </ol>
        </details>
    </li>
    <li class="toggle">
        <details>
            <summary>附加组件</summary>
            <ol>
              <li><a href="/zh-CN/Add-ons/WebExtensions">浏览器扩展</a></li>
              <li><a href="/zh-CN/Add-ons/Themes">主题</a></li>
            </ol>
        </details>
    </li>
    <li class="toggle">
        <details>
            <summary>Firefox 的内部机制</summary>
            <ol>
              <li><a href="/zh-CN/docs/Mozilla/">Mozilla 项目</a></li>
              <li><a href="/zh-CN/docs/Mozilla/Gecko">Gecko</a></li>
              <li><a href="/zh-CN/docs/Mozilla/Firefox/Headless_mode">Headless mode</a></li>
              <li><a href="/zh-CN/docs/Mozilla/JavaScript_code_modules">JavaScript代码模块</a></li>
              <li><a href="/zh-CN/docs/Mozilla/js-ctypes">JS-ctypes</a></li>
              <li><a href="/zh-CN/docs/Mozilla/MathML_Project">MathML 项目</a></li>
              <li><a href="/zh-CN/docs/Mozilla/MFBT">MFBT</a></li>
              <li><a href="/zh-CN/docs/Mozilla/Projects">Mozilla 项目</a></li>
              <li><a href="/zh-CN/docs/Mozilla/Preferences">Preference 系统</a></li>
              <li><a href="/zh-CN/docs/Mozilla/WebIDL_bindings">WebIDL 绑定</a></li>
              <li><a href="/zh-CN/docs/Mozilla/Tech/XPCOM">XPCOM</a></li>
              <li><a href="/zh-CN/docs/Mozilla/Tech/XUL">XUL</a></li>
            </ol>
        </details>
    </li>
    <li class="toggle">
        <details>
            <summary>构建与作出贡献</summary>
            <ol>
              <li><a href="/zh-CN/docs/Mozilla/Developer_guide/Build_Instructions">构建说明</a></li>
              <li><a href="/zh-CN/docs/Mozilla/Developer_guide/Build_Instructions/Configuring_Build_Options">配置构建选项</a></li>
              <li><a href="/zh-CN/docs/Mozilla/Developer_guide/Build_Instructions/How_Mozilla_s_build_system_works">构建系统如何工作</a></li>
              <li><a href="/zh-CN/docs/Mozilla/Developer_guide/Source_Code/Mercurial">Mozilla源代码</a></li>
              <li><a href="/zh-CN/docs/Mozilla/Localization">本地化</a></li>
              <li><a href="/zh-CN/docs/Mozilla/Mercurial">Mercurial</a></li>
              <li><a href="/zh-CN/docs/Mozilla/QA">质量保证</a></li>
              <li><a href="/zh-CN/docs/Mozilla/Using_Mozilla_code_in_other_projects">在其他项目中使用来自Mozilla的代码</a></li>
            </ol>
        </details>
    </li>
  </ol>
</section></div>

<p><span class="comment">英文原文取自于 <a class="external" href="http://developer.mozilla.org/en/docs/Extensions" rel="freelink">http://developer.mozilla.org/en/docs/Extensions</a></span>  这篇文章将对于那些想把他们的扩展在Firefox 3中正常运行的开发者提供一些有用的信息。</p>

<p>在进入主题之前,首先要提示一下:如果你的扩展所需要的唯一改变只是安装文件中的<code>maxVersion</code>信息,并且你的扩展所在的主机是<a class="link-https" href="https://addons.mozilla.org">addons.mozilla.org</a>,事实上你不需要上传你的新的版本的扩展!只需要在AMO中使用开发者控制面板调整<code>maxVersion</code>。通过这种方式你可以避免你的扩展被再次审核。</p>

<h3 id=".E7.AC.AC.E4.B8.80.E6.AD.A5_.E5.8D.87.E7.BA.A7.E5.AE.89.E8.A3.85.E6.96.87.E4.BB.B6" name=".E7.AC.AC.E4.B8.80.E6.AD.A5:_.E5.8D.87.E7.BA.A7.E5.AE.89.E8.A3.85.E6.96.87.E4.BB.B6">第一步: 升级安装文件</h3>

<p>第一步,当然,对于大多数的扩展也仅需要这一步——更新安装文件<code>install.rdf</code>,声明扩展兼容Firefox 3。</p>

<p>找到声明兼容的最大版本号的那一行(对于Firefox2,如下):</p>

<pre class="eval"> <span class="nowiki">&lt;em:maxVersion&gt;2.0.*&lt;/em:maxVersion&gt;</span>
</pre>

<p>对于Firefox 3,如下:</p>

<pre class="eval"> <span class="nowiki">&lt;em:maxVersion&gt;3.0.*&lt;/em:maxVersion&gt;</span>
</pre>

<p>然后重新安装扩展。</p>

<p>注意,在Firefox3的本版号中没有额外的“.0”,所以请使用“3.0.*”,而非“3.0.0.*”。</p>

<div class="blockIndicator note"><strong>Note:</strong> Note that at this point more changes in Firefox 3 are expected. These changes may break some extensions, so you shouldn't release an extension with <code>3.0.*</code> <code>maxVersion</code> to the users until the Firefox 3 release candidate is out. During the Firefox 3 Beta period, you should use <code>3.0b5</code> as your <code>maxVersion</code>.</div>

<p><br>
 There have been (and will continue to be) a number of API changes that will likely break some extensions. We're still working on compiling a complete list of these changes.</p>

<div class="blockIndicator note"><strong>Note:</strong> If your extension still uses an <code><a href='"cn/Install.js"'>Install.js</a></code> script instead of an <a href='"cn/Install_Manifests"'>install manifest</a>, you need to make the transition to an install manifest now. Firefox 3 no longer supports <code>install.js</code> scripts in XPI files.</div>

<h4 id="Add_localizations_to_the_install_manifest" name="Add_localizations_to_the_install_manifest">Add localizations to the install manifest</h4>

<p>Firefox 3 supports new properties in the install manifest to specify localized descriptions. The old methods still work however the new allow Firefox to pick up the localizations even when the add-on is disabled and pending install. See <a href="/cn/Localizing_extension_descriptions" title="cn/Localizing_extension_descriptions">Localizing extension descriptions</a> for more details.</p>

<h3 id="Step_2_.E7.A1.AE.E4.BF.9D.E6.8F.90.E4.BE.9B.E5.AE.89.E5.85.A8.E7.9A.84.E6.9B.B4.E6.96.B0" name="Step_2:_.E7.A1.AE.E4.BF.9D.E6.8F.90.E4.BE.9B.E5.AE.89.E5.85.A8.E7.9A.84.E6.9B.B4.E6.96.B0">Step 2: 确保提供安全的更新</h3>

<p>If you are hosting addons yourself and not on a secure add-on hosting provider like <a class="link-https" href="https://addons.mozilla.org">addons.mozilla.org</a> then you must provide a secure method of updating your add-on. This will either involve hosting your updates on an SSL website, or using cryptographic keys to sign the update information. Read <a href="/cn/Extension_Versioning,_Update_and_Compatibility#Securing_Updates" title="cn/Extension_Versioning,_Update_and_Compatibility#Securing_Updates">Securing Updates</a> for more information.</p>

<h3 id="Step_3_Deal_with_changed_APIs" name="Step_3:_Deal_with_changed_APIs">Step 3: Deal with changed APIs</h3>

<p>Several APIs have been changed in significant ways. The most significant of these, which will likely affect a large number of extensions, are:</p>

<h4 id="DOM" name="DOM">DOM</h4>


<p>将外部文档的节点插入当前文档之前,你必须使用 <a href="/zh-CN/docs/Web/API/Document/importNode" title="将外部文档的一个节点拷贝一份,然后可以把这个拷贝的节点插入到当前文档中."><code>document.importNode()</code></a> 从外部文档导入源节点,或者使用 <a href="/zh-CN/docs/Web/API/Document/adoptNode" title="从其他的document文档中获取一个节点。 该节点以及它的子树上的所有节点都会从原文档删除 (如果有这个节点的话), 并且它的ownerDocument 属性会变成当前的document文档。 之后你可以把这个节点插入到当前文档中。"><code>document.adoptNode()</code></a>导入源节点,
    想要了解更多的 <a href="/zh-CN/docs/Web/API/Node/ownerDocument" title="Node.ownerDocument 只读属性会返回当前节点的顶层的 document 对象。"><code>Node.ownerDocument</code></a> 问题,请参考 <a class="external" href="http://www.w3.org/DOM/faq.html#ownerdoc" rel="noopener">W3C DOM FAQ</a>.</p>

    <p>即使你不执行导入动作,就执行插入外部文档中的节点.Firefox目前也不会报错(如果严格按标准执行,很多已有的网站都无法正常运行).
    我们鼓励开发者严格按标准修改自己已有的不符合上述标准的代码.</p>

<h4 id="Bookmarks__History" name="Bookmarks_&amp;_History">Bookmarks &amp; History</h4>

<p>If your extension accesses bookmark or history data in any way, it will need substantial work to be compatible with Firefox 3. The old APIs for accessing this information have been replaced by the new <a href="/cn/Places" title="cn/Places">Places</a> architecture. See the <a href="/cn/Places_migration_guide" title="cn/Places_migration_guide">Places migration guide</a> for details on updating your existing extension to use the Places API.</p>

<h4 id="Download_Manager" name="Download_Manager">Download Manager</h4>

<p>The Download Manager API has changed slightly due to the transition from an RDF data store to using the <a href="/cn/Storage" title="cn/Storage">Storage</a> API. This should be a pretty easy transition to make. In addition, the API for monitoring download progress has changed to support multiple download manager listeners. See <code><a href="/zh-CN/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIDownloadManager" title="">nsIDownloadManager</a></code>, <code><a href="/zh-CN/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIDownloadProgressListener" title="">nsIDownloadProgressListener</a></code>, and <a href="/cn/Monitoring_downloads" title="cn/Monitoring_downloads">Monitoring downloads</a> for more information.</p>

<h4 id="Password_Manager" name="Password_Manager">Password Manager</h4>

<p>If your extension accesses user login information using the Password Manager, it will need to be updated to use the new Login Manager API.</p>

<ul>
 <li>The article <a href="/cn/Using_nsILoginManager" title="cn/Using_nsILoginManager">Using nsILoginManager</a> includes examples, including a demonstration of how to write your extension to work with both the Password Manager and the Login Manager, so it will work with both Firefox 3 and earlier versions.</li>
 <li><code><a href="/cn/NsILoginInfo" title="cn/NsILoginInfo">nsILoginInfo</a></code></li>
 <li><code><a href="/cn/NsILoginManager" title="cn/NsILoginManager">nsILoginManager</a></code></li>
</ul>

<p>You can also override the built-in password manager storage if you want to provide your own password storage implementation in your extensions. See <a href="/cn/Creating_a_Login_Manager_storage_module" title="cn/Creating_a_Login_Manager_storage_module">Creating a Login Manager storage module</a> for details.</p>

<h4 id="Popups_.28Menus.2C_Context_Menus.2C_Tooltips_and_Panels.29" name="Popups_.28Menus.2C_Context_Menus.2C_Tooltips_and_Panels.29">Popups (Menus, Context Menus, Tooltips and Panels)</h4>

<p>The XUL Popup system was heavily modified in Firefox 3. The Popup system includes main menus, context menus and popup panels. A guide to <a href="/cn/XUL/PopupGuide" title="cn/XUL/PopupGuide">using Popups</a> has been created, detailing how the system works. One thing to note is that <code>popup.<span id="m-showPopup"><code><a href="https://developer.mozilla.org/zh-CN/docs/Mozilla/Tech/XUL/Method/showPopup">showPopup</a></code></span></code> has been deprecated in favor of new <code>popup.<span id="m-openPopup"><code><a href="https://developer.mozilla.org/zh-CN/docs/Mozilla/Tech/XUL/Method/openPopup">openPopup</a></code></span></code> and <code>popup.<span id="m-openPopupAtScreen"><code><a href="https://developer.mozilla.org/zh-CN/docs/Mozilla/Tech/XUL/Method/openPopupAtScreen">openPopupAtScreen</a></code></span></code>.</p>

<h4 id="Autocomplete" name="Autocomplete">Autocomplete</h4>

<p>The <code><a href="/zh-CN/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIAutoCompleteController" title="">nsIAutoCompleteController</a></code> interface's <code><a href="/cn/NsIAutoCompleteController#handleEnter.28.29" title="cn/NsIAutoCompleteController#handleEnter.28.29">handleEnter()</a></code> method has been changed to accept an argument that indicates whether the text was selected from the autocomplete popup or by the user pressing enter after typing text.</p>

<h4 id="DOMParser" name="DOMParser">DOMParser</h4>

<ul>
 <li>When a <code>DOMParser</code> is instantiated, it inherits the calling code's principal and the <code>documentURI</code> and <code>baseURI</code> of the window the constructor came from.</li>
 <li>If the caller has UniversalXPConnect privileges, it can pass parameters to <code>new DOMParser()</code>. If fewer than three parameters are passed, the remaining parameters will default to <code>null</code>.
  <ul>
   <li>The first parameter is the principal to use; this overrides the default principal normally inherited.</li>
   <li>The second parameter is the <code>documentURI</code> to use.</li>
   <li>The third parameter is the <code>baseURI</code> to use.</li>
  </ul>
 </li>
 <li>If you initialize a <code>DOMParser</code> using a contract, such as by calling <code>createInstance()</code>, and you don't call the <code>DOMParser</code>'s <code>init()</code> method, attempting to initiate a parsing operation will automatically create and initialize the <code>DOMParser</code> with a null principal and <code>null</code> pointers for <code>documentURI</code> and <code>baseURI</code>.</li>
</ul>

<h4 id="Removed_interfaces" name="Removed_interfaces">Removed interfaces</h4>

<p>The following interfaces were removed from Gecko 1.9, which drives Firefox 3. If your extension makes use of any of these, you'll need to update your code:</p>

<ul>
 <li><code>nsIDOMPaintListener</code></li>
 <li><code>nsIDOMScrollListener</code></li>
 <li><code>nsIDOMMutationListener</code></li>
 <li><code>nsIDOMPageTransitionListener</code></li>
 <li><code>nsICloseAllWindows</code> (see <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=386200" title='FIXED: SeaMonkey only: no "view cert button" in untrusted cert error dialog'>bug 386200</a>)</li>
</ul>

<h3 id="Step_4_Check_for_relevant_chrome_changes" name="Step_4:_Check_for_relevant_chrome_changes">Step 4: Check for relevant chrome changes</h3>

<p>There has been a minor change to the chrome that may require changes in your code. A new <code>vbox</code> has been added, called "browser-bottombox", which encloses the find bar and status bar at the bottom of the browser window. Although this doesn't affect the appearance of the display, it may affect your extension if it overlays chrome relative to these elements.</p>

<p>For example, if you previously overlaid some chrome before the status bar, like this:</p>

<pre>&lt;window id="main-window"&gt;
  &lt;something insertbefore="status-bar" /&gt;
&lt;/window&gt;
</pre>

<p>You should now overlay it like this:</p>

<pre>&lt;vbox id="browser-bottombox"&gt;
  &lt;something insertbefore="status-bar" /&gt;
&lt;/vbox&gt;
</pre>

<p>Or use the following technique to make your overlay work on both Firefox 2 and Firefox 3:</p>

<pre>&lt;window id="main-window"&gt;
  &lt;vbox id="browser-bottombox" insertbefore="status-bar"&gt;
    &lt;something insertbefore="status-bar" /&gt;
  &lt;/vbox&gt;
&lt;/window&gt;
</pre>

<div class="blockIndicator note"><strong>Note:</strong> This change is effective for Firefox 3 beta 4 and the pre-beta 4 nightlies.</div>

<h3 id="Other_changes" name="Other_changes">其他方面的修改</h3>

<p><em>Add simple changes you had to make while updating your extension to work with Firefox 3 here.</em></p>

<ul>
 <li><code><a class="external" rel="freelink">chrome://browser/base/utilityOverlay.js</a></code> is no longer supported for security reasons. If you were previously using this, you should switch to <code><a class="external" rel="freelink">chrome://browser/content/utilityOverlay.js</a></code>.</li>
 <li><code><a href="/zh-CN/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIAboutModule" title="">nsIAboutModule</a></code> implementations are now required to support the <code>getURIFlags</code> method. See <a href="https://dxr.mozilla.org/mozilla-central/source/netwerk/protocol/about/public/nsIAboutModule.idl" rel="custom">nsIAboutModule.idl</a> for documentation. This affects extensions that provide new <code>about:</code> URIs. (<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=337746" title='FIXED: [FIX]Move "safe about" hardcoding out of security manager'>bug 337746</a>)</li>
 <li>The <code><a href="/zh-CN/docs/Mozilla/Tech/XUL/tabbrowser" title="tabbrowser">tabbrowser</a></code> element is no longer part of "toolkit" (<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=339964" title="FIXED: move tabbrowser.xml out of mozilla/toolkit and into mozilla/browser">bug 339964</a>). This means this element is no longer available to XUL applications and extensions. It continues to be used in the main Firefox window (browser.xul).</li>
 <li>Changes to <a href="/cn/NsISupports_proxies" title="cn/NsISupports_proxies">nsISupports proxies</a> and possibly to threading-related interfaces need to be documented.</li>
 <li>If you use XML processing instructions, such as <code>&lt;?xml-stylesheet ?&gt;</code> in your XUL files, be aware of the changes made in <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=319654" title="FIXED: Processing instructions in XUL are not added to the content model">bug 319654</a>:
  <ol>
   <li>XML PIs are now added to a XUL document's DOM. This means <a href="/zh-CN/docs/Web/API/Document/firstChild" title="此页面仍未被本地化, 期待您的翻译!"><code>document.firstChild</code></a> is no longer guaranteed to be the root element. If you need to get the root document in your script, use <a href="/zh-CN/docs/Web/API/Document/documentElement" title="Document.documentElement 是一个会返回文档对象(document)的根元素的只读属性(如HTML文档的 &lt;html> 元素)。"><code>document.documentElement</code></a> instead.</li>
   <li><code>&lt;?xml-stylesheet ?&gt;</code> and <code>&lt;?xul-overlay ?&gt;</code> processing instructions now have no effect outside the document prolog.</li>
  </ol>
 </li>
 <li><code>window.addEventListener("load", myFunc, true)</code> is not fired when loading web content (browser page loads). This is due to <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=296639" title="FIXED: Split windows into an inner and outer object">bug 296639</a> which changes the way inner and outer windows communicate. The simple fix here is to use <code>gBrowser.addEventListener("load", myFunc, true)</code> as described <a href="/cn/Code_snippets/Tabbed_browser#Detecting_page_load" title="cn/Code_snippets/Tabbed_browser#Detecting_page_load">here</a> and works in Firefox 2 as well.</li>
 <li><code>content.window.getSelection()</code> gives an object (which can be converted to a string by <code>toString()</code>), unlike the now deprecated <code>content.document.getSelection()</code> which returns a string</li>
 <li><code>event.preventBubble()</code> was deprecated in Firefox 2 and has been removed in Firefox 3. Use <a href="/cn/DOM/event.stopPropagation" title="cn/DOM/event.stopPropagation"><code>event.stopPropagation()</code></a>, which works in Firefox 2 as well.</li>
 <li>Timers that are initiated using <code>setTimeout()</code> are now blocked by modal windows due to the fix made for <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=52209" title="FIXED: JS timers can fire while a modal dialog is open">bug 52209</a>. You may use <code>nsITimer</code> instead.</li>
 <li>If your extension needs to allow an untrusted source (e.g., a web site) to access the extension's chrome, then you must use the new <a href="/cn/Chrome_Registration#contentaccessible" title="cn/Chrome_Registration#contentaccessible"><code>contentaccessible</code> flag</a>.</li>
</ul>