--- title: 为Firefox 3升级扩展 slug: Updating_extensions_for_Firefox_3 tags: - Firefox 3 translation_of: Mozilla/Firefox/Releases/3/Updating_extensions ---

英文原文取自于 http://developer.mozilla.org/en/docs/Extensions 这篇文章将对于那些想把他们的扩展在Firefox 3中正常运行的开发者提供一些有用的信息。

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

第一步: 升级安装文件

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

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

 <em:maxVersion>2.0.*</em:maxVersion>

对于Firefox 3,如下:

 <em:maxVersion>3.0.*</em:maxVersion>

然后重新安装扩展。

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

Note: 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 3.0.* maxVersion to the users until the Firefox 3 release candidate is out. During the Firefox 3 Beta period, you should use 3.0b5 as your maxVersion.


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.

Note: If your extension still uses an Install.js script instead of an install manifest, you need to make the transition to an install manifest now. Firefox 3 no longer supports install.js scripts in XPI files.

Add localizations to the install manifest

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 Localizing extension descriptions for more details.

Step 2: 确保提供安全的更新

If you are hosting addons yourself and not on a secure add-on hosting provider like addons.mozilla.org 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 Securing Updates for more information.

Step 3: Deal with changed APIs

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

DOM

将外部文档的节点插入当前文档之前,你必须使用 document.importNode() 从外部文档导入源节点,或者使用 document.adoptNode()导入源节点, 想要了解更多的 Node.ownerDocument 问题,请参考 W3C DOM FAQ.

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

Bookmarks & History

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 Places architecture. See the Places migration guide for details on updating your existing extension to use the Places API.

Download Manager

The Download Manager API has changed slightly due to the transition from an RDF data store to using the Storage 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 nsIDownloadManager, nsIDownloadProgressListener, and Monitoring downloads for more information.

Password Manager

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

You can also override the built-in password manager storage if you want to provide your own password storage implementation in your extensions. See Creating a Login Manager storage module for details.

Popups (Menus, Context Menus, Tooltips and Panels)

The XUL Popup system was heavily modified in Firefox 3. The Popup system includes main menus, context menus and popup panels. A guide to using Popups has been created, detailing how the system works. One thing to note is that popup.showPopup has been deprecated in favor of new popup.openPopup and popup.openPopupAtScreen.

Autocomplete

The nsIAutoCompleteController interface's handleEnter() 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.

DOMParser

Removed interfaces

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:

Step 4: Check for relevant chrome changes

There has been a minor change to the chrome that may require changes in your code. A new vbox 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.

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

<window id="main-window">
  <something insertbefore="status-bar" />
</window>

You should now overlay it like this:

<vbox id="browser-bottombox">
  <something insertbefore="status-bar" />
</vbox>

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

<window id="main-window">
  <vbox id="browser-bottombox" insertbefore="status-bar">
    <something insertbefore="status-bar" />
  </vbox>
</window>
Note: This change is effective for Firefox 3 beta 4 and the pre-beta 4 nightlies.

其他方面的修改

Add simple changes you had to make while updating your extension to work with Firefox 3 here.