epiphany r7967 - in trunk: doc/reference/tmpl embed/mozilla



Author: chpe
Date: Mon Feb 18 13:40:59 2008
New Revision: 7967
URL: http://svn.gnome.org/viewvc/epiphany?rev=7967&view=rev

Log:
Fix prompt service for xr 1.9 wrt. DOM notifications. Bug #504445.


Added:
   trunk/embed/mozilla/AutoModalDialog.cpp
   trunk/embed/mozilla/AutoModalDialog.h
Modified:
   trunk/doc/reference/tmpl/EphySingle.sgml
   trunk/doc/reference/tmpl/ephy-embed.sgml
   trunk/embed/mozilla/ContentHandler.cpp
   trunk/embed/mozilla/EphyPromptService.cpp
   trunk/embed/mozilla/FilePicker.cpp
   trunk/embed/mozilla/GeckoCookiePromptService.cpp
   trunk/embed/mozilla/GeckoFormSigningDialog.cpp
   trunk/embed/mozilla/GeckoPrintService.cpp
   trunk/embed/mozilla/GtkNSSClientAuthDialogs.cpp
   trunk/embed/mozilla/GtkNSSDialogs.cpp
   trunk/embed/mozilla/GtkNSSKeyPairDialogs.cpp
   trunk/embed/mozilla/GtkNSSSecurityWarningDialogs.cpp
   trunk/embed/mozilla/Makefile.am

Modified: trunk/doc/reference/tmpl/EphySingle.sgml
==============================================================================
--- trunk/doc/reference/tmpl/EphySingle.sgml	(original)
+++ trunk/doc/reference/tmpl/EphySingle.sgml	Mon Feb 18 13:40:59 2008
@@ -22,7 +22,7 @@
 
 </para>
 
- aHistory: 
+ aOwningWidget: 
 @Returns: 
 
 

Modified: trunk/doc/reference/tmpl/ephy-embed.sgml
==============================================================================
--- trunk/doc/reference/tmpl/ephy-embed.sgml	(original)
+++ trunk/doc/reference/tmpl/ephy-embed.sgml	Mon Feb 18 13:40:59 2008
@@ -150,6 +150,38 @@
 
 </para>
 
+ ephyembed: the object which received the signal.
+ arg1: 
+ arg2: 
+ arg3: 
+
+<!-- ##### SIGNAL EphyEmbed::ge-search-key-press ##### -->
+<para>
+
+</para>
+
+ ephyembed: the object which received the signal.
+ event: 
+ Returns: 
+
+<!-- ##### SIGNAL EphyEmbed::ge-search-link ##### -->
+<para>
+
+</para>
+
+ ephyembed: the object which received the signal.
+ arg1: 
+ arg2: 
+ arg3: 
+
+<!-- ##### SIGNAL EphyEmbed::ge-zoom-change ##### -->
+<para>
+
+</para>
+
+ ephyembed: the object which received the signal.
+ arg1: 
+
 <!-- ##### SIGNAL EphyEmbed::new-document-now ##### -->
 <para>
 
@@ -233,38 +265,8 @@
 @: 
 @: 
 @: 
-@: 
 @:
 @Param2: 
- Param3: 
- Param4: 
-
-<!-- ##### SIGNAL EphyEmbed::ge-search-key-press ##### -->
-<para>
-
-</para>
-
- ephyembed: the object which received the signal.
- event: 
- Returns: 
-
-<!-- ##### SIGNAL EphyEmbed::ge-search-link ##### -->
-<para>
-
-</para>
-
- ephyembed: the object which received the signal.
- arg1: 
- arg2: 
- arg3: 
-
-<!-- ##### SIGNAL EphyEmbed::ge-zoom-change ##### -->
-<para>
-
-</para>
-
- ephyembed: the object which received the signal.
- arg1: 
 
 <!-- ##### STRUCT EphyEmbedIface ##### -->
 <para>
@@ -288,6 +290,7 @@
 @new_window: 
 @search_key_press: 
 @close_request: 
+ new_document_now: 
 @load_url: 
 @load: 
 @stop_load: 

