From 7e04c76bce9bafba6833426def5f99c0c851053c Mon Sep 17 00:00:00 2001 From: Martin Natano Date: Mon, 16 Apr 2012 19:55:09 +0200 Subject: [PATCH] Handle empty tabs due to download links with a target Fixes: https://bugs.launchpad.net/midori/+bug/973646 --- midori/midori-browser.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/midori/midori-browser.c b/midori/midori-browser.c index a409663d..aae2d118 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -1453,11 +1453,25 @@ midori_browser_download_prepare_destination_uri (WebKitDownload* download, return destination_uri; } +static gboolean +midori_browser_remove_tab_idle (gpointer view) +{ + MidoriBrowser* browser; + + g_return_val_if_fail (GTK_IS_WIDGET (view), FALSE); + browser = midori_browser_get_for_widget (GTK_WIDGET (view)); + midori_browser_remove_tab (browser, GTK_WIDGET (view)); + return G_SOURCE_REMOVE; +} + static gboolean midori_view_download_requested_cb (GtkWidget* view, WebKitDownload* download, MidoriBrowser* browser) { + GtkWidget* web_view; + WebKitWebFrame* web_frame; + WebKitWebDataSource* datasource; gboolean handled; g_return_val_if_fail (MIDORI_IS_VIEW (view), FALSE); @@ -1514,6 +1528,13 @@ midori_view_download_requested_cb (GtkWidget* view, g_free (destination_uri); } } + + /* Close empty tabs due to download links with a target */ + web_view = midori_view_get_web_view (MIDORI_VIEW (view)); + web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view)); + datasource = webkit_web_frame_get_data_source (web_frame); + if (midori_view_is_blank (MIDORI_VIEW (view)) && webkit_web_data_source_get_data (datasource) == NULL) + g_idle_add (midori_browser_remove_tab_idle, view); return handled; }