aboutsummaryrefslogtreecommitdiffstats
path: root/embed
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 /embed
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.
Diffstat (limited to 'embed')
-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
4 files changed, 106 insertions, 0 deletions
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);