[epiphany] download: Handle focus stealing prevention properly



commit 0283906a4ba772d447bde4a9c5b738a6e027edaa
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Sat Mar 5 13:33:57 2016 -0600

    download: Handle focus stealing prevention properly
    
    Currently, we always pass the start time of the download to
    ephy_embed_shell_launch_handler for focus stealing preventing. This is
    wrong as it causes apps to not be focused when opening files manually.
    For example, I became confused today when I tried to open an image file,
    and it opened in eog, but eog appeared beneath the Epiphany window and
    did not receive focus, so I could not see it.
    
    Instead, use the current time for focus stealing prevention when the
    download action is activated from somewhere external to this file (e.g.
    the downloads popover), and only use the start time when the download
    action is set in advance via ephy_download_set_download_action(), or
    when opening the download automatically without user interaction.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=610586

 embed/ephy-download.c |   54 ++++++++++++++++++++++++++++--------------------
 1 files changed, 31 insertions(+), 23 deletions(-)
---
diff --git a/embed/ephy-download.c b/embed/ephy-download.c
index f09b691..7b071b1 100644
--- a/embed/ephy-download.c
+++ b/embed/ephy-download.c
@@ -411,20 +411,10 @@ ephy_download_failed (EphyDownload *download,
   return FALSE;
 }
 
-/**
- * ephy_download_do_download_action:
- * @download: an #EphyDownload
- * @action: one of #EphyDownloadActionType
- *
- * Executes the given @action for @download, this can be any of
- * #EphyDownloadActionType.
- *
- * Returns: %TRUE if the action was executed succesfully.
- *
- **/
-gboolean
-ephy_download_do_download_action (EphyDownload          *download,
-                                  EphyDownloadActionType action)
+static gboolean
+ephy_download_do_download_action_internal (EphyDownload *download,
+                                           EphyDownloadActionType action,
+                                           guint32 user_time)
 {
   GFile *destination;
   const char *destination_uri;
@@ -434,16 +424,16 @@ ephy_download_do_download_action (EphyDownload          *download,
   destination = g_file_new_for_uri (destination_uri);
 
   switch ((action ? action : download->action)) {
-    case EPHY_DOWNLOAD_ACTION_BROWSE_TO:
-      LOG ("ephy_download_do_download_action: browse_to");
-      ret = ephy_file_browse_to (destination, download->start_time);
-      break;
     case EPHY_DOWNLOAD_ACTION_OPEN:
       LOG ("ephy_download_do_download_action: open");
       ret = ephy_embed_shell_launch_handler (ephy_embed_shell_get_default (),
-                                             destination, NULL, download->start_time);
-      if (!ret)
-        ret = ephy_file_browse_to (destination, download->start_time);
+                                             destination, NULL, user_time);
+      /* Fall through if we did not open anything. */
+      if (ret)
+        break;
+    case EPHY_DOWNLOAD_ACTION_BROWSE_TO:
+      LOG ("ephy_download_do_download_action: browse_to");
+      ret = ephy_file_browse_to (destination, user_time);
       break;
     case EPHY_DOWNLOAD_ACTION_NONE:
       LOG ("ephy_download_do_download_action: none");
@@ -457,6 +447,24 @@ ephy_download_do_download_action (EphyDownload          *download,
   return ret;
 }
 
+/**
+ * ephy_download_do_download_action:
+ * @download: an #EphyDownload
+ * @action: one of #EphyDownloadActionType
+ *
+ * Executes the given @action for @download, this can be any of
+ * #EphyDownloadActionType.
+ *
+ * Returns: %TRUE if the action was executed succesfully.
+ *
+ **/
+gboolean
+ephy_download_do_download_action (EphyDownload          *download,
+                                  EphyDownloadActionType action)
+{
+  return ephy_download_do_download_action_internal (download, action, g_get_real_time ());
+}
+
 static void
 ephy_download_dispose (GObject *object)
 {
@@ -691,9 +699,9 @@ download_finished_cb (WebKitDownload *wk_download,
 
   if (g_settings_get_boolean (EPHY_SETTINGS_MAIN, EPHY_PREFS_AUTO_DOWNLOADS) &&
       download->action == EPHY_DOWNLOAD_ACTION_NONE)
-    ephy_download_do_download_action (download, EPHY_DOWNLOAD_ACTION_OPEN);
+    ephy_download_do_download_action_internal (download, EPHY_DOWNLOAD_ACTION_OPEN, download->start_time);
   else
-    ephy_download_do_download_action (download, download->action);
+    ephy_download_do_download_action_internal (download, download->action, download->start_time);
 }
 
 static void


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