1

I'm trying to find out how to get a Firefox's X11 WId (window id) from within a Firefox addon/extension.

Checked out nsIWindowMediator, nsIXULBrowserWindow, nsIXULWindow but haven't found it.

I'd rather not go the usual way of (ab)using Xlib to search the window tree for one that matches the attributes of the current window like title, type and so on.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Ivan
  • 640
  • 5
  • 9

1 Answers1

0

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.

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
  • Really wanted to stay out of XPCOM and do a js-ctypes-only implementation. But if nothing else is possible, it is an acceptable solution. Thanks – Ivan Jun 16 '12 at 16:45
  • Was hoping for more ideas (guessing unanswered questions draw more attention) so I left it to linger for a while. – Ivan Jun 17 '12 at 18:56