I think that the only place where you can get it is nsIEmbeddingSiteWindow.siteWindow (its type is GtkWidget*
on Linux, it should be possible to get the window id from that). Getting an nsIEmbeddingSiteWindow
instance for a top-level window is relatively straightforward:
Components.utils.import("resource://gre/modules/Services.jsm");
var embedding = Services.ww.getChromeForWindow(window)
.QueryInterface(Components.interfaces.nsIEmbeddingSiteWindow);
The problem is that the siteWindow
property is marked with the [noscript]
annotator - it isn't accessible from JavaScript. So I had to use a binary XPCOM component (written in C++) to actually retrieve that property. Don't know whether that's an acceptable solution for you. The only alternative should be searching the window tree indeed.