#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include guint32 get_base_window_xid (nsCOMPtr baseWindow) { nsCOMPtr mainWidget; baseWindow->GetMainWidget(getter_AddRefs(mainWidget)); if (!mainWidget) return 0; GdkWindow *window = static_cast(mainWidget->GetNativeData(NS_NATIVE_WINDOW)); if (!window) return 0; window = gdk_window_get_toplevel(window); return GDK_WINDOW_XID (window); } extern "C" { guint32 get_xid_for_outer_window_with_id (guint32 id) { nsCOMPtr wm = do_GetService("@mozilla.org/appshell/window-mediator;1"); if (!wm) return 0; nsCOMPtr recentWindow; wm->GetMostRecentWindow(NULL, getter_AddRefs(recentWindow)); if (!recentWindow) return 0; nsCOMPtr domWindowUtils = do_GetInterface(recentWindow); if (!domWindowUtils) return 0; nsCOMPtr windowWithID; domWindowUtils->GetOuterWindowWithId(id, getter_AddRefs(windowWithID)); if (!windowWithID) return 0; nsCOMPtr pWindow = do_QueryInterface(windowWithID); if (!pWindow) return 0; nsIDocShell *docShell = pWindow->GetDocShell(); if (!docShell) return 0; nsCOMPtr docShellTreeItem = do_GetInterface(docShell); if (!docShellTreeItem) return 0; nsCOMPtr docShellTreeOwner; docShellTreeItem->GetTreeOwner(getter_AddRefs(docShellTreeOwner)); if (!docShellTreeOwner) return 0; nsCOMPtr baseWindow = do_QueryInterface(docShellTreeOwner); if (!baseWindow) return 0; return get_base_window_xid (baseWindow); } }