Added: trunk/embed/mozilla/AutoModalDialog.cpp
==============================================================================
--- (empty file)
+++ trunk/embed/mozilla/AutoModalDialog.cpp	Mon Feb 18 13:40:59 2008
@@ -0,0 +1,182 @@
+/* 
+ *  Copyright  2006, 2008 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Some code taken from mozilla/embedding/components/windowwatcher/src/nsPromptService.cpp
+ *  which was under MPL/LGPL/GPL tri-licence and is here being used under the licence above.
+ *  Original notice:
+ *
+ *   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 (C) 2001
+ *   the Initial Developer. All Rights Reserved.
+ */
+
+#include <xpcom-config.h>
+#include <config.h>
+
+#ifdef HAVE_GECKO_1_9
+#include <nsIDOMDocumentEvent.h>
+#include <nsIDOMDocument.h>
+#include <nsIDOMEvent.h>
+#include <nsIDOMEventTarget.h>
+#include <nsIJSContextStack.h>
+#include <nsIPrivateDOMEvent.h>
+#include <nsPIDOMWindow.h>
+#include <nsServiceManagerUtils.h>
+#include <nsThreadUtils.h>
+#endif /* HAVE_GECKO_1_9 */
+
+#include <gtk/gtkdialog.h>
+
+#include "EphyUtils.h"
+
+#include "AutoModalDialog.h"
+
+AutoModalDialog::AutoModalDialog (nsIDOMWindow *aWindow,
+                                  PRBool aNotifyDOM)
+  : mWindow (aWindow),
+    mStack (),
+    mModalState (aWindow),
+#ifdef HAVE_GECKO_1_9
+    mDefaultEnabled (DispatchEvent ("DOMWillOpenModalDialog", aNotifyDOM)),
+#endif
+    mContextPushed (NS_SUCCEEDED (mStack.Init ()))
+{
+}
+
+AutoModalDialog::~AutoModalDialog ()
+{
+#ifdef HAVE_GECKO_1_9
+  if (mDefaultEnabled) {
+    DispatchEvent ("DOMModalDialogClosed", PR_TRUE);
+  }
+#endif /* HAVE_GECKO_1_9 */
+}
+
+GtkWindow *
+AutoModalDialog::GetParent ()
+{
+  return GTK_WINDOW (EphyUtils::FindGtkParent (mWindow));
+}
+
+int
+AutoModalDialog::Run (GtkDialog *aDialog)
+{
+  NS_ASSERTION (ShouldShow(), "Calling ::Run on a prevented dialogue!");
+
+  nsCOMPtr<nsPIDOMWindow> pWindow (do_QueryInterface (mWindow));
+
+  // Reset popup state while opening a modal dialog, and firing
+  // events about the dialog, to prevent the current state from
+  // being active the whole time a modal dialog is open.
+  nsAutoPopupStatePusher popupStatePusher (pWindow, openAbused);
+  
+#if 1
+  return gtk_dialog_run (aDialog);
+#else
+  /* Do NOT use gtk_dialog_run here, since it blocks the network thread!
+   * See https://bugzilla.mozilla.org/show_bug.cgi?id=338225
+   */
+  
+  g_object_ref_sink (aDialog);
+  mResponse = GTK_RESPONSE_DELETE_EVENT;
+
+  gulong responseHandler = g_signal_connect (aDialog, "response",
+                                             G_CALLBACK (ResponseCallback),
+                                             reinterpret_cast<void*>(this));
+  gulong deleteHandler = g_signal_connect (aDialog, "delete-event",
+                                           G_CALLBACK (DeleteCallback), NULL);
+
+  gtk_window_present (GTK_WINDOW (aDialog));
+
+  nsCOMPtr<nsIThread> thread (do_GetCurrentThread ());
+  NS_ASSERTION (thread, "No UI thread?");
+  
+  mContinueModalLoop = PR_TRUE;
+  while (mContinueModalLoop) {
+    if (!NS_ProcessNextEvent (thread))
+      break;
+  }
+
+  g_signal_handler_disconnect (aDialog, responseHandler);
+  g_signal_handler_disconnect (aDialog, deleteHandler);
+  g_object_unref (aDialog);
+
+  return mResponse;
+#endif
+}
+
+#ifdef HAVE_GECKO_1_9
+
+PRBool
+AutoModalDialog::DispatchEvent (const char *aEventName,
+                                PRBool aDoNotify)
+{
+  if (!mWindow || !aDoNotify) {
+    return PR_TRUE;
+  }
+
+  nsCOMPtr<nsIDOMDocument> domdoc;
+  mWindow->GetDocument (getter_AddRefs (domdoc));
+
+  nsCOMPtr<nsIDOMDocumentEvent> docevent (do_QueryInterface (domdoc));
+  nsCOMPtr<nsIDOMEvent> event;
+
+  PRBool defaultActionEnabled = PR_TRUE;
+
+  if (docevent) {
+    docevent->CreateEvent (NS_LITERAL_STRING ("Events"), getter_AddRefs (event));
+
+    nsCOMPtr<nsIPrivateDOMEvent> privateEvent (do_QueryInterface (event));
+    if (privateEvent) {
+      event->InitEvent (NS_ConvertASCIItoUTF16 (aEventName), PR_TRUE, PR_TRUE);
+
+      privateEvent->SetTrusted(PR_TRUE);
+
+      nsCOMPtr<nsIDOMEventTarget> target (do_QueryInterface (mWindow));
+
+      target->DispatchEvent (event, &defaultActionEnabled);
+    }
+  }
+
+  return defaultActionEnabled;
+}
+
+/* static */ void PR_CALLBACK
+AutoModalDialog::ResponseCallback (GtkWidget *aDialog,
+                                   int aResponse,
+                                   void *aData)
+{
+  AutoModalDialog *obj = reinterpret_cast<AutoModalDialog*>(aData);
+
+  gtk_widget_hide (aDialog);
+  obj->mResponse = aResponse;
+  obj->mContinueModalLoop = PR_FALSE;
+}
+
+/* static */ gboolean PR_CALLBACK
+AutoModalDialog::DeleteCallback (GtkWidget *aDialog,
+                                 void *aEvent,
+                                 void *aData)
+{
+  gtk_dialog_response (GTK_DIALOG (aDialog), GTK_RESPONSE_DELETE_EVENT);
+  return TRUE;
+}
+
+#endif /* HAVE_GECKO_1_9 */

Added: trunk/embed/mozilla/AutoModalDialog.h
==============================================================================
--- (empty file)
+++ trunk/embed/mozilla/AutoModalDialog.h	Mon Feb 18 13:40:59 2008
@@ -0,0 +1,70 @@
+/* 
+ *  Copyright  2006, 2008 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef AUTOMODALDIALOG_H
+#define AUTOMODALDIALOG_H
+
+#include <nsCOMPtr.h>
+
+#include <gtk/gtkwidget.h>
+
+#include "AutoJSContextStack.h"
+#include "AutoWindowModalState.h"
+
+/**
+ * AutoModalDialog:
+ * A stack-based helper class for modal GTK+ dialogues.
+ * 
+ * You MUST check ::ShouldShow() before showing the dialogue!
+ */
+class AutoModalDialog
+{
+  public:
+    AutoModalDialog (nsIDOMWindow *, PRBool);
+    ~AutoModalDialog ();
+
+    GtkWindow *GetParent ();
+ 
+    PRBool ShouldShow () { return mDefaultEnabled && mContextPushed; }
+
+    int Run (GtkDialog *aDialog);
+
+  private: 
+    // stack only please
+    void *operator new (size_t) CPP_THROW_NEW;
+
+    nsCOMPtr<nsIDOMWindow> mWindow;
+
+    AutoJSContextStack mStack;
+    AutoWindowModalState mModalState;
+
+#ifdef HAVE_GECKO_1_9
+    static void PR_CALLBACK ResponseCallback (GtkWidget*, int, void*);
+    static gboolean PR_CALLBACK DeleteCallback (GtkWidget*, void*, void*);
+
+    PRBool DispatchEvent (const char*, PRBool);
+
+    int mResponse;
+    PRPackedBool mContinueModalLoop;
+#endif
+
+    PRPackedBool mDefaultEnabled;
+    PRPackedBool mContextPushed;
+};
+
+#endif

Modified: trunk/embed/mozilla/ContentHandler.cpp
==============================================================================
--- trunk/embed/mozilla/ContentHandler.cpp	(original)
+++ trunk/embed/mozilla/ContentHandler.cpp	Mon Feb 18 13:40:59 2008
@@ -56,8 +56,7 @@
 #include "ephy-prefs.h"
 #include "ephy-stock-icons.h"
 
-#include "AutoJSContextStack.h"
-#include "AutoWindowModalState.h"
+#include "AutoModalDialog.h"
 #include "EphyUtils.h"
 #include "MozDownload.h"
 
@@ -144,18 +143,15 @@
 	{
 		return BuildDownloadPath (defaultFile.get(), _retval);
 	}
-
-	nsresult rv;
-	AutoJSContextStack stack;
-	rv = stack.Init ();
-	if (NS_FAILED (rv)) return rv;
-
 	nsCOMPtr<nsIDOMWindow> parentDOMWindow (do_GetInterface (aWindowContext));
-	GtkWidget *parentWindow = GTK_WIDGET (EphyUtils::FindGtkParent (parentDOMWindow));
 
-	AutoWindowModalState modalState (parentDOMWindow);
+        AutoModalDialog modalDialog (parentDOMWindow, PR_FALSE);
+        if (!modalDialog.ShouldShow ())
+          return NS_ERROR_FAILURE;
+
+	GtkWindow *parentWindow = modalDialog.GetParent ();
 
-	dialog = ephy_file_chooser_new (_("Save"), parentWindow,
+	dialog = ephy_file_chooser_new (_("Save"), GTK_WIDGET (parentWindow),
 					GTK_FILE_CHOOSER_ACTION_SAVE,
 					CONF_STATE_SAVE_DIR,
 					EPHY_FILE_FILTER_ALL);
@@ -175,7 +171,7 @@
 	do
 	{
 		g_free (filename);
-		response = gtk_dialog_run (GTK_DIALOG (dialog));
+		response = modalDialog.Run (GTK_DIALOG (dialog));
 		filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
 	} while (response == GTK_RESPONSE_ACCEPT
 		 && !ephy_gui_check_location_writable (GTK_WIDGET (dialog), filename));

Modified: trunk/embed/mozilla/EphyPromptService.cpp
==============================================================================
--- trunk/embed/mozilla/EphyPromptService.cpp	(original)
+++ trunk/embed/mozilla/EphyPromptService.cpp	Mon Feb 18 13:40:59 2008
@@ -36,8 +36,7 @@
 #include "ephy-gui.h"
 #include "ephy-debug.h"
 
-#include "AutoJSContextStack.h"
-#include "AutoWindowModalState.h"
+#include "AutoModalDialog.h"
 #include "EphyUtils.h"
 
 #include "EphyPromptService.h"
@@ -470,12 +469,9 @@
 	}
 #endif
 
-	nsresult rv;
-	AutoJSContextStack stack;
-	rv = stack.Init ();
-	if (NS_FAILED (rv)) return rv;
-
-	AutoWindowModalState modalState (mWindow);
+        AutoModalDialog modalDialog (mWindow, PR_TRUE);
+        if (!modalDialog.ShouldShow ())
+                return GTK_RESPONSE_CANCEL;
 
 	if (mDelay)
 	{
@@ -491,7 +487,7 @@
 
 	GtkWidget *widget = GTK_WIDGET (mDialog);
 	gtk_widget_show (widget);
-	mResponse = gtk_dialog_run (mDialog);
+	mResponse = modalDialog.Run (mDialog);
 	gtk_widget_hide (widget);
 
 	g_object_set_data (G_OBJECT (mDialog), TIMEOUT_DATA_KEY, NULL);

Modified: trunk/embed/mozilla/FilePicker.cpp
==============================================================================
--- trunk/embed/mozilla/FilePicker.cpp	(original)
+++ trunk/embed/mozilla/FilePicker.cpp	Mon Feb 18 13:40:59 2008
@@ -46,8 +46,7 @@
 #include "ephy-gui.h"
 #include "ephy-prefs.h"
 
-#include "AutoJSContextStack.h"
-#include "AutoWindowModalState.h"
+#include "AutoModalDialog.h"
 #include "EphyUtils.h"
 
 #include "FilePicker.h"
@@ -390,12 +389,12 @@
 /* short show (); */
 NS_IMETHODIMP GFilePicker::Show(PRInt16 *_retval)
 {
-	nsresult rv;
-	AutoJSContextStack stack;
-	rv = stack.Init ();
-	if (NS_FAILED (rv)) return rv;
-
-	AutoWindowModalState modelState (mParent);
+        AutoModalDialog modalDialog (mParent, PR_FALSE);
+        if (!modalDialog.ShouldShow ()) {
+          *_retval = nsIFilePicker::returnCancel;
+          return NS_OK;
+        }
+          
 	mParent = nsnull;
 
 	LOG ("GFilePicker::Show");
@@ -425,7 +424,7 @@
 
 	do
 	{
-		response = gtk_dialog_run (GTK_DIALOG (mDialog));
+		response = modalDialog.Run (GTK_DIALOG (mDialog));
 
 		g_free (filename);
 		filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (mDialog));

Modified: trunk/embed/mozilla/GeckoCookiePromptService.cpp
==============================================================================
--- trunk/embed/mozilla/GeckoCookiePromptService.cpp	(original)
+++ trunk/embed/mozilla/GeckoCookiePromptService.cpp	Mon Feb 18 13:40:59 2008
@@ -36,8 +36,7 @@
 #include "ephy-gui.h"
 #include "ephy-stock-icons.h"
 
-#include "AutoJSContextStack.h"
-#include "AutoWindowModalState.h"
+#include "AutoModalDialog.h"
 #include "EphyUtils.h"
 
 #include "GeckoCookiePromptService.h"
@@ -72,22 +71,20 @@
   // TODO short-circuit and accept session cookies as per preference
   // TODO until mozilla starts supporting it natively?
 
-  GtkWidget *parent = EphyUtils::FindGtkParent (aParent);
-  NS_ENSURE_TRUE(parent, NS_ERROR_INVALID_POINTER);
-
-  nsresult rv;
-  AutoJSContextStack stack;
-  rv = stack.Init ();
-  if (NS_FAILED (rv)) {
-    return rv;
+  AutoModalDialog modalDialog (aParent, PR_FALSE);
+  if (!modalDialog.ShouldShow ()) {
+    *_retval = PR_FALSE;
+    *_checkValue = PR_FALSE;
+    return NS_OK;
   }
 
-  AutoWindowModalState modalState (aParent);
+  GtkWindow *parent = modalDialog.GetParent ();
+  NS_ENSURE_TRUE(parent, NS_ERROR_INVALID_POINTER);
 
   nsCString host(aHostname);
 
   GtkWidget *dialog = gtk_message_dialog_new
-                        (GTK_WINDOW (parent),
+                        (parent,
                          GTK_DIALOG_MODAL /* FIXME mozilla sucks! */,
                          GTK_MESSAGE_QUESTION,
                          GTK_BUTTONS_NONE,
@@ -141,7 +138,7 @@
                          _("_Accept"), GTK_RESPONSE_ACCEPT);
   gtk_dialog_set_default_response (gdialog, GTK_RESPONSE_ACCEPT);
 
-  int response = gtk_dialog_run (gdialog);
+  int response = modalDialog.Run (gdialog);
 
   if (response == GTK_RESPONSE_ACCEPT || response == GTK_RESPONSE_REJECT) {
     *_retval = (response == GTK_RESPONSE_ACCEPT);

Modified: trunk/embed/mozilla/GeckoFormSigningDialog.cpp
==============================================================================
--- trunk/embed/mozilla/GeckoFormSigningDialog.cpp	(original)
+++ trunk/embed/mozilla/GeckoFormSigningDialog.cpp	Mon Feb 18 13:40:59 2008
@@ -39,8 +39,7 @@
 #include "ephy-file-helpers.h"
 #include "ephy-prefs.h"
 
-#include "AutoJSContextStack.h"
-#include "AutoWindowModalState.h"
+#include "AutoModalDialog.h"
 #include "EphyUtils.h"
 
 #include "GeckoFormSigningDialog.h"
@@ -83,11 +82,6 @@
 {
   /* FIXME: limit |signText| to a sensitlbe length (maybe 100k)? */
 
-  nsresult rv;
-  AutoJSContextStack stack;
-  rv = stack.Init ();
-  if (NS_FAILED (rv)) return rv;
-
   nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx));
   if (!parent) {
     parent = EphyJSUtils::GetDOMWindowFromCallContext ();
@@ -95,7 +89,11 @@
   }
   GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
 
-  AutoWindowModalState modalState (parent);
+  AutoModalDialog modalDialog (parent, PR_TRUE);
+  if (!modalDialog.ShouldShow ()) {
+    *_cancelled = PR_TRUE;
+    return NS_OK;
+  }
 
   GladeXML *gxml = glade_xml_new (ephy_file ("form-signing-dialog.glade"),
 				  "form_signing_dialog", NULL);
@@ -143,7 +141,7 @@
 
   g_object_unref (gxml);
 
-  int response = gtk_dialog_run (GTK_DIALOG (dialog));
+  int response = modalDialog.Run (GTK_DIALOG (dialog));
 
   *_cancelled = response != GTK_RESPONSE_ACCEPT;
 

Modified: trunk/embed/mozilla/GeckoPrintService.cpp
==============================================================================
--- trunk/embed/mozilla/GeckoPrintService.cpp	(original)
+++ trunk/embed/mozilla/GeckoPrintService.cpp	Mon Feb 18 13:40:59 2008
@@ -46,8 +46,7 @@
 #include "ephy-prefs.h"
 #include "ephy-stock-icons.h"
 
-#include "AutoJSContextStack.h"
-#include "AutoWindowModalState.h"
+#include "AutoModalDialog.h"
 #include "EphyUtils.h"
 #include "GeckoPrintSession.h"
 
@@ -121,16 +120,12 @@
   rv = aSettings->GetHowToEnableFrameUI (&frameUI);
   NS_ENSURE_SUCCESS (rv, rv);
 
-  GtkWidget *parent = EphyUtils::FindGtkParent (aParent);
-  NS_ENSURE_TRUE(parent, NS_ERROR_INVALID_POINTER);
-
-  AutoJSContextStack stack;
-  rv = stack.Init ();
-  if (NS_FAILED (rv)) {
-    return rv;
-  }
+  AutoModalDialog modalDialog (aParent, PR_TRUE);
+  if (!modalDialog.ShouldShow ())
+    return NS_ERROR_ABORT;
 
-  AutoWindowModalState modalState (aParent);
+  GtkWindow *parent = modalDialog.GetParent ();
+  NS_ENSURE_TRUE(parent, NS_ERROR_INVALID_POINTER);
 
   EphyEmbedShell *shell = ephy_embed_shell_get_default ();
 
@@ -200,7 +195,7 @@
 
   gtk_window_set_icon_name (GTK_WINDOW (dialog), EPHY_STOCK_EPHY);
 
-  int response = gtk_dialog_run (GTK_DIALOG (dialog));
+  int response = modalDialog.Run (GTK_DIALOG (dialog));
   gtk_widget_hide (dialog);
 
   GtkPrinter *printer = gtk_print_unix_dialog_get_selected_printer (print_dialog);

Modified: trunk/embed/mozilla/GtkNSSClientAuthDialogs.cpp
==============================================================================
--- trunk/embed/mozilla/GtkNSSClientAuthDialogs.cpp	(original)
+++ trunk/embed/mozilla/GtkNSSClientAuthDialogs.cpp	Mon Feb 18 13:40:59 2008
@@ -57,8 +57,7 @@
 #include "ephy-state.h"
 #include "ephy-stock-icons.h"
 
-#include "AutoJSContextStack.h"
-#include "AutoWindowModalState.h"
+#include "AutoModalDialog.h"
 #include "EphyUtils.h"
 
 #include "GtkNSSClientAuthDialogs.h"
@@ -146,18 +145,19 @@
 	char *msg, *markup_text;
 	PRUint32 i;
 
-	nsresult rv;
-	AutoJSContextStack stack;
-	rv = stack.Init ();
-	if (NS_FAILED (rv)) return rv;
-
 	nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx));
-	GtkWindow *gparent = GTK_WINDOW (EphyUtils::FindGtkParent (parent));
 
-	AutoWindowModalState modalState (parent);
+        AutoModalDialog modalDialog (parent, PR_FALSE);
+        if (!modalDialog.ShouldShow ())
+        {
+                *canceled = PR_TRUE;
+                return NS_OK;
+        }
+
+	GtkWindow *gparent = modalDialog.GetParent ();
 
 	dialog = gtk_dialog_new_with_buttons ("",
-					      GTK_WINDOW (gparent),
+					      gparent,
 					      GTK_DIALOG_DESTROY_WITH_PARENT,
 					      GTK_STOCK_CANCEL,
 					      GTK_RESPONSE_CANCEL,
@@ -268,7 +268,7 @@
 	gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
 
 	/* run the dialog */
-	int res = gtk_dialog_run (GTK_DIALOG (dialog));
+	int res = modalDialog.Run (GTK_DIALOG (dialog));
 	if (res == GTK_RESPONSE_OK)
 	{
 		*canceled = PR_FALSE;

Modified: trunk/embed/mozilla/GtkNSSDialogs.cpp
==============================================================================
--- trunk/embed/mozilla/GtkNSSDialogs.cpp	(original)
+++ trunk/embed/mozilla/GtkNSSDialogs.cpp	Mon Feb 18 13:40:59 2008
@@ -88,8 +88,8 @@
 #include "ephy-password-dialog.h"
 #include "ephy-stock-icons.h"
 
-#include "AutoJSContextStack.h"
-#include "AutoWindowModalState.h"
+#include "AutoModalDialog.h"
+
 #include "EphyUtils.h"
 
 #include "GtkNSSDialogs.h"
@@ -239,18 +239,16 @@
 	g_return_val_if_fail (markup_text, GTK_RESPONSE_CANCEL);
 	g_return_val_if_fail (!checkbox_text || checkbox_value, GTK_RESPONSE_CANCEL);
 
-	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!
 	 */
 	nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx));
-	GtkWindow *gparent = GTK_WINDOW (EphyUtils::FindGtkParent (parent));
+	
+        AutoModalDialog modalDialog (parent, PR_FALSE);
+        if (!modalDialog.ShouldShow ())
+                return GTK_RESPONSE_CANCEL;
 
-	AutoWindowModalState modalState (parent);
+        GtkWindow *gparent = modalDialog.GetParent ();
 
 	dialog = gtk_dialog_new_with_buttons ("", gparent,
 					      GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -305,7 +303,7 @@
 
 	while (1)
 	{
-		res = gtk_dialog_run (GTK_DIALOG (dialog));
+		res = modalDialog.Run (GTK_DIALOG (dialog));
 		if (res == NSSDIALOG_RESPONSE_VIEW_CERT)
 		{
                       view_certificate (ctx, cert);
@@ -619,15 +617,16 @@
 	GtkWidget *dialog, *label;
 	char *msg, *primary;
 
-	nsresult rv;
-	AutoJSContextStack stack;
-	rv = stack.Init ();
-	if (NS_FAILED (rv)) return rv;
-
 	nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx));
-	GtkWindow *gparent = GTK_WINDOW (EphyUtils::FindGtkParent (parent));
+        
+        AutoModalDialog modalDialog (parent, PR_FALSE);
+        if (!modalDialog.ShouldShow ())
+        {
+                *_retval = PR_FALSE;
+                return NS_OK;
+        }
 
-	AutoWindowModalState modalState (parent);
+	GtkWindow *gparent = modalDialog.GetParent ();
 
 	dialog = gtk_dialog_new_with_buttons (_("Trust new Certificate Authority?"), gparent,
 					      GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -670,7 +669,7 @@
 
 	while (1)
 	{
-		ret = gtk_dialog_run (GTK_DIALOG (dialog));
+		ret = modalDialog.Run (GTK_DIALOG (dialog));
 		if (ret == NSSDIALOG_RESPONSE_VIEW_CERT)
 		{
 		      view_certificate (ctx, cert);
@@ -751,17 +750,18 @@
 	GtkWidget *dialog;
 	char *msg;
 
-	nsresult rv;
-	AutoJSContextStack stack;
-	rv = stack.Init ();
-	if (NS_FAILED (rv)) return rv;
-
 	nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx));
-	GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
+        
+        AutoModalDialog modalDialog (parent, PR_FALSE);
+        if (!modalDialog.ShouldShow ())
+        {
+                *_retval = PR_FALSE;
+                return NS_OK;
+        }
 
-	AutoWindowModalState modalState (parent);
+	GtkWindow *gparent = modalDialog.GetParent ();
 
-	dialog = ephy_password_dialog_new (gparent,
+	dialog = ephy_password_dialog_new (GTK_WIDGET (gparent),
 					   _("Select Password"),
 					   EphyPasswordDialogFlags(EPHY_PASSWORD_DIALOG_FLAGS_SHOW_NEW_PASSWORD |
 								   EPHY_PASSWORD_DIALOG_FLAGS_SHOW_QUALITY_METER));
@@ -776,7 +776,7 @@
 	gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), msg);
 	g_free (msg);
 
-	int response = gtk_dialog_run (GTK_DIALOG (dialog));
+	int response = modalDialog.Run (GTK_DIALOG (dialog));
 	gtk_widget_hide (dialog);
 	
 	if (response == GTK_RESPONSE_ACCEPT)
@@ -801,18 +801,19 @@
 {
 	g_print ("GtkNSSDialogs::GetPKCS12FilePassword\n");
 
-	nsresult rv;
-	AutoJSContextStack stack;
-	rv = stack.Init ();
-	if (NS_FAILED (rv)) return rv;
-
 	nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx));
-	GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
+        
+        AutoModalDialog modalDialog (parent, PR_FALSE);
+        if (!modalDialog.ShouldShow ())
+        {
+                *_retval = PR_FALSE;
+                return NS_OK;
+        }
 
-	AutoWindowModalState modalState (parent);
+	GtkWindow *gparent = modalDialog.GetParent ();
 
 	GtkWidget *dialog = ephy_password_dialog_new
-				(gparent,
+				(GTK_WIDGET (gparent),
 				 "",
 				 EphyPasswordDialogFlags (EPHY_PASSWORD_DIALOG_FLAGS_SHOW_PASSWORD));
 	EphyPasswordDialog *password_dialog = EPHY_PASSWORD_DIALOG (dialog);
@@ -825,7 +826,7 @@
 	gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), msg);
 	g_free (msg);
 			
-	int response = gtk_dialog_run (GTK_DIALOG (dialog));
+	int response = modalDialog.Run (GTK_DIALOG (dialog));
 
 	if (response == GTK_RESPONSE_ACCEPT)
 	{
@@ -1213,10 +1214,13 @@
 	PRUnichar ** usage;
 	GtkSizeGroup * sizegroup;
 
-	nsresult rv;
-	AutoJSContextStack stack;
-	rv = stack.Init ();
-	if (NS_FAILED (rv)) return rv;
+	nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx));
+        
+        AutoModalDialog modalDialog (parent, PR_FALSE);
+        if (!modalDialog.ShouldShow ())
+                return NS_OK;
+
+	GtkWindow *gparent = modalDialog.GetParent ();
 
 	gxml = glade_xml_new (ephy_file ("certificate-dialogs.glade"),
 			      "viewcert_dialog", NULL);
@@ -1225,11 +1229,6 @@
 	dialog = glade_xml_get_widget (gxml, "viewcert_dialog");
 	g_return_val_if_fail (dialog != NULL, NS_ERROR_FAILURE);
 
-	nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx));
-	GtkWindow *gparent = GTK_WINDOW (EphyUtils::FindGtkParent (parent));
-
-	AutoWindowModalState modalState (parent);
-
 	if (gparent)
 	{
 		gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(gparent));
@@ -1255,6 +1254,7 @@
 	gtk_size_group_add_widget (sizegroup, widget);
 	g_object_unref (sizegroup);
 
+        nsresult rv;
 	rv = cert->GetUsagesArray (FALSE, &verifystate, &count, &usage);
 	if (NS_FAILED(rv)) return rv;
 
@@ -1371,7 +1371,7 @@
 	int res;
 	while (1)
 	{
-		res = gtk_dialog_run (GTK_DIALOG (dialog));
+		res = modalDialog.Run (GTK_DIALOG (dialog));
 		if (res == GTK_RESPONSE_HELP)
 		{
 			ephy_gui_help (GTK_WINDOW (dialog), "epiphany", "using-certificate-viewer");
@@ -1412,9 +1412,15 @@
 	slot->GetStatus (&status);
 
 	nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (aCtx));
-	GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
 
-	AutoWindowModalState modalState (parent);
+        AutoModalDialog modalDialog (parent, PR_FALSE);
+        if (!modalDialog.ShouldShow ())
+        {
+                *aCancelled = PR_TRUE;
+                return NS_OK;
+        }
+
+	GtkWindow *gparent = modalDialog.GetParent ();
 
 	EphyPasswordDialogFlags flags =
 		EphyPasswordDialogFlags (EPHY_PASSWORD_DIALOG_FLAGS_SHOW_NEW_PASSWORD |
@@ -1423,7 +1429,7 @@
 		flags = EphyPasswordDialogFlags (flags | EPHY_PASSWORD_DIALOG_FLAGS_SHOW_PASSWORD);
 
 	GtkWidget *dialog = ephy_password_dialog_new
-				(gparent,
+				(GTK_WIDGET (gparent),
 				 _("Change Token Password"),
 				 flags);
 	EphyPasswordDialog *password_dialog = EPHY_PASSWORD_DIALOG (dialog);
@@ -1445,7 +1451,7 @@
 	nsString oldPassword;
 	PRBool pwdOk, needsLogin;
 	do {
-		response = gtk_dialog_run (GTK_DIALOG (dialog));
+		response = modalDialog.Run (GTK_DIALOG (dialog));
 
 		if (status != nsIPKCS11Slot::SLOT_UNINITIALIZED)
 		{
@@ -1503,20 +1509,22 @@
 	NS_ENSURE_SUCCESS (rv, rv);
 	NS_ENSURE_TRUE (token && slot, NS_ERROR_FAILURE);
 
-	AutoJSContextStack stack;
-	rv = stack.Init ();
-	if (NS_FAILED (rv)) return rv;
-
 	nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (aCtx));
-	GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
 
-	AutoWindowModalState modalState (parent);
+        AutoModalDialog modalDialog (parent, PR_FALSE);
+        if (!modalDialog.ShouldShow ())
+        {
+                *aCancelled = PR_TRUE;
+                return NS_OK;
+        }
+
+	GtkWindow *gparent = modalDialog.GetParent ();
 
 	EphyPasswordDialogFlags flags =
 		EphyPasswordDialogFlags (EPHY_PASSWORD_DIALOG_FLAGS_SHOW_PASSWORD);
 
 	GtkWidget *dialog = ephy_password_dialog_new
-				(gparent,
+				(GTK_WIDGET (gparent),
 				 _("Get Token Password"), /* FIXME */
 				 flags);
 	EphyPasswordDialog *password_dialog = EPHY_PASSWORD_DIALOG (dialog);
@@ -1531,7 +1539,7 @@
 				       message);
 	g_free (message);
 
-	int response = gtk_dialog_run (GTK_DIALOG (dialog));
+	int response = modalDialog.Run (GTK_DIALOG (dialog));
 
 	if (response == GTK_RESPONSE_ACCEPT)
 	{
@@ -1571,23 +1579,23 @@
   NS_ENSURE_ARG (tokenNameList);
   NS_ENSURE_ARG (count);
 
-  nsresult rv;
-  AutoJSContextStack stack;
-  rv = stack.Init ();
-  if (NS_FAILED (rv)) return rv;
-
   /* Didn't you know it? MOZILLA SUCKS! ChooseToken is always called with |aContext| == NULL! See
    * http://bonsai.mozilla.org/cvsblame.cgi?file=mozilla/security/manager/ssl/src/nsKeygenHandler.cpp&rev=1.39&mark=346#346
    * Need to investigate if we it's always called directly from code called from JS, in which case we
    * can use EphyJSUtils::GetDOMWindowFromCallContext.
    */
   nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (aContext));
-  GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
 
-  AutoWindowModalState modalState (parent);
+  AutoModalDialog modalDialog (parent, PR_FALSE);
+  if (!modalDialog.ShouldShow ()) {
+    *_cancelled = PR_TRUE;
+    return NS_OK;
+  }
+
+  GtkWindow *gparent = modalDialog.GetParent ();
 
   GtkWidget *dialog = gtk_message_dialog_new
-		  (GTK_WINDOW (gparent),
+		  (gparent,
 		   GTK_DIALOG_DESTROY_WITH_PARENT,
 		   GTK_MESSAGE_OTHER,
 		   GTK_BUTTONS_CANCEL,
@@ -1615,7 +1623,7 @@
 
   gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_REJECT);
 
-  int response = gtk_dialog_run (GTK_DIALOG (dialog));
+  int response = modalDialog.Run (GTK_DIALOG (dialog));
   int selected = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
 
   gtk_widget_destroy (dialog);
@@ -1660,16 +1668,21 @@
   nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (aCtx));
 #endif
   nsCOMPtr<nsIDOMWindow> parent (EphyJSUtils::GetDOMWindowFromCallContext ());
-  GtkWidget *gparent = EphyUtils::FindGtkParent (parent);
 
-  AutoWindowModalState modalState (parent);
+  AutoModalDialog modalDialog (parent, PR_FALSE);
+  if (!modalDialog.ShouldShow ()) {
+    *_retval = PR_FALSE;
+    return NS_OK;
+  }
+
+  GtkWindow *gparent = modalDialog.GetParent ();
 
   /* FIXME: is that guaranteed to be non-empty? */
   nsString commonName;
   aEscrowAuthority->GetCommonName (commonName);
 
   GtkWidget *dialog = gtk_message_dialog_new
-			(GTK_WINDOW (gparent),
+			(gparent,
 			 GTK_DIALOG_DESTROY_WITH_PARENT,
 			 GTK_MESSAGE_WARNING /* QUESTION really but it's also a strong warnings... */,
 			 GTK_BUTTONS_NONE,
@@ -1703,7 +1716,7 @@
   gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_REJECT);
   gtk_widget_grab_focus (button);
 
-  int response = gtk_dialog_run (GTK_DIALOG (dialog));
+  int response = modalDialog.Run (GTK_DIALOG (dialog));
   gtk_widget_destroy (dialog);
 	
   *_retval = response == GTK_RESPONSE_ACCEPT;

Modified: trunk/embed/mozilla/GtkNSSKeyPairDialogs.cpp
==============================================================================
--- trunk/embed/mozilla/GtkNSSKeyPairDialogs.cpp	(original)
+++ trunk/embed/mozilla/GtkNSSKeyPairDialogs.cpp	Mon Feb 18 13:40:59 2008
@@ -49,9 +49,7 @@
 #include "ephy-gui.h"
 #include "ephy-stock-icons.h"
 
-#include "AutoJSContextStack.h"
-#include "AutoWindowModalState.h"
-#include "EphyUtils.h"
+#include "AutoModalDialog.h"
 
 #include "GtkNSSKeyPairDialogs.h"
 
@@ -142,15 +140,12 @@
 	GtkWidget *dialog, *progress, *label, *vbox;
 	gint timeout_id;
 
-	nsresult rv;
-	AutoJSContextStack stack;
-	rv = stack.Init ();
-	if (NS_FAILED (rv)) return rv;
+	nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx));
+        AutoModalDialog modalDialog (parent, PR_FALSE);
+        if (!modalDialog.ShouldShow ())
+                return NS_ERROR_ABORT;
 
-	nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx);
-	GtkWindow *gparent = GTK_WINDOW (EphyUtils::FindGtkParent (parent));
-
-	AutoWindowModalState modalState (parent);
+        GtkWindow *gparent = modalDialog.GetParent ();
 
 	dialog = gtk_dialog_new_with_buttons ("", gparent,
 					      GTK_DIALOG_DESTROY_WITH_PARENT, (char *) NULL);
@@ -199,7 +194,7 @@
 
 	begin_busy (dialog);
 	runnable->StartKeyGeneration (helper);
-	int res = gtk_dialog_run (GTK_DIALOG (dialog));
+	int res = modalDialog.Run (GTK_DIALOG (dialog));
 	if (res != GTK_RESPONSE_OK && helper->close_called == FALSE)
 	{
 		/* Ignore the already_closed flag, our nsIDOMWindowInterna::Close

Modified: trunk/embed/mozilla/GtkNSSSecurityWarningDialogs.cpp
==============================================================================
--- trunk/embed/mozilla/GtkNSSSecurityWarningDialogs.cpp	(original)
+++ trunk/embed/mozilla/GtkNSSSecurityWarningDialogs.cpp	Mon Feb 18 13:40:59 2008
@@ -62,9 +62,7 @@
 #include <nsIServiceManager.h>
 #include <nsServiceManagerUtils.h>
 
-#include "AutoJSContextStack.h"
-#include "AutoWindowModalState.h"
-#include "EphyUtils.h"
+#include "AutoModalDialog.h"
 
 #include "GtkNSSSecurityWarningDialogs.h"
 
@@ -236,28 +234,30 @@
 	 * https://bugzilla.mozilla.org/show_bug.cgi?id=277587
 	 */
 	nsCOMPtr<nsIDOMWindow> domWin (do_GetInterface (aContext));
-	GtkWidget *parent = EphyUtils::FindGtkParent (domWin);
 
-	AutoJSContextStack stack;
-	rv = stack.Init ();
-	if (NS_FAILED (rv)) return;
+        AutoModalDialog modalDialog (domWin, PR_FALSE);
+        if (!modalDialog.ShouldShow ())
+        {
+                *_retval = PR_FALSE;
+                return;
+        }
 
-	AutoWindowModalState modalState (domWin);
+	GtkWindow *parent = modalDialog.GetParent ();
 
-	GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
+	GtkWidget *dialog = gtk_message_dialog_new (parent,
 						    GTK_DIALOG_MODAL, aType,
-						    aButtons, aPrimary);
+						    aButtons, "%s", aPrimary);
 
-	if (parent && GTK_WINDOW (parent)->group)
+	if (parent && parent->group)
 	{
-		gtk_window_group_add_window (GTK_WINDOW (parent)->group,
+		gtk_window_group_add_window (parent->group,
 					     GTK_WINDOW (dialog));
 	}
 
 	if (aSecondary)
 	{
 		gtk_message_dialog_format_secondary_text
-			(GTK_MESSAGE_DIALOG (dialog), aSecondary);
+			(GTK_MESSAGE_DIALOG (dialog), "%s", aSecondary);
 	}
 
 	if (aButtonText)
@@ -271,7 +271,7 @@
 	gtk_window_set_title (GTK_WINDOW (dialog), aTitle);
 	gtk_window_set_icon_name (GTK_WINDOW (dialog), EPHY_STOCK_EPHY);
 
-	int response = gtk_dialog_run (GTK_DIALOG (dialog));
+	int response = modalDialog.Run (GTK_DIALOG (dialog));
 	gtk_widget_destroy (dialog);
 
 	*_retval = (response == GTK_RESPONSE_ACCEPT || response == GTK_RESPONSE_OK);

Modified: trunk/embed/mozilla/Makefile.am
==============================================================================
--- trunk/embed/mozilla/Makefile.am	(original)
+++ trunk/embed/mozilla/Makefile.am	Mon Feb 18 13:40:59 2008
@@ -3,6 +3,8 @@
 libephymozillaembed_la_SOURCES = 	\
 	AutoJSContextStack.cpp		\
 	AutoJSContextStack.h		\
+	AutoModalDialog.cpp		\
+	AutoModalDialog.h		\
 	AutoWindowModalState.cpp	\
 	AutoWindowModalState.h		\
 	ContentHandler.cpp		\



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]