From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/extensions/firefox/index.html | 11 + files/zh-cn/extensions/index.html | 140 ++++++++ files/zh-cn/extensions/mobile/index.html | 76 +++++ .../index.html" | 369 +++++++++++++++++++++ 4 files changed, 596 insertions(+) create mode 100644 files/zh-cn/extensions/firefox/index.html create mode 100644 files/zh-cn/extensions/index.html create mode 100644 files/zh-cn/extensions/mobile/index.html create mode 100644 "files/zh-cn/extensions/\345\274\225\345\257\274\345\236\213\346\211\251\345\261\225/index.html" (limited to 'files/zh-cn/extensions') diff --git a/files/zh-cn/extensions/firefox/index.html b/files/zh-cn/extensions/firefox/index.html new file mode 100644 index 0000000000..9bbac87b84 --- /dev/null +++ b/files/zh-cn/extensions/firefox/index.html @@ -0,0 +1,11 @@ +--- +title: Firefox +slug: Extensions/Firefox +translation_of: Mozilla/Add-ons +--- +

The following articles provide help with developing extensions for Firefox. In addition, please refer to the general extension documentation that applies to all Mozilla applications. In the future, you may also develop extensions with an alternative, trimmed down but simpler API developed at Mozilla labs' Jetpack project.

+ +

Documentation

Community

  • View Mozilla forums...

{{ DiscussionList("dev-extensions", "mozilla.dev.extensions") }}

Tools

... more tools ...

View All...

XUL, JavaScript, XPCOM, Themes, Developing Mozilla
+
+

{{ languages( { "ja": "ja/Extensions/Firefox" } ) }}

+
diff --git a/files/zh-cn/extensions/index.html b/files/zh-cn/extensions/index.html new file mode 100644 index 0000000000..7dbf1a691f --- /dev/null +++ b/files/zh-cn/extensions/index.html @@ -0,0 +1,140 @@ +--- +title: 扩展 +slug: Extensions +tags: + - Extensions + - 扩展 +translation_of: Mozilla/Add-ons +--- +
+ 构建一个扩展
+ 一步步地了解如何为 Firefox 构建一个扩展。
+
+

扩展是能为 Mozilla 程序(例如 Firefox、Seamonkey和 Thunderbird)添加新功能的小巧的附加软件。从工具栏按钮到全新特性,它们能添加任何东西。它们允许用户定制程序,以适合自己的个性需要(如果他们需要新的特性);同时又保持了程序的小巧,方便下载。

+

扩展不同于插件,插件帮助浏览器现实类似于播放多媒体文件这样的特定的内容。扩展也不同于搜索插件,搜索插件在搜索栏插入附加的搜索引擎。

+
+

基本取自于 Mozilla Update 中国,但是也有不少修改的地方。

+ + + + + + + +
+

文档

+

 

+

常规 (适用于全部 Mozilla 应用程序)

+
+
+ 设置扩展的开发环境
+
+ 一些可以令开发扩展更容易的设置的精华提示。
+
+ 引导式扩展 {{gecko_minversion_inline("2.0")}}
+
+ 介绍创建无需重启即可被安装、卸载和升级的扩展的方法。
+
+ XUL 学习教程
+
+ 一个全面的扩展开发教程
+
+ 构建一个扩展
+
+ 一步步地阐述如何创建一个扩展。
+
+ 内嵌选项
+
+ {{gecko_minversion_inline("7.0")}}
+
+ 介绍如何自定义在Firefox 7开始出现的内嵌在附加组件管理器窗口中的新用户界面。
+
+ 扩展安全性指导(英)
+
+ 指导开发人员,以确保用户扩展的安全性
+
+ 扩展性能指导(英)
+
+ 介绍如何创建优质且高效的扩展。
+
+ 扩展用户体验指导(英)
+
+ 通用的尽可能提高扩展用户体验的做法。
+
+ 扩展打包
+
+ 如何把你的 Firefox 扩展打包,以供下载和安装。
+
+ XUL
+
+ 介绍用于描述Mozilla扩展用户界面的XUL标记语言。
+
+ 性能(英)
+
+ 提供一些帮助你提高附加组件性能(且体验良好)的指导和工具。
+
+ 安装扩展(英)
+
+ 介绍如何以编程方式安装扩展。
+
+ 提交附加组件到AMO(英)
+
+ 如何发布你的附加组件AMO
+
+ 扩展的常见问题解答
+
+ 关于扩展开发的常见问题解答。
+
+

针对特定程序的指导

+

Firefox(英语)

+

Thunderbird(英语)

+

SeaMonkey(英语)从SeaMonkey 2起支持扩展

+

Firefox 安卓版

+

Fennec(英语) (移动版火狐)

+

查看所有“扩展”标签…

+
+
+
+

社区

+

估计相当长时间内都不会被我们中国用户使用的东西,我就省略了。

+ 查看Mozilla扩展开发论坛{{DiscussionList("dev-extensions", "mozilla.dev.extensions")}} + +

工具

+ +

... more tools ...

+ +

查看所有…

+

相关页面

+ +

相关话题

+
+
+ XUL, JavaScript, XPCOM, Themes, Developing Mozilla
+
+
+

Categories

+

Interwiki Language Links

diff --git a/files/zh-cn/extensions/mobile/index.html b/files/zh-cn/extensions/mobile/index.html new file mode 100644 index 0000000000..e1608005d8 --- /dev/null +++ b/files/zh-cn/extensions/mobile/index.html @@ -0,0 +1,76 @@ +--- +title: Extensions for Firefox for Android +slug: Extensions/Mobile +translation_of: Archive/Add-ons/Legacy_Firefox_for_Android +--- +

{{LegacyAddonsNotice}}{{AddonSidebar}}

+ +

下面的文章为想要开发Firefox for Android扩展的人提供了帮助.

+ +

In addition, please refer to the general extension documentation that applies to all Mozilla applications.

+ + + + + + + + +
+

Documentation

+ +
Tutorials
+ +
+
Walkthrough
+
Developing, packaging and installing a simple add-on for Firefox for Android.
+
Initialization and Cleanup
+
How to initialize your add-on when it is started and clean up when it is shut down.
+
Creating a UI
+
A quick guide to using the NativeWindow API to create user interface components.
+
Interacting with the Browser
+
A quick guide to using the BrowserApp API to access browser tabs and the web content they host.
+
+ +
API Reference & Code Samples
+ +
+
NativeWindow
+
Create native Android UI widgets.
+
BrowserApp
+
Access browser tabs and the web content they host.
+
Code Snippets
+
Code samples for common tasks
+
+
+

Community

+ +
    +
  • +

    View Mozilla extension development forums...

    +
  • +
+ +

{{ DiscussionList("dev-extensions", "mozilla.dev.extensions") }}

+ + + +

Tools

+ +

 

+ +

View All...

+
+ + + +
+
XUL, JavaScript, XPCOM, Themes, Developing Mozilla
+
+ +

View all pages tagged with "Extensions"...

+ +

 

diff --git "a/files/zh-cn/extensions/\345\274\225\345\257\274\345\236\213\346\211\251\345\261\225/index.html" "b/files/zh-cn/extensions/\345\274\225\345\257\274\345\236\213\346\211\251\345\261\225/index.html" new file mode 100644 index 0000000000..49420e5a8a --- /dev/null +++ "b/files/zh-cn/extensions/\345\274\225\345\257\274\345\236\213\346\211\251\345\261\225/index.html" @@ -0,0 +1,369 @@ +--- +title: 自引导型扩展 +slug: Extensions/引导型扩展 +translation_of: Archive/Add-ons/Bootstrapped_extensions +--- +

