[Project_owners] XPCOM call local function
Anton Glazatov
antonglv at gmail.com
Sun Feb 1 12:32:36 PST 2009
>> 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
> Project_owners at mozdev.org
> https://www.mozdev.org/mailman/listinfo/project_owners
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ext2.xpi
Type: application/x-xpinstall
Size: 3098 bytes
Desc: not available
URL: <http://www.mozdev.org/pipermail/project_owners/attachments/20090202/d2b20928/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ext1.xpi
Type: application/x-xpinstall
Size: 3188 bytes
Desc: not available
URL: <http://www.mozdev.org/pipermail/project_owners/attachments/20090202/d2b20928/attachment-0001.bin>
More information about the Project_owners
mailing list