[Project_owners] XPCOM call local function

joe ertaba belaviyo at gmail.com
Sun Feb 1 05:10:16 PST 2009


Thanks Anton

Second method looks great, but I have few problems with it


or you may implement any interface in your extension's object, it may be
> somethink like
>
> // xpcom .idl
> ...
> interface YourComponent: nsISupports
> {
> ...
>   void init (in YourComponentCallback obj);
> ...
> };
>
> interface YourComponentCallback: nsISupports
> {
> ...
>   void foo ();
> ...
> };
>


Is it possible to declare object variable into the idl file?
something like

interface YourComponent: nsISupports {  void init (in object obj); };

As I think it doesnt mean to declare object in idl! so I should use your
trick, but I think I should reverse them, something like

// xpcom .idl
...

interface YourComponentCallback: nsISupports
{
...
  void foo ();
...
};

interface YourComponent: nsISupports
{
...
  void init (in YourComponentCallback obj);
...
};


>
> // xpcom
> ...
> extobject: null,
> ...
> init: function (obj) { this. extobject = obj; },
> ...
> bar: function () { this. extobject. foo (); }, // call extension's function
> ...
>
> // extension
> var yourextensionobject =
> {
> ...
> init: function () {
>   var mycomponent = Components. classes ["@yourcomponent.cid"].
> createInstance (Components. interfaces. YourComponent);
>   mycomponent. init (this);
> },
> ...
> foo: function () { ... },
> ...
> QueryIntrface: function (iid)
> {
>   if ((!iid. equals (Components. interfaces. nsISupprots) && (!iid. equals
> (Components. interfaces. nsIYourComponentCallback)) Components. results.
> NS_ERROR_NO_INTERFACE;
>   return this;
> }


I don't exactly know why I need QueryIntrface here in my extension js file
beside in component, if it helps to declare object (YourComponentCallback)
then is it enough or some other things also needed (in xpcom we need lots of
other thing like Factories, Modules,... )

Maybe I am somehow confized! because I never see idl & QueryIntrface for
normal js (not compont)

Would you please give me a sample extension file or at least some toturial
which explain these concepts :)

Thanks in advance
Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mozdev.org/pipermail/project_owners/attachments/20090201/dd970cff/attachment.html>


More information about the Project_owners mailing list