[epiphany] web-overview: Do not drop thumbnail update requests



commit d1784f095b392998473eb42d879f62762336ccc8
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 |   54 +++++++++++++++++++++++++++++-
 1 files changed, 52 insertions(+), 2 deletions(-)
---
diff --git a/embed/web-extension/ephy-web-overview.c b/embed/web-extension/ephy-web-overview.c
index bafda8c..67d9cd1 100644
--- a/embed/web-extension/ephy-web-overview.c
+++ b/embed/web-extension/ephy-web-overview.c
@@ -32,6 +32,8 @@ struct _EphyWebOverview
   WebKitWebPage *web_page;
   EphyWebOverviewModel *model;
   GList *items;
+
+  GHashTable *delayed_thumbnail_changes;
 };
 
 G_DEFINE_TYPE (EphyWebOverview, ephy_web_overview, G_TYPE_OBJECT)
@@ -224,6 +226,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->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,
@@ -231,13 +255,30 @@ ephy_web_overview_model_thumbnail_changed (EphyWebOverviewModel *model,
                                            EphyWebOverview *overview)
 {
   GList *l;
-
   for (l = overview->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->delayed_thumbnail_changes) {
+    overview->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->delayed_thumbnail_changes, g_strdup (url), g_strdup (path));
 }
 
 static void
@@ -330,6 +371,13 @@ ephy_web_overview_document_loaded (WebKitWebPage *web_page,
   }
   g_object_unref (nodes);
   overview->items = g_list_reverse (overview->items);
+
+  if (overview->delayed_thumbnail_changes) {
+    g_hash_table_foreach_remove (overview->delayed_thumbnail_changes,
+                                 apply_delayed_thumbnail_change,
+                                 overview);
+    g_clear_pointer (&overview->delayed_thumbnail_changes, g_hash_table_unref);
+  }
 }
 
 static void
@@ -364,6 +412,8 @@ ephy_web_overview_dispose (GObject *object)
     overview->items = NULL;
   }
 
+  g_clear_pointer (&overview->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]