Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Question about creating XPCOM component

8 views
Skip to first unread message

Alex Iskold

unread,
Nov 3, 2006, 6:15:31 PM11/3/06
to
Hello,

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

Myk Melez

unread,
Nov 3, 2006, 7:14:39 PM11/3/06
to
Alex Iskold wrote:

> 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

miles zarathustra

unread,
Nov 5, 2006, 6:04:51 AM11/5/06
to

>
> Every example I have come across thus far has seemed overly
> complicated,

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 Ponomarev

unread,
Nov 5, 2006, 7:39:32 AM11/5/06
to Alex Iskold, dev-ext...@lists.mozilla.org
On 11/4/06, Alex Iskold <alex....@adaptiveblue.com> wrote:
> Every example I have come across thus far has seemed overly
> complicated, I'm looking for the "wrappedJSObject trick" hello world.
>
Extension developer's best friend Ted Mielczarek is working on a
component wizard. Dev version is here:
http://mavra.perilith.com/~luser/jscomponentwiz/
The "Create as a service" checkbox doesn't work currently, but
otherwise it's a very nice tool.

Nickolay

0 new messages