Commit 29c990d5 authored by Gustavo Noronha Silva's avatar Gustavo Noronha Silva

If a tab is created only for a download, close it

If a tab that has just been created ends up being just a download, then
close it down. If it's the only one on the window, then make it show the
overview instead.

https://bugzilla.gnome.org/show_bug.cgi?id=607233
parent cd8d55b2
......@@ -1245,6 +1245,22 @@ ephy_web_view_class_init (EphyWebViewClass *klass)
G_TYPE_NONE,
0);
/**
* EphyWebView::donload-only-load:
* @view: the #EphyWebView that received the signal
*
* The ::download-only-load signal is emitted when the @view has its main load
* replaced by a download, and that is the only reason why the @view has been created.
**/
g_signal_new ("download-only-load",
EPHY_TYPE_WEB_VIEW,
G_SIGNAL_RUN_FIRST,
0,
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
g_type_class_add_private (gobject_class, sizeof (EphyWebViewPrivate));
}
......@@ -1852,10 +1868,15 @@ load_failed_cb (WebKitWebView *web_view,
}
}
break;
/* In case we are downloading something or the resource is going to
* be showed with a plugin just let WebKit do it */
case WEBKIT_PLUGIN_ERROR_WILL_HANDLE_LOAD:
case WEBKIT_POLICY_ERROR_FRAME_LOAD_INTERRUPTED_BY_POLICY_CHANGE:
/* If we are going to download something, and this is the first
* page to load in this tab, we may want to close it down. */
if (!webkit_web_view_can_go_back (web_view))
g_signal_emit_by_name (view, "download-only-load", NULL);
break;
/* In case the resource is going to be showed with a plugin just let
* WebKit do it */
case WEBKIT_PLUGIN_ERROR_WILL_HANDLE_LOAD:
default:
break;
}
......
......@@ -2605,6 +2605,31 @@ present_on_idle_cb (GtkWindow *window)
return FALSE;
}
static gboolean
delayed_remove_child (gpointer data)
{
GtkWidget *widget = GTK_WIDGET (data);
EphyEmbedContainer *container = EPHY_EMBED_CONTAINER (gtk_widget_get_toplevel (widget));
ephy_embed_container_remove_child (container, widget);
return FALSE;
}
static void
download_only_load_cb (EphyWebView *view,
EphyWindow *window)
{
EphyWindowPrivate *priv = window->priv;
if (gtk_notebook_get_n_pages (priv->notebook) == 1) {
ephy_web_view_load_homepage (view);
return;
}
g_idle_add (delayed_remove_child, EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (view));
}
static void
notebook_page_added_cb (EphyNotebook *notebook,
EphyEmbed *embed,
......@@ -2623,6 +2648,9 @@ notebook_page_added_cb (EphyNotebook *notebook,
G_CONNECT_SWAPPED);
#endif
g_signal_connect_object (ephy_embed_get_web_view (embed), "download-only-load",
G_CALLBACK (download_only_load_cb), window, G_CONNECT_AFTER);
g_signal_connect_object (ephy_embed_get_web_view (embed), "ge-modal-alert",
G_CALLBACK (embed_modal_alert_cb), window, G_CONNECT_AFTER);
......@@ -2655,6 +2683,9 @@ notebook_page_removed_cb (EphyNotebook *notebook,
window);
#endif
g_signal_handlers_disconnect_by_func
(ephy_embed_get_web_view (embed), G_CALLBACK (download_only_load_cb), window);
g_signal_handlers_disconnect_by_func
(ephy_embed_get_web_view (embed), G_CALLBACK (embed_modal_alert_cb), window);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment