Firefox 扩展开发 install.rdf和chrome.manifest

现在我们以一个hello world扩展为例来说明Firefox 扩展的基本运行方式。先下载 Hello World extension,解压缩,下面假定路径是c:\helloworld.
设置firefox扩展代理文件

Firefox 扩展包实际上就是一个zip压缩文件,显然开发时每做一点改动都重新打包安装会很麻烦。firefox提供了一种代理机制,可以把文件夹作为一个扩展。编辑扩展包中的文件helloworld@mozilla.doslash.org,把内容改为c:\helloworld,复制到配置dev\extensions,运行firefox,会出现提示,安装了新扩展的,但不兼容新版本(如果你用的是2.0以后版本)。

install.rdf
现在我们来看install.rdf文件:

<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>helloworld@mozilla.doslash.org</em:id>
<em:name>Hello World (Firefox 1.5 edition)</em:name>
<em:version>1.0</em:version>
<em:description>Classic first extension from MozillaZine KB</em:description>
<em:creator>Nickolay Ponomarev</em:creator>
<!-- optional items -->
<em:contributor>A person who helped you</em:contributor>
<em:contributor>Another one</em:contributor>
<em:homepageURL>http://kb.mozillazine.org/Getting_started_with_extension_development</em:homepageURL>
<!--em: optionsURL>chrome://sampleext/content/settings.xul</em: optionsURL>
<em:aboutURL>chrome://sampleext/content/about.xul</em:aboutURL>
<em:iconURL>chrome://sampleext/skin/mainicon.png</em:iconURL>
<em:updateURL>http://sampleextension.mozdev.org/update.rdf</em:updateURL-->
<!-- Firefox -->
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>1.5</em:minVersion>
<em:maxVersion>3.5.*</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

  • helloworld@mozilla.doslash.org,扩展的ID,email格式,但不应该是你实际的email,扩展代理文件用作文件名。
  • em:minVersion,em:maxVersion,兼容的firefox最小和最大版本。

修改em:maxVersion为合适值,重新安装扩展,菜单->工具项会多出了一项红色“Hello World!",点击会弹出一个新窗口。

chrome.manifest

Chrome 指的是应用程序窗口的内容区域之外的用户界面元素的集合,这些用户界面元素包括工具条,菜单,进度条和窗口的标题栏等。Chrome 提供者能为特定的窗口类型(如浏览器窗口)提供 chrome。有三种基本的 chrome 提供者:

* 内容(Content):通常是 XUL 文件。
* 区域(Locale) :存放本地化信息。
* 皮肤(Skin):描述 chrome 的外观。通常包含 CSS 和图像文件。
firefox通过Chrome URIs来存取这些文件,比如chrome://browser/content/browser.xul是浏览器的主界面,在地址栏输入这个URL试试。

文件chrome.manifest用来注册Chrome包和物理地址的对应关系,简单的说明:

content helloworld content/

这句定义了helloworld包的content的实际位置为content/目录,最后的斜线是必须的

overlay chrome://browser/content/browser.xul chrome://helloworld/content/overlay.xul

覆盖(overlay):这句把overlay.xul合并到browser.xul上。

locale helloworld en-US locale/en-US/

英语

skin helloworld classic/1.0 skin/

皮肤

style chrome://global/content/customizeToolbar.xul chrome://helloworld/skin/


posted on 2013-04-02 16:11  马晓锋  阅读(496)  评论(0编辑  收藏  举报