browser.bookmarks.export( function() {...} // optional function ){{LegacyAddonsNotice}}{{AddonSidebar}}

+ +

{{ gecko_minversion_header("2.0") }}

+ +
+

注意:所有使用 Add-on SDK 创建的扩展都是自引导的。其引导代码已经自动生成,所以你不必考虑该问题。没有使用 Add-on SDK?那就继续读下去吧……

+
+ +

传统形式的扩展包含覆盖接口程序段(overlay),应用程序可以从扩展的程序包中载入 XUL,并自动将其覆盖在自己的 UI 之上。这使得创建的扩展加入到应用程序的用户界面比较容易,但同时更新、安装或禁用扩展需要应用程序重启。

+ + +

Traditional extensions include overlays, wherein the application can load up XUL from the extension's package and automatically apply it on top its own UI. While this makes creating extensions that add to the application's user interface relatively easy, it means that updating, installing, or disabling an extension requires an application restart.

+ + +

Gecko 2.0 {{ geckoRelease("2.0") }} 引入了自引导型(bootstrapped)扩展。这是种特别的扩展,它们不使用覆盖界面来将它们的用户界面应用到应用程序中,而是用程序将它们自己插入到应用程序。这是通过包含在扩展中的一个特制的脚本文件来实现,脚本中包含了一些函数可供浏览器调用,来指挥扩展的安装、卸载、启动和关闭。

+ +

应用程序所需做的就是调用该脚本文件;由扩展负责添加和去除它的用户界面,和处理任何其它所需的设置和关闭任务。

+ +

本文论述了自引导型扩展将如何工作。

+ +

作为题外话,所有用 Add-on SDKAdd-on Builder 创建的扩展都是自引导型的;但是,所有的引导代码都是为您特别生成的,所以实际上您并不需要真的去研究它。

+ +

启动和关闭程序(process)

+ +

自引导型扩展的一个关键特征是,它们必须按照应用程序的要求启动和关闭。当扩展的 startup() 函数被调用,它必须手动将它的用户界面和其它行为注入到应用程序中。同样,当它的 shutdown() 函数被调用,它必须移除添加到应用程序中的任何东西,也包括对它的所有对象的所有引用。

+ +

startup() 函数会在多个场景中被调用;比如:

+ + + +

shutdown() 函数会被调用的一些场景:

+ + + +

修改应用程序用户界面的说明

+ +

引导型附加组件中的 chrome.manifest

+ +

您可以在自引导型附加组件中使用 chrome.manifest 文件来:

+ +
    +
  1. 通过 chrome:// URL[在清单(manifest)中使用 contentlocaleskin 指令]使您附加组件的内容生效;
  2. +
  3. 用您的内容替换已经存在的 chrome:// URI(使用 override 指令)。
  4. +
+ +

不是所有的 chrome.manifest 指令都被自引导型附加组件支持,比如在自引导型附加组件中,您仍然不能注册 XUL 覆盖界面。详见 chrome.manifest 文档。

+ +

在 Firefox 10 及以上版本中,放在附加组件 XPI 根目录下的 chrome.manifest 文件(与 install.rdf 同级)会被自动加载。在 Firefox 8 和 9 中,您必须手动加载/卸载清单,使用 {{ ifmethod("nsIComponentManager", "addBootstrappedManifestLocation") }} 和 {{ ifmethod("nsIComponentManager", "removeBootstrappedManifestLocation") }}。该特征在 Firefox 8 以前的版本中无效。

+ +

手动添加用户界面

+ +

如果您决定继续尝试开发一个修改应用程序用户界面的自引导型扩展,这儿有几个建议给您。

+ +

您需要在相关应用程序中调用 {{ domxref("document.getElementById()") }},通过 UI 元素的 ID 来查找它们,然后操纵它们来注入您的 UI。例如,您可以通过 document.getElementById("main-menubar") 来访问 Firefox 的菜单栏。

+ +

确保在关闭时移除您添加的任何用户界面。

+ +

创建自引导型扩展

+ +

为标示一个扩展为可引导的,您需要添加下列元素到它的 安装清单

+ +
<em:bootstrap>true</em:bootstrap>
+ +

然后您需要添加一个 bootstrap.js 文件,它包含所要求的函数;在扩展的包中,它应该与 install.rdf 文件同级。

+ +

向后兼容

+ +

因为旧版本的 Firefox 并不知道 bootstrap 属性或 bootstrap.js 文件,创建一个既能作为可引导扩展又能作为传统扩展来工作的 XPI 不是特别困难。按照可引导扩展来创建您的扩展,然后同样地添加传统的覆盖界面。新版本的 Firefox 将使用 bootstrap.js 脚本并忽略部件(components)和覆盖界面,同时旧版本将使用覆盖界面。

+ +

引导切入点(entry points)

+ +

bootstrap.js 脚本应该包含几个特殊函数,浏览器调用它们来管理扩展。该脚本被放在一个有特权的(privileged)沙箱中执行,这个沙箱一直被保存(cached)到扩展关闭。

+ +

startup

+ +

当扩展需要启动它自己时被调用。它发生在应用程序启动时,或启用被禁用的扩展时(或在为安装更新而被关闭后)。可见,在应用程序的生命期内,它会被多次调用。

+ +

您的附加组件应当在这时注入 UI,启动任何可能需要运行的任务,等等。

+ +
void startup(
+  data,
+  reason
+);
+
+ +
参数
+ +
+
data
+
引导数据结构
+
reason
+
原因常量之一,表明扩展为什么被启动。可以是 APP_STARTUPADDON_ENABLE、ADDON_INSTALLADDON_UPGRADEADDON_DOWNGRADE 之一。
+
+ +

shutdown

+ +

当扩展需要关闭它自己时被调用,比如应用程序退出时,或准备更新/禁用扩展时。在这里必须移除所有已被注入的用户界面,关闭所有任务,并处理掉所有对象。

+ +
void shutdown(
+  data,
+  reason
+);
+
+ +
参数
+ +
+
data
+
引导数据结构
+
reason
+
原因常量之一,表明扩展为什么被关闭。可以是 APP_SHUTDOWNADDON_DISABLE、ADDON_UNINSTALL、ADDON_UPGRADEADDON_DOWNGRADE 之一。
+
+ +

install

+ +

您的引导脚本必须包括 install() 函数,应用程序在安装、升级或降级扩展后,第一次调用 startup() 之前调用它。

+ +
注意:如果从未启动扩展,则不会调用该方法;例如,如果扩展虽被安装但并不兼容当前版本的应用程序,且在变为兼容之前被卸载,则 install() 始终不会被调用。但是,如果扩展被升级到一个兼容应用程序的版本,将在第一次调用 startup() 之前调用它的 install() 函数。
+ +
void install(
+  data,
+  reason
+);
+
+ +
参数
+ +
+
data
+
引导数据结构
+
reason
+
原因常量之一,表明扩展为什么被安装。可以是 ADDON_INSTALLADDON_UPGRADEADDON_DOWNGRADE 之一。
+
+ +

uninstall

+ +

该函数在卸载扩展的某个版本之前,最后一次调用 shutdown() 之后被调用。如果始终未调用 install(),也不会调用此函数。

+ +
注意:记住这一点很重要——即使对于当前被禁用或不兼容当前应用程序的扩展,都会被调用 uninstall()。鉴于此,在实现该函数时,优雅地处理那些也许并不存在于应用程序中的 API 变得非常重要。如果一个第三方应用程序在 Firefox 未运行时移除了该扩展,该函数也不会被调用。
+ +
Note: The uninstall function fires on downgrade and upgrade as well so you should make sure it is an uninstall by doing this:
+function uninstall(aData, aReason) {
+ if (aReason == ADDON_UNINSTALL) {
+ console.log('really uninstalling');
+ } else {
+ console.log('not a permanent uninstall, likely an upgrade or downgrade');
+ }
+}
+ +
void uninstall(
+  data,
+  reason
+);
+
+ +
参数
+ +
+
data
+
引导数据结构
+
reason
+
原因常量之一,表明扩展为什么被卸载。可以是 ADDON_UNINSTALLADDON_UPGRADEADDON_DOWNGRADE 之一。
+
+ +

原因常量

+ +

上述引导函数都接受一个 reason 参数,该参数向扩展解释为什么调用该函数。 这些原因常量如下:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
常量描述
APP_STARTUP1应用程序启动。
APP_SHUTDOWN2应用程序关闭。
ADDON_ENABLE3启用附加组件。
ADDON_DISABLE4禁用附加组件。(同时被错用于卸载
ADDON_INSTALL5安装附加组件。
ADDON_UNINSTALL6卸载附加组件。
ADDON_UPGRADE7升级附加组件。
ADDON_DOWNGRADE8降级附加组件。
+ +

引导数据

+ +

每个切入点被传入一个简单的数据结构,它包含一些关于引导附加组件的有用信息。调用 AddonManager.getAddonByID() 可以获得更多关于附加组件的信息。该数据是一个简单的 JavaScript 对象,它包括以下属性:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
属性类型描述
idstring被引导附加组件的 ID。
versionstring被引导附加组件的版本。
installPathnsIFile被引导附加组件的安装位置。可能是一个目录或一个 XPI 文件,这取决于安装该附加组件时是否解包。
resourceURInsIURI附加组件文件根目录的 URI,可能是 jar:file: URI,这取决于安装该附加组件时是否解包。{{ gecko_minversion_inline("7.0") }}
oldVersionstring以前的安装版本,如果原因是 ADDON_UPGRADEADDON_DOWNGRADE,并且方法是 installstartup。{{ gecko_minversion_inline("22.0") }}
newVersionstring将要安装的版本,如果原因是 ADDON_UPGRADEADDON_DOWNGRADE,并且方法是 shutdownuninstall。{{ gecko_minversion_inline("22.0") }}
+ +
+

注意:附加组件可能会在程序启动时升降级,此时 startup 方法的原因是 APP_STARTUP,并且不会设置 oldVersion 属性。 另外需注意,在某些情形下有可能发生附加组件升降级但 uninstall 方法没有被调用的情况。

+
+ + +

拓展调试器

+ +

From Firefox 31 onwards, you can use the Add-on Debugger to debug bootstrapped add-ons.

+ +

本地化(L10n)

+ +

Localizing bootstrapped add-ons is very much the same since Firefox 7, as that is when chrome.manifest compatibility landed.

+ +

JS and JSM Files - Using Property Files

+ +

To localize your .js and .jsm files you have to use property files.

+ +

The absolute minimum needed here is:

+ +
    +
  1. File: install.rdf
  2. +
  3. File: chrome.manifest
  4. +
  5. File: bootstrap.js
  6. +
  7. Folder: locale +
      +
    1. Folder: VALID_LOCALE_HERE +
        +
      1. File: ANYTHING.properties
      2. +
      +
    2. +
    +
  8. +
+ +

In the locale folder you must have folders for each of the languages you want to provide; each folder must be named a valid locale (ex: en-US). Inside this folder must be a property file. Inside the chrome.manifest file these locale must be defined. For example if you had a subfolder of en-US in locale folder your chrome.manifest file will have to contain: locale NAME_OF_YOUR_ADDON en-US locale/en-US/

+ +

Here is an example: GitHub :: l10n-properties - on startup of this add-on it will show a prompt saying USA or Great Britain, which ever it deems closest to your locale. You can test different locale by going to about:config and changing preference of general.useragent.locale to en-US and then to en-GB and disabling then re-enabling the add-on.

+ +

XUL and HTML Files - Using Entities from DTD Files

+ +

Many times HTML pages are used, however they cannot be localized with DTD files. There are three changes you must make:

+ +
    +
  1. You have to change the HTML file's extension to be .xhtml
  2. +
  3. The doctype must be defined point to a DTD file in your locale folder such as: <!DOCTYPE html SYSTEM "chrome://l10n/locale/mozilla.dtd">
  4. +
  5. Must add xmlns attribute to html tag for example: <html xmlns="http://www.w3.org/1999/xhtml">
  6. +
  7. If you have multiple DTD files read on here: Using multiple DTDs
  8. +
+ +

The bare minimum needed is:

+ +
    +
  1. File: install.rdf
  2. +
  3. File: chrome.manifest
  4. +
  5. File: bootstrap.js
  6. +
  7. Folder: locale +
      +
    1. Folder: VALID_LOCALE_HERE +
        +
      1. File: ANYTHING.dtd
      2. +
      +
    2. +
    +
  8. +
+ +

The chrome.manifest file must include a definition for content for example: content NAME_OF_YOUR_ADDON ./

+ +

The chrome.manifest file must also include a line pointing to the locale, just like in the above property section, if you had a folder named en-US in locale, the chrome.manifest file should contain: locale NAME_OF_YOUR_ADDON en-US locale/en-US/

+ +

Here is an example add-on that opens an HTML page and a XUL page on install: GitHub :: l10n-xhtml-xul. Here is an example showing how to use a localized HTML page as an options page: GitHub :: l10n-html-options. You can go to about:config and change the value of the preference general.useragent.locale to en-US and then to en-GB and then reload the open pages to see the localization change.

+ + +

延伸阅读

+ + -- cgit v1.2.3-54-g00ecf