Snippets code from my daily experience

September 26, 2010

Firefox 4, packed XPI files and extensions test environments

Filed under: extension,firefox,gecko — dafi @ 8:50 am

My test environment is simple

  1. Create an XPI file with all files unzipped (no jar file inside)
  2. Install the XPI on a separated (and clean) profile, this is applicable to any Gecko application: Firefox, Thunderbird, Komodo, SeaMonkey 2.x
  3. Run unit tests or use the extension
  4. If some test fails I edit code (xul, js, css) directly on installed files
  5. Move edited files on main code build tree
  6. Repeat the process starting from 1.

Any developer uses its own approach, someone prefers to edit the chrome.manifest to point to files on specific directories, someone uses other enterprise-big-team oriented ways.

No matters the approach you use under Gecko 2.0 (ie Firefox 4.0) the XPI file will not unpacked by default, this can complicate your development process but the solution is easy.

em:unpack

Add to your install.rdf the following line and everything comes back (more details here)

<em:unpack>true</em:unpack>

My dev environment has two XPI creation tasks, debug and dist so it’s easy to insert <em:unpack/> only when necessary (debug mode in my case)

RTFM

Please visit often Firefox 4 for developers (better to follow the feed) because FF4 is a little/big awesome revolution and extensions can be affected in many ways.

August 29, 2010

Sunday thought: Discarding localizations from extensions

Filed under: extension,localization,sunday_thought — dafi @ 11:30 am

XUL is so flexible that creating localized extensions is incredible easy, adding new languages is simple and the developer effort is very low.

So adding locales is technically trivial but having locales updated can have a dramatic impact on release process.

Everything is based on voluntary contribution and this is simply awesome but very often localizers stop translation without tell anything, other translators can’t respect deadlines, this is voluntary activity so if they can’t do it means simply they can’t do!

I’m very sad but I’ve decided to drop localizations inclusion from my extensions I leave only my mother tongue and obviously English.

Epic fails

A short list of attempts I’ve done to obtain completed locales but without success

  • Contacting localizers asking to complete localization without receiving reply (bad citizens???)
  • Searching other people to continue translations
  • Asking translations for less than ten strings per release (including accesskeys and key)
  • Setting long deadlines (two/three weeks) discarding periods closer to holidays (summer/winter)

Technical workarounds

I know there are many ways to have an incomplete locale using en-US for missing strings, (read Firebug lesson) but I really dislike mixed locales and I’m a zero-or-one man so complete locales go inside XPI, incomplete locales not bundled!

I surrender

So finally I’ve decided to stop locales inclusion, I will continue to write code compliant with locale rules (eg no hard coded strings) because it’s easy and really useful.

January 8, 2010

How to programmatically change XUL tree’s pseudo-classes

Filed under: extension,nsITreeView,xul — dafi @ 3:45 pm

I encountered the following problem: Change font and color for XUL tree based on user input. The user chooses the font and picks the color from a dialog and the tree widget is immediately redrawn with the new styles.

Changing styles for XUL trees requires the implementation of a nsITreeView, some nsIAtomService manipulation and some Mozilla CSS Extensions, definitively a bit verbose but enough simple after a dozen of attempts :P.

The Mozilla CSS tree extensions are mainly pseudo-classes that can’t be modified from code, so you need to create a CSS text snippet with new values and then “reload” it.

Reloading CSS files can be accomplished using the nsIStyleSheetService service, it only requires a nsIURI pointing to the CSS resource.

Based on the scenario described above the styles are generated at runtime so I need to create a CSS style representation and stores it for example on a temp file. The styles don’t really need to be persisted on disk so why do I need to create an unuseful file?

Well using the “data:” protocol it is possible to encode the generated CSS string and pass to nsIURI the data uri without needs to create temporary files as shown below.

function applyUserStyles(cssStyles) {
    // myTreeChildren is the CSS class name used for the tree
    // obviously can be parametrized
    var css = '.myTreeChildren::-moz-tree-cell-text {' + cssStyles + '}';
    var data = 'data:text/css;charset=utf-8,' + encodeURI(css);
    var sss = Components.classes["@mozilla.org/content/style-sheet-service;1"]
                .getService(Components.interfaces.nsIStyleSheetService);
    var ios = Components.classes["@mozilla.org/network/io-service;1"]
                .getService(Components.interfaces.nsIIOService);
    var u = ios.newURI(data, null, null);
    if (sss.sheetRegistered(u, sss.USER_SHEET)) {
        sss.unregisterSheet(u, sss.USER_SHEET);
    }
    sss.loadAndRegisterSheet(u, sss.USER_SHEET);
}
 

Maybe a simpler solution exists and my code is the worst way to proceed, if you know a better way please tell me 🙂

January 4, 2010

VisualDiffer 1.2 beta 1

I spent the Christmas holidays working on VisualDiffer, the Komodo visual folders/files comparison extension.

Now I want to migrate VisualDiffer from extension to standalone application using XULRunner because the folders comparison feature is mature and using it from an extension can be a bit complicated.

The migration requires some intermediate steps

  • Remove dependencies from Komodo code (especially the unified diff algorithm)
  • Remove dependencies from unified diff algorithm!!
  • Complete the file comparison feature allowing in-place editing using Bespin.
    Bespin can greatly simplify syntax highlight for different languages, search in file and so on
    Honestly I’m considering also to stay with Scintilla (actually used by Komodo) but I love Bespin
  • Use a cool graphic layout, especially toolbar icons
    I’m not a GIMP guru so if somebody would to help me he/she would be welcomed 🙂
  • Allow user defined fonts and colors (low priority task)

I hope to release the VisualDiffer V1.2 for Komodo in a couple of weeks but also not Komodo aficionados can take a look to it installing the beta version on Firefox 3.5.x (also 3.6b5) and SeaMonkey 2.x.

Under Firefox and SeaMonkey the “files differ” feature isn’t implemented (Komodo dependencies) but you can test the folders differ feature that is totally based on standard Gecko interfaces, you can find the VisualDiffer item under the Tools menu.

Obviously VisualDiffer on Firefox is a nonsense because it isn’t a browser oriented extension I distribute this version with Firefox support with the hope a larger community can try it and give me feedback before I jump on the XULRunner world.

The V1.2 beta 1 can be downloaded from here.

VisualDiffer is inspired by the fantastic Beyond Compare but this isn’t a mystery 😉

December 20, 2009

Contributions, now it’s my turn (Sunday Thought)

Thanks to the contribution platform available at AMO I bought one book and a couple of software licenses (not open sourced).

I can say that the AMO contribution feature is a great success for me, dozen of donors for two ‘not so famous‘ extensions like Table2Clipboard and ViewSourceWith.

Now I’ve a little budget to use to make contributions because NOW it’s my turn!

I’ll contribute to Firefox extensions without forget other open source projects especially the utilities, I love the little time saver applications 😛

I chosen low ‘Suggested Donation’ amount for my extensions but this has generated very expensive PayPal fees per transaction so I’ll make fewer contributions but all higher than 5$, I would the software authors take maximum profits from donations.

I hope in my country (Italy) PayPal made available micropayments very soon.

I would like to receive contributions also for my Komodo extensions, strangely the official dafizilla website doesn’t attract donors (I don’t like to fill it with banners and donations messages), I hope rumors about the Add-On Store will be confirmed and the store will host not only browser (i.e. Firefox) extensions and more important it will host also free/open source components.

October 18, 2009

.NET Framework Assistant, automatic plugin installation and PluginChecker

Filed under: extension,plugins,xul — dafi @ 2:21 pm

In these days the net is populated by blog posts about the .NET Framework Assistant plugin for Firefox, its disabling and the fact Firefox does not warn user when a plugin installs itself without explicit permission.

Well, this is a old problem at least for me, indeed I discovered it some time ago when my Firefox crashed (apparently) without reason, discovering after a couple of days that Microsoft Office 2003 plugin fought with Foxit Reader and Google update plugins.

The problem was that I never installed Office plugin!

plugins

Disabling Office plugin Firefox stopped to crash.

After that experience I decided to write a simple (very simple) extension that at every Firefox startup checks if there are new plugins installed.

plugincheckerNothing so cool, only a quick and dirty solution implemented in a few of hours.

Waiting Mozilla implements a better solution than mine you can install PluginChecker.

If you expect to find PluginChecker innovative or the “I-can-live-without-it” extension you are on the wrong place, if you expect a not intrusive and simple solution to unattended plugins installation than you can take a look at it.

You can download PluginChecker from SourceForge.

September 14, 2009

Table2Clipboard 1.0 now preserves styles

Filed under: excel,extension,firefox,openoffice,table2clipboard,xul — dafi @ 6:49 pm

Finally after almost a year I release a new version of Table2Clipboard, one of twelve extensions that won in 2008 the Firefox 2 Contest in the section Runners Up.

What’s new

Until now Table2Clipboard has pasted to clipboard the structure of HTML tables without the styles (colors, borders, fonts) but many users have asked me that the behavior was much more similar to that of Internet Explorer (IE) which indeed maintains many details.

Well, the version 1.0 preserves the styles and in certain cases the result is better than that obtained with IE.

IE inserts also the DOM elements declared “not visible”, for example the table shown in Figure 1  is pasted in Excel as shown in Figure 2.

ie

Figure 1

Table selection on Internet Explorer

excel-from-ie

Figure 2

Copy from Internet Explorer paste to Microsoft Excel

Table2Clipboard discards hidden DOM elements as shown in Figure 3, this makes more sense for me.

Paste from Firefox with Table2Clipboard to Microsoft Excel

Figure 3

Copy from Firefox with Table2Clipboard paste to Microsoft Excel

Other little improvements

Now web links are copied and user can choose to copy images (tag IMG), too.
All defaults settings can be modified from configuration dialog.

The copy of styles on OpenOffice doesn’t work as well as the one on Microsoft products.
The “Paste Special” feature available on OpenOffice doesn’t recognize CSS styles but only deprecated tags like FONT.

I will add support for OpenOffice soon but I prefer the “release early release often” (after a year??? :P) approach so this version has poor styles support on the popular open source office automation suite.

