aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla/EphyUtils.cpp
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2006-07-24 03:55:18 +0800
committerChristian Persch <chpe@src.gnome.org>2006-07-24 03:55:18 +0800
commitff3e857464ce32f626e080f93ea66ce1b5c372e3 (patch)
treeaefe9124a3dad057d88f4061e4d3c7de8106221c /embed/mozilla/EphyUtils.cpp
parent63e95001e7f36aa5833acea04643b52f8b70b765 (diff)
downloadgsoc2013-epiphany-ff3e857464ce32f626e080f93ea66ce1b5c372e3.tar
gsoc2013-epiphany-ff3e857464ce32f626e080f93ea66ce1b5c372e3.tar.gz
gsoc2013-epiphany-ff3e857464ce32f626e080f93ea66ce1b5c372e3.tar.bz2
gsoc2013-epiphany-ff3e857464ce32f626e080f93ea66ce1b5c372e3.tar.lz
gsoc2013-epiphany-ff3e857464ce32f626e080f93ea66ce1b5c372e3.tar.xz
gsoc2013-epiphany-ff3e857464ce32f626e080f93ea66ce1b5c372e3.tar.zst
gsoc2013-epiphany-ff3e857464ce32f626e080f93ea66ce1b5c372e3.zip
Implement nsIDOMCryptoDialogs, nsITokenDialogs and
2006-07-22 Christian Persch <chpe@cvs.gnome.org> * embed/mozilla/GtkNSSDialogs.cpp: * embed/mozilla/GtkNSSDialogs.h: * embed/mozilla/MozRegisterComponents.cpp: Implement nsIDOMCryptoDialogs, nsITokenDialogs and nsITokenPasswordDialogs. Bug #312869. * embed/mozilla/EphyUtils.cpp: * embed/mozilla/EphyUtils.h: Add a helper function to get the DOM window off the native call context, to work around unavailable parent window in nsIDOMCryptoDialogs ( https://bugzilla.mozilla.org/show_bug.cgi?id=341914).
Diffstat (limited to 'embed/mozilla/EphyUtils.cpp')
-rw-r--r--embed/mozilla/EphyUtils.cpp50
1 files changed, 46 insertions, 4 deletions
diff --git a/embed/mozilla/EphyUtils.cpp b/embed/mozilla/EphyUtils.cpp
index ab6d78e1a..d5ac7fec6 100644
--- a/embed/mozilla/EphyUtils.cpp
+++ b/embed/mozilla/EphyUtils.cpp
@@ -21,21 +21,28 @@
#include "mozilla-config.h"
#include "config.h"
+#include <nsStringAPI.h>
+
#include <gtkmozembed.h>
#include <nsCOMPtr.h>
#include <nsIDOMWindow.h>
#include <nsIEmbeddingSiteWindow.h>
#include <nsIFile.h>
#include <nsIIOService.h>
-#include <nsIPrintSettings.h>
#include <nsIServiceManager.h>
#include <nsIURI.h>
#include <nsIWebBrowserChrome.h>
#include <nsIWindowWatcher.h>
+#include <nsIXPConnect.h>
#include <nsServiceManagerUtils.h>
-#include <nsStringAPI.h>
#include <nsXPCOM.h>
-#include <nsIXPConnect.h>
+
+#ifdef HAVE_GECKO_1_9
+#include <nsPIDOMWindow.h>
+#include <nsDOMJSUtils.h> /* for GetScriptContextFromJSContext */
+#include <nsIScriptContext.h>
+#include <nsIScriptGlobalObject.h>
+#endif
#include "ephy-embed-shell.h"
#include "ephy-embed-single.h"
@@ -131,7 +138,7 @@ GtkWidget *
EphyUtils::FindGtkParent (nsIDOMWindow *aDOMWindow)
{
GtkWidget *embed = FindEmbed (aDOMWindow);
- NS_ENSURE_TRUE (embed, nsnull);
+ if (!embed) return nsnull;
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (embed));
if (!GTK_WIDGET_TOPLEVEL (toplevel)) return nsnull;
@@ -174,3 +181,38 @@ EphyJSUtils::IsCalledFromScript ()
return nsnull != ncc;
}
+
+/* NOTE: Only call this when we're SURE that we're called directly from JS! */
+nsIDOMWindow *
+EphyJSUtils::GetDOMWindowFromCallContext ()
+{
+ /* TODO: We can do this on 1.8 too, but we'd need to use headers which include private string API
+ * so we'll have to move this to MozillaPrivate
+ */
+#ifdef HAVE_GECKO_1_9
+ nsresult rv;
+ nsCOMPtr<nsIXPConnect> xpc (do_GetService(nsIXPConnect::GetCID(), &rv));
+ NS_ENSURE_SUCCESS (rv, nsnull);
+
+ nsCOMPtr<nsIXPCNativeCallContext> 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<nsPIDOMWindow> piWindow (do_QueryInterface (globalObject));
+ if (!piWindow) return nsnull;
+
+ return piWindow->GetOuterWindow ();
+#else
+ return nsnull;
+#endif
+}