分享

【FireFox】制作可自动升级的扩展

 命運之輪 2011-03-25
firefox 扩展开发—— 制作可自动升级的扩展
2009-02-25 21:29

 

通过 HTTPS 方式

参考文章 http:///archives/2005/03/09/enabling-extension-updates/

这种方式比较简单,根据参考文章照做就行。

如果找不到 支持 https的空间,建议使用 google app engine,不过目前 GAE只支持最大为 1M的文件。

例如 :https://jlufirefox./update.xml

----------------------------------------------------
通过 HTTP 方式


参考文章:(1) https://developer.mozilla.org/en/Extension_Versioning (2) https://developer.mozilla.org/en/Install_Manifests

一 处理安装脚本 install.rdf

添加 updateURL 标签(该url所指向的文件为一个 rdf&xml 格式的文件,文件名任意,但要确保改url所返回的header 类型为 text/rdf, text/xml or application/xml+rdf,否则浏览器端的 update checker无法识别) 例如:

<em:updateURL>http://www./jlufirefox/update.xml</em:updateURL>

这里如果使用https:// 链接,则不需要指定 updateKey,如果使用 http 则必须指定。例如:

   <em:updateKey>MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDK426erD/H3XtsjvaB5+PJqbhj
               Zc9EDI5OCJS8R3FIObJ9ZHJK1TXeaE7JWqt9WUmBWTEFvwS+FI9vWu8058N9CHhD
               NyeP6i4LuUYjTURnn7Yw/IgzyIJ2oKsYa32RuxAyteqAWqPT/J63wBixIeCxmysf
               awB/zH4KaPiY3vnrzQIDAQAB</em:updateKey>

