[epiphany] Make the favicon cache work on top of new WebKit API, and WebKitDownload



commit 5e0f51772f48a473d3e1fce9757320a15c6d82d5
Author: Gustavo Noronha Silva <gns gnome org>
Date:   Wed Dec 9 17:35:59 2009 -0200

    Make the favicon cache work on top of new WebKit API, and WebKitDownload
    
    This restores basic favicon functionality. In the future we will want
    to replace our favicon cache with the IconDatabase that is available
    in WebKit.
    
    Bug #601859

 embed/ephy-embed.c         |    9 ++++
 embed/ephy-favicon-cache.c |   88 +++++++++++++++++++-------------------------
 embed/ephy-web-view.c      |   14 +++---
 3 files changed, 54 insertions(+), 57 deletions(-)
---
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index b839c6b..fd981ce 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -772,6 +772,14 @@ load_error_cb (WebKitWebView *web_view,
 }
 
 static void
+icon_loaded_cb (WebKitWebView *web_view, const char* icon_uri, gpointer *data)
+{
+  g_signal_emit_by_name (EPHY_WEB_VIEW (web_view),
+                         "favicon",
+                         icon_uri);
+}
+
+static void
 ephy_embed_constructed (GObject *object)
 {
   EphyEmbed *embed = (EphyEmbed*)object;
@@ -794,6 +802,7 @@ ephy_embed_constructed (GObject *object)
                     "signal::notify::title", G_CALLBACK (title_changed_cb), embed,
                     "signal::notify::uri", G_CALLBACK (uri_changed_cb), embed,
                     "signal::load-error", G_CALLBACK (load_error_cb), embed,
+                    "signal::icon-loaded", G_CALLBACK (icon_loaded_cb), embed,
                     NULL);
 
   embed->priv->inspector_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
diff --git a/embed/ephy-favicon-cache.c b/embed/ephy-favicon-cache.c
index c1e3cf7..7cb398d 100644
--- a/embed/ephy-favicon-cache.c
+++ b/embed/ephy-favicon-cache.c
@@ -445,50 +445,42 @@ ephy_favicon_cache_finalize (GObject *object)
 }
 
 static void
