mozilla

Revision 178152 of How To Pass an XPCOM Object to a New Window

  • Revision slug: How_To_Pass_an_XPCOM_Object_to_a_New_Window
  • Revision title: How To Pass an XPCOM Object to a New Window
  • Revision id: 178152
  • Created:
  • Creator: Shaver
  • Is current revision? No
  • Comment

Revision Content

This is an article seed captured raw from an IRC discussion. You are very much encouraged to flesh it out into something more useful.

Captured from #extdev:

19:46 <someguy> so if i create a (xul) window from an XPCOM object
19:47 <someguy> and i want to call functions within the XPCOM object from the                  
                xul window,
19:47 <someguy> do i need to call a getService within that xul window to get a 
                 handle on the XPCOM object,
19:47 <shaver> you should pass the object as one of the arguments to the 
                window creation
19:47 < shaver> and then the XUL window's script can use window.arguments[0] to 
                get the ref
19:55 <someguy> this.ww = 
Components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(Components.interfaces.nsIWindowWatcher);
19:55 <someguy> this.win = this.ww.openWindow(null, 
                 "chrome://myextension/content/debug.xul",
19:55 <someguy> "debug history", "chrome,centerscreen,resizable", this);
19:58 < shaver> sure, or 
                Components.utils.reportError(String(window.arguments[0]))
19:59 <someguy> yep, the object is there: [xpconnect wrapped nsIMyXPCOMObject]

Revision Source

<p><i>This is an article seed captured raw from an IRC discussion.  You are very much encouraged to flesh it out into something more useful.</i>
</p><p>Captured from #extdev:
</p>
<pre>19:46 &lt;someguy&gt; so if i create a (xul) window from an XPCOM object
19:47 &lt;someguy&gt; and i want to call functions within the XPCOM object from the                  
                xul window,
19:47 &lt;someguy&gt; do i need to call a getService within that xul window to get a 
                 handle on the XPCOM object,
19:47 &lt;shaver&gt; you should pass the object as one of the arguments to the 
                window creation
19:47 &lt; shaver&gt; and then the XUL window's script can use window.arguments[0] to 
                get the ref
</pre>
<pre>19:55 &lt;someguy&gt; this.ww = 
Components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(Components.interfaces.nsIWindowWatcher);
19:55 &lt;someguy&gt; this.win = this.ww.openWindow(null, 
                 "chrome://myextension/content/debug.xul",
19:55 &lt;someguy&gt; "debug history", "chrome,centerscreen,resizable", this);
19:58 &lt; shaver&gt; sure, or 
                Components.utils.reportError(String(window.arguments[0]))
19:59 &lt;someguy&gt; yep, the object is there: [xpconnect wrapped nsIMyXPCOMObject]
</pre>
Revert to this revision