2008年11月4日星期二

开发Firefox插件入门

开发Firefox插件实际上就是写xul,css,js然后把它们package为xpi(其实就是zip),开始开发之前先要配置好开发环境。首先就是:
设置Firefox
firefox非常强大,我们要为它开发插件首先就是要单独配置一个profile,免得开发工作造成日常使用的firefox出毛病。
  • tags: no_tag

    • To get started setting up your multiple browser users, you'll start up the Firefox profile manager. To do so, from the command line, run Firefox with the --profilemanager argument.
    • firefox.exe -P blogging starts up the blogging profile.
    • By default you can't run two different Firefox profiles at the same time
    • So you'd edit the shortcut in the screenshot above to read:

      \path\to\firefox.exe -P buffy -no-remote
    • This is also useful if you want to run different Firefox versions at once, for example if you want to run Firefox 3 Beta, but still want to keep all your current extensions working in Firefox 2. Just use different profiles for each of the versions. You can only run one version at a time though, although that might be fixed with the MOZ_NO_REMOTE=1
    • As of Firefox 2.0, you can also use the "-no-remote" command line option instead of setting the var in a batch file
    • It's also worth noting that using no-remote breaks external links. That is, if you click on a link from your favorite chat client, the link will not open in your Firefox instance.

      A way around this, assuming you want to run two profiles at once, is to start your primary Firefox instance normally, and then start your second instance using -no-remote. This way, external links will still work (they will open in the primary instance).

选择IDE
虽然在大部分的教程中说到firefox extension的开发,都是直接使用文本编辑工具和一些firefox的插件。这其中,当然有firebug、DOM Inspector这些东东啦。不过,最特别的是Extension Developer,特别为插件开发定制,有一组很好用的工具。然而,高效的开发当然离不开自动完成、上下文提示、自动语法检查和更正建议等等功能,我们需要一个IDE。
google了下这方面口碑较好的有XULBooster和Spket。由于,XULBooster比较重量级(虽然都是for eclipse, 但是需要wtp2.0),我暂时没有安装它,而是选择了Spket。
  • Spket IDE is powerful toolkit for JavaScript and XML development. The powerful editor for JavaScript, XUL/XBL and Yahoo! Widget development. The JavaScript editor provides features like code completion, syntax highlighting and content outline that helps developers productively create efficient JavaScript code.

    tags: no_tag

不幸的是,这个鸟东东没有XUL的runner,我想在接下来的开发中多少会有不便的。虽然可以使用Extension Developer提供的,但是C & P过来过去的肯定不是好办法。
而且,这厮竟然要注册(上帝啊,原谅我说脏话、不厚道),我只好对其com.spket.ui.internal.License 痛下杀手了(BS下自己先,做为软件从业人员,竟然吃里扒外)。现在搞定了这个东东,试试看是否有愉快的体验呢。我在这里声明,一旦从这个东东上获益,make any money from it,我一定买个License。

开发入门
说实话,这个插件开发的技术比较简单,这是几个比较有用的资源。对了,还有一本书《Programming Firefox》不错,正在看。
  • 在eclipse中动态开发Firefox扩展

    tags: eclipse, firefox, firefox extension

    • XULBooster与spket
  • tags: no_tag

    • sample@example.net - the ID of the extension
    • Make it unique
    • Specify 2 -- the 2 declares that it is installing an extension.  If you were to install a theme it would be 4
    • {ec8030f7-c20a-464f-9b0e-13a3a9e97384} - Firefox's application ID.
    • 1.5 - the minimum version of Firefox you're saying this extension will work with
    • (In Firefox version 3.0.1, you can not set both em:minVersion and em:maxVersion to "3.0.*". If you try the extension install will fail with the error "Not compatible with Firefox 3.0.1". I am not clear on the reason for this so will not speculate and will leave the explanation to somebody who is more informed. Setting em:minVersion to "3" and em:maxVersion to "3.0.*" fixed the problem for me.)
    • Firefox's user interface is written in XUL and JavaScript.  XUL is an XML grammar that provides user interface widgets like buttons, menus, toolbars, trees, etc.  User actions are bound to functionality using JavaScript.

      To extend the browser, we modify parts of the browser UI by adding or modifying widgets.  We add widgets by inserting new XUL DOM elements into the browser window and modify them by using script and attaching event handlers.

    • The browser is implemented in a XUL file called browser.xul ($FIREFOX_INSTALL_DIR/chrome/browser.jar contains content/browser/browser.xul). 
    • XUL Overlays are a way of attaching other UI widgets to a XUL document at run time.  A XUL Overlay is a .xul file that specifies XUL fragments to insert at specific merge points within a "master" document.  These fragments can specify widgets to be inserted, removed, or modified.
    • The called status-bar specifies the "merge point" within the browser window that we want to attach to
    • There are three types: content (XUL, JavaScript, XBL bindings, etc. that form the structure and behavior of an application UI), locale (DTD, .properties files etc that contain strings for the UI's localization), and skin (CSS and images that form the theme of the UI)
    • (Don't forget the trailing slash, "/"! Without it, the extension won't get registered.)

      (my_extension may not work! Redirect seems to break if the folder name contains an underscore.)

  • tags: no_tag

    • start "" "%ProgramFiles%\Mozilla Firefox\firefox.exe" -no-remote -P dev
Posted from Diigo. The rest of my favorite links are here.

没有评论: