Callback in XPCOM

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Callback in XPCOM

crayne
Is this possible:

1.  Javascript code registers a callback in an XPCOM
2.  Javascript code invokes a method in the XPCOM
3.  XPCOM code invokes an internal method and passes it some data
4.  Javascript callback function gets invoked with the data as a parameter

??

And if so, is there any example code available?


Thanks,
Susan


_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Reply | Threaded
Open this post in threaded view
|

Re: Callback in XPCOM

Nickolay Ponomarev
On 4/26/06, Susan Crayne <[hidden email]> wrote:
> Is this possible:
>
> 1.  Javascript code registers a callback in an XPCOM
> 2.  Javascript code invokes a method in the XPCOM
> 3.  XPCOM code invokes an internal method and passes it some data
> 4.  Javascript callback function gets invoked with the data as a parameter
>
Yes, the easiest way to do callbacks to JS from native code is via
XPCOM. Your callback code should be in a JS object implementing an
interface appropriate for you (you can use an existing interface, such
as nsIObserver or a custom interface).

I don't know of an example demonstrating this specific technique, but
it's commonly used in the platform itself. The observer service is
doing a similar thing, here's how to implement an nsIObserver in JS:
http://kb.mozillazine.org/Using_observers
and you can inspect the nsObserverService code to see how the C++ part works.

Nickolay
_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Reply | Threaded
Open this post in threaded view
|

Re: Callback in XPCOM

crayne
In reply to this post by crayne
Thanks.  I'll check this out.

"Nickolay Ponomarev" <[hidden email]> wrote in message
news:[hidden email]...
On 4/26/06, Susan Crayne <[hidden email]> wrote:
> Is this possible:
>
> 1.  Javascript code registers a callback in an XPCOM
> 2.  Javascript code invokes a method in the XPCOM
> 3.  XPCOM code invokes an internal method and passes it some data
> 4.  Javascript callback function gets invoked with the data as a parameter
>
Yes, the easiest way to do callbacks to JS from native code is via
XPCOM. Your callback code should be in a JS object implementing an
interface appropriate for you (you can use an existing interface, such
as nsIObserver or a custom interface).

I don't know of an example demonstrating this specific technique, but
it's commonly used in the platform itself. The observer service is
doing a similar thing, here's how to implement an nsIObserver in JS:
http://kb.mozillazine.org/Using_observers
and you can inspect the nsObserverService code to see how the C++ part
works.

Nickolay


_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom