>> Is it possible to declare object variable into the idl file?
No, it isn't possible. Component method's argument should implement any interface.

>> but I think I should reverse them, something like
Yes, you are right.

>> I don't exactly know why I need QueryIntrface here in my extension js file beside in component If you will use wrappedJSObject in your component constructor (see here: https://developer.mozilla.org/en/How_to_Build_an_XPCOM_Component_in_Javascript), you need not to define extra interface for callback.

>> Would you please give me a sample extension file
You can see attached files. The ext1 doesn't use wrappedJSObject, and ext2 use wrappedJSObject.

Btw, there is third way to call extension's function from xpcom component - you may use global notifications (see nsIObserverService / nsIObserver).

joe ertaba wrote:
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

------------------------------------------------------------------------

_______________________________________________
Project_owners mailing list
[email protected]
https://www.mozdev.org/mailman/listinfo/project_owners

Attachment: ext2.xpi
Description: application/xpinstall

Attachment: ext1.xpi
Description: application/xpinstall

_______________________________________________
Project_owners mailing list
[email protected]
https://www.mozdev.org/mailman/listinfo/project_owners

Reply via email to