Chinaunix首页 | 论坛 | 博客
  • 博客访问: 918333
  • 博文数量: 132
  • 博客积分: 9976
  • 博客等级: 中将
  • 技术积分: 1781
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-30 20:40
文章分类

全部博文(132)

文章存档

2013年(1)

2011年(1)

2010年(15)

2009年(77)

2008年(36)

2007年(2)

我的朋友

分类: 系统运维

2009-04-03 10:09:14

编写firfox和thunderbird扩展

http://kb.mozillazine.org/Getting_started_with_extension_development
================================================================================

Getting started with extension development

From MozillaZine Knowledge Base

This page is part of the extension development documentation project.

Ask your questions in . Also .

Note: development documentation is in process of being moved to Mozilla Development Center (MDC).

Two major extension developers' features introduced in Firefox 1.5 were the greatly simplified chrome registration scheme and the . These changes make it even easier to start writing extensions.

This article describes steps needed to get started with extensions development. Last two sections have a few development tips and packaging information. Most of it is targeted at beginners in extension development, although the setup tips should be useful for everybody. This article is concise and doesn't go into discussing the technologies involved; it's more of a crash-course. Another, more detailed tutorial, is available at developer.mozilla.org.

It's a wiki page, so feel free to make improvements to this page and to add your feedback on the Talk page. However questions and requests for help are better suited for the .

Extensions created in this way will only work on Firefox/Thunderbird 1.5 and later, but you should be able to make changes to ensure your extension is compatible with Firefox 1.0 quite easily.

Again, this will work only in Firefox/Thunderbird 1.5 or later, not 1.0.x! Not 1.0.6, 1.0.7 or anything like that. Only 1.5 or later.

Contents

[]

Setting up your environment

This article focuses on Firefox extensions, although it also applies to other Toolkit applications, such as Thunderbird.

The first thing you need to do is download a recent version of your application. You can get Firefox . As was mentioned above, you need Firefox 1.5 or later, setup tips from this article will not work in earlier versions.

For further instructions, see Setting up extension development environment. Do read that page, it will save you many hours when developing and debugging your extension. In particular, you must set the javascript.options.showInConsole pref to true.

What this Extension Does

This extension adds an item called 'Hello World!' to the Tools Menu in Firefox. It's a good example of creating an extension that pops up a new window when you activate it.

Planning your extension

You should plan what you need for your extension; we will use an example that provides a new menu option that creates a message in a window. The following files are required, choose your own names if you like (but if you change any names remember to update all references to them), except for the folders and files 'chrome.manifest' and 'install.rdf'.

FilenamePurpose
chrome.manifestTells Firefox where your chrome files are and what to do with them
install.rdfThe description file for your extension ("Install manifest")
overlay.xulThe file describing UI elements to add to the browser window
overlay.jsThe file with scripts to run in the browser window
overlay.dtdContains translation for text string codes in overlay.xul
hello.dtdContains translation for the strings in hello.xul
overlay.cssLets you adjust appearance of UI elements with CSS
hello.xulThe file describing the UI of the new window
helloworld@mozilla.doslash.orgA pointer to your extension files

Creating stub extension files

As you should already know, extensions usually modify an application's UI ("chrome") and behavior by providing overlays to already existent windows/documents. Those overlays are a part of the extension's content package (content provider). Most extensions also have one or more locales and skins. (If you didn't know that, we advise you to read chapter from XULPlanet's XUL Tutorial and document).

This section describes what directory structure and what files are needed in order to make Firefox register your extension's files.

You can download the with all necessary stub files and appropriate folder structure and skip to Registering your extension in the Extension Manager. It's recommended that you nonetheless read the below subsections, as they explain the function of each file in the package and provide links to other resources.

Folder structure

Below is the folder structure we will use. You may use a different structure, as long as you also update your chrome.manifest (see below) accordingly. Create the following structure in the folder where you intend to develop your project:

helloworld/
chrome.manifest
install.rdf
content/
overlay.js
overlay.xul
hello.xul
locale/
en-US/
overlay.dtd
hello.dtd
skin/
overlay.css

The folders are traditionally named "content", "locale" and "skin", and you should follow the tradition. You may call the files inside those folders whatever you want (except chrome.manifest and install.rdf).

Note: This folder structure is for development, you'll need different folder structure when packaging your extension.

Stub files

chrome.manifest

Recent versions of Firefox read a simple plaintext chrome.manifest file (instead of the old and confusing ) to determine what packages and overlays your extension provides. The format of this file is described in the Chrome Registration document. In the following example we'll create a chrome.manifest file for our folder structure.

It looks like this (assuming your extension's package name is "helloworld"):

1
2
3
4
5
6
7

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

locale helloworld en-US locale/en-US/

skin helloworld classic/1.0 skin/
style chrome://global/content/customizeToolbar.xul chrome://helloworld/skin/overlay.css

What each line of the file does:

  • Line 1 registers a content provider: it maps the contents of chrome://helloworld/content/ to the content folder.
  • Line 2 registers an overlay for chrome://browser/content/browser.xul location, allowing you to modify Firefox's main window UI from your overlay.xul file.
  • Line 4 registers a en-US locale provider.
  • Line 6 registers a default skin provider.
  • Line 7 applies your overlay.css style file to chrome://global/content/customizeToolbar.xul document (used, for example, when ). You could instead register an overlay and include the stylesheet in the overlay using the processing instruction.

Warning: Don't forget the end slash at the end of the paths : "content/" works, whereas "content" doesn't. Also note that the package name ('helloworld' in this case) has to be all lowercase.

Note: this file will be a bit different when you create an XPI for your extension, see the Packaging section below.

overlay.xul

overlay.xul is a simple XUL overlay. You can read more about overlays at and MDC.

A simple overlay looks like this:

1
2
3
4
5
6
7
8
9
10
11
12




    xmlns="">
   阅读(834) | 评论(0) | 转发(0) |

0

上一篇:静态库的生成方法

下一篇:linux i2c driver

给主人留下些什么吧!~~