aboutsummaryrefslogtreecommitdiffstats
path: root/embed/xulrunner/src/GeckoUtils.cpp
blob: c71fce4bad9fdfbe00c837e58402cbcd7984ec9c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation; either version 2.1, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *  The Original Code is mozilla.org code.
 *
 *  The Initial Developer of the Original Code is
 *  Netscape Communications Corporation.
 *  Portions created by the Initial Developer are Copyright © 2003
 *  the Initial Developer. All Rights Reserved.
 *
 *  Contributor(s):
 *   Brian Ryner <bryner@brianryner.com>
 *
 *  $Id$
 */

#include <xpcom-config.h>
#include "config.h"

#include "GeckoUtils.h"

#include "gecko-embed.h"

#include <nsCOMPtr.h>
#include <nsIDOMWindow.h>
#include <nsIWindowWatcher.h>
#include <nsIWebBrowserChrome.h>
#include <nsIEmbeddingSiteWindow.h>
#include <nsIServiceManager.h>
#include <nsServiceManagerUtils.h>

GtkWidget *
GeckoUtils::GetGeckoEmbedForDOMWindow (nsIDOMWindow * aDOMWindow)
{
  if (!aDOMWindow)
    return NULL;

  /* Get the toplevel DOM window, in case this window is a frame */
  nsCOMPtr<nsIDOMWindow> domWin;
  aDOMWindow->GetTop (getter_AddRefs (domWin));
  if (!domWin)
    return NULL;

  nsCOMPtr< nsIWindowWatcher> wwatch
    (do_GetService ("@mozilla.org/embedcomp/window-watcher;1"));
  NS_ENSURE_TRUE (wwatch, NULL);

  nsCOMPtr<nsIWebBrowserChrome> chrome;
  wwatch->GetChromeForWindow (domWin, getter_AddRefs (chrome));

  nsCOMPtr <nsIEmbeddingSiteWindow> siteWindow (do_QueryInterface (chrome));
  if (!siteWindow)
    return NULL;

  GtkWidget *widget;
  siteWindow->GetSiteWindow ((void **) &widget);
  if (!widget || !GECKO_IS_EMBED (widget))
    return NULL;

  return widget;
}

GtkWidget *
GeckoUtils::GetGtkWindowForDOMWindow (nsIDOMWindow * aDOMWindow)
{
  GtkWidget *embed = GeckoUtils::GetGeckoEmbedForDOMWindow (aDOMWindow);
  if (!embed)
    return NULL;

  GtkWidget *gtkWin = gtk_widget_get_toplevel (embed);
  if (!GTK_WIDGET_TOPLEVEL (gtkWin))
    return NULL;

  return gtkWin;
}