From b5d229937e31e9cec6cf599ae816e22888237aa0 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Thu, 2 Feb 2006 22:25:18 +0000 Subject: Helper class that pushes a null JS context on the stack, and pops it in 2006-02-02 Christian Persch * embed/mozilla/Makefile.am: * embed/mozilla/AutoJSContextStack.cpp: * embed/mozilla/AutoJSContextStack.h: Helper class that pushes a null JS context on the stack, and pops it in the destructor. * embed/mozilla/ContentHandler.cpp: * embed/mozilla/EphyPromptService.cpp: * embed/mozilla/FilePicker.cpp: * embed/mozilla/GtkNSSClientAuthDialogs.cpp: * embed/mozilla/GtkNSSDialogs.cpp: * embed/mozilla/GtkNSSKeyPairDialogs.cpp: * embed/mozilla/GtkNSSSecurityWarningDialogs.cpp: * embed/mozilla/PrintingPromptService.cpp: Push a null JS context on the stack when we run a recursive mainloop. Fixes the epiphany equivalend of camino bug https://bugzilla.mozilla.org/show_bug.cgi?id=179307. --- embed/mozilla/AutoJSContextStack.cpp | 48 ++++++++++++++++++++++++++ embed/mozilla/AutoJSContextStack.h | 41 ++++++++++++++++++++++ embed/mozilla/ContentHandler.cpp | 6 ++++ embed/mozilla/EphyPromptService.cpp | 6 ++++ embed/mozilla/FilePicker.cpp | 6 ++++ embed/mozilla/GtkNSSClientAuthDialogs.cpp | 6 ++++ embed/mozilla/GtkNSSDialogs.cpp | 27 ++++++++++++++- embed/mozilla/GtkNSSKeyPairDialogs.cpp | 5 +++ embed/mozilla/GtkNSSSecurityWarningDialogs.cpp | 7 +++- embed/mozilla/Makefile.am | 2 ++ embed/mozilla/PrintingPromptService.cpp | 18 ++++++++-- 11 files changed, 167 insertions(+), 5 deletions(-) create mode 100644 embed/mozilla/AutoJSContextStack.cpp create mode 100644 embed/mozilla/AutoJSContextStack.h (limited to 'embed') diff --git a/embed/mozilla/AutoJSContextStack.cpp b/embed/mozilla/AutoJSContextStack.cpp new file mode 100644 index 000000000..77bbb81eb --- /dev/null +++ b/embed/mozilla/AutoJSContextStack.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 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 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$ + */ + +#include "mozilla-config.h" +#include "config.h" + +#include "AutoJSContextStack.h" + +#include +#include + +AutoJSContextStack::~AutoJSContextStack() +{ + if (mStack) + { + JSContext* cx; + mStack->Pop (&cx); + + NS_ASSERTION(cx == nsnull, "We pushed a null context but popped a non-null context!?"); + } +} + +nsresult +AutoJSContextStack::Init() +{ + nsresult rv; + mStack = do_GetService ("@mozilla.org/js/xpc/ContextStack;1", &rv); + if (NS_FAILED (rv)) return rv; + + return mStack->Push (nsnull); +} diff --git a/embed/mozilla/AutoJSContextStack.h b/embed/mozilla/AutoJSContextStack.h new file mode 100644 index 000000000..5f4069293 --- /dev/null +++ b/embed/mozilla/AutoJSContextStack.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 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 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 AUTO_JSCONTEXTSTACK_H +#define AUTO_JSCONTEXTSTACK_H + +struct JSContext; + +#include +#include + +class AutoJSContextStack +{ + public: + AutoJSContextStack () { } + ~AutoJSContextStack (); + + nsresult Init (); + + private: + nsCOMPtr mStack; +}; + +#endif diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp index e7d7ca885..6c3acd696 100644 --- a/embed/mozilla/ContentHandler.cpp +++ b/embed/mozilla/ContentHandler.cpp @@ -26,6 +26,7 @@ #include "config.h" #include "ContentHandler.h" +#include "AutoJSContextStack.h" #include #include @@ -166,6 +167,11 @@ NS_IMETHODIMP GContentHandler::PromptForSaveToFile( return BuildDownloadPath (defaultFile.get(), _retval); } + nsresult rv; + AutoJSContextStack stack; + rv = stack.Init (); + if (NS_FAILED (rv)) return rv; + nsCOMPtr parentDOMWindow = do_GetInterface (aWindowContext); GtkWidget *parentWindow = GTK_WIDGET (EphyUtils::FindGtkParent (parentDOMWindow)); diff --git a/embed/mozilla/EphyPromptService.cpp b/embed/mozilla/EphyPromptService.cpp index 6b6abf382..1d251d051 100644 --- a/embed/mozilla/EphyPromptService.cpp +++ b/embed/mozilla/EphyPromptService.cpp @@ -22,6 +22,7 @@ #include "config.h" #include "EphyPromptService.h" +#include "AutoJSContextStack.h" #include #include @@ -483,6 +484,11 @@ Prompter::Run (PRBool *aSuccess) } #endif + nsresult rv; + AutoJSContextStack stack; + rv = stack.Init (); + if (NS_FAILED (rv)) return rv; + if (mDelay) { guint timeout = g_timeout_add (TIMEOUT, diff --git a/embed/mozilla/FilePicker.cpp b/embed/mozilla/FilePicker.cpp index 9159e72ac..43b6b3688 100644 --- a/embed/mozilla/FilePicker.cpp +++ b/embed/mozilla/FilePicker.cpp @@ -25,6 +25,7 @@ #include "FilePicker.h" #include "EphyUtils.h" +#include "AutoJSContextStack.h" #include #undef MOZILLA_INTERNAL_API @@ -430,6 +431,11 @@ NS_IMETHODIMP GFilePicker::GetFiles(nsISimpleEnumerator * *aFiles) /* short show (); */ NS_IMETHODIMP GFilePicker::Show(PRInt16 *_retval) { + nsresult rv; + AutoJSContextStack stack; + rv = stack.Init (); + if (NS_FAILED (rv)) return rv; + LOG ("GFilePicker::Show"); gtk_window_set_modal (GTK_WINDOW (mDialog), TRUE); diff --git a/embed/mozilla/GtkNSSClientAuthDialogs.cpp b/embed/mozilla/GtkNSSClientAuthDialogs.cpp index ae88a6b25..b5169823b 100644 --- a/embed/mozilla/GtkNSSClientAuthDialogs.cpp +++ b/embed/mozilla/GtkNSSClientAuthDialogs.cpp @@ -25,6 +25,7 @@ #include "config.h" #include "EphyUtils.h" +#include "AutoJSContextStack.h" #include #include @@ -145,6 +146,11 @@ GtkNSSClientAuthDialogs::ChooseCertificate (nsIInterfaceRequestor *ctx, char *msg, *markup_text; PRUint32 i; + nsresult rv; + AutoJSContextStack stack; + rv = stack.Init (); + if (NS_FAILED (rv)) return rv; + nsCOMPtr parent = do_GetInterface (ctx); GtkWindow *gparent = GTK_WINDOW (EphyUtils::FindGtkParent (parent)); diff --git a/embed/mozilla/GtkNSSDialogs.cpp b/embed/mozilla/GtkNSSDialogs.cpp index a9c4f4c25..b9dfca829 100644 --- a/embed/mozilla/GtkNSSDialogs.cpp +++ b/embed/mozilla/GtkNSSDialogs.cpp @@ -31,6 +31,7 @@ #include "config.h" #include "EphyUtils.h" +#include "AutoJSContextStack.h" #include #include @@ -207,6 +208,11 @@ display_cert_warning_box (nsIInterfaceRequestor *ctx, GtkWidget *dialog, *label, *checkbox, *vbox, *button; int res; + nsresult rv; + AutoJSContextStack stack; + rv = stack.Init (); + if (NS_FAILED (rv)) return rv; + /* NOTE: Due to a mozilla bug [https://bugzilla.mozilla.org/show_bug.cgi?id=306288], * we will always end up without a parent! */ @@ -539,6 +545,11 @@ GtkNSSDialogs::ConfirmDownloadCACert(nsIInterfaceRequestor *ctx, GtkWidget *dialog, *label; char *msg, *primary; + nsresult rv; + AutoJSContextStack stack; + rv = stack.Init (); + if (NS_FAILED (rv)) return rv; + nsCOMPtr parent = do_GetInterface (ctx); GtkWindow *gparent = GTK_WINDOW (EphyUtils::FindGtkParent (parent)); @@ -751,6 +762,11 @@ GtkNSSDialogs::SetPKCS12FilePassword(nsIInterfaceRequestor *ctx, GtkWidget *progress; char *msg; + nsresult rv; + AutoJSContextStack stack; + rv = stack.Init (); + if (NS_FAILED (rv)) return rv; + nsCOMPtr parent = do_GetInterface (ctx); GtkWindow *gparent = GTK_WINDOW (EphyUtils::FindGtkParent (parent)); @@ -869,6 +885,11 @@ GtkNSSDialogs::GetPKCS12FilePassword(nsIInterfaceRequestor *ctx, GtkWidget *dialog, *hbox, *label, *entry, *vbox; char *msg; + nsresult rv; + AutoJSContextStack stack; + rv = stack.Init (); + if (NS_FAILED (rv)) return rv; + nsCOMPtr parent = do_GetInterface (ctx); GtkWindow *gparent = GTK_WINDOW (EphyUtils::FindGtkParent (parent)); @@ -1313,11 +1334,15 @@ GtkNSSDialogs::ViewCert(nsIInterfaceRequestor *ctx, GtkWidget *dialog, *widget; GladeXML *gxml; nsEmbedString value; - nsresult rv; PRUint32 verifystate, count; PRUnichar ** usage; GtkSizeGroup * sizegroup; + nsresult rv; + AutoJSContextStack stack; + rv = stack.Init (); + if (NS_FAILED (rv)) return rv; + gxml = glade_xml_new (ephy_file ("certificate-dialogs.glade"), "viewcert_dialog", NULL); g_return_val_if_fail (gxml != NULL, NS_ERROR_FAILURE); diff --git a/embed/mozilla/GtkNSSKeyPairDialogs.cpp b/embed/mozilla/GtkNSSKeyPairDialogs.cpp index 5931a4e22..cd8315604 100644 --- a/embed/mozilla/GtkNSSKeyPairDialogs.cpp +++ b/embed/mozilla/GtkNSSKeyPairDialogs.cpp @@ -40,6 +40,7 @@ #include "config.h" #include "EphyUtils.h" +#include "AutoJSContextStack.h" #include #include @@ -197,6 +198,10 @@ GtkNSSKeyPairDialogs::DisplayGeneratingKeypairInfo (nsIInterfaceRequestor *ctx, GtkWidget *dialog, *progress, *label, *vbox; gint timeout_id; + nsresult rv; + AutoJSContextStack stack; + rv = stack.Init (); + if (NS_FAILED (rv)) return rv; nsCOMPtr parent = do_GetInterface (ctx); GtkWindow *gparent = GTK_WINDOW (EphyUtils::FindGtkParent (parent)); diff --git a/embed/mozilla/GtkNSSSecurityWarningDialogs.cpp b/embed/mozilla/GtkNSSSecurityWarningDialogs.cpp index 5bdc894d3..fe87b192f 100644 --- a/embed/mozilla/GtkNSSSecurityWarningDialogs.cpp +++ b/embed/mozilla/GtkNSSSecurityWarningDialogs.cpp @@ -47,6 +47,7 @@ #include "GtkNSSSecurityWarningDialogs.h" #include "EphyUtils.h" +#include "AutoJSContextStack.h" #include #include @@ -225,7 +226,11 @@ GtkNSSSecurityWarningDialogs::DoDialog (nsIInterfaceRequestor *aContext, *_retval = PR_TRUE; return; } - + + AutoJSContextStack stack; + rv = stack.Init (); + if (NS_FAILED (rv)); + /* Didn't you know it, mozilla SUCKS! * the "aContext" interface requestor is made from a nsIDOMWindow, * but can only give out a nsIPrompt, from where there's no way to get diff --git a/embed/mozilla/Makefile.am b/embed/mozilla/Makefile.am index f5504128b..e8c747e8f 100644 --- a/embed/mozilla/Makefile.am +++ b/embed/mozilla/Makefile.am @@ -1,6 +1,8 @@ noinst_LTLIBRARIES = libephymozillaembed.la libephymozillaembed_la_SOURCES = \ + AutoJSContextStack.cpp \ + AutoJSContextStack.h \ ContentHandler.cpp \ ContentHandler.h \ EphyAboutModule.cpp \ diff --git a/embed/mozilla/PrintingPromptService.cpp b/embed/mozilla/PrintingPromptService.cpp index 2770f0d30..218c63b81 100644 --- a/embed/mozilla/PrintingPromptService.cpp +++ b/embed/mozilla/PrintingPromptService.cpp @@ -24,6 +24,10 @@ #include "config.h" +#include "PrintingPromptService.h" +#include "EphyUtils.h" +#include "AutoJSContextStack.h" + #include #include @@ -31,8 +35,6 @@ #include "print-dialog.h" #include "ephy-embed.h" #include "ephy-command-manager.h" -#include "EphyUtils.h" -#include "PrintingPromptService.h" #include "eel-gconf-extensions.h" #include "ephy-prefs.h" #include "ephy-debug.h" @@ -72,6 +74,11 @@ NS_IMETHODIMP GPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIW return NS_ERROR_ABORT; } + nsresult rv; + AutoJSContextStack stack; + rv = stack.Init (); + if (NS_FAILED (rv)) return rv; + EphyEmbed *embed = EPHY_EMBED (EphyUtils::FindEmbed (parent)); NS_ENSURE_TRUE (embed, NS_ERROR_FAILURE); @@ -136,7 +143,8 @@ NS_IMETHODIMP GPrintingPromptService::ShowProgress(nsIDOMWindow *parent, nsIWebB } /* void showPageSetup (in nsIDOMWindow parent, in nsIPrintSettings printSettings, in nsIObserver printObserver); */ -NS_IMETHODIMP GPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent, nsIPrintSettings *printSettings, +NS_IMETHODIMP GPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent, + nsIPrintSettings *printSettings, nsIObserver *printObserver) { EphyDialog *dialog; @@ -148,6 +156,10 @@ NS_IMETHODIMP GPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent, nsIPri return rv; } + AutoJSContextStack stack; + rv = stack.Init (); + if (NS_FAILED (rv)) return rv; + dialog = ephy_print_setup_dialog_new (); ephy_dialog_set_modal (dialog, TRUE); -- cgit v1.2.3