RoboGeek

RoboGeek's (David Herron) Weblog: co-developer of Robot and several other things related to Java testing.


« Previous month (Jul 2004) | Main | Next month (Sep 2004) »
20040804 Wednesday August 04, 2004

More on Mozilla messiness

On this page http://www.mozilla.org/xpfe/ we have an overview of XPToolkit, or the "Cross Platform Toolkit" which is the module that allows Mozilla applications to be cross-platform.

Notice towards the bottom a link for the clipboard service. The clipboard is the facility through which drag and drop and other style of datatransfer between applications occurs. The link refers to this page:

http://www.mozilla.org/xpfe/xptoolkit/clipboard.html

Towards the end of that page there is an example of using the clipboard. As a code sample it is pretty nice, simple, easy to understand, and I value having it there. However ...

Let's back up a little and talk about the Mozilla architecture a bit. The design is to have a pile of loosely coupled components or modules. The name is "XPCOM" or cross-platform common-object-module. Any service you use in Mozilla, you first must get an XPCOM style handle onto the service. The XPCOM layering allows XPCOM modules to be used from "any" programming language (for which XPCOM bindings have been created). The list includes javascript, C++, python, Java, perl, etc (the usual suspects).

From Javascript the idiom is:

   var xyz = Components.classes[class-id].getService();
   xyz = xyz.QueryInterface(Components.interfaces.nsIXyz);

The "class-id" is a string with a form like: "@mozilla.org/network/server-socket;1". The "nsIxyz" identifier refers to the interface description (by convention) stored somewhere as a file named nsIxyz.idl. This is nice and loosely structured allowing a great deal of flexibility in bringing pieces and parts together to make an application.

HOWEVER ... If you look at the example you see:

var clipboard = Components.classes["component://netscape/widget/clipboard"].getService();
...
var trans = Components.classes["component://netscape/widget/transferable"].createInstance();
...

When I copied that code into my application it failed. Why? Because it didn't recognize the class-id string. Why? Well, probably the documentation is out of date. Why? HeckifIknow, I sure don't know why the mozilla.org team is presenting bad or wrong documentation as the way to do things.

Here's the problem -- it's not at all obvious what the class-id string for a given IDL interface is. The class-id string is not given in the IDL file, but is stored elsewhere. Where? I haven't been able to determine a search pattern which will always result in finding the class-id string. Sometimes it is located in a ".h" (header) file related to the class, but not always.

In the case of the clipboard and transferable objects they ended up located here:

http://lxr.mozilla.org/seamonkey/source/xpfe/global/resources/content/nsClipboard.js

http://lxr.mozilla.org/seamonkey/source/xpfe/global/resources/content/nsTransferable.js

It was nice to be able to find this - however, these class-id strings are such a crucial part of writing code for Mozilla that it's absolutely outrageous that it is so difficult to find them.

(2004-08-04 10:41:39.0) Permalink Comments [2]