~robru/unity-firefox-extension/quantal-sru-candidate

« back to all changes in this revision

Viewing changes to libufe-xidgetter/xid-getter.cpp

  • Committer: Ken VanDine
  • Date: 2012-09-11 20:20:06 UTC
  • mfrom: (83.37.51)
  • Revision ID: ken.vandine@canonical.com-20120911202006-cnidpkmvipd1m901
Tags: 2.3-0quantal1
releasing version 2.3-0quantal1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <xpcom-config.h>
2
 
#include <nsCOMPtr.h>
3
 
#include <nsIContent.h>
4
 
#include <nsIObserverService.h>
5
 
#include <nsStringAPI.h>
6
 
#include <nsDebug.h>
7
 
#include <nsComponentManagerUtils.h>
8
 
#include <nsIInterfaceRequestorUtils.h>
9
 
#include <nsServiceManagerUtils.h>
10
 
#include <nsIWidget.h>
11
 
#include <nsIWindowMediator.h>
12
 
#include <nsIBaseWindow.h>
13
 
#include <nsIXULWindow.h>
14
 
#include <nsIDOMWindowUtils.h>
15
 
#include <nsIDocShell.h>
16
 
#include <nsIDocShellTreeItem.h>
17
 
#include <nsIDocShellTreeOwner.h>
18
 
#include <prenv.h>
19
 
 
20
1
#include <glib-object.h>     
21
2
#include <gdk/gdk.h>
22
3
#include <gdk/gdkx.h>
23
4
 
 
5
extern "C" {
 
6
 
24
7
guint32
25
 
get_base_window_xid (nsCOMPtr<nsIBaseWindow> baseWindow)
 
8
get_base_window_xid (intptr_t pointer)
26
9
{
27
 
  nsCOMPtr<nsIWidget> mainWidget;
28
 
  baseWindow->GetMainWidget(getter_AddRefs(mainWidget));
29
 
  if (!mainWidget)
30
 
    return 0;
31
 
  
32
 
  GdkWindow *window = static_cast<GdkWindow *>(mainWidget->GetNativeData(NS_NATIVE_WINDOW));
 
10
  GdkWindow *window = reinterpret_cast<GdkWindow *> (pointer);
 
11
 
33
12
  if (!window)
34
13
    return 0;
35
14
 
36
15
  window = gdk_window_get_toplevel(window);
37
 
  
 
16
 
38
17
  return GDK_WINDOW_XID (window);
39
 
 
40
 
}
41
 
 
42
 
extern "C" {
43
 
 
44
 
guint32
45
 
get_xid_for_outer_window_with_id (guint32 id)
46
 
{
47
 
  nsCOMPtr<nsIWindowMediator> wm =
48
 
    do_GetService("@mozilla.org/appshell/window-mediator;1");
49
 
  
50
 
  if (!wm)
51
 
    return 0;
52
 
 
53
 
  nsCOMPtr<nsIDOMWindow> recentWindow;
54
 
  wm->GetMostRecentWindow(NULL, getter_AddRefs(recentWindow));
55
 
  
56
 
  if (!recentWindow)
57
 
    return 0;
58
 
 
59
 
  nsCOMPtr<nsIDOMWindowUtils> domWindowUtils = do_GetInterface(recentWindow);
60
 
 
61
 
  if (!domWindowUtils)
62
 
    return 0;
63
 
 
64
 
  nsCOMPtr<nsIDOMWindow> windowWithID;
65
 
  domWindowUtils->GetOuterWindowWithId(id, getter_AddRefs(windowWithID));
66
 
  
67
 
  if (!windowWithID)
68
 
    return 0;
69
 
 
70
 
  nsCOMPtr<nsPIDOMWindow> pWindow = do_QueryInterface(windowWithID);
71
 
  
72
 
  if (!pWindow)
73
 
    return 0;
74
 
 
75
 
  nsIDocShell *docShell = pWindow->GetDocShell();
76
 
  
77
 
  if (!docShell)
78
 
    return 0;
79
 
 
80
 
  nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem = do_GetInterface(docShell);
81
 
  
82
 
  if (!docShellTreeItem)
83
 
    return 0;
84
 
 
85
 
  nsCOMPtr<nsIDocShellTreeOwner> docShellTreeOwner;
86
 
  docShellTreeItem->GetTreeOwner(getter_AddRefs(docShellTreeOwner));
87
 
  
88
 
  if (!docShellTreeOwner)
89
 
    return 0;
90
 
 
91
 
  nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(docShellTreeOwner);
92
 
  
93
 
  if (!baseWindow)
94
 
    return 0;
95
 
  
96
 
  return get_base_window_xid (baseWindow);
97
18
}
98
19
 
99
20
}