[epiphany] embed-shell: Do not drop overview thumbnail updates here either



commit b77c5568b30280e94fa67e08474b92f40c51fab8
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Sat Feb 27 11:38:19 2016 -0600

    embed-shell: Do not drop overview thumbnail updates here either
    
    Wait for the EphyWebExtension in the web process to start listening for
    method calls before sending them. We know it's ready when it sends the
    PageCreated signal.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=758470

 embed/ephy-embed-shell.c |   55 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 2 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 854a8c1..5777cc9 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -323,6 +323,52 @@ history_service_cleared_cb (EphyHistoryService *service,
   }
 }
 
+typedef struct {
+  EphyWebExtensionProxy *extension;
+  char *url;
+  char *path;
+} DelayedThumbnailUpdateData;
+
+static DelayedThumbnailUpdateData *
+delayed_thumbnail_update_data_new (EphyWebExtensionProxy *extension,
+                                   const char *url,
+                                   const char *path)
+{
+  DelayedThumbnailUpdateData *data = g_new (DelayedThumbnailUpdateData, 1);
+  data->extension = extension;
+  data->url = g_strdup (url);
+  data->path = g_strdup (path);
+  g_object_add_weak_pointer (G_OBJECT (extension), (gpointer *)&data->extension);
+  return data;
+}
+
+static void
+delayed_thumbnail_update_data_free (DelayedThumbnailUpdateData *data)
+{
+  g_object_remove_weak_pointer (G_OBJECT (data->extension), (gpointer *)&data->extension);
+  g_free (data->url);
+  g_free (data->path);
+  g_free (data);
+}
+
+static gboolean
+delayed_thumbnail_update_cb (DelayedThumbnailUpdateData *data)
+{
+  if (!data->extension) {
+    delayed_thumbnail_update_data_free (data);
+    return G_SOURCE_REMOVE;
+  }
+
+  if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (data->extension), "initialized"))) {
+    ephy_web_extension_proxy_history_set_url_thumbnail (data->extension, data->url, data->path);
+    delayed_thumbnail_update_data_free (data);
+    return G_SOURCE_REMOVE;
+  }
+
+  /* Web extension is not initialized yet, try again later.... */
+  return G_SOURCE_CONTINUE;
+}
+
 void
 ephy_embed_shell_set_thumbnail_path (EphyEmbedShell *shell,
                                      const char *url,
@@ -338,8 +384,12 @@ ephy_embed_shell_set_thumbnail_path (EphyEmbedShell *shell,
 
   for (l = priv->web_extensions; l; l = g_list_next (l)) {
     EphyWebExtensionProxy *web_extension = (EphyWebExtensionProxy *)l->data;
-
-    ephy_web_extension_proxy_history_set_url_thumbnail (web_extension, url, path);
+    if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (web_extension), "initialized"))) {
+      ephy_web_extension_proxy_history_set_url_thumbnail (web_extension, url, path);
+    } else {
+      DelayedThumbnailUpdateData *data = delayed_thumbnail_update_data_new (web_extension, url, path);
+      g_timeout_add (50, (GSourceFunc)delayed_thumbnail_update_cb, data);
+    }
   }
 }
 
@@ -495,6 +545,7 @@ web_extension_page_created (EphyWebExtensionProxy *extension,
                             guint64 page_id,
                             EphyEmbedShell *shell)
 {
+  g_object_set_data (G_OBJECT (extension), "initialized", GINT_TO_POINTER (TRUE));
   g_signal_emit (shell, signals[PAGE_CREATED], 0, page_id, extension);
 }
 


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