There is really nothing special here. DOM windows implement the nsIInterfaceRequestor
interface that allows getting related objects. One such object is the docshell that is associated with the window - you get it by asking for the nsIWebNavigation
interface but it also implements the nsIDocShell
and nsIDocShellTreeItem
interfaces - and nsIInterfaceRequestor
. The docshell for the current window lets you get to the docshell for the top window, despite the security boundary between chrome and content. And there you can use the nsIInterfaceRequestor
interface again to ask the docshell for the window associated with it.
You can simply implement the nsIInterfaceRequestor
interface in your XPCOM component just like any other interface. I don't see any reason to ever do that however, it's an ugly hack to hide internal window-related interfaces from the DOM.