Helloworld 套件製作
出自 MozTW Wiki
前言
關於套件的開發,在台灣的腳步似乎慢了不少,在此,建立此篇文章,幫助想要開發套件的設計者踏出第一步。
來源:Writing an Extension for Firefox
http://www.dubh.org/jdevimages/ff_hello_toolsmenu.png http://www.dubh.org/jdevimages/ff_hello_extman.png
建立內容檔
建立 contents.rdf ,這個檔案是用來描述套件的內容。一開始,必須建立幾個目錄,以及 contents.rdf 檔案。
結構如下:
c:\myextensions\
- + - helloworld
- + - content
- + - contents.rdf
- + - contents.rdf
- + - content
myextensions 是自訂的目錄,其下包含一個子目錄 helloworld,在 helloworld 下再建立子目錄 content,
並建立一個文字檔 contents.rdf。
將下列程式碼放置在 contents.rdf,編碼格式為 UTF-8:
<?xml version="1.0"?>
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
<RDF:Seq about="urn:mozilla:package:root">
<RDF:li resource="urn:mozilla:package:helloworld"/>
</RDF:Seq>
<RDF:Description about="urn:mozilla:package:helloworld"
chrome:displayName="Hello World"
chrome:author="Brian Duff"
chrome:authorURL="http://modev.dubh.org/helloworld"
chrome:name="helloworld"
chrome:extension="true"
chrome:description="A simple demonstration firefox extension.">
</RDF:Description>
<RDF:Seq about="urn:mozilla:overlays">
<RDF:li resource="chrome://browser/content/browser.xul"/>
</RDF:Seq>
<RDF:Seq about="chrome://browser/content/browser.xul">
<RDF:li>chrome://helloworld/content/helloworld-Overlay.xul</RDF:li>
</RDF:Seq>
</RDF:RDF>
覆載(overlay)使用者介面元件
建立 helloworld-Overlay.xul 檔案,將其放置在 content 目錄下,與 contents.rdf 同一目錄。
將下列程式碼放置在 helloworld-Overlay.xul,編碼格式為 UTF-8:
<?xml version="1.0"?>
<overlay id="helloworldOverlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<menupopup id="menu_ToolsPopup">
<menuitem label="Hello World" position="1" />
</menupopup>
</overlay>
建立安裝清單
建立 install.rdf 檔案,將其放置在 helloworld 目錄下。
將下列程式碼放置在 install.rdf,編碼格式為 UTF-8:
<?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:name>Hello World</em:name>
<em:id>{12a1584b-2123-473d-8752-e82e74e3cb1b}</em:id>
<em:version>0.1</em:version>
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>0.9</em:minVersion>
<em:maxVersion>1.5.*</em:maxVersion>
</Description>
</em:targetApplication>
<em:file>
<Description about="urn:mozilla:extension:file:helloworld.jar">
<em:package>content/</em:package>
</Description>
</em:file>
</Description>
</RDF>
在這一段落
<em:name>Hello World</em:name>
<em:id>{12a1584b-2123-473d-8752-e82e74e3cb1b}</em:id>
<em:version>0.1</em:version>
em:id 的內容是全球唯一代號(GUID),這是為了區別這個套件與其他套件。
在建立你自己的套件時,應該用GUID 產生器產生一組與其他套件不同的代號,
包裝套件安裝檔
這是最後一件你要做的事,就是將套件封裝起來以方便安裝。
首先,將 content 以 zip 格式壓縮成 helloworld.jar。
helloworld.jar
- + - content
- + - contents.rdf
- + - helloworld-Overlay.xul
- + - contents.rdf
並在 helloworld 目錄下建立 chrome 目錄,將 helloworld.jar 放置在 chrome 目錄,
再將 install.rdf 及 chrome 以 zip 格式壓縮成 helloworld.xpi。
helloworld.xpi
- + - install.rdf
- + - chrome/
- + - helloworld.jar
- + - chrome/
安裝測試
將你建立的 helloworld.xpi 拉到 Firefox 視窗測試。
‧返回上一頁: 開發人員文件主頁
