[EMAIL PROTECTED] wrote:
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


There's the custom IDL method...

  [function, scriptable, uuid()]
  /* this interface is implemented in JS */
  interface ICallback : nsISupports {
    void call( PRInt32 aParam );
  };

  [scriptable, uuid()]
  /* this interface is implemented in C++ */
  interface IFoo : nsISupports {
    void docall( in ICallback aCallback);
  };

and from JS:
  function bar( aParam ) {
    alert(aParam);
  }

  var foo = Components.classes[...].createInstance(IFoo);
  foo.docall(bar);

(As with the observers case Sandip proposed, the JS needs to have chrome privileges)

HTH
--
Mook
mook dot moz plus a whole ton of stuff at gmail dot com
_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to