eBlogzilla

Tuesday, November 5, 2013

New way to access status bar panel in Firefox 25+

Since Firefox 25 old way to access status bar using getElementById("statusbar-display") is not working anymore. Instead of this old way you need to use gBrowser.getStatusPanel() code. So, update your extensions in accordance with the last changes. But don't forget about those users who will not install Firefox 25 :-).

Friday, January 4, 2013

How to specify unpack option in Addon SDK

Everyone thinks that it should be really easy to specify unpack option for your extension using Firefox Addon SDK. But it is not so easy as it looks at the first glance. Addon SDK has no such command line option.

So you've two ways to do that:

1. You can edit this file: %ADDON_SDK_HOME%\python-lib\cuddlefish\app-extension\install.rdf. In this file just find the next line:
<em:unpack>false</em:unpack>
and change to
<em:unpack>true</em:unpack>
After that all extensions compiled with Addon SDK will have unpack option set to true.

2. If you need to compile only one extension with this option specified to true then you'll need to perform bit more work. You need to edit __init__.py and rdf.py files in %ADDON_SDK_HOME%\python-lib\cuddlefish folder. That should be quite easy to do. Just search for "update_url" term in these files and see how exactly this option is implemented. After a couple of minutes you should be able to add your own options to the command line of Addon SDK.

Thursday, April 5, 2012

How to specify updateKey in Addon SDK v. 1.5

A couple of days ago I need to specify <em:updateKey> tag in install.rdf file. After some research I've realized that there is simply no way to do that. So, I've added necessary changes into the Addon SDK. You just need to replace three files in the SDK. You can download them from my site and place to the necessary place:

%SDK_HOME%/python-lib/cuddlefish/__init__.py
%SDK_HOME%/python-lib/cuddlefish/rdf.py
%SDK_HOME%/python-lib/cuddlefish/app-extension/install.rdf

Then just execute cfx xpi with --update-key "YOUR_KEY" argument and generated install.rdf file will contain <em:updateKey> tag with specified value.

Thursday, April 21, 2011

How to show message in Firefox statusbar

Today I've spent bit more time then expected trying to show message in Firefox status bar. (I know that there is no statusbar by default in Firefox 4). The solution was simple, as usual :-):
    document.getElementById("statusbar-display").label = "Your message here";


That is all!

Wednesday, September 1, 2010

How to change background color of notificationbox

If you take a look on official documentation for notificationbox, you will not find any attributes or properties which allows to change background color. But it is possible to do. Let's assume that you have create notification box with the next code:
    var nb = gBrowser.getNotificationBox();
    nb.appendNotification(
        "This is my message",
        "my-notification",
        "chrome://myext/skin/notification.gif",
        nb.PRIORITY_INFO_MEDIUM,
        [
            {
                label: "More info",
                accessKey: "M",
                callback: function() {alert('More info action!')}
            }
        ]);
Take a look on the second parameter of appendNotification function. This parameter will be used as value attribute for notification element which will be created. We can use this fact. So only one thing that you need is to add one rule in CSS file of the extension. Something like this:
  notification[value='my-notification'] {
    background-color: green;
  }
You will see your notification with green background color. You can also add more CSS rules and specify value of color property and etc.

Thursday, August 26, 2010

How to add new menu item in context menu

For some extensions it has sense to think on adding new menu item in standard context menu. Such menu item can be useful for end-users and improve usability of your extension.

I assume that you already have some XUL overlay:
overlay chrome://browser/content/browser.xul chrome://myext/content/myext.xul
Now you need to add in myext.xul file the next code:
<popup id="contentAreaContextMenu">
        <menuitem id="my-menu-item"
                  insertafter="context-selectall"
                  accesskey="H"
                  class="menuitem-iconic"
                  label="Hello world!"
                  oncommand="alert('Hello again');"/>
    </popup>
You can see that I've added CSS class there: class="menuitem-iconic". It will allow you to add icon for the menu item. You can do that in CSS file which should be included in the current XUL file:
#my-menu-item {
    list-style-image: url("chrome://myext/skin/icon16.png");
}
That is all. Make your extensions user-friendly!

Monday, May 24, 2010

How to detect is a socket free or busy

Sometimes you need to perform very simple task. But unexpectedly this task can take much more time that you have expected at the start.

I've met this case when I was need to check if some socket is free or busy. I've spent some time on playing with core Mozilla interfaces like nsIServerSocket or nsISocketTransportService. But was not able to find right solution.

Finally, I've used not very traditional method to solve my problem. I've managed all work to Java classes:
function isPortAvailable(port) {
    try {
        var srv = new java.net.ServerSocket(port);
        srv.close();
        srv = null;
        return true;
    } catch (e) {
        return false;
    }
}

This solution has one limitation. You need to be ensure that Java in installed on user's machine. But in my case this limitation was not significant.