identity:// protocol

25 Jun 2012

On the Mozilla Zine forums, Lithopsian pointed me in the right direction as far as getting the protocol registered. cfx run, at least as I'm using it doesn't seem to do anything with a chrome.manifest, but the protocol can be registered in the javascript.

What I needed was a factory: line added after QueryInterface: like thus:

  QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]),
  factory: { createInstance: function (aOuter, aIID) { return (new identityProtocol()).QueryInterface(aIID) } },
And to have the factory registered, which did with this bit of code at the end of main.js:
function registerIdentity() {
    var manager = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);   
    var proto = identityProtocol.prototype;
    manager.registerFactory(proto.classID, proto.classDescription, proto.contractID, proto.factory);

    console.log("identity registered");
}

registerIdentity();

Current status: Initial pages load now, but included assets (images, etc) do not unless there is a full scheme://site/asset style URL. At this point I'm curious about this snippet:

  newURI: function(aSpec, aOriginCharset, aBaseURI)
  {
    var uri = Cc["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI);
    uri.spec = aSpec;
    return uri;
  },
That word "simple" makes me wonder if I'm using the right class.

Here are the (updated) files in the identity extension:

identity.0.1.tar.gz has all the files.

22 Jun 2012

This is intended as an experiment in writing an extension that implements a new protocol in Firefox. All identity://URI URLs are supposed to work just like http://URI URLs.

I started with the Mike Kaply protocol handler example and put it into the framework that addon-sdk-1.7's cfx init creates.

Runing with cfx run, I see console log message that indicate my code is running (with an error that occurs before anything else starts, so I suspect to be unimportant). And I see my extension show up in the Extensions section of Addons. However Firefox still tells me that it does not recognize the identity: protocol.

Here's what happens in my terminal when I run it:

(addon-sdk-1.7)$ cfx -b $firefox run
No 'id' in package.json: creating a new ID for you.
package.json modified: please re-run 'cfx run'
(addon-sdk-1.7)$ cfx -b $firefox run
Using binary at '/home/username/builds/firefox/LATEST/firefox'.
Using profile at '/tmp/tmp3rOGHT.mozrunner'.
*** e = [Exception... "Component returned failure code: 0x80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE) [nsIJSCID.getService]"  nsresult: "0x80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE)"  location: "JS frame :: chrome://browser/content/utilityOverlay.js :: getShellService :: line 380"  data: no]
info: identity starting.
info: identity reached end.
Total time: 38.391250 seconds
Program terminated successfully.
(addon-sdk-1.7)$ 

The Firefox is version 12.0 (my LATEST installed). The chrome://browser/content/utilityOverlay.js error occurs even for a main.js that only include a single console.log() message.

So what am I doing wrong? Email me at username eli at obvious site (don't include the "www." part).