[epiphany] ephy-shell: There can be two widgets for the same download in WebKit2



commit 6f0ffa44c1bca2927e3e1a337fa1ce7349bd0e66
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Fri Jan 4 14:50:37 2013 +0100

    ephy-shell: There can be two widgets for the same download in WebKit2
    
    In WebKit2 WebKitWebContext::download-started signal is always emitted,
    even for downloads started manually. We only want to create a new
    download when the download operation has been started by WebKit.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=678993

 embed/ephy-download.c |    1 +
 src/ephy-shell.c      |   14 +++++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/embed/ephy-download.c b/embed/ephy-download.c
index 988a0ab..4457482 100644
--- a/embed/ephy-download.c
+++ b/embed/ephy-download.c
@@ -1062,6 +1062,7 @@ ephy_download_new_for_download (WebKitDownload *download,
 
   ephy_download->priv->download = g_object_ref (download);
 #ifdef HAVE_WEBKIT2
+  g_object_set_data (G_OBJECT (download), "ephy-download-set", GINT_TO_POINTER (TRUE));
   request = webkit_download_get_request (download);
   ephy_download->priv->source = g_strdup (webkit_uri_request_get_uri (request));
 #else
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 1ae07ac..452ded7 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -595,10 +595,9 @@ download_started_cb (WebKitWebContext *web_context,
                      WebKitDownload *download,
                      EphyShell *shell)
 {
-  EphyDownload *ed;
   GtkWindow *window = NULL;
   WebKitWebView *web_view;
-  GtkWidget *toplevel;
+  gboolean ephy_download_set;
 
   /* Is download locked down? */
   if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
@@ -607,6 +606,15 @@ download_started_cb (WebKitWebContext *web_context,
     return;
   }
 
+  /* Only create an EphyDownload for the WebKitDownload if it doesn't exist yet.
+   * This can happen when the download has been started automatically by WebKit,
+   * due to a context menu action or policy checker decision. Downloads started
+   * explicitly by Epiphany are marked with ephy-download-set GObject data.
+   */
+  ephy_download_set = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (download), "ephy-download-set"));
+  if (ephy_download_set)
+    return;
+
   web_view = webkit_download_get_web_view (download);
   if (web_view) {
     GtkWidget *toplevel;
@@ -619,7 +627,7 @@ download_started_cb (WebKitWebContext *web_context,
   if (!window)
     window = gtk_application_get_active_window (GTK_APPLICATION (shell));
 
-  ed = ephy_download_new_for_download (download, window);
+  ephy_download_new_for_download (download, window);
 }
 #endif
 



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