Compatibility issues with Thunderbird 3.x are now fixed.

Table2Clipboard can be installed from AMO or from the project site on dafizilla.

August 1, 2009

Table2Clipboard and clipboard application interoperability

Filed under: calc,clipboard,excel,extension,openoffice,table2clipboard,xul — dafi @ 10:35 am

calc_excel_t2cMany users asked to me to add to the extension Table2Clipboard (T2C for friends) the ability to preserve web links and maintain the styles during tables copy.

Preserving links and other HTML tags was a very easy task, I’ve written the code very quickly and both OpenOffice Calc and Microsoft Excel have handled correctly the pasted content.

When I started to support style preservation I discovered different and ugly results on the two popular office suites making harder to write cross platform XUL code.

Actually T2C pastes to clipboard inserting data in two different formats (flavors), unicode plain text and HTML format.
When users do “Paste Special” the HTML format is pasted and applications (Excel or Calc) render inside the data sheet.

Both Excel and Calc handle only the deprecated FONT tag and a subset of TABLE tag attributes and this represents a great limitation for style preservation from T2C.

If you try to paste from Microsoft Explorer to Microsoft Excel you discover everything is copied, the styles are totally preserved but if you paste from Explorer to OpenOffice Calc all style are lost!!!

Well, Explorer inserts to clipboard also RTF formatted text and Excel works very fine with the barely public RTF file format.

Clipboard application interoperability goes to hell, HTML is not fully supported by the “Paste Special” feature available on both suites, and as usual Microsoft uses semi proprietary data formats to exchange informations between applications.

I think at least OpenOffice should improve its “Paste” feature simply adding support for HTML style attribute.

T2C can preserve correctly styles only implementing platform specific code for OpenOffice and Microsoft Office and I really hate write specific platform.

I’m considering other alternatives but I see only the darkness of C++, OLE and core dump…

July 18, 2009

Discontinue extensions support for some applications

Filed under: extension,firefox,flock,komodo,kompozer,seamonkey — dafi @ 4:46 pm

Before publish new updates for my extensions I try to test them on every application declared supported on install.rdf, this is a very expensive activity when a specific extension runs on different kind of applications and versions.

I add support for a new application (e.g browser, email client, multimedia applet)

  • when I use the application itself and I need the extension functionality on it
  • when other users ask to me

Now I must decide to drop support for some applications and for specific versions to simplify my release tests cycle.

In some cases it’s easy to decide, for example Firefox 2.x is no longer supported by Mozilla and users continuing to use it are braves or simply fools.

Supporting SeaMonkey 1.x is very hard for me, no special technical problems SM is a very good product but I simply don’t use it.
Instead I’m a satisfied SeaMonkey 2.0 user since alpha1 version.

Supporting Flock, the “social” browser, is easy due to the fact is very compatible with Firefox 3.x but sometimes little differences caused me headaches.
I think to drop support for extensions not Flock centric considering the decision taken from its team last December

Komodo 4.x is no longer upgraded by ActiveState but many people continues to use it, Komodo has a commercial version, KomodoIDE, and not all users purchased the upgrade (me too) so it is very difficult to drop the very old 4.x architecture.

NVU is dead but many users continue to use it also if its sibling/son Kompozer should be strong preferred.

What specifically means “discontinue support”

I would to remove specific tricky code present in extensions to make them cleaner but this can be a bad solution, regressions are always possible so the cure can be worse than the disease…

Removing SeaMonkey 1.x support will make my extension build system cleaner no longer install.js, contents.rdf  and informations present both in install.rdf and chrome.manifest, obviously I don’t discard support only to remove a couple of configuration files but I consider it another complication.

So, “discontinue support” for me means moving attention and energies on applications (and versions) I can test easily, on application I daily use, on applications I receive feedback from other users.

June 5, 2009

gContextMenu’s imageURL property refactored on Firefox 3.5x

Filed under: extension,firefox,xul — dafi @ 5:04 pm
Tags: , , ,

Edited on 9 June 2009 Mozilla guys decided to add a getter for imageURL so no extension will be affected by new property mediaURL replacement, you can read the full story at bug 497098.

Another time Mozilla community demonstrates its strength, why nobody considered the impact before modification is another story 😉

Today a ViewSourceWith user filed a bug about a regression on Firefox 3.5b4, causing VSW to no more open images 😯

After dressing the debug uniform I started to investigate the problem.

I’ve realized the object gContextMenu doesn’t more contain the property imageURL used by VSW and maybe many other extensions.

The imageURL property has been renamed/refactored to mediaURL.

Honestly the new name fits better its new usage and maybe the imageURL property is not intended for usage from extensions.

The poor gContextMenu documentation doesn’t describe imageURL so maybe I abused its usage.

I think gContextMenu need a better documentation because its usage is so sexy inside extensions.

The workaround

A string find/replace inside code fixed the bug, to maintain compatibility with FF 3.0.x I’ve modified the code as shown below

var imageURL = gContextMenu.imageURL || gContextMenu.mediaURL;
Next Page »

Create a free website or blog at WordPress.com.