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 /src | |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/ephy-tab.c | 414 | ||||
-rw-r--r-- | src/ephy-window.c | 29 |
2 files changed, 13 insertions, 430 deletions
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); |