Search code examples
firefoxfirefox-addonxpcomthunderbirdthunderbird-addon

Calling Firefox XPCOM component from Thunderbird extension


I'm doing a Thunderbird extension that will get the stored username/password in Firefox and import those accounts into Thunderbird. This results in the need of nsILoginManager, but I'm not sure how to make it work from a Thunderbird extension. Is it possible to do so?


Solution

  • You pretty much cannot. In addition to XPCOM simply not working across different processes, the complications are:

    • What if Firefox isn't running?
    • What if the password storage is encrypted with a master password?
    • What if there is more than one Firefox profile?

    The best you could do would be:

    • Start Firefox with a command line like firefox -url file://foo/bar/extension.xpi - make sure that Firefox is running and the user is asked to install extension.xpi. It should be a bootstrapped extension so that no browser restart is required.
    • That extension gets the necessary data from nsILoginManager (which involves a password prompt if the user has a master password defined) and sends it back to Thunderbird.
    • After that this extension uses the Add-on Manager API to uninstall itself.

    This is far from being a smooth user experience of course. As to how the two extensions (one in Thunderbird, the other in Firefox) would communicate - TCP sockets would probably be the easiest way. The Thunderbird extension would create a server socket and wait for the Firefox extension to connect to it.