diff options
author | Xan Lopez <xan@src.gnome.org> | 2007-10-27 23:40:04 +0800 |
---|---|---|
committer | Xan Lopez <xan@src.gnome.org> | 2007-10-27 23:40:04 +0800 |
commit | 3df8ead647f1b25704e33d7e81ce9959d30a065c (patch) | |
tree | 7e143d87872c6acb6346d3bbdb95e81a613c9b69 | |
parent | 13f17264d9757eaf01eaa1ff2842812872385c56 (diff) | |
download | gsoc2013-epiphany-3df8ead647f1b25704e33d7e81ce9959d30a065c.tar gsoc2013-epiphany-3df8ead647f1b25704e33d7e81ce9959d30a065c.tar.gz gsoc2013-epiphany-3df8ead647f1b25704e33d7e81ce9959d30a065c.tar.bz2 gsoc2013-epiphany-3df8ead647f1b25704e33d7e81ce9959d30a065c.tar.lz gsoc2013-epiphany-3df8ead647f1b25704e33d7e81ce9959d30a065c.tar.xz gsoc2013-epiphany-3df8ead647f1b25704e33d7e81ce9959d30a065c.tar.zst gsoc2013-epiphany-3df8ead647f1b25704e33d7e81ce9959d30a065c.zip |
Move popups-allowed and hidden-popup-count from EphyTab to EphyEmbed.
Popup management is non-working now, see bug #490672
svn path=/trunk/; revision=7575
-rw-r--r-- | embed/ephy-embed.c | 15 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed.cpp | 351 | ||||
-rw-r--r-- | src/ephy-tab.c | 414 | ||||
-rw-r--r-- | src/ephy-window.c | 29 |
4 files changed, 376 insertions, 433 deletions
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c index baa75c400..caa7b8a2e 100644 --- a/embed/ephy-embed.c +++ b/embed/ephy-embed.c @@ -512,6 +512,21 @@ ephy_embed_base_init (gpointer g_class) "The embed icon's address", NULL, (G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB))); + g_object_interface_install_property (g_class, + g_param_spec_int ("hidden-popup-count", + "Number of Blocked Popups", + "The embed's number of blocked popup windows", + 0, + G_MAXINT, + 0, + G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); + + g_object_interface_install_property (g_class, + g_param_spec_boolean ("popups-allowed", + "Popups Allowed", + "Whether popup windows are to be displayed", + FALSE, + G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); initialized = TRUE; } diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp index f1a45c0c7..399fb3795 100644 --- a/embed/mozilla/mozilla-embed.cpp +++ b/embed/mozilla/mozilla-embed.cpp @@ -110,6 +110,13 @@ static void mozilla_embed_favicon_cb (EphyEmbed *embed, static gboolean mozilla_embed_open_uri_cb (EphyEmbed *embed, const char *uri, MozillaEmbed *membed); +static void mozilla_embed_file_monitor_cancel (MozillaEmbed *embed); +#if 0 +static guint popup_blocker_n_hidden (MozillaEmbed *embed); +static gboolean mozilla_embed_get_popups_allowed (MozillaEmbed *embed); +static void mozilla_embed_set_popups_allowed (MozillaEmbed *embed, + gboolean allowed); +#endif static void mozilla_embed_file_monitor_cancel (MozillaEmbed *embed); static void impl_set_typed_address (EphyEmbed *embed, const char *address, @@ -127,6 +134,7 @@ typedef enum MOZILLA_EMBED_LOAD_STOPPED } MozillaEmbedLoadState; +#define MAX_HIDDEN_POPUPS 5 #define MAX_TITLE_LENGTH 512 /* characters */ #define RELOAD_DELAY 250 /* ms */ #define RELOAD_DELAY_MAX_TICKS 40 /* RELOAD_DELAY * RELOAD_DELAY_MAX_TICKS = 10 s */ @@ -164,7 +172,10 @@ struct MozillaEmbedPrivate /* File watch */ GnomeVFSMonitorHandle *monitor; guint reload_scheduled_id; - guint reload_delay_ticks; + guint reload_delay_ticks; + + GSList *hidden_popups; + GSList *shown_popups; }; #define WINDOWWATCHER_CONTRACTID "@mozilla.org/embedcomp/window-watcher;1" @@ -174,12 +185,14 @@ enum PROP_0, PROP_ADDRESS, PROP_DOCUMENT_TYPE, + PROP_HIDDEN_POPUP_COUNT, PROP_ICON, PROP_ICON_ADDRESS, PROP_LINK_MESSAGE, PROP_LOAD_PROGRESS, PROP_LOAD_STATUS, PROP_NAVIGATION, + PROP_POPUPS_ALLOWED, PROP_SECURITY, PROP_STATUS_MESSAGE, PROP_TITLE, @@ -187,6 +200,13 @@ enum PROP_ZOOM }; +typedef struct +{ + char *url; + char *name; + char *features; +} PopupInfo; + static void impl_manager_do_command (EphyCommandManager *manager, const char *command) @@ -294,6 +314,10 @@ mozilla_embed_get_property (GObject *object, case PROP_DOCUMENT_TYPE: g_value_set_enum (value, priv->document_type); break; + case PROP_HIDDEN_POPUP_COUNT: + g_value_set_int (value, 0); + // g_value_set_int (value, popup_blocker_n_hidden (embed)); + break; case PROP_ICON: g_value_set_object (value, priv->icon); break; @@ -312,6 +336,10 @@ mozilla_embed_get_property (GObject *object, case PROP_NAVIGATION: g_value_set_flags (value, priv->nav_flags); break; + case PROP_POPUPS_ALLOWED: + g_value_set_boolean (value, FALSE); + // g_value_set_boolean (value, mozilla_embed_get_popups_allowed (embed)); + break; case PROP_SECURITY: g_value_set_enum (value, priv->security_level); break; @@ -349,8 +377,12 @@ mozilla_embed_set_property (GObject *object, impl_set_typed_address (EPHY_EMBED (object), g_value_get_string (value), EPHY_EMBED_ADDRESS_EXPIRE_NOW); break; + case PROP_POPUPS_ALLOWED: + //mozilla_embed_set_popups_allowed (MOZILLA_EMBED (object), g_value_get_boolean (value)); + break; case PROP_ADDRESS: case PROP_DOCUMENT_TYPE: + case PROP_HIDDEN_POPUP_COUNT: case PROP_ICON: case PROP_LOAD_PROGRESS: case PROP_LOAD_STATUS: @@ -400,6 +432,8 @@ mozilla_embed_class_init (MozillaEmbedClass *klass) g_object_class_override_property (object_class, PROP_LINK_MESSAGE, "link-message"); g_object_class_override_property (object_class, PROP_ICON, "icon"); g_object_class_override_property (object_class, PROP_ICON_ADDRESS, "icon-address"); + g_object_class_override_property (object_class, PROP_POPUPS_ALLOWED, "popups-allowed"); + g_object_class_override_property (object_class, PROP_HIDDEN_POPUP_COUNT, "hidden-popup-count"); g_type_class_add_private (object_class, sizeof(MozillaEmbedPrivate)); } @@ -525,6 +559,10 @@ mozilla_embed_finalize (GObject *object) embed->priv->icon = NULL; } +#if 0 + popups_manager_reset (embed); +#endif + g_free (embed->priv->icon_address); g_free (embed->priv->address); g_free (embed->priv->typed_address); @@ -538,6 +576,314 @@ mozilla_embed_finalize (GObject *object) g_object_unref (embed_shell); } +#if 0 +static void +ephy_tab_content_change_cb (EphyEmbed *embed, const char *address, EphyTab *tab) +{ + popups_manager_reset (tab); + g_object_notify (G_OBJECT (tab), "popups-allowed"); +} + +static void +ephy_tab_new_window_cb (EphyEmbed *embed, + EphyEmbed *new_embed, + EphyTab *tab) +{ + EphyWindow *window; + + g_return_if_fail (new_embed != NULL); + + window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (new_embed))); + g_return_if_fail (window != NULL); + + popups_manager_add_window (tab, window); +} + +static void +ephy_tab_popup_blocked_cb (EphyEmbed *embed, + const char *url, + const char *name, + const char *features, + EphyTab *tab) +{ + popups_manager_add (tab, url, name, features); +} + +static void +popups_manager_free_info (PopupInfo *popup) +{ + g_free (popup->url); + g_free (popup->name); + g_free (popup->features); + g_free (popup); +} + +static void +popups_manager_add (MozillaEmbed *embed, + const char *url, + const char *name, + const char *features) +{ + MozillaEmbedPrivate *priv = embed->priv; + PopupInfo *popup; + + LOG ("popups_manager_add: embed %p, url %s, features %s", + embed, url, features); + + popup = g_new0 (PopupInfo, 1); + + popup->url = (url == NULL) ? NULL : g_strdup (url); + popup->name = g_strdup (name); + popup->features = g_strdup (features); + + priv->hidden_popups = g_slist_prepend (priv->hidden_popups, popup); + + if (popup_blocker_n_hidden (embed) > MAX_HIDDEN_POPUPS) /* bug #160863 */ + { + /* Remove the oldest popup */ + GSList *l = embed->priv->hidden_popups; + + while (l->next->next != NULL) + { + l = l->next; + } + + popup = (PopupInfo *) l->next->data; + popups_manager_free_info (popup); + + l->next = NULL; + } + else + { + g_object_notify (G_OBJECT (embed), "hidden-popup-count"); + } +} + +static gboolean +popups_manager_remove_window (MozillaEmbed *embed, + EphyWindow *window) +{ + embed->priv->shown_popups = g_slist_remove (embed->priv->shown_popups, + window); + + return FALSE; +} + +static void +disconnect_popup (EphyWindow *window, + MozillaEmbed *embed) +{ + g_signal_handlers_disconnect_by_func + (window, G_CALLBACK (popups_manager_remove_window), embed); +} + +static void +popups_manager_add_window (MozillaEmbed *embed, + EphyWindow *window) +{ + LOG ("popups_manager_add_window: embed %p, window %p", embed, window); + + embed->priv->shown_popups = g_slist_prepend + (embed->priv->shown_popups, window); + + g_signal_connect_swapped (window, "destroy", + G_CALLBACK (popups_manager_remove_window), + embed); +} + +static gboolean +mozilla_embed_get_popups_allowed (MozillaEmbed *embed) +{ + EphyPermissionManager *permission_manager; + EphyPermission response; + EphyEmbed *embed; + char *location; + gboolean allow; + + permission_manager = EPHY_PERMISSION_MANAGER + (ephy_embed_shell_get_embed_single (embed_shell)); + g_return_val_if_fail (EPHY_IS_PERMISSION_MANAGER (permission_manager), + FALSE); + + location = ephy_embed_get_location (embed, TRUE); + if (location == NULL) return FALSE; /* FALSE, TRUE… same thing */ + + response = ephy_permission_manager_test_permission + (permission_manager, location, EPT_POPUP); + + switch (response) + { + case EPHY_PERMISSION_ALLOWED: + allow = TRUE; + break; + case EPHY_PERMISSION_DENIED: + allow = FALSE; + break; + case EPHY_PERMISSION_DEFAULT: + default: + allow = eel_gconf_get_boolean + (CONF_SECURITY_ALLOW_POPUPS); + break; + } + + g_free (location); + + LOG ("mozilla_embed_get_popups_allowed: embed %p, allowed: %d", embed, allow); + + return allow; +} + +static void +popups_manager_show (PopupInfo *popup, + MozillaEmbed *embed) +{ + EphyEmbed *embed; + EphyEmbedSingle *single; + + /* Only show popup with non NULL url */ + if (popup->url != NULL) + { + embed = ephy_embed_get_embed (embed); + + single = EPHY_EMBED_SINGLE + (ephy_embed_shell_get_embed_single (embed_shell)); + + ephy_embed_single_open_window (single, embed, popup->url, + popup->name, popup->features); + } + popups_manager_free_info (popup); +} + +static void +popups_manager_show_all (MozillaEmbed *embed) +{ + LOG ("popup_blocker_show_all: embed %p", embed); + + g_slist_foreach (embed->priv->hidden_popups, + (GFunc) popups_manager_show, embed); + g_slist_free (embed->priv->hidden_popups); + embed->priv->hidden_popups = NULL; + + g_object_notify (G_OBJECT (embed), "hidden-popup-count"); +} + +static char * +popups_manager_new_window_info (EphyWindow *window) +{ + MozillaEmbed *embed; + EphyEmbedChrome chrome; + gboolean is_popup; + char *features; + + g_object_get (window, "chrome", &chrome, "is-popup", &is_popup, NULL); + g_return_val_if_fail (is_popup, g_strdup ("")); + + embed = ephy_window_get_active_embed (window); + g_return_val_if_fail (embed != NULL, g_strdup ("")); + + features = g_strdup_printf + ("width=%d,height=%d,menubar=%d,status=%d,toolbar=%d", + embed->priv->width, embed->priv->height, + (chrome & EPHY_EMBED_CHROME_MENUBAR) > 0, + (chrome & EPHY_EMBED_CHROME_STATUSBAR) > 0, + (chrome & EPHY_EMBED_CHROME_TOOLBAR) > 0); + + return features; +} + +static void +popups_manager_hide (EphyWindow *window, + MozillaEmbed *parent_embed) +{ + EphyEmbed *embed; + char *location; + char *features; + + embed = ephy_window_get_active_embed (window); + g_return_if_fail (EPHY_IS_EMBED (embed)); + + location = ephy_embed_get_location (embed, TRUE); + if (location == NULL) return; + + features = popups_manager_new_window_info (window); + + popups_manager_add (parent_embed, location, "" /* FIXME? maybe _blank? */, features); + + gtk_widget_destroy (GTK_WIDGET (window)); + + g_free (location); + g_free (features); +} + +static void +popups_manager_hide_all (MozillaEmbed *embed) +{ + LOG ("popup_blocker_hide_all: embed %p", embed); + + g_slist_foreach (embed->priv->shown_popups, + (GFunc) popups_manager_hide, embed); + g_slist_free (embed->priv->shown_popups); + embed->priv->shown_popups = NULL; +} + +static void +mozilla_embed_set_popups_allowed (MozillaEmbed *embed, + gboolean allowed) +{ + char *location; + EphyEmbed *embed; + EphyPermissionManager *manager; + EphyPermission permission; + + embed = ephy_embed_get_embed (embed); + + location = ephy_embed_get_location (embed, TRUE); + g_return_if_fail (location != NULL); + + manager = EPHY_PERMISSION_MANAGER + (ephy_embed_shell_get_embed_single (embed_shell)); + g_return_if_fail (EPHY_IS_PERMISSION_MANAGER (manager)); + + permission = allowed ? EPHY_PERMISSION_ALLOWED + : EPHY_PERMISSION_DENIED; + + ephy_permission_manager_add_permission (manager, location, EPT_POPUP, permission); + + if (allowed) + { + popups_manager_show_all (embed); + } + else + { + popups_manager_hide_all (embed); + } + + g_free (location); +} + +static guint +popup_blocker_n_hidden (MozillaEmbed *embed) +{ + return g_slist_length (embed->priv->hidden_popups); +} + +static void +popups_manager_reset (MozillaEmbed *embed) +{ + g_slist_foreach (embed->priv->hidden_popups, + (GFunc) popups_manager_free_info, NULL); + g_slist_free (embed->priv->hidden_popups); + embed->priv->hidden_popups = NULL; + + g_slist_foreach (embed->priv->shown_popups, + (GFunc) disconnect_popup, embed); + g_slist_free (embed->priv->shown_popups); + embed->priv->shown_popups = NULL; + + g_object_notify (G_OBJECT (embed), "hidden-popup-count"); +} +#endif + static void impl_load_url (EphyEmbed *embed, const char *url) @@ -1512,7 +1858,7 @@ mozilla_embed_load_icon (MozillaEmbed *embed) EphyFaviconCache *cache; if (priv->icon_address == NULL || priv->icon != NULL) return; -#if 0 + shell = ephy_embed_shell_get_default (); cache = EPHY_FAVICON_CACHE (ephy_embed_shell_get_favicon_cache (shell)); @@ -1520,7 +1866,6 @@ mozilla_embed_load_icon (MozillaEmbed *embed) priv->icon = ephy_favicon_cache_get (cache, priv->icon_address); g_object_notify (G_OBJECT (embed), "icon"); -#endif } static void diff --git a/src/ephy-tab.c b/src/ephy-tab.c index 03ec35136..893472ad6 100644 --- a/src/ephy-tab.c +++ b/src/ephy-tab.c @@ -72,16 +72,12 @@ #define EPHY_TAB_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_TAB, EphyTabPrivate)) -#define MAX_HIDDEN_POPUPS 5 - struct _EphyTabPrivate { guint id; int width; int height; - GSList *hidden_popups; - GSList *shown_popups; guint idle_resize_handler; }; @@ -93,19 +89,8 @@ static void ephy_tab_finalize (GObject *object); enum { PROP_0, - PROP_ICON, - PROP_ICON_ADDRESS, - PROP_HIDDEN_POPUP_COUNT, - PROP_POPUPS_ALLOWED, }; -typedef struct -{ - char *url; - char *name; - char *features; -} PopupInfo; - static GObjectClass *parent_class; /* We need to assign unique IDs to tabs, otherwise accels get confused in the @@ -116,13 +101,6 @@ static GObjectClass *parent_class; static GArray *tabs_id_array = NULL; static guint n_tabs = 0; -/* internal functions, accessible only from this file */ -static guint popup_blocker_n_hidden (EphyTab *tab); -static gboolean ephy_tab_get_popups_allowed (EphyTab *tab); -static void ephy_tab_set_popups_allowed (EphyTab *tab, - gboolean allowed); -static void ephy_tab_file_monitor_cancel (EphyTab *tab); - /* Class functions */ GType @@ -165,47 +143,6 @@ ephy_tab_get_type (void) } static void -ephy_tab_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - EphyTab *tab = EPHY_TAB (object); - - switch (prop_id) - - { - case PROP_POPUPS_ALLOWED: - ephy_tab_set_popups_allowed (tab, g_value_get_boolean (value)); - break; - case PROP_HIDDEN_POPUP_COUNT: - /* read only */ - break; - } -} - -static void -ephy_tab_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - EphyTab *tab = EPHY_TAB (object); - - switch (prop_id) - { - case PROP_HIDDEN_POPUP_COUNT: - g_value_set_int (value, popup_blocker_n_hidden (tab)); - break; - case PROP_POPUPS_ALLOWED: - g_value_set_boolean - (value, ephy_tab_get_popups_allowed (tab)); - break; - } -} - - -static void ephy_tab_size_request (GtkWidget *widget, GtkRequisition *requisition) { @@ -285,324 +222,16 @@ ephy_tab_class_init (EphyTabClass *class) object_class->dispose = ephy_tab_dispose; object_class->finalize = ephy_tab_finalize; - object_class->get_property = ephy_tab_get_property; - object_class->set_property = ephy_tab_set_property; widget_class->size_allocate = ephy_tab_size_allocate; widget_class->size_request = ephy_tab_size_request; widget_class->map = ephy_tab_map; widget_class->grab_focus = ephy_tab_grab_focus; - g_object_class_install_property (object_class, - PROP_HIDDEN_POPUP_COUNT, - g_param_spec_int ("hidden-popup-count", - "Number of Blocked Popups", - "The tab's number of blocked popup windows", - 0, - G_MAXINT, - 0, - G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); - - g_object_class_install_property (object_class, - PROP_POPUPS_ALLOWED, - g_param_spec_boolean ("popups-allowed", - "Popups Allowed", - "Whether popup windows are to be displayed", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); - g_type_class_add_private (object_class, sizeof (EphyTabPrivate)); } static void -popups_manager_free_info (PopupInfo *popup) -{ - g_free (popup->url); - g_free (popup->name); - g_free (popup->features); - g_free (popup); -} - -static void -popups_manager_add (EphyTab *tab, - const char *url, - const char *name, - const char *features) -{ - EphyTabPrivate *priv = tab->priv; - PopupInfo *popup; - - LOG ("popups_manager_add: tab %p, url %s, features %s", - tab, url, features); - - g_return_if_fail (EPHY_IS_TAB (tab)); - - popup = g_new0 (PopupInfo, 1); - - popup->url = (url == NULL) ? NULL : g_strdup (url); - popup->name = g_strdup (name); - popup->features = g_strdup (features); - - priv->hidden_popups = g_slist_prepend (priv->hidden_popups, popup); - - if (popup_blocker_n_hidden (tab) > MAX_HIDDEN_POPUPS) /* bug #160863 */ - { - /* Remove the oldest popup */ - GSList *l = tab->priv->hidden_popups; - - while (l->next->next != NULL) - { - l = l->next; - } - - popup = (PopupInfo *) l->next->data; - popups_manager_free_info (popup); - - l->next = NULL; - } - else - { - g_object_notify (G_OBJECT (tab), "hidden-popup-count"); - } -} - -static gboolean -popups_manager_remove_window (EphyTab *tab, - EphyWindow *window) -{ - tab->priv->shown_popups = g_slist_remove (tab->priv->shown_popups, - window); - - return FALSE; -} - -static void -disconnect_popup (EphyWindow *window, - EphyTab *tab) -{ - g_signal_handlers_disconnect_by_func - (window, G_CALLBACK (popups_manager_remove_window), tab); -} - -static void -popups_manager_add_window (EphyTab *tab, - EphyWindow *window) -{ - LOG ("popups_manager_add_window: tab %p, window %p", tab, window); - - g_return_if_fail (EPHY_IS_TAB (tab)); - g_return_if_fail (EPHY_IS_WINDOW (window)); - - tab->priv->shown_popups = g_slist_prepend - (tab->priv->shown_popups, window); - - g_signal_connect_swapped (window, "destroy", - G_CALLBACK (popups_manager_remove_window), - tab); -} - -static gboolean -ephy_tab_get_popups_allowed (EphyTab *tab) -{ - EphyPermissionManager *permission_manager; - EphyPermission response; - EphyEmbed *embed; - char *location; - gboolean allow; - - g_return_val_if_fail (EPHY_IS_TAB (tab), FALSE); - - permission_manager = EPHY_PERMISSION_MANAGER - (ephy_embed_shell_get_embed_single (embed_shell)); - g_return_val_if_fail (EPHY_IS_PERMISSION_MANAGER (permission_manager), - FALSE); - - embed = ephy_tab_get_embed (tab); - g_return_val_if_fail (EPHY_IS_EMBED (embed), FALSE); - - location = ephy_embed_get_location (embed, TRUE); - if (location == NULL) return FALSE; /* FALSE, TRUE… same thing */ - - response = ephy_permission_manager_test_permission - (permission_manager, location, EPT_POPUP); - - switch (response) - { - case EPHY_PERMISSION_ALLOWED: - allow = TRUE; - break; - case EPHY_PERMISSION_DENIED: - allow = FALSE; - break; - case EPHY_PERMISSION_DEFAULT: - default: - allow = eel_gconf_get_boolean - (CONF_SECURITY_ALLOW_POPUPS); - break; - } - - g_free (location); - - LOG ("ephy_tab_get_popups_allowed: tab %p, allowed: %d", tab, allow); - - return allow; -} - -static void -popups_manager_show (PopupInfo *popup, - EphyTab *tab) -{ - EphyEmbed *embed; - EphyEmbedSingle *single; - - /* Only show popup with non NULL url */ - if (popup->url != NULL) - { - embed = ephy_tab_get_embed (tab); - - single = EPHY_EMBED_SINGLE - (ephy_embed_shell_get_embed_single (embed_shell)); - - ephy_embed_single_open_window (single, embed, popup->url, - popup->name, popup->features); - } - popups_manager_free_info (popup); -} - -static void -popups_manager_show_all (EphyTab *tab) -{ - LOG ("popup_blocker_show_all: tab %p", tab); - - g_slist_foreach (tab->priv->hidden_popups, - (GFunc) popups_manager_show, tab); - g_slist_free (tab->priv->hidden_popups); - tab->priv->hidden_popups = NULL; - - g_object_notify (G_OBJECT (tab), "hidden-popup-count"); -} - -static char * -popups_manager_new_window_info (EphyWindow *window) -{ - EphyTab *tab; - EphyEmbedChrome chrome; - gboolean is_popup; - char *features; - - g_object_get (window, "chrome", &chrome, "is-popup", &is_popup, NULL); - g_return_val_if_fail (is_popup, g_strdup ("")); - - tab = ephy_window_get_active_tab (window); - g_return_val_if_fail (tab != NULL, g_strdup ("")); - - features = g_strdup_printf - ("width=%d,height=%d,menubar=%d,status=%d,toolbar=%d", - tab->priv->width, tab->priv->height, - (chrome & EPHY_EMBED_CHROME_MENUBAR) > 0, - (chrome & EPHY_EMBED_CHROME_STATUSBAR) > 0, - (chrome & EPHY_EMBED_CHROME_TOOLBAR) > 0); - - return features; -} - -static void -popups_manager_hide (EphyWindow *window, - EphyTab *parent_tab) -{ - EphyEmbed *embed; - char *location; - char *features; - - embed = ephy_window_get_active_embed (window); - g_return_if_fail (EPHY_IS_EMBED (embed)); - - location = ephy_embed_get_location (embed, TRUE); - if (location == NULL) return; - - features = popups_manager_new_window_info (window); - - popups_manager_add (parent_tab, location, "" /* FIXME? maybe _blank? */, features); - - gtk_widget_destroy (GTK_WIDGET (window)); - - g_free (location); - g_free (features); -} - -static void -popups_manager_hide_all (EphyTab *tab) -{ - LOG ("popup_blocker_hide_all: tab %p", tab); - - g_slist_foreach (tab->priv->shown_popups, - (GFunc) popups_manager_hide, tab); - g_slist_free (tab->priv->shown_popups); - tab->priv->shown_popups = NULL; -} - -static void -ephy_tab_set_popups_allowed (EphyTab *tab, - gboolean allowed) -{ - char *location; - EphyEmbed *embed; - EphyPermissionManager *manager; - EphyPermission permission; - - g_return_if_fail (EPHY_IS_TAB (tab)); - - embed = ephy_tab_get_embed (tab); - - location = ephy_embed_get_location (embed, TRUE); - g_return_if_fail (location != NULL); - - manager = EPHY_PERMISSION_MANAGER - (ephy_embed_shell_get_embed_single (embed_shell)); - g_return_if_fail (EPHY_IS_PERMISSION_MANAGER (manager)); - - permission = allowed ? EPHY_PERMISSION_ALLOWED - : EPHY_PERMISSION_DENIED; - - ephy_permission_manager_add_permission (manager, location, EPT_POPUP, permission); - - if (allowed) - { - popups_manager_show_all (tab); - } - else - { - popups_manager_hide_all (tab); - } - - g_free (location); -} - -static guint -popup_blocker_n_hidden (EphyTab *tab) -{ - return g_slist_length (tab->priv->hidden_popups); -} - -static void -popups_manager_reset (EphyTab *tab) -{ - g_return_if_fail (EPHY_IS_TAB (tab)); - - g_slist_foreach (tab->priv->hidden_popups, - (GFunc) popups_manager_free_info, NULL); - g_slist_free (tab->priv->hidden_popups); - tab->priv->hidden_popups = NULL; - - g_slist_foreach (tab->priv->shown_popups, - (GFunc) disconnect_popup, tab); - g_slist_free (tab->priv->shown_popups); - tab->priv->shown_popups = NULL; - - g_object_notify (G_OBJECT (tab), "hidden-popup-count"); -} - -static void ephy_tab_dispose (GObject *object) { EphyTab *tab = EPHY_TAB (object); @@ -624,8 +253,6 @@ ephy_tab_finalize (GObject *object) EphyTabPrivate *priv = tab->priv; guint id = priv->id; - popups_manager_reset (tab); - G_OBJECT_CLASS (parent_class)->finalize (object); #ifdef ENABLE_PYTHON @@ -799,38 +426,6 @@ ephy_tab_set_size (EphyTab *tab, /* Private callbacks for embed signals */ -static void -ephy_tab_content_change_cb (EphyEmbed *embed, const char *address, EphyTab *tab) -{ - popups_manager_reset (tab); - g_object_notify (G_OBJECT (tab), "popups-allowed"); -} - -static void -ephy_tab_new_window_cb (EphyEmbed *embed, - EphyEmbed *new_embed, - EphyTab *tab) -{ - EphyWindow *window; - - g_return_if_fail (new_embed != NULL); - - window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (new_embed))); - g_return_if_fail (window != NULL); - - popups_manager_add_window (tab, window); -} - -static void -ephy_tab_popup_blocked_cb (EphyEmbed *embed, - const char *url, - const char *name, - const char *features, - EphyTab *tab) -{ - popups_manager_add (tab, url, name, features); -} - static gboolean open_link_in_new (EphyTab *tab, const char *link_address, @@ -1050,18 +645,9 @@ ephy_tab_init (EphyTab *tab) gtk_container_add (GTK_CONTAINER (tab), GTK_WIDGET (embed)); gtk_widget_show (GTK_WIDGET (embed)); - g_signal_connect_object (embed, "ge_new_window", - G_CALLBACK (ephy_tab_new_window_cb), - tab, 0); - g_signal_connect_object (embed, "ge_popup_blocked", - G_CALLBACK (ephy_tab_popup_blocked_cb), - tab, 0); g_signal_connect_object (embed, "ge_dom_mouse_click", G_CALLBACK (ephy_tab_dom_mouse_click_cb), tab, 0); - g_signal_connect_object (embed, "ge_content_change", - G_CALLBACK (ephy_tab_content_change_cb), - tab, 0); } /* private */ diff --git a/src/ephy-window.c b/src/ephy-window.c index 2bef6530b..90dd59600 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -1611,14 +1611,14 @@ sync_tab_security (EphyEmbed *embed, } static void -sync_tab_popup_windows (EphyTab *tab, +sync_tab_popup_windows (EphyEmbed *embed, GParamSpec *pspec, EphyWindow *window) { guint num_popups = 0; char *tooltip = NULL; - g_object_get (G_OBJECT (tab), + g_object_get (G_OBJECT (embed), "hidden-popup-count", &num_popups, NULL); @@ -1639,21 +1639,21 @@ sync_tab_popup_windows (EphyTab *tab, } static void -sync_tab_popups_allowed (EphyTab *tab, +sync_tab_popups_allowed (EphyEmbed *embed, GParamSpec *pspec, EphyWindow *window) { GtkAction *action; gboolean allow; - g_return_if_fail (EPHY_IS_TAB (tab)); + g_return_if_fail (EPHY_IS_EMBED (embed)); g_return_if_fail (EPHY_IS_WINDOW (window)); action = gtk_action_group_get_action (window->priv->action_group, "ViewPopupWindows"); g_return_if_fail (GTK_IS_ACTION (action)); - g_object_get (G_OBJECT (tab), "popups-allowed", &allow, NULL); + g_object_get (G_OBJECT (embed), "popups-allowed", &allow, NULL); g_signal_handlers_block_by_func (G_OBJECT (action), @@ -2142,15 +2142,14 @@ ephy_window_set_active_tab (EphyWindow *window, EphyTab *new_tab) if (old_tab != NULL) { - g_signal_handlers_disconnect_by_func (old_tab, + embed = ephy_tab_get_embed (old_tab); + + g_signal_handlers_disconnect_by_func (embed, G_CALLBACK (sync_tab_popup_windows), window); - g_signal_handlers_disconnect_by_func (old_tab, + g_signal_handlers_disconnect_by_func (embed, G_CALLBACK (sync_tab_popups_allowed), window); - - embed = ephy_tab_get_embed (old_tab); - g_signal_handlers_disconnect_by_func (embed, G_CALLBACK (sync_tab_security), window); @@ -2205,17 +2204,15 @@ ephy_window_set_active_tab (EphyWindow *window, EphyTab *new_tab) sync_tab_address (embed, NULL, window); sync_tab_icon (embed, NULL, window); sync_tab_message (embed, NULL, window); + sync_tab_popup_windows (embed, NULL, window); + sync_tab_popups_allowed (embed, NULL, window); - sync_tab_popup_windows (new_tab, NULL, window); - sync_tab_popups_allowed (new_tab, NULL, window); - - g_signal_connect_object (new_tab, "notify::hidden-popup-count", + g_signal_connect_object (embed, "notify::hidden-popup-count", G_CALLBACK (sync_tab_popup_windows), window, 0); - g_signal_connect_object (new_tab, "notify::popups-allowed", + g_signal_connect_object (embed, "notify::popups-allowed", G_CALLBACK (sync_tab_popups_allowed), window, 0); - g_signal_connect_object (embed, "notify::title", G_CALLBACK (sync_tab_title), window, 0); |