rendered paste body#include <xpcom-config.h>
#include <nsCOMPtr.h>
#include <nsIContent.h>
#include <nsIObserverService.h>
#include <nsStringAPI.h>
#include <nsDebug.h>
#include <nsComponentManagerUtils.h>
#include <nsIInterfaceRequestorUtils.h>
#include <nsServiceManagerUtils.h>
#include <nsIWidget.h>
#include <nsIWindowMediator.h>
#include <nsIBaseWindow.h>
#include <nsIXULWindow.h>
#include <nsIDOMWindowUtils.h>
#include <nsIDocShell.h>
#include <nsIDocShellTreeItem.h>
#include <nsIDocShellTreeOwner.h>
#include <prenv.h>
#include <glib-object.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
guint32
get_base_window_xid (nsCOMPtr<nsIBaseWindow> baseWindow)
{
nsCOMPtr<nsIWidget> mainWidget;
baseWindow->GetMainWidget(getter_AddRefs(mainWidget));
if (!mainWidget)
return 0;
GdkWindow *window = static_cast<GdkWindow *>(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<nsIWindowMediator> wm =
do_GetService("@mozilla.org/appshell/window-mediator;1");
if (!wm)
return 0;
nsCOMPtr<nsIDOMWindow> recentWindow;
wm->GetMostRecentWindow(NULL, getter_AddRefs(recentWindow));
if (!recentWindow)
return 0;
nsCOMPtr<nsIDOMWindowUtils> domWindowUtils = do_GetInterface(recentWindow);
if (!domWindowUtils)
return 0;
nsCOMPtr<nsIDOMWindow> windowWithID;
domWindowUtils->GetOuterWindowWithId(id, getter_AddRefs(windowWithID));
if (!windowWithID)
return 0;
nsCOMPtr<nsPIDOMWindow> pWindow = do_QueryInterface(windowWithID);
if (!pWindow)
return 0;
nsIDocShell *docShell = pWindow->GetDocShell();
if (!docShell)
return 0;
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem = do_GetInterface(docShell);
if (!docShellTreeItem)
return 0;
nsCOMPtr<nsIDocShellTreeOwner> docShellTreeOwner;
docShellTreeItem->GetTreeOwner(getter_AddRefs(docShellTreeOwner));
if (!docShellTreeOwner)
return 0;
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(docShellTreeOwner);
if (!baseWindow)
return 0;
return get_base_window_xid (baseWindow);
}
}