From 234742d9a6c75c8163a47bd1f3b1eeeba15e58cc Mon Sep 17 00:00:00 2001 From: Adam Hooper Date: Mon, 21 Jun 2004 11:09:56 +0000 Subject: Implement popup-blocking signals. Part of bug #111930. --- embed/ephy-embed-single.c | 14 +++++++++ embed/ephy-embed.c | 21 ++++++++++++- embed/ephy-embed.h | 4 ++- embed/mozilla/EphyBrowser.cpp | 54 ++++++++++++++++++++++++++++++++++ embed/mozilla/EphyBrowser.h | 7 +++++ embed/mozilla/mozilla-embed-single.cpp | 16 ++++++---- 6 files changed, 108 insertions(+), 8 deletions(-) diff --git a/embed/ephy-embed-single.c b/embed/ephy-embed-single.c index 0ea626128..9581883e4 100644 --- a/embed/ephy-embed-single.c +++ b/embed/ephy-embed-single.c @@ -170,6 +170,20 @@ ephy_embed_single_get_font_list (EphyEmbedSingle *single, return iface->get_font_list (single, lang_group); } +/** + * ephy_embed_single_open_window: + * @single: the #EphyEmbedSingle + * @parent: the requested window's parent #EphyEmbed + * @address: the URL to load + * @features: a Javascript features string + * + * Opens a new window, as if it were opened in @parent using the Javascript + * method and arguments: window.open("@address", + * "_blank", "@features");. + * + * Use ephy_shell_new_tab() unless this handling of the @features string is + * required. + */ void ephy_embed_single_open_window (EphyEmbedSingle *single, EphyEmbed *parent, diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c index 341c66d49..9893c1ac0 100644 --- a/embed/ephy-embed.c +++ b/embed/ephy-embed.c @@ -101,6 +101,25 @@ ephy_embed_base_init (gpointer g_class) 2, G_TYPE_POINTER, G_TYPE_INT); +/** + * EphyEmbed::ge-popup-blocked: + * @embed: + * @address: The requested URL + * @features: The requested features: for example, "height=400,width=200" + * + * The ::ge_popup_blocked signal is emitted when the viewed web page requests + * a popup window (with javascript:open()) but popup windows are not allowed. + **/ + g_signal_new ("ge_popup_blocked", + EPHY_TYPE_EMBED, + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (EphyEmbedIface, popup_blocked), + NULL, NULL, + ephy_marshal_VOID__STRING_STRING, + G_TYPE_NONE, + 2, + G_TYPE_POINTER, + G_TYPE_POINTER); /** * EphyEmbed::ge-context-menu: * @embed: @@ -142,7 +161,7 @@ ephy_embed_base_init (gpointer g_class) * @address: the new URL @embed is visiting * * The ::ge_location signal is emitted when @embed begins to load a new web - * page. For example, if the user clicks on a link or enters an address of if + * page. For example, if the user clicks on a link or enters an address or if * the previous web page had JavaScript or a META REFRESH tag. * * The ::ge_location signal will be emitted even when @embed is simply diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h index 259d94ddf..5820b7b43 100644 --- a/embed/ephy-embed.h +++ b/embed/ephy-embed.h @@ -160,7 +160,9 @@ struct _EphyEmbedIface EphyEmbedEvent *event); gboolean (* dom_mouse_down) (EphyEmbed *embed, EphyEmbedEvent *event); - void (* popup_blocked) (EphyEmbed *embed); + void (* popup_blocked) (EphyEmbed *embed, + const char *address, + const char *features); void (* security_change) (EphyEmbed *embed, EmbedSecurityLevel level); void (* zoom_change) (EphyEmbed *embed, diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp index eb86d5fd4..8481cee56 100644 --- a/embed/mozilla/EphyBrowser.cpp +++ b/embed/mozilla/EphyBrowser.cpp @@ -57,6 +57,7 @@ #include "nsIDOM3Document.h" #include "nsIDOMEvent.h" #include "nsIDOMEventTarget.h" +#include "nsIDOMPopupBlockedEvent.h" #include "nsIDOMNode.h" #include "nsIDOMElement.h" #include "nsIDOMWindow2.h" @@ -69,6 +70,9 @@ static PRUnichar DOMLinkAdded[] = { 'D', 'O', 'M', 'L', 'i', 'n', 'k', 'A', 'd', 'd', 'e', 'd', '\0' }; +static PRUnichar DOMPopupBlocked[] = { 'D', 'O', 'M', 'P', 'o', 'p', + 'u', 'p', 'B', 'l', 'o', 'c', + 'k', 'e', 'd', '\0' }; EphyEventListener::EphyEventListener(void) : mOwner(nsnull) @@ -160,8 +164,45 @@ EphyFaviconEventListener::HandleEvent(nsIDOMEvent* aDOMEvent) return NS_OK; } +NS_IMETHODIMP +EphyPopupBlockEventListener::HandleEvent (nsIDOMEvent * aDOMEvent) +{ + nsresult rv; + + NS_ENSURE_TRUE (mOwner != NULL, NS_ERROR_FAILURE); + + nsCOMPtr popupEvent = + do_QueryInterface (aDOMEvent, &rv); + NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + + nsCOMPtr popupWindowURI; + rv = popupEvent->GetPopupWindowURI (getter_AddRefs (popupWindowURI)); + NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS (popupWindowURI != NULL, NS_ERROR_FAILURE); + + nsEmbedCString popupWindowURIString; + rv = popupWindowURI->GetSpec (popupWindowURIString); + NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + + nsEmbedString popupWindowFeatures; + rv = popupEvent->GetPopupWindowFeatures (popupWindowFeatures); + NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + + nsEmbedCString popupWindowFeaturesString; + NS_UTF16ToCString (popupWindowFeatures, + NS_CSTRING_ENCODING_UTF8, + popupWindowFeaturesString); + + g_signal_emit_by_name(mOwner, "ge_popup_blocked", + popupWindowURIString.get(), + popupWindowFeaturesString.get()); + + return NS_OK; +} + EphyBrowser::EphyBrowser () : mFaviconEventListener(nsnull) +, mPopupBlockEventListener(nsnull) , mInitialized(PR_FALSE) { } @@ -194,6 +235,12 @@ nsresult EphyBrowser::Init (GtkMozEmbed *mozembed) rv = mFaviconEventListener->Init (EPHY_EMBED (mozembed)); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + mPopupBlockEventListener = new EphyPopupBlockEventListener(); + if (!mPopupBlockEventListener) return NS_ERROR_OUT_OF_MEMORY; + + rv = mPopupBlockEventListener->Init (EPHY_EMBED (mozembed)); + NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + rv = GetListener(); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); @@ -236,6 +283,10 @@ EphyBrowser::AttachListeners(void) mFaviconEventListener, PR_FALSE); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + rv = target->AddEventListener(nsEmbedString(DOMPopupBlocked), + mPopupBlockEventListener, PR_FALSE); + NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + return NS_OK; } @@ -254,6 +305,9 @@ EphyBrowser::DetachListeners(void) mFaviconEventListener, PR_FALSE); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + rv = target->RemoveEventListener(nsEmbedString(DOMPopupBlocked), + mPopupBlockEventListener, PR_FALSE); + return NS_OK; } diff --git a/embed/mozilla/EphyBrowser.h b/embed/mozilla/EphyBrowser.h index 07023887c..72d69a8a7 100644 --- a/embed/mozilla/EphyBrowser.h +++ b/embed/mozilla/EphyBrowser.h @@ -66,6 +66,12 @@ private: nsresult HandleFaviconLink (nsIDOMNode *node); }; +class EphyPopupBlockEventListener : public EphyEventListener +{ +public: + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); +}; + class EphyBrowser { public: @@ -128,6 +134,7 @@ private: nsCOMPtr mEventReceiver; nsCOMPtr mDOMWindow; EphyFaviconEventListener *mFaviconEventListener; + EphyPopupBlockEventListener *mPopupBlockEventListener; PRBool mInitialized; nsresult GetListener (void); diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp index bf74c9305..6513c8095 100644 --- a/embed/mozilla/mozilla-embed-single.cpp +++ b/embed/mozilla/mozilla-embed-single.cpp @@ -840,13 +840,15 @@ impl_permission_manager_list (EphyPermissionManager *manager, return list; } -void -mozilla_embed_single_open_window (EphyEmbedSingle *single, - EphyEmbed *parent, - const char *address, - const char *features) +static void +impl_open_window (EphyEmbedSingle *single, + EphyEmbed *parent, + const char *address, + const char *features) { nsCOMPtr domWindow; + nsCOMPtr dummy; + if (parent) { EphyBrowser *browser; @@ -858,7 +860,8 @@ mozilla_embed_single_open_window (EphyEmbedSingle *single, } nsCOMPtr wWatch(do_GetService ("@mozilla.org/embedcomp/window-watcher;1")); - wWatch->OpenWindow (domWindow, address, "", features, nsnull, nsnull); + wWatch->OpenWindow (domWindow, address, "", features, nsnull, + getter_AddRefs (dummy)); } static void @@ -881,6 +884,7 @@ ephy_embed_single_iface_init (EphyEmbedSingleIface *iface) iface->set_offline_mode = impl_set_offline_mode; iface->load_proxy_autoconf = impl_load_proxy_autoconf; iface->get_font_list = impl_get_font_list; + iface->open_window = impl_open_window; } static void -- cgit v1.2.3