From 033a9214932e228af131a35322461d3a3e7e06ae Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Thu, 13 Sep 2007 20:36:04 +0000 Subject: Move EphyUtils and GeckoUtils to utils/. svn path=/trunk/; revision=7434 --- embed/xulrunner/embed/EphyUtils.cpp | 207 ----------------------------------- embed/xulrunner/embed/EphyUtils.h | 66 ----------- embed/xulrunner/embed/Makefile.am | 2 - embed/xulrunner/src/GeckoUtils.cpp | 87 --------------- embed/xulrunner/src/GeckoUtils.h | 34 ------ embed/xulrunner/src/Makefile.am | 2 - embed/xulrunner/utils/EphyUtils.cpp | 203 ++++++++++++++++++++++++++++++++++ embed/xulrunner/utils/EphyUtils.h | 66 +++++++++++ embed/xulrunner/utils/GeckoUtils.cpp | 87 +++++++++++++++ embed/xulrunner/utils/GeckoUtils.h | 34 ++++++ embed/xulrunner/utils/Makefile.am | 5 + 11 files changed, 395 insertions(+), 398 deletions(-) delete mode 100644 embed/xulrunner/embed/EphyUtils.cpp delete mode 100644 embed/xulrunner/embed/EphyUtils.h delete mode 100644 embed/xulrunner/src/GeckoUtils.cpp delete mode 100644 embed/xulrunner/src/GeckoUtils.h create mode 100644 embed/xulrunner/utils/EphyUtils.cpp create mode 100644 embed/xulrunner/utils/EphyUtils.h create mode 100644 embed/xulrunner/utils/GeckoUtils.cpp create mode 100644 embed/xulrunner/utils/GeckoUtils.h diff --git a/embed/xulrunner/embed/EphyUtils.cpp b/embed/xulrunner/embed/EphyUtils.cpp deleted file mode 100644 index af030d6f5..000000000 --- a/embed/xulrunner/embed/EphyUtils.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright © 2004 Marco Pesenti Gritti - * - * 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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include -#include "config.h" - -#include - -#include -#include /* for GetScriptContextFromJSContext */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ephy-embed-shell.h" -#include "ephy-embed-single.h" -#include "ephy-file-helpers.h" - -#include "EphyUtils.h" - -nsresult -EphyUtils::GetIOService (nsIIOService **ioService) -{ - nsresult rv; - - nsCOMPtr mgr; - NS_GetServiceManager (getter_AddRefs (mgr)); - if (!mgr) return NS_ERROR_FAILURE; - - rv = mgr->GetServiceByContractID ("@mozilla.org/network/io-service;1", - NS_GET_IID (nsIIOService), - (void **)ioService); - return rv; -} - -nsresult -EphyUtils::NewURI (nsIURI **result, - const nsAString &spec, - const char *charset, - nsIURI *baseURI) -{ - nsCString cSpec; - NS_UTF16ToCString (spec, NS_CSTRING_ENCODING_UTF8, cSpec); - - return NewURI (result, cSpec, charset, baseURI); -} - -nsresult -EphyUtils::NewURI (nsIURI **result, - const nsACString &spec, - const char *charset, - nsIURI *baseURI) -{ - nsresult rv; - nsCOMPtr ioService; - rv = EphyUtils::GetIOService (getter_AddRefs (ioService)); - NS_ENSURE_SUCCESS (rv, rv); - - return ioService->NewURI (spec, charset, baseURI, result); -} - -nsresult -EphyUtils::NewFileURI (nsIURI **result, - nsIFile *spec) -{ - nsresult rv; - nsCOMPtr ioService; - rv = EphyUtils::GetIOService (getter_AddRefs (ioService)); - NS_ENSURE_SUCCESS (rv, rv); - - return ioService->NewFileURI (spec, result); -} - -GtkWidget * -EphyUtils::FindEmbed (nsIDOMWindow *aDOMWindow) -{ - if (!aDOMWindow) return nsnull; - - nsCOMPtr wwatch - (do_GetService("@mozilla.org/embedcomp/window-watcher;1")); - NS_ENSURE_TRUE (wwatch, nsnull); - - /* this DOM window may belong to some inner frame, we need - * to get the topmost DOM window to get the embed - */ - nsCOMPtr topWindow; - aDOMWindow->GetTop (getter_AddRefs (topWindow)); - if (!topWindow) return nsnull; - - nsCOMPtr windowChrome; - wwatch->GetChromeForWindow (topWindow, getter_AddRefs(windowChrome)); - NS_ENSURE_TRUE (windowChrome, nsnull); - - nsCOMPtr window (do_QueryInterface(windowChrome)); - NS_ENSURE_TRUE (window, nsnull); - - nsresult rv; - GtkWidget *mozembed; - rv = window->GetSiteWindow ((void **)&mozembed); - NS_ENSURE_SUCCESS (rv, nsnull); - - return mozembed; -} - -GtkWidget * -EphyUtils::FindGtkParent (nsIDOMWindow *aDOMWindow) -{ - GtkWidget *embed = FindEmbed (aDOMWindow); - if (!embed) return nsnull; - - GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (embed)); - if (!GTK_WIDGET_TOPLEVEL (toplevel)) return nsnull; - - return toplevel; -} - -char * -EphyUtils::ConvertUTF16toUTF8 (const PRUnichar *aText, - PRInt32 aMaxLength) -{ - if (aText == nsnull) return NULL; - - /* This depends on the assumption that - * typeof(PRUnichar) == typeof (gunichar2) == uint16, - * which should be pretty safe. - */ - glong n_read = 0, n_written = 0; - char *converted = g_utf16_to_utf8 ((gunichar2*) aText, aMaxLength, - &n_read, &n_written, NULL); - /* FIXME loop from the end while !g_unichar_isspace (char)? */ - - return converted; -} - -/* This isn't completely accurate: if you do window.prompt in one window, then - * call this in another window, it still returns TRUE ! Those are the wonders - * of recursive mainloops :-( - */ -PRBool -EphyJSUtils::IsCalledFromScript () -{ - nsresult rv; - nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID(), &rv)); - NS_ENSURE_SUCCESS (rv, PR_FALSE); - - nsCOMPtr ncc; - rv = xpc->GetCurrentNativeCallContext (getter_AddRefs (ncc)); - NS_ENSURE_SUCCESS(rv, PR_FALSE); - - return nsnull != ncc; -} - -/* NOTE: Only call this when we're SURE that we're called directly from JS! */ -nsIDOMWindow * -EphyJSUtils::GetDOMWindowFromCallContext () -{ - nsresult rv; - nsCOMPtr xpc (do_GetService(nsIXPConnect::GetCID(), &rv)); - NS_ENSURE_SUCCESS (rv, nsnull); - - nsCOMPtr ncc; - rv = xpc->GetCurrentNativeCallContext (getter_AddRefs (ncc)); - NS_ENSURE_SUCCESS (rv, nsnull); - - JSContext *cx = nsnull; - rv = ncc->GetJSContext(&cx); - NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && cx, nsnull); - - nsIScriptContext* scriptContext = GetScriptContextFromJSContext (cx); - if (!scriptContext) return nsnull; - - nsIScriptGlobalObject *globalObject = scriptContext->GetGlobalObject(); - if (!globalObject) return nsnull; - - nsCOMPtr piWindow (do_QueryInterface (globalObject)); - if (!piWindow) return nsnull; - - return piWindow->GetOuterWindow (); -} diff --git a/embed/xulrunner/embed/EphyUtils.h b/embed/xulrunner/embed/EphyUtils.h deleted file mode 100644 index 65b1edb04..000000000 --- a/embed/xulrunner/embed/EphyUtils.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright © 2004 Marco Pesenti Gritti - * - * 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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef EPHY_UTILS_H -#define EPHY_UTILS_H - -#include - -#include - -class nsACString; -class nsAString; -class nsIDOMWindow; -class nsIFile; -class nsIIOService; -class nsIURI; - -namespace EphyUtils -{ - nsresult GetIOService (nsIIOService **ioService); - - nsresult NewURI (nsIURI **result, - const nsAString &spec, - const char *charset = nsnull, - nsIURI *baseURI = nsnull); - - nsresult NewURI (nsIURI **result, - const nsACString &spec, - const char *charset = nsnull, - nsIURI *baseURI = nsnull); - - nsresult NewFileURI (nsIURI **result, - nsIFile *spec); - - GtkWidget *FindEmbed (nsIDOMWindow *aDOMWindow); - - GtkWidget *FindGtkParent (nsIDOMWindow *aDOMWindow); - - char * ConvertUTF16toUTF8 (const PRUnichar*, PRInt32); -} - -namespace EphyJSUtils -{ - PRBool IsCalledFromScript (); - - /* not addref'd! */ nsIDOMWindow* GetDOMWindowFromCallContext (); -} - -#endif diff --git a/embed/xulrunner/embed/Makefile.am b/embed/xulrunner/embed/Makefile.am index d7c9bd503..3fcc011fc 100644 --- a/embed/xulrunner/embed/Makefile.am +++ b/embed/xulrunner/embed/Makefile.am @@ -13,8 +13,6 @@ libephyxulrunnerembed_la_SOURCES = \ EphyHistoryListener.h \ EphySingle.cpp \ EphySingle.h \ - EphyUtils.cpp \ - EphyUtils.h \ EventContext.cpp \ EventContext.h \ mozilla-download.cpp \ diff --git a/embed/xulrunner/src/GeckoUtils.cpp b/embed/xulrunner/src/GeckoUtils.cpp deleted file mode 100644 index c71fce4ba..000000000 --- a/embed/xulrunner/src/GeckoUtils.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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 - * - * $Id$ - */ - -#include -#include "config.h" - -#include "GeckoUtils.h" - -#include "gecko-embed.h" - -#include -#include -#include -#include -#include -#include -#include - -GtkWidget * -GeckoUtils::GetGeckoEmbedForDOMWindow (nsIDOMWindow * aDOMWindow) -{ - if (!aDOMWindow) - return NULL; - - /* Get the toplevel DOM window, in case this window is a frame */ - nsCOMPtr 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 chrome; - wwatch->GetChromeForWindow (domWin, getter_AddRefs (chrome)); - - nsCOMPtr 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; -} diff --git a/embed/xulrunner/src/GeckoUtils.h b/embed/xulrunner/src/GeckoUtils.h deleted file mode 100644 index 05012e6b2..000000000 --- a/embed/xulrunner/src/GeckoUtils.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright © 2006 Christian Persch - * - * 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. - * - * $Id$ - */ - -#ifndef GECKO_UTILS_H -#define GECKO_UTILS_H - -#include - -class nsIDOMWindow; - -namespace GeckoUtils -{ - GtkWidget* GetGeckoEmbedForDOMWindow (nsIDOMWindow*); - GtkWidget* GetGtkWindowForDOMWindow (nsIDOMWindow*); -} - -#endif diff --git a/embed/xulrunner/src/Makefile.am b/embed/xulrunner/src/Makefile.am index ec9847849..0d205386a 100644 --- a/embed/xulrunner/src/Makefile.am +++ b/embed/xulrunner/src/Makefile.am @@ -93,8 +93,6 @@ libgnomegeckoembed_la_SOURCES = \ GeckoBrowser.h \ GeckoSingle.cpp \ GeckoSingle.h \ - GeckoUtils.cpp \ - GeckoUtils.h \ $(NULL) libgnomegeckoembed_la_CPPFLAGS = \ diff --git a/embed/xulrunner/utils/EphyUtils.cpp b/embed/xulrunner/utils/EphyUtils.cpp new file mode 100644 index 000000000..a433294c8 --- /dev/null +++ b/embed/xulrunner/utils/EphyUtils.cpp @@ -0,0 +1,203 @@ +/* + * Copyright © 2004 Marco Pesenti Gritti + * + * 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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $Id$ + */ + +#include +#include "config.h" + +#include + +#include +#include /* for GetScriptContextFromJSContext */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "EphyUtils.h" + +nsresult +EphyUtils::GetIOService (nsIIOService **ioService) +{ + nsresult rv; + + nsCOMPtr mgr; + NS_GetServiceManager (getter_AddRefs (mgr)); + if (!mgr) return NS_ERROR_FAILURE; + + rv = mgr->GetServiceByContractID ("@mozilla.org/network/io-service;1", + NS_GET_IID (nsIIOService), + (void **)ioService); + return rv; +} + +nsresult +EphyUtils::NewURI (nsIURI **result, + const nsAString &spec, + const char *charset, + nsIURI *baseURI) +{ + nsCString cSpec; + NS_UTF16ToCString (spec, NS_CSTRING_ENCODING_UTF8, cSpec); + + return NewURI (result, cSpec, charset, baseURI); +} + +nsresult +EphyUtils::NewURI (nsIURI **result, + const nsACString &spec, + const char *charset, + nsIURI *baseURI) +{ + nsresult rv; + nsCOMPtr ioService; + rv = EphyUtils::GetIOService (getter_AddRefs (ioService)); + NS_ENSURE_SUCCESS (rv, rv); + + return ioService->NewURI (spec, charset, baseURI, result); +} + +nsresult +EphyUtils::NewFileURI (nsIURI **result, + nsIFile *spec) +{ + nsresult rv; + nsCOMPtr ioService; + rv = EphyUtils::GetIOService (getter_AddRefs (ioService)); + NS_ENSURE_SUCCESS (rv, rv); + + return ioService->NewFileURI (spec, result); +} + +GtkWidget * +EphyUtils::FindEmbed (nsIDOMWindow *aDOMWindow) +{ + if (!aDOMWindow) return nsnull; + + nsCOMPtr wwatch + (do_GetService("@mozilla.org/embedcomp/window-watcher;1")); + NS_ENSURE_TRUE (wwatch, nsnull); + + /* this DOM window may belong to some inner frame, we need + * to get the topmost DOM window to get the embed + */ + nsCOMPtr topWindow; + aDOMWindow->GetTop (getter_AddRefs (topWindow)); + if (!topWindow) return nsnull; + + nsCOMPtr windowChrome; + wwatch->GetChromeForWindow (topWindow, getter_AddRefs(windowChrome)); + NS_ENSURE_TRUE (windowChrome, nsnull); + + nsCOMPtr window (do_QueryInterface(windowChrome)); + NS_ENSURE_TRUE (window, nsnull); + + nsresult rv; + GtkWidget *mozembed; + rv = window->GetSiteWindow ((void **)&mozembed); + NS_ENSURE_SUCCESS (rv, nsnull); + + return mozembed; +} + +GtkWidget * +EphyUtils::FindGtkParent (nsIDOMWindow *aDOMWindow) +{ + GtkWidget *embed = FindEmbed (aDOMWindow); + if (!embed) return nsnull; + + GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (embed)); + if (!GTK_WIDGET_TOPLEVEL (toplevel)) return nsnull; + + return toplevel; +} + +char * +EphyUtils::ConvertUTF16toUTF8 (const PRUnichar *aText, + PRInt32 aMaxLength) +{ + if (aText == nsnull) return NULL; + + /* This depends on the assumption that + * typeof(PRUnichar) == typeof (gunichar2) == uint16, + * which should be pretty safe. + */ + glong n_read = 0, n_written = 0; + char *converted = g_utf16_to_utf8 ((gunichar2*) aText, aMaxLength, + &n_read, &n_written, NULL); + /* FIXME loop from the end while !g_unichar_isspace (char)? */ + + return converted; +} + +/* This isn't completely accurate: if you do window.prompt in one window, then + * call this in another window, it still returns TRUE ! Those are the wonders + * of recursive mainloops :-( + */ +PRBool +EphyJSUtils::IsCalledFromScript () +{ + nsresult rv; + nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID(), &rv)); + NS_ENSURE_SUCCESS (rv, PR_FALSE); + + nsCOMPtr ncc; + rv = xpc->GetCurrentNativeCallContext (getter_AddRefs (ncc)); + NS_ENSURE_SUCCESS(rv, PR_FALSE); + + return nsnull != ncc; +} + +/* NOTE: Only call this when we're SURE that we're called directly from JS! */ +nsIDOMWindow * +EphyJSUtils::GetDOMWindowFromCallContext () +{ + nsresult rv; + nsCOMPtr xpc (do_GetService(nsIXPConnect::GetCID(), &rv)); + NS_ENSURE_SUCCESS (rv, nsnull); + + nsCOMPtr ncc; + rv = xpc->GetCurrentNativeCallContext (getter_AddRefs (ncc)); + NS_ENSURE_SUCCESS (rv, nsnull); + + JSContext *cx = nsnull; + rv = ncc->GetJSContext(&cx); + NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && cx, nsnull); + + nsIScriptContext* scriptContext = GetScriptContextFromJSContext (cx); + if (!scriptContext) return nsnull; + + nsIScriptGlobalObject *globalObject = scriptContext->GetGlobalObject(); + if (!globalObject) return nsnull; + + nsCOMPtr piWindow (do_QueryInterface (globalObject)); + if (!piWindow) return nsnull; + + return piWindow->GetOuterWindow (); +} diff --git a/embed/xulrunner/utils/EphyUtils.h b/embed/xulrunner/utils/EphyUtils.h new file mode 100644 index 000000000..65b1edb04 --- /dev/null +++ b/embed/xulrunner/utils/EphyUtils.h @@ -0,0 +1,66 @@ +/* + * Copyright © 2004 Marco Pesenti Gritti + * + * 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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $Id$ + */ + +#ifndef EPHY_UTILS_H +#define EPHY_UTILS_H + +#include + +#include + +class nsACString; +class nsAString; +class nsIDOMWindow; +class nsIFile; +class nsIIOService; +class nsIURI; + +namespace EphyUtils +{ + nsresult GetIOService (nsIIOService **ioService); + + nsresult NewURI (nsIURI **result, + const nsAString &spec, + const char *charset = nsnull, + nsIURI *baseURI = nsnull); + + nsresult NewURI (nsIURI **result, + const nsACString &spec, + const char *charset = nsnull, + nsIURI *baseURI = nsnull); + + nsresult NewFileURI (nsIURI **result, + nsIFile *spec); + + GtkWidget *FindEmbed (nsIDOMWindow *aDOMWindow); + + GtkWidget *FindGtkParent (nsIDOMWindow *aDOMWindow); + + char * ConvertUTF16toUTF8 (const PRUnichar*, PRInt32); +} + +namespace EphyJSUtils +{ + PRBool IsCalledFromScript (); + + /* not addref'd! */ nsIDOMWindow* GetDOMWindowFromCallContext (); +} + +#endif diff --git a/embed/xulrunner/utils/GeckoUtils.cpp b/embed/xulrunner/utils/GeckoUtils.cpp new file mode 100644 index 000000000..c71fce4ba --- /dev/null +++ b/embed/xulrunner/utils/GeckoUtils.cpp @@ -0,0 +1,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 + * + * $Id$ + */ + +#include +#include "config.h" + +#include "GeckoUtils.h" + +#include "gecko-embed.h" + +#include +#include +#include +#include +#include +#include +#include + +GtkWidget * +GeckoUtils::GetGeckoEmbedForDOMWindow (nsIDOMWindow * aDOMWindow) +{ + if (!aDOMWindow) + return NULL; + + /* Get the toplevel DOM window, in case this window is a frame */ + nsCOMPtr 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 chrome; + wwatch->GetChromeForWindow (domWin, getter_AddRefs (chrome)); + + nsCOMPtr 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; +} diff --git a/embed/xulrunner/utils/GeckoUtils.h b/embed/xulrunner/utils/GeckoUtils.h new file mode 100644 index 000000000..05012e6b2 --- /dev/null +++ b/embed/xulrunner/utils/GeckoUtils.h @@ -0,0 +1,34 @@ +/* + * Copyright © 2006 Christian Persch + * + * 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. + * + * $Id$ + */ + +#ifndef GECKO_UTILS_H +#define GECKO_UTILS_H + +#include + +class nsIDOMWindow; + +namespace GeckoUtils +{ + GtkWidget* GetGeckoEmbedForDOMWindow (nsIDOMWindow*); + GtkWidget* GetGtkWindowForDOMWindow (nsIDOMWindow*); +} + +#endif diff --git a/embed/xulrunner/utils/Makefile.am b/embed/xulrunner/utils/Makefile.am index faeab4716..ef773f3fb 100644 --- a/embed/xulrunner/utils/Makefile.am +++ b/embed/xulrunner/utils/Makefile.am @@ -9,9 +9,14 @@ libephyxulrunnerutils_la_SOURCES = \ AutoWindowModalState.h \ EphyBadCertRejector.cpp \ EphyBadCertRejector.h \ + EphyUtils.cpp \ + EphyUtils.h \ + GeckoUtils.cpp \ + GeckoUtils.h \ $(NULL) libephyxulrunnerutils_la_CPPFLAGS = \ + -I$(top_srcdir)/embed/xulrunner/src \ $(LIBXUL_CXXCPPFLAGS) \ $(LIBXUL_INCLUDES) \ $(AM_CPPFLAGS) -- cgit v1.2.3