其中的空白符会被 update checker 忽略掉。updateKey 公钥字符串可以使用 McCoy (https://developer.mozilla.org/en/McCoy) 来制作,流程如下:

 

1 . 点击 create 制作新的key

2 右键点击 Copy Public Key(复制的内容就是所需的 updatekey).这个key要留好哦~~,签发扩展是还要用到。

二 处理处理远程更新脚本 update.xml ,

我先把例子贴出来然后一一解释.

<?xml version="1.0" encoding="UTF-8"?>

<RDF:RDF xmlns:RDF="http://www./1999/02/22-rdf-syntax-ns#"
         xmlns:em="http://www.mozilla.org/2004/em-rdf#">
        
<RDF:Description about="urn:mozilla:extension:jlu_ff@">
    <em:updates>
      <RDF:Seq>
        <RDF:li>
          <RDF:Description>
            <em:version>0.1.0</em:version> <!-- This is the version number of the add-on -->
            <em:targetApplication>
              <RDF:Description>
                <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
                <em:minVersion>1.5.*</em:minVersion>
                <em:maxVersion>3.*</em:maxVersion>

                <em:updateLink>http://www./jlufirefox/jlu_ff_0.1.0.xpi</em:updateLink>

                <em:updateHash>sha1:8a9e3b724f68ffde45a72c9c13533cf7a1f10b80</em:updateHash>
               
                <em:updateInfoURL>http://www./jlufirefox/jlu_ff_0.1.0.xhtml</em:updateInfoURL>
              </RDF:Description>
            </em:targetApplication>
          </RDF:Description>
        </RDF:li>

        <RDF:li>
          <RDF:Description>
            <em:version>0.1.1</em:version>
            <em:targetApplication>
              <RDF:Description>
                <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
                <em:minVersion>1.5.*</em:minVersion>
                <em:maxVersion>3.*</em:maxVersion>

                <em:updateLink>http://www./jlufirefox/jlu_ff_0.1.1.xpi</em:updateLink>

                <em:updateHash>sha1:8a9e3b724f68ffde45a72c9c13533cf7a1f10b80</em:updateHash>
               
                <em:updateInfoURL>http://www./jlufirefox/jlu_ff_0.1.1.xhtml</em:updateInfoURL>
              </RDF:Description>
            </em:targetApplication>
          </RDF:Description>
        </RDF:li>
       

      </RDF:Seq>
    </em:updates>

    <em:signature>MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDjJ16Qd8HK/S/KyU6X52BH1HjUrTR22A7UFN9goV9g5oCM4jTMfnto8PIBdPQYMky8Cs8pmSMfEFgiikvS6m6kNZxJpDgV6nFFCgT6xGvzbrVTwhscGNN9Dcowit7sVQPbdxOg62vGwd+2P2092hqB2Tdq0wGiyIfTv4YjnBu+fwIDAQAB</em:signature>
</RDF:Description>
</RDF:RDF>

1.

其中 <RDF:Description about="urn:mozilla:extension:jlu_ff@">

对于firefox扩展必须使用 urn:mozilla:extension 为前缀(see:https://developer.mozilla.org/en/Extension_Versioning%2c_Update_and_Compatibility#Update_RDF_Format)

2.

updateInfoURL 是对新版本的介绍的url。在扩展需要更新时在更新面板中的右侧起作用,例如:

在该更新信息文件中只接受如下标签 <h1><h2><h3><p><ul><ol>,其他的均被忽略。

3 .

updateLink 为 xpi 扩展文件的url。如果需要使用 https:// 链接则不需要指定 updateHash 元素,如果使用http:// 这需要指定 updateHash ,这是为了保证xpi文件的完整性。(see: developer.mozilla.org/en/Extension_Versioning%2c_Update_and_Compatibility#Update_Hashes)

我们可以使用 CoreUtils for Windows (http://gnuwin32./packages/coreutils.htm) 套件中的 sha1sum 工具来或者hash串。例如:

其中 "8a9e3b724f68ffde45a72c9c13533cf7a1f10b80" 就是我们需要的串。另外对于updateHash,还要加上使用的sha算法,这里使用的sha1算法.

   <em:updateHash>sha1:8a9e3b724f68ffde45a72c9c13533cf7a1f10b80</em:updateHash>

4

将前文的 updatekey 添加 signature 到中,例如

   <em:signature>MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDK426erD/H3XtsjvaB5+PJqbhj
               Zc9EDI5OCJS8R3FIObJ9ZHJK1TXeaE7JWqt9WUmBWTEFvwS+FI9vWu8058N9CHhD
               NyeP6i4LuUYjTURnn7Yw/IgzyIJ2oKsYa32RuxAyteqAWqPT/J63wBixIeCxmysf
               awB/zH4KaPiY3vnrzQIDAQAB</em:signature>

然后再用 McCoy 签发 update.xml (当 update.xml 每次改变时都需要签发一次)

 

选择 update.xml 签发,签发之后 update.xml格式变为.

<?xml version="1.0"?>
<RDF:RDF xmlns:em="http://www.mozilla.org/2004/em-rdf#"
         xmlns:NC="http://home./NC-rdf#"
         xmlns:RDF="http://www./1999/02/22-rdf-syntax-ns#">
<RDF:Description RDF:about="rdf:#$nwoYG2"
                   em:version="0.1.0">
    <em:targetApplication RDF:resource="rdf:#$qwoYG2"/>
</RDF:Description>
<RDF:Description RDF:about="rdf:#$qwoYG2"
                   em:id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"
                   em:minVersion="1.5.*"
                   em:maxVersion="3.*"
                   em:updateLink="http://www./jlufirefox/jlu_ff_0.1.0.xpi"
                   em:updateHash="sha1:8a9e3b724f68ffde45a72c9c13533cf7a1f10b80"
                   em:updateInfoURL="http://www./jlufirefox/jlu_ff_0.1.0.xhtml" />
<RDF:Description RDF:about="urn:mozilla:extension:jlu_ff@"
                   em:signature="MIGTMA0GCSqGSIb3DQEBDQUAA4GBAIwLFX3/IHk6BhKylrMu1W4M64AlqcdH1ObFploIxlvYV4Adf0HlEg+mUrtlX6DfHXk5dfjB4pB63RTlkndNDu5YCuwO/8Jvld3fHsZcgK8zN9gZyOZzsAVjwZIVOQ+IJNjpgFdxK6pahgZYjF9vmIbN/HorFGy0oaSsMOUfovIX">
    <em:updates RDF:resource="rdf:#$mwoYG2"/>
</RDF:Description>
<RDF:Description RDF:about="rdf:#$xwoYG2"
                   em:version="0.1.1">
    <em:targetApplication RDF:resource="rdf:#$AwoYG2"/>
</RDF:Description>
<RDF:Seq RDF:about="rdf:#$mwoYG2">
    <RDF:li RDF:resource="rdf:#$nwoYG2"/>
    <RDF:li RDF:resource="rdf:#$xwoYG2"/>
</RDF:Seq>
<RDF:Description RDF:about="rdf:#$AwoYG2"
                   em:id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"
                   em:minVersion="1.5.*"
                   em:maxVersion="3.*"
                   em:updateLink="http://www./jlufirefox/jlu_ff_0.1.1.xpi"
                   em:updateHash="sha1:8a9e3b724f68ffde45a72c9c13533cf7a1f10b80"
                   em:updateInfoURL="http://www./jlufirefox/jlu_ff_0.1.1.xhtml" />
</RDF:RDF>

对于其他的标签同 install.rdf 一样。

如果有版本变动,只需要添加新的 <RDF:li> 。。。 </RDF:li> 内容即可。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多