I port a Chrome extension to Firefox. Because the XUL-based API is quite different from Chrome API, so I use the new add-on SDK of firefox.
There is a interface called
Erik Vold has created a library that allows you to do this:
https://github.com/erikvold/toolbarbutton-jplib/blob/master/lib/toolbarbutton.js
While this code isn't included in the SDK libraries, it can be used to get the result you want with the current version of the SDK. You can see a quick example using Erik's library here:
https://builder.addons.mozilla.org/addon/1031142/latest/