Tuesday, February 23, 2010

Porting Firefox extension to Thunderbird


After I published the Autohide Tabbar Firefox extension, some positive comments were received. Thank you! It encourages me to keep improving it. One of the comments was asking whether the Autohide Tabbar extension could be added to Mozilla Thunderbird. I looked into Thunderbird and found out that since version 3, tabs were introduced. After some more investigations, it was discovered that porting a Mozilla Firefox extension to Thunderbird is easy.

First, just making a little changes on files install.rdf and chrome.manifest, you could install your Firefox extension on Thunderbird. Use the Autohide Tabbar extension as an example. In file install.rdf, look for the "em:targetApplication" block. What you already have is for Firefox. You can add another "em:targetApplication" block for Thunderbird right after it:
        <!-- Firefox -->
        <em:targetApplication>
            <Description>
                <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
                <em:minVersion>3.0</em:minVersion>
                <em:maxVersion>3.6.*</em:maxVersion>
            </Description>
        </em:targetApplication>

        <!-- Thunderbird -->
        <em:targetApplication>
            <Description>
                <em:id>{3550f703-e582-4d05-9a08-453d09bdfdc6}</em:id>
                <em:minVersion>3.0</em:minVersion>
                <em:maxVersion>3.0.*</em:maxVersion>
            </Description>
        </em:targetApplication>
In file chrome.manifest, you need to add a new overlay for Thunderbird. As we know, browser.xul is to be overlay-ed for Firefox. For Thunderbird, we would overlay messenger.xul. We also add the application ID at the end. {ec8030f7-c20a-464f-9b0e-13a3a9e97384} is the application ID of Firefox and {3550f703-e582-4d05-9a08-453d09bdfdc6} is that of Thunderbird. The Autohide Tabbar extension overlays messenger.xul with autohidetabbar_t.xul, which is a clone of autohidetabbar.xul, which is for Firefox. If your extension needs no extra code changes for Thunderbird, you do not even need to clone your XXX.xul file to XXX_t.xul. Just use the same XXX.xul file for both overlay.
      overlay chrome://browser/content/browser.xul chrome://ahtb12/content/autohidetabbar.xul   application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
      overlay chrome://messenger/content/messenger.xul chrome://ahtb12/content/autohidetabbar_t.xul   application={3550f703-e582-4d05-9a08-453d09bdfdc6}
Basically, after changing install.rdf and chrome.manifest, you can try your extension on Thunderbird. If the extension is a simple one, it may work and your job is done. Our Autohide Tabbar extension uses elements specifically for Firefox, so it did not work right after. Then we have to go to the next step.

We do not want our changes for Thunderbird impacts the functions on Firefox, so we clone autohidetabbar.xul and autohidetabbar.js to autohidetabbar_t.xul and autohidetabbar_t.js and make the changes for Thunderbird on the new ones. Those changes are specifically for this extension, so I would not give the details here. If you are interested, you can download both the old version and the new version to check out their differences.

Both the flavors of the Autohide Tabbar extension share the same Options dialog, default preferences, locale between Firefox and Thunderbird. We do not need more works to port them. However, you may want to carefully exam the labels, descriptions and printouts to make sure they do not mention Firefox only.

No comments:

 
Get This <