[Project_owners] XPCOM call local function

Anton Glazatov antonglv at gmail.com
Sat Jan 31 10:30:33 PST 2009


*joe*, you may use code like this:

var windowService = Components. classes 
["@mozilla.org/appshell/window-mediator;1"].
                    getService (Components. interfaces. nsIWindowMediator);
var mrWindow = windowService. getMostRecentWindow ("navigator:browser");
mrWindow. foo ();

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 ();
...
};

// 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;
}
};


joe ertaba wrote:
> Hi
>
> I have a XPCOM Component in my extension for observing a process, it 
> can detect process, now my question is how to call extension functions 
> from XPCOM Component ?
>
> example:
>
> MyExtension
> -component
> -chrome
> --content
> ---a_js_file.js
>    function foo(var1){
>      .....
>    }
> ---a_xul_file.xul
>
> what I want to do is to call foo(...) from XPCOM
>
> can somebody help?
> ------------------------------------------------------------------------
>
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> https://www.mozdev.org/mailman/listinfo/project_owners
>   



More information about the Project_owners mailing list