-favicon_download_completed_cb (EphyEmbedPersist *persist,
-			       EphyFaviconCache *cache)
+favicon_download_status_changed_cb (WebKitDownload *download,
+				    GParamSpec *spec,
+				    EphyFaviconCache *cache)
 {
-	const char *url;
+	WebKitDownloadStatus status = webkit_download_get_status (download);
+	const char* url = webkit_download_get_uri (download);
 
-	url = ephy_embed_persist_get_source (persist);
-	g_return_if_fail (url != NULL);
+	switch (status) {
+	case WEBKIT_DOWNLOAD_STATUS_FINISHED:
+		LOG ("Favicon cache download completed for %s", url);
 
-	LOG ("Favicon cache download completed for %s", url);
+		g_hash_table_remove (cache->priv->downloads_hash, url);
 
-	g_hash_table_remove (cache->priv->downloads_hash, url);
+		g_signal_emit (G_OBJECT (cache), signals[CHANGED], 0, url);
 
-	g_signal_emit (G_OBJECT (cache), signals[CHANGED], 0, url);
+		g_object_unref (download);
 
-	g_object_unref (persist);
+		cache->priv->dirty = TRUE;
 
-	cache->priv->dirty = TRUE;
-}
+		break;
+	case WEBKIT_DOWNLOAD_STATUS_ERROR:
+	case WEBKIT_DOWNLOAD_STATUS_CANCELLED:
+		LOG ("Favicon cache download cancelled %s", url);
 
-static void
-favicon_download_cancelled_cb (EphyEmbedPersist *persist,
-			       EphyFaviconCache *cache)
-{
-	const char *url, *dest;
+		g_hash_table_remove (cache->priv->downloads_hash, url);
 
-	url = ephy_embed_persist_get_source (persist);
-	g_return_if_fail (url != NULL);
+		/* TODO: remove a partially downloaded file */
+		/* FIXME: re-schedule to try again after n days? */
 
-	LOG ("Favicon cache download cancelled %s", url);
+		g_object_unref (download);
 
-	g_hash_table_remove (cache->priv->downloads_hash, url);
-
-	/* remove a partially downloaded file */
-		dest = ephy_embed_persist_get_dest (persist);
-	if (g_unlink (dest) < 0)
-	{
-		LOG ("Unable to delete %s", dest);
+		cache->priv->dirty = TRUE;
+		break;
+	default:
+		break;
 	}
-
-	/* FIXME: re-schedule to try again after n days? */
-
-	g_object_unref (persist);
-
-	cache->priv->dirty = TRUE;
 }
 
 static void
@@ -496,8 +488,10 @@ ephy_favicon_cache_download (EphyFaviconCache *cache,
 			     const char *favicon_url,
 			     const char *filename)
 {
-	EphyEmbedPersist *persist;
+	WebKitNetworkRequest *request;
+	WebKitDownload *download;
 	char *dest;
+	char *dest_uri;
 
 	LOG ("Download favicon: %s", favicon_url);
 
@@ -505,31 +499,25 @@ ephy_favicon_cache_download (EphyFaviconCache *cache,
 	g_return_if_fail (favicon_url != NULL);
 	g_return_if_fail (filename != NULL);
 
-	dest = g_build_filename (cache->priv->directory, filename, NULL);
+	request = webkit_network_request_new (favicon_url);
+	download = webkit_download_new (request);
+	g_object_unref (request);
 
-	persist = EPHY_EMBED_PERSIST
-		(g_object_new (EPHY_TYPE_EMBED_PERSIST, NULL));
+	dest = g_build_filename (cache->priv->directory, filename, NULL);
+	dest_uri = g_filename_to_uri (dest, NULL, NULL);
 
-	ephy_embed_persist_set_dest (persist, dest);
-	ephy_embed_persist_set_flags (persist, EPHY_EMBED_PERSIST_NO_VIEW |
-					       EPHY_EMBED_PERSIST_NO_CERTDIALOGS |
-					       EPHY_EMBED_PERSIST_DO_CONVERSION |
-					       EPHY_EMBED_PERSIST_NO_COOKIES
-				               );
-	ephy_embed_persist_set_max_size (persist, EPHY_FAVICON_MAX_SIZE);
-	ephy_embed_persist_set_source (persist, favicon_url);
+	webkit_download_set_destination_uri (download, dest_uri);
 
 	g_free (dest);
+	g_free (dest_uri);
 
-	g_signal_connect (G_OBJECT (persist), "completed",
-			  G_CALLBACK (favicon_download_completed_cb), cache);
-	g_signal_connect (G_OBJECT (persist), "cancelled",
-			  G_CALLBACK (favicon_download_cancelled_cb), cache);
+	g_signal_connect (G_OBJECT (download), "notify::status",
+			  G_CALLBACK (favicon_download_status_changed_cb), cache);
 
 	g_hash_table_insert (cache->priv->downloads_hash,
-			     g_strdup (favicon_url), persist);
+			     g_strdup (favicon_url), download);
 
-	ephy_embed_persist_save (persist);
+	webkit_download_start (download);
 }
 
 /**
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index a0a7c3a..04d3172 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -694,14 +694,14 @@ ephy_web_view_class_init (EphyWebViewClass *klass)
             G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
 
 /**
- * EphyWebView::ge-favicon:
+ * EphyWebView::favicon:
  * @view: the #EphyWebView that received the signal
  * @address: the URL to @embed's web site's favicon
  *
  * The ::ge_favicon signal is emitted when @embed discovers that a favourite
  * icon (favicon) is available for the site it is visiting.
  **/
-    g_signal_new ("ge_favicon",
+    g_signal_new ("favicon",
             EPHY_TYPE_WEB_VIEW,
             G_SIGNAL_RUN_FIRST,
             G_STRUCT_OFFSET (EphyWebViewClass, favicon),
@@ -929,9 +929,9 @@ icon_cache_changed_cb (EphyFaviconCache *cache,
 }
 
 static void
-ge_favicon_cb (EphyWebView *view,
-               const char *address,
-               gpointer user_data)
+favicon_cb (EphyWebView *view,
+            const char *address,
+            gpointer user_data)
 {
   ephy_web_view_set_icon_address (view, address);
 }
@@ -1077,8 +1077,8 @@ ephy_web_view_init (EphyWebView *web_view)
                     G_CALLBACK (mime_type_policy_decision_requested_cb),
                     NULL);
 
-  g_signal_connect_object (web_view, "ge_favicon",
-                           G_CALLBACK (ge_favicon_cb),
+  g_signal_connect_object (web_view, "favicon",
+                           G_CALLBACK (favicon_cb),
                            web_view, (GConnectFlags)0);
 
   g_signal_connect_object (web_view, "ge_new_window",



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