[epiphany/gnome-3-18] web-overview: Do not drop thumbnail update requests



commit a0205cba301a07d40edcb50b7a46afc1040220ec
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Mon Jan 18 19:08:13 2016 -0600

    web-overview: Do not drop thumbnail update requests
    
    When the overview is opened in a new tab, it normally works fine, but
    when the overview is opened in the first tab when starting Epiphany,
    there are no thumbnails for any of the sites: just empty placeholder
    images, at least on my machine. That's not good.
    
    The snapshot service does not have the images ready immediately when
    requested by EphyAboutHandler, so EphyAboutHandler is not able to insert
    them into the overview HTML when it is created. Instead, it inserts a
    placeholder image. Then, when the snapshot service has finished getting
    the thumbnail, it makes a D-Bus call to the web extension to convey the
    file URI for the thumbnail (for each URL in the overview).
    EphyWebOverview replaces the placeholder image with the thumbnail when
    it receives the call.
    
    The problem is the call can occur before WebKit has finished loading the
    overview HTML, in which case the thumbnail changes get dropped and we
    wind up with a bunch of placeholder images. Instead, remember the
    thumbnail change requests as they come in, then apply them all after the
    document has loaded.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=758470

 embed/web-extension/ephy-web-overview.c |   53 ++++++++++++++++++++++++++++++-
 1 files changed, 52 insertions(+), 1 deletions(-)
---
diff --git a/embed/web-extension/ephy-web-overview.c b/embed/web-extension/ephy-web-overview.c
index c1a4ebd..b951212 100644
--- a/embed/web-extension/ephy-web-overview.c
+++ b/embed/web-extension/ephy-web-overview.c
@@ -32,6 +32,8 @@ struct _EphyWebOverviewPrivate
   WebKitWebPage *web_page;
   EphyWebOverviewModel *model;
   GList *items;
+
+  GHashTable *delayed_thumbnail_changes;
 };
 
 enum
@@ -221,6 +223,28 @@ ephy_web_overview_model_urls_changed (EphyWebOverviewModel *model,
   }
 }
 
+static gboolean
+apply_delayed_thumbnail_change (gpointer key,
+                                gpointer value,
+                                gpointer user_data)
+{
+  EphyWebOverview *overview = EPHY_WEB_OVERVIEW (user_data);
+  const char *url = key;
+  const char *path = value;
+  GList *l;
+
+  for (l = overview->priv->items; l; l = g_list_next (l)) {
+    OverviewItem *item = (OverviewItem *)l->data;
+
+    if (g_strcmp0 (item->url, url) == 0) {
+      update_thumbnail_element_style (item->thumbnail, path);
+      return TRUE;
+    }
+  }
+
+  g_assert_not_reached ();
+}
+
 static void
 ephy_web_overview_model_thumbnail_changed (EphyWebOverviewModel *model,
                                            const char *url,
@@ -232,9 +256,27 @@ ephy_web_overview_model_thumbnail_changed (EphyWebOverviewModel *model,
   for (l = overview->priv->items; l; l = g_list_next (l)) {
     OverviewItem *item = (OverviewItem *)l->data;
 
-    if (g_strcmp0 (item->url, url) == 0)
+    if (g_strcmp0 (item->url, url) == 0) {
       update_thumbnail_element_style (item->thumbnail, path);
+      return;
+    }
+  }
+
+  if (!overview->priv->delayed_thumbnail_changes) {
+    overview->priv->delayed_thumbnail_changes = g_hash_table_new_full (g_str_hash,
+                                                                       g_str_equal,
+                                                                       g_free,
+                                                                       g_free);
   }
+
+  /* We got the thumbnail change request before document-loaded. Save the
+   * request, else we will wind up with an overview showing placeholder icons.
+   * This isn't needed for title and URL changes because EphyAboutHandler is
+   * sure to have those right when creating the overview HTML. But thumbnail
+   * changes can arrive delayed if the snapshot service does not have the right
+   * snapshot on demand.
+   */
+  g_hash_table_insert (overview->priv->delayed_thumbnail_changes, g_strdup (url), g_strdup (path));
 }
 
 static void
@@ -327,6 +369,13 @@ ephy_web_overview_document_loaded (WebKitWebPage *web_page,
   }
   g_object_unref (nodes);
   overview->priv->items = g_list_reverse (overview->priv->items);
+
+  if (overview->priv->delayed_thumbnail_changes) {
+    g_hash_table_foreach_remove (overview->priv->delayed_thumbnail_changes,
+                                 apply_delayed_thumbnail_change,
+                                 overview);
+    g_clear_pointer (&overview->priv->delayed_thumbnail_changes, g_hash_table_unref);
+  }
 }
 
 static void
@@ -361,6 +410,8 @@ ephy_web_overview_dispose (GObject *object)
     overview->priv->items = NULL;
   }
 
+  g_clear_pointer (&overview->priv->delayed_thumbnail_changes, g_hash_table_unref);
+
   G_OBJECT_CLASS (ephy_web_overview_parent_class)->dispose (object);
 }
 


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