I am writing a bootstrap Firefox addon and need to register a new protocol/schema handler (e.g. foo:somthing
). I have looked all over and I only see ways to do this using chrome.manifest
, which bootstrapped add-ons cannot use.
So, does anyone know a way or is it possible to register a custom protocol handler in a bootstrapped add-on?
Although @nmair's answer is a good general thing I'll keep in mind, I was able to find a better solution to my own problem. I noticed that there was an HTML5 method that would try to ask the user to register a handler for a protocol/schema, and after picking around in omni.ja
(firefox source code), I found it's definition. After fiddling around, I wrote this:
var handler = Cc["@mozilla.org/uriloader/web-handler-app;1"]
.createInstance(Ci.nsIWebHandlerApp);
handler.name='My Protocol';
handler.uriTemplate='chrome://myprotocol/content/launcher.xul#%s';
var eps=Cc["@mozilla.org/uriloader/external-protocol-service;1"].
getService(Ci.nsIExternalProtocolService);
var handlerInfo=eps.getProtocolHandlerInfo('myprotocol');
handlerInfo.possibleApplicationHandlers.appendElement(handler, false);
handlerInfo.alwaysAskBeforeHandling=false; // don't ask the user
handlerInfo.preferredApplicationHandler=handler; // set my handler as default
hi=handlerInfo;
var hs=Cc["@mozilla.org/uriloader/handler-service;1"].
getService(Ci.nsIHandlerService);
hs.store(handlerInfo);
Registers the protocol, no restart or components required.