I am trying to create a singleton component to share objects between
windows. I have been searching around, and it looks like what I want is
a XPCOM component done using the "wrappedJSObject trick". What I have
yet to find is a good example of what this "trick" is. I've gathered it
needs to look something like:
function MyComponent() {
this.wrappedJSObject = this;
}
//... implementation of MyComponent ...
//... XPCOM registration ...
Then, to retrieve the object:
var obj = Components.classes["@example.org/mycomponent;1"]
.getService().wrappedJSObject;
...
What is the simplest "mplementation of MyComponent" and "XPCOM
registration" code. Also, it seems that some part of "mplementation of
MyComponent" requires generating some sort of unique id, in the form of
XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX, how exactly do I generate it?
Every example I have come across thus far has seemed overly
complicated, I'm looking for the "wrappedJSObject trick" hello world.
Alex
--
alex iskold
founder & cto
http://www.adaptiveblue.com
> I am trying to create a singleton component to share objects between
> windows. I have been searching around, and it looks like what I want is
> a XPCOM component done using the "wrappedJSObject trick". What I have
> yet to find is a good example of what this "trick" is.
The "wrappedJSObject" property is just a way to get to the underlying
JSObject of XPCOM components implemented in JavaScript. Presumably in
most cases you're better off defining an interface to your component and
then accessing it through that interface.
> What is the simplest "mplementation of MyComponent" and "XPCOM
> registration" code.
http://developer.mozilla.org/en/docs/How_to_Build_an_XPCOM_Component_in_Javascript
The only thing to do differently from this example is to retrieve your
component via getService rather than createInstance.
> Also, it seems that some part of "mplementation of
> MyComponent" requires generating some sort of unique id, in the form of
> XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX, how exactly do I generate it?
The uuidgen command-line tool, available (at least) on Mac OS X and in
many Linux distributions (perhaps only with optional installation), will
generate one of these. You can also get one by sending the message
"uuid" to ssdbot on irc.mozilla.org. Or google "generate uuid" to find
online generators.
-myk
If you dislike the overly complicated, stay away from XPCOM!!
-= miles =-
(knowing I'll regret having said it, but the temptation is just too great).
Nickolay