[epiphany/mcatanzaro/shell-downloads] Move download management from EphyShell to EphyEmbedShell



commit 999098c96e348576615fc6a7bead1266d1e8bd4e
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Tue Jan 1 15:52:16 2019 -0600

    Move download management from EphyShell to EphyEmbedShell
    
    This code is a bit misplaced in EphyShell. All the classes it uses are
    available in embed, so it should probably go there.

 embed/ephy-embed-shell.c | 34 ++++++++++++++++++++++++++++++++++
 src/ephy-shell.c         | 35 -----------------------------------
 2 files changed, 34 insertions(+), 35 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 75d565941..b798fbecd 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -25,6 +25,7 @@
 #include "ephy-about-handler.h"
 #include "ephy-dbus-util.h"
 #include "ephy-debug.h"
+#include "ephy-downloads-manager.h"
 #include "ephy-embed-container.h"
 #include "ephy-embed-prefs.h"
 #include "ephy-embed-type-builtins.h"
@@ -1134,6 +1135,36 @@ adblock_filters_dir (EphyEmbedShell *shell)
   return result;
 }
 
+static void
+download_started_cb (WebKitWebContext *web_context,
+                     WebKitDownload   *download,
+                     EphyEmbedShell   *shell)
+{
+  EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell);
+  EphyDownload *ephy_download;
+  gboolean ephy_download_set;
+
+  /* Is download locked down? */
+  if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
+                              EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK)) {
+    webkit_download_cancel (download);
+    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;
+
+  ephy_download = ephy_download_new (download);
+  ephy_downloads_manager_add_download (priv->downloads_manager, ephy_download);
+  g_object_unref (ephy_download);
+}
+
 static void
 ephy_embed_shell_startup (GApplication *application)
 {
@@ -1283,6 +1314,9 @@ ephy_embed_shell_startup (GApplication *application)
   filters_dir = adblock_filters_dir (shell);
   priv->filters_manager = ephy_filters_manager_new (filters_dir);
   g_free (filters_dir);
+
+  g_signal_connect (priv->web_context, "download-started",
+                    G_CALLBACK (download_started_cb), shell);
 }
 
 static void
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 8684ee63f..31bd68f74 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -24,7 +24,6 @@
 #include "ephy-shell.h"
 
 #include "ephy-debug.h"
-#include "ephy-downloads-manager.h"
 #include "ephy-embed-container.h"
 #include "ephy-embed-utils.h"
 #include "ephy-file-helpers.h"
@@ -280,36 +279,6 @@ static GActionEntry app_mode_app_entries[] = {
   { "quit", quit_application, NULL, NULL, NULL },
 };
 
-static void
-download_started_cb (WebKitWebContext *web_context,
-                     WebKitDownload   *download,
-                     EphyShell        *shell)
-{
-  EphyDownload *ephy_download;
-  gboolean ephy_download_set;
-
-  /* Is download locked down? */
-  if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
-                              EPHY_PREFS_LOCKDOWN_SAVE_TO_DISK)) {
-    webkit_download_cancel (download);
-    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;
-
-  ephy_download = ephy_download_new (download);
-  ephy_downloads_manager_add_download (ephy_embed_shell_get_downloads_manager (EPHY_EMBED_SHELL (shell)),
-                                       ephy_download);
-  g_object_unref (ephy_download);
-}
-
 static void
 register_synchronizable_managers (EphyShell       *shell,
                                   EphySyncService *service)
@@ -396,10 +365,6 @@ ephy_shell_startup (GApplication *application)
   G_APPLICATION_CLASS (ephy_shell_parent_class)->startup (application);
 
   /* We're not remoting; start our services */
-  g_signal_connect (ephy_embed_shell_get_web_context (embed_shell),
-                    "download-started",
-                    G_CALLBACK (download_started_cb),
-                    application);
 
   mode = ephy_embed_shell_get_mode (embed_shell);
   if (mode != EPHY_EMBED_SHELL_MODE_APPLICATION) {


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