[epiphany] If a tab is created only for a download, close it



commit 29c990d5a4662467e4708db1ab1cc06c4901fc7f
Author: Gustavo Noronha Silva <gns gnome org>
Date:   Sat Aug 10 22:06:32 2013 -0300

    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

 embed/ephy-web-view.c |   27 ++++++++++++++++++++++++---
 src/ephy-window.c     |   31 +++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 3 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index f4e0136..b48aae9 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -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;
   }
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 67bbf06..1ceca46 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -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);
 
@@ -2656,6 +2684,9 @@ notebook_page_removed_cb (EphyNotebook *notebook,
 #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);
 
        tab_accels_update (window);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]