aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2004-10-31 01:46:05 +0800
committerChristian Persch <chpe@src.gnome.org>2004-10-31 01:46:05 +0800
commit96b61f1e2c50ce20423136738e1a3e0a9d7364dc (patch)
treedcb97f1e845ac42fa5dba1e920d89f114c0fd8d0
parentc9ccac921537b68b5620b485848094a0ffecc3c1 (diff)
downloadgsoc2013-epiphany-96b61f1e2c50ce20423136738e1a3e0a9d7364dc.tar
gsoc2013-epiphany-96b61f1e2c50ce20423136738e1a3e0a9d7364dc.tar.gz
gsoc2013-epiphany-96b61f1e2c50ce20423136738e1a3e0a9d7364dc.tar.bz2
gsoc2013-epiphany-96b61f1e2c50ce20423136738e1a3e0a9d7364dc.tar.lz
gsoc2013-epiphany-96b61f1e2c50ce20423136738e1a3e0a9d7364dc.tar.xz
gsoc2013-epiphany-96b61f1e2c50ce20423136738e1a3e0a9d7364dc.tar.zst
gsoc2013-epiphany-96b61f1e2c50ce20423136738e1a3e0a9d7364dc.zip
When showing a modal alert put up by a web page, switch the window to that
2004-10-30 Christian Persch <chpe@cvs.gnome.org> * configure.ac: * embed/ephy-embed.c: (ephy_embed_base_init): * embed/ephy-embed.h: * embed/mozilla/EphyBrowser.cpp: * embed/mozilla/EphyBrowser.h: * src/ephy-window.c: (modal_alert_cb), (tab_added_cb), (tab_removed_cb): When showing a modal alert put up by a web page, switch the window to that tab.
-rw-r--r--ChangeLog13
-rw-r--r--configure.ac2
-rw-r--r--embed/ephy-embed.c33
-rw-r--r--embed/ephy-embed.h2
-rw-r--r--embed/mozilla/EphyBrowser.cpp64
-rw-r--r--embed/mozilla/EphyBrowser.h7
-rw-r--r--src/ephy-window.c37
7 files changed, 157 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index a8c14ec40..e432a3228 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2004-10-30 Christian Persch <chpe@cvs.gnome.org>
+ * configure.ac:
+ * embed/ephy-embed.c: (ephy_embed_base_init):
+ * embed/ephy-embed.h:
+ * embed/mozilla/EphyBrowser.cpp:
+ * embed/mozilla/EphyBrowser.h:
+ * src/ephy-window.c: (modal_alert_cb), (tab_added_cb),
+ (tab_removed_cb):
+
+ When showing a modal alert put up by a web page, switch the window
+ to that tab.
+
+2004-10-30 Christian Persch <chpe@cvs.gnome.org>
+
* lib/ephy-shlib-loader.c: (impl_release_object):
* src/ephy-extensions-manager.c: (idle_unref), (unload_extension):
diff --git a/configure.ac b/configure.ac
index 58b4f12b9..c30027419 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,7 +33,7 @@ AM_MAINTAINER_MODE
AC_PROG_INTLTOOL([0.29])
-GLIB_REQUIRED=2.5.4
+GLIB_REQUIRED=2.5.5
PANGO_REQUIRED=1.5.1
GTK_REQUIRED=2.5.4
LIBXML_REQUIRED=2.6.12
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index 6d3cce0fb..cd6027b0f 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -287,6 +287,39 @@ ephy_embed_base_init (gpointer g_class)
1,
G_TYPE_STRING);
+/**
+ * EphyEmbed::ge-modal-alert:
+ * @embed:
+ *
+ * The ::ge-modal-alert signal is emitted when a DOM event will open a
+ * modal alert.
+ *
+ * Return %TRUE to prevent the dialog from being opened.
+ **/
+ g_signal_new ("ge_modal_alert",
+ EPHY_TYPE_EMBED,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EphyEmbedIface, modal_alert),
+ g_signal_accumulator_true_handled, NULL,
+ ephy_marshal_BOOLEAN__VOID,
+ G_TYPE_BOOLEAN,
+ 0);
+/**
+ * EphyEmbed::ge-modal-alert-closed:
+ * @embed:
+ *
+ * The ::ge-modal-alert-closed signal is emitted when a modal alert put up by a
+ * DOM event was closed.
+ **/
+ g_signal_new ("ge_modal_alert_closed",
+ EPHY_TYPE_EMBED,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EphyEmbedIface, modal_alert_closed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
initialized = TRUE;
}
}
diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h
index 2ebc3b69a..daa9cba0e 100644
--- a/embed/ephy-embed.h
+++ b/embed/ephy-embed.h
@@ -131,6 +131,8 @@ struct _EphyEmbedIface
float new_zoom);
void (* content_change) (EphyEmbed *embed,
const char *uri);
+ gboolean (* modal_alert) (EphyEmbed *embed);
+ void (* modal_alert_closed) (EphyEmbed *embed);
/* Methods */
void (* load_url) (EphyEmbed *embed,
diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp
index 040b7615f..efb8a80d2 100644
--- a/embed/mozilla/EphyBrowser.cpp
+++ b/embed/mozilla/EphyBrowser.cpp
@@ -59,6 +59,7 @@
#include "nsIDOMDocument.h"
#include "nsIDOM3Document.h"
#include "nsIDOMEvent.h"
+#include "nsIDOMNSEvent.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMPopupBlockedEvent.h"
#include "nsIDOMNode.h"
@@ -82,6 +83,13 @@ static PRUnichar DOMLinkAdded[] = { 'D', 'O', 'M', 'L', 'i', 'n', 'k',
static PRUnichar DOMPopupBlocked[] = { 'D', 'O', 'M', 'P', 'o', 'p',
'u', 'p', 'B', 'l', 'o', 'c',
'k', 'e', 'd', '\0' };
+static PRUnichar DOMWillOpenModalDialog[] = { 'D', 'O', 'M', 'W', 'i', 'l', 'l',
+ 'O', 'p', 'e', 'n', 'M', 'o', 'd',
+ 'a', 'l', 'D', 'i', 'a', 'l', 'o',
+ 'g', '\0' };
+static PRUnichar DOMModalDialogClosed[] = { 'D', 'O', 'M', 'M', 'o', 'd', 'a',
+ 'l', 'D', 'i', 'a', 'l', 'o', 'g',
+ 'C', 'l', 'o', 's', 'e', 'd', '\0' };
EphyEventListener::EphyEventListener(void)
: mOwner(nsnull)
@@ -205,9 +213,51 @@ EphyPopupBlockEventListener::HandleEvent (nsIDOMEvent * aDOMEvent)
return NS_OK;
}
+NS_IMETHODIMP
+EphyModalAlertEventListener::HandleEvent (nsIDOMEvent * aDOMEvent)
+{
+ NS_ENSURE_TRUE (mOwner, NS_ERROR_FAILURE);
+
+ /* make sure the event is trusted */
+ nsCOMPtr<nsIDOMNSEvent> nsEvent (do_QueryInterface (aDOMEvent));
+ PRBool isTrusted = PR_FALSE;
+ nsEvent->GetIsTrusted (&isTrusted);
+ if (!isTrusted) return NS_OK;
+
+ nsresult rv;
+ nsEmbedString type;
+ rv = aDOMEvent->GetType (type);
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ nsEmbedCString cType;
+ NS_UTF16ToCString (type, NS_CSTRING_ENCODING_UTF8, cType);
+
+ LOG ("ModalAlertListener event %s", cType.get());
+
+ if (strcmp (cType.get(), "DOMWillOpenModalDialog") == 0)
+ {
+ gboolean retval = FALSE;
+ g_signal_emit_by_name (mOwner, "ge-modal-alert", &retval);
+
+ /* suppress alert */
+ if (retval)
+ {
+ aDOMEvent->PreventDefault ();
+ aDOMEvent->StopPropagation();
+ }
+ }
+ else if (strcmp (cType.get(), "DOMModalDialogClosed") == 0)
+ {
+ g_signal_emit_by_name (mOwner, "ge-modal-alert-closed");
+ }
+
+ return NS_OK;
+}
+
EphyBrowser::EphyBrowser ()
: mFaviconEventListener(nsnull)
, mPopupBlockEventListener(nsnull)
+, mModalAlertListener(nsnull)
, mInitialized(PR_FALSE)
{
LOG ("EphyBrowser ctor (%p)", this)
@@ -247,6 +297,12 @@ nsresult EphyBrowser::Init (GtkMozEmbed *mozembed)
rv = mPopupBlockEventListener->Init (EPHY_EMBED (mozembed));
NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
+ mModalAlertListener = new EphyModalAlertEventListener ();
+ if (!mModalAlertListener) return NS_ERROR_OUT_OF_MEMORY;
+
+ rv = mModalAlertListener->Init (EPHY_EMBED (mozembed));
+ NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
+
rv = GetListener();
NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
@@ -282,6 +338,10 @@ EphyBrowser::AttachListeners(void)
mFaviconEventListener, PR_FALSE);
rv |= mEventTarget->AddEventListener(nsEmbedString(DOMPopupBlocked),
mPopupBlockEventListener, PR_FALSE);
+ rv |= mEventTarget->AddEventListener(nsEmbedString(DOMWillOpenModalDialog),
+ mModalAlertListener, PR_TRUE);
+ rv |= mEventTarget->AddEventListener(nsEmbedString(DOMModalDialogClosed),
+ mModalAlertListener, PR_TRUE);
NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
return NS_OK;
@@ -297,6 +357,10 @@ EphyBrowser::DetachListeners(void)
mFaviconEventListener, PR_FALSE);
rv |= mEventTarget->RemoveEventListener(nsEmbedString(DOMPopupBlocked),
mPopupBlockEventListener, PR_FALSE);
+ rv |= mEventTarget->RemoveEventListener(nsEmbedString(DOMWillOpenModalDialog),
+ mModalAlertListener, PR_TRUE);
+ rv |= mEventTarget->RemoveEventListener(nsEmbedString(DOMModalDialogClosed),
+ mModalAlertListener, PR_TRUE);
NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
return NS_OK;
diff --git a/embed/mozilla/EphyBrowser.h b/embed/mozilla/EphyBrowser.h
index d7fc5a148..deb96b15a 100644
--- a/embed/mozilla/EphyBrowser.h
+++ b/embed/mozilla/EphyBrowser.h
@@ -77,6 +77,12 @@ public:
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
};
+class EphyModalAlertEventListener : public EphyEventListener
+{
+public:
+ NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
+};
+
class EphyBrowser
{
public:
@@ -145,6 +151,7 @@ private:
nsCOMPtr<nsISupports> mSecurityInfo;
EphyFaviconEventListener *mFaviconEventListener;
EphyPopupBlockEventListener *mPopupBlockEventListener;
+ EphyModalAlertEventListener *mModalAlertListener;
PRBool mInitialized;
nsresult GetListener (void);
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 73495a6fd..4be634d05 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -1957,11 +1957,34 @@ update_tabs_menu_sensitivity (EphyWindow *window)
g_object_set (action, "sensitive", detach, NULL);
}
+static gboolean
+modal_alert_cb (EphyEmbed *embed,
+ EphyWindow *window)
+{
+ EphyTab *tab;
+ char *address;
+
+ tab = ephy_tab_for_embed (embed);
+ g_return_val_if_fail (tab != NULL, FALSE);
+
+ ephy_window_jump_to_tab (window, tab);
+
+ /* make sure the location entry shows the real URL of the tab's page */
+ address = ephy_embed_get_location (embed, TRUE);
+ toolbar_set_location (window->priv->toolbar, address);
+ g_free (address);
+
+ /* don't suppress alert */
+ return FALSE;
+}
+
static void
tab_added_cb (EphyNotebook *notebook,
EphyTab *tab,
EphyWindow *window)
{
+ EphyEmbed *embed;
+
g_return_if_fail (EPHY_IS_TAB (tab));
window->priv->num_tabs++;
@@ -1970,6 +1993,12 @@ tab_added_cb (EphyNotebook *notebook,
g_signal_connect_object (G_OBJECT (tab), "notify::visible",
G_CALLBACK (sync_tab_visibility), window, 0);
+
+ embed = ephy_tab_get_embed (tab);
+ g_return_if_fail (embed != NULL);
+
+ g_signal_connect_after (embed, "ge-modal-alert",
+ G_CALLBACK (modal_alert_cb), window);
}
static void
@@ -1977,6 +2006,8 @@ tab_removed_cb (EphyNotebook *notebook,
EphyTab *tab,
EphyWindow *window)
{
+ EphyEmbed *embed;
+
g_return_if_fail (EPHY_IS_TAB (tab));
g_signal_handlers_disconnect_by_func (G_OBJECT (tab),
@@ -1989,6 +2020,12 @@ tab_removed_cb (EphyNotebook *notebook,
{
update_tabs_menu_sensitivity (window);
}
+
+ embed = ephy_tab_get_embed (tab);
+ g_return_if_fail (embed != NULL);
+
+ g_signal_handlers_disconnect_by_func
+ (embed, G_CALLBACK (modal_alert_cb), window);
}
static void