Hello Sandip,
Thank you, this solution worked well! The only change I needed to make
was to add the following line to the beginning of my function,
otherwise I received an exception when trying to access
Components.classes.
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
The error was "Permission denied to get property UnnamedClass.classes",
which could probably be reworded :)
I guess this is common knowledge, which is probably why you didn't
include this information, but hopefully this post will help another
newbie get past this problem.
Thanks,
Kevin
Sandip Ghosh wrote:
> You probably want to use nsIObserver/nsIObserverService interfaces to call
> into your javascript from C++ XPCOM. So in your javascript you implement the
> nsIObserver interface, like so:
>
> // your JS code
> var myObserver = { observe : function(subject, topic, data) {
> if (topic == "myTopic") {
> // callback from C++ XPCOM
> }
> }
> };
>
>
>
> // your JS code
> // register the observer
> var observerService =
> Components.classes["@mozilla.org/observer-service;1"].
>
> getService(Components.interfaces.nsIObserverService);
> observerService.addObserver(myObserver, "myTopic", false);
>
>
> // your C++ code:
> nsCOMPtr<nsIObserverService> observerService =
> do_GetService("@mozilla.org/observer-service;1");
> observerService.NotifyObservers (mySubject, "myTopic", myData);
>
> The Observer Service will call all registered observers when a notification
> of type "myTopic" is received. The registered "myTopic" observer in the JS
> will get invoked when the NotifyObservers method is called from C++.
>
> HTH
> -Sandip
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> [EMAIL PROTECTED]
> Sent: Friday, June 23, 2006 10:36 AM
> To: [email protected]
> Subject: Calling JS functions from XPCOM component (FF 1.5)
>
> Hi,
>
> I have written an C++ XPCOM component that correctly loads into Firefox
> 1.5, and I can successfully call methods on the component thanks to
> XPConnect. What I would like to do now is allow the component to call
> back into the javascript VM, as I can do with an IE ActiveX control
> using ActiveX "events". Is it possible to do this? I would guess the
> method would be something like this:
>
> - Use the DOM from C++ to find a JS method which must be defined in the
> script code of the calling web page. Alternately this method could be
> passed to my component as an argument of some kind.
> - Use some kind of magic glue code (nsXPConnect?) to call the JS
> function from C++, packaging up the arguments as necessary.
>
> So far I've found nothing to describe this process on the XPConnect
> (http://www.mozilla.org/scriptable/) or XPCom
> (http://www.mozilla.org/projects/xpcom/index.html) sites, and google
> searches haven't helped either.
>
> Can anyone explain A) if what I want to do is possible, and B) how to
> do it or at least a pointer to the right header file.
>
> I should point out that I am NOT building the Mozilla source code. I
> am building my component on Win32 using the precompiled gecko SDK
> (v1.8b1).
>
> Thanks in advance,
> Kevin
>
> _______________________________________________
> dev-tech-xpcom mailing list
> [email protected]
> https://lists.mozilla.org/listinfo/dev-tech-xpcom
_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom