diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2004-10-31 01:49:42 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2004-10-31 01:49:42 +0800 |
commit | 43e01459631237732f52b29639220ed7eb71bd4f (patch) | |
tree | 0cf5233cd1e48d4566896119c823c8144af96ffe | |
parent | faa39db900ac68efda9f1632878407757e52a187 (diff) | |
download | gsoc2013-epiphany-43e01459631237732f52b29639220ed7eb71bd4f.tar.gz gsoc2013-epiphany-43e01459631237732f52b29639220ed7eb71bd4f.tar.zst gsoc2013-epiphany-43e01459631237732f52b29639220ed7eb71bd4f.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>
* doc/reference/tmpl/ephy-embed.sgml:
* 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-- | ChangeLog | 13 | ||||
-rw-r--r-- | doc/reference/tmpl/ephy-embed.sgml | 19 | ||||
-rw-r--r-- | embed/ephy-embed.c | 33 | ||||
-rw-r--r-- | embed/ephy-embed.h | 2 | ||||
-rw-r--r-- | embed/mozilla/EphyBrowser.cpp | 65 | ||||
-rw-r--r-- | embed/mozilla/EphyBrowser.h | 7 | ||||
-rw-r--r-- | src/ephy-window.c | 37 |
7 files changed, 176 insertions, 0 deletions
@@ -1,3 +1,16 @@ +2004-10-30 Christian Persch <chpe@cvs.gnome.org> + + * doc/reference/tmpl/ephy-embed.sgml: + * 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-29 Christian Persch <chpe@cvs.gnome.org> * src/bookmarks/ephy-topic-action.c: (can_open_in_tabs), diff --git a/doc/reference/tmpl/ephy-embed.sgml b/doc/reference/tmpl/ephy-embed.sgml index bf8a33dde..edf35cc6c 100644 --- a/doc/reference/tmpl/ephy-embed.sgml +++ b/doc/reference/tmpl/ephy-embed.sgml @@ -93,6 +93,21 @@ be done by casting). @ephyembed: the object which received the signal. @arg1: +<!-- ##### SIGNAL EphyEmbed::ge-modal-alert ##### --> +<para> + +</para> + +@ephyembed: the object which received the signal. +@Returns: + +<!-- ##### SIGNAL EphyEmbed::ge-modal-alert-closed ##### --> +<para> + +</para> + +@ephyembed: the object which received the signal. + <!-- ##### SIGNAL EphyEmbed::ge-net-state ##### --> <para> @@ -158,6 +173,8 @@ be done by casting). @: @: @: +@: +@: @: <!-- ##### SIGNAL EphyEmbed::ge-security-change ##### --> @@ -193,6 +210,8 @@ be done by casting). @security_change: @zoom_change: @content_change: +@modal_alert: +@modal_alert_closed: @load_url: @stop_load: @reload: diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c index 76e8ea0c8..36e87fa24 100644 --- a/embed/ephy-embed.c +++ b/embed/ephy-embed.c @@ -288,6 +288,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..30fed7195 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,52 @@ 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)); + NS_ENSURE_TRUE (nsEvent, NS_ERROR_FAILURE); + 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 +298,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 +339,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 +358,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 ce09eaa57..8c6439644 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -1817,11 +1817,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++; @@ -1830,6 +1853,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 @@ -1837,6 +1866,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), @@ -1849,6 +1880,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 |