diff options
author | Sergio Villar Senin <svillar@igalia.com> | 2012-03-08 01:28:02 +0800 |
---|---|---|
committer | Xan Lopez <xan@igalia.com> | 2012-03-20 18:55:11 +0800 |
commit | 6119b95ca4c0c2d4d78b27422dfb6ba9203bab56 (patch) | |
tree | 498151645cb0e38ba8854f738d749e04b39bb58c /src | |
parent | bc0e3b41f8c21fa0b4bd0cd89e305b0fee049b6a (diff) | |
download | gsoc2013-epiphany-6119b95ca4c0c2d4d78b27422dfb6ba9203bab56.tar.gz gsoc2013-epiphany-6119b95ca4c0c2d4d78b27422dfb6ba9203bab56.tar.zst gsoc2013-epiphany-6119b95ca4c0c2d4d78b27422dfb6ba9203bab56.zip |
Replace EphyFaviconCache by WebKit's icon database cache
https://bugzilla.gnome.org/show_bug.cgi?id=648653
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmark-action.c | 44 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-editor.c | 44 | ||||
-rw-r--r-- | src/ephy-completion-model.c | 61 | ||||
-rw-r--r-- | src/ephy-history-window.c | 24 | ||||
-rw-r--r-- | src/ephy-shell.c | 1 | ||||
-rw-r--r-- | src/pdm-dialog.c | 5 | ||||
-rw-r--r-- | src/prefs-dialog.c | 1 |
8 files changed, 117 insertions, 65 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 56e699b77..7ea753b5b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -224,7 +224,6 @@ EPHY_GIR_H_FILES = \ $(top_srcdir)/embed/ephy-embed-event.h \ $(top_srcdir)/embed/ephy-embed-shell.h \ $(top_srcdir)/embed/ephy-embed-single.h \ - $(top_srcdir)/embed/ephy-favicon-cache.h \ $(top_srcdir)/embed/ephy-history.h \ $(top_srcdir)/embed/ephy-permission-manager.h \ $(top_srcdir)/embed/ephy-web-view.h \ @@ -254,7 +253,6 @@ EPHY_GIR_C_FILES = \ $(top_srcdir)/embed/ephy-embed-event.c \ $(top_srcdir)/embed/ephy-embed-shell.c \ $(top_srcdir)/embed/ephy-embed-single.c \ - $(top_srcdir)/embed/ephy-favicon-cache.c \ $(top_srcdir)/embed/ephy-history.c \ $(top_srcdir)/embed/ephy-permission-manager.c \ $(top_srcdir)/embed/ephy-web-view.c \ diff --git a/src/bookmarks/ephy-bookmark-action.c b/src/bookmarks/ephy-bookmark-action.c index 814fadd7e..7aa30010b 100644 --- a/src/bookmarks/ephy-bookmark-action.c +++ b/src/bookmarks/ephy-bookmark-action.c @@ -26,7 +26,7 @@ #include "ephy-bookmarks.h" #include "ephy-debug.h" #include "ephy-dnd.h" -#include "ephy-favicon-cache.h" +#include "ephy-embed-prefs.h" #include "ephy-gui.h" #include "ephy-shell.h" #include "ephy-string.h" @@ -67,20 +67,22 @@ typedef struct G_DEFINE_TYPE (EphyBookmarkAction, ephy_bookmark_action, EPHY_TYPE_LINK_ACTION) static void -favicon_cache_changed_cb (EphyFaviconCache *cache, - const char *icon_address, - EphyBookmarkAction *action) +favicon_loaded_cb (WebKitFaviconDatabase *database, + const char *page_address, + EphyBookmarkAction *action) { const char *icon; + char *icon_address; g_return_if_fail (action->priv->node != NULL); icon = ephy_node_get_property_string (action->priv->node, EPHY_NODE_BMK_PROP_ICON); - - if (icon != NULL && strcmp (icon, icon_address) == 0) + icon_address = webkit_favicon_database_get_favicon_uri (database, page_address); + + if (g_strcmp0 (icon, icon_address) == 0) { - g_signal_handler_disconnect (cache, action->priv->cache_handler); + g_signal_handler_disconnect (database, action->priv->cache_handler); action->priv->cache_handler = 0; g_object_notify (G_OBJECT (action), "icon"); @@ -93,28 +95,27 @@ ephy_bookmark_action_sync_icon (GtkAction *action, GtkWidget *proxy) { EphyBookmarkAction *bma = EPHY_BOOKMARK_ACTION (action); - const char *icon_location; - EphyFaviconCache *cache; + const char *page_location; + WebKitFaviconDatabase *database; GdkPixbuf *pixbuf = NULL; g_return_if_fail (bma->priv->node != NULL); - icon_location = ephy_node_get_property_string (bma->priv->node, - EPHY_NODE_BMK_PROP_ICON); + page_location = ephy_node_get_property_string (bma->priv->node, + EPHY_NODE_BMK_PROP_LOCATION); - cache = EPHY_FAVICON_CACHE (ephy_embed_shell_get_favicon_cache - (ephy_embed_shell_get_default ())); - - if (icon_location && *icon_location) + database = webkit_get_favicon_database (); + if (page_location && *page_location) { - pixbuf = ephy_favicon_cache_get (cache, icon_location); + pixbuf = webkit_favicon_database_try_get_favicon_pixbuf (database, page_location, + FAVICON_SIZE, FAVICON_SIZE); if (pixbuf == NULL && bma->priv->cache_handler == 0) { bma->priv->cache_handler = g_signal_connect_object - (cache, "changed", - G_CALLBACK (favicon_cache_changed_cb), + (database, "icon-loaded", + G_CALLBACK (favicon_loaded_cb), action, 0); } } @@ -370,14 +371,11 @@ ephy_bookmark_action_dispose (GObject *object) { EphyBookmarkAction *action = (EphyBookmarkAction *) object; EphyBookmarkActionPrivate *priv = action->priv; - GObject *cache; if (priv->cache_handler != 0) { - cache = ephy_embed_shell_get_favicon_cache - (ephy_embed_shell_get_default ()); - - g_signal_handler_disconnect (cache, priv->cache_handler); + WebKitFaviconDatabase *database = webkit_get_favicon_database (); + g_signal_handler_disconnect (database, priv->cache_handler); priv->cache_handler = 0; } diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c index c64d1db48..b30b542b6 100644 --- a/src/bookmarks/ephy-bookmarks-editor.c +++ b/src/bookmarks/ephy-bookmarks-editor.c @@ -26,7 +26,7 @@ #include "ephy-bookmarks-ui.h" #include "ephy-debug.h" #include "ephy-dnd.h" -#include "ephy-favicon-cache.h" +#include "ephy-embed-prefs.h" #include "ephy-file-chooser.h" #include "ephy-file-helpers.h" #include "ephy-gui.h" @@ -1461,26 +1461,42 @@ node_dropped_cb (EphyNodeView *view, } static void +icon_loaded_cb (WebKitFaviconDatabase *database, GAsyncResult *result, GValue *value) +{ + GdkPixbuf *favicon = webkit_favicon_database_get_favicon_pixbuf_finish (database, result, NULL); + if (!favicon) + return; + + g_value_take_object (value, favicon); +} + +static void provide_favicon (EphyNode *node, GValue *value, gpointer user_data) { - EphyFaviconCache *cache; - const char *icon_location; - GdkPixbuf *pixbuf = NULL; + const char *page_location; + GdkPixbuf *favicon = NULL; - cache = EPHY_FAVICON_CACHE - (ephy_embed_shell_get_favicon_cache (EPHY_EMBED_SHELL (ephy_shell))); - icon_location = ephy_node_get_property_string - (node, EPHY_NODE_BMK_PROP_ICON); + page_location = ephy_node_get_property_string + (node, EPHY_NODE_BMK_PROP_LOCATION); - LOG ("Get favicon for %s", icon_location ? icon_location : "None"); + LOG ("Get favicon for %s", page_location ? page_location : "None"); - if (icon_location) - { - pixbuf = ephy_favicon_cache_get (cache, icon_location); - } + if (page_location) + { + WebKitFaviconDatabase *database = webkit_get_favicon_database (); + + /* Try with the sync version first as this method will be frequently called. */ + favicon = webkit_favicon_database_try_get_favicon_pixbuf (database, page_location, + FAVICON_SIZE, FAVICON_SIZE); + + if (!favicon && webkit_favicon_database_get_favicon_uri (database, page_location)) + webkit_favicon_database_get_favicon_pixbuf (database, page_location, + FAVICON_SIZE, FAVICON_SIZE, NULL, + (GAsyncReadyCallback) icon_loaded_cb, value); + } g_value_init (value, GDK_TYPE_PIXBUF); - g_value_take_object (value, pixbuf); + g_value_take_object (value, favicon); } static void diff --git a/src/ephy-completion-model.c b/src/ephy-completion-model.c index e3f25bda5..9b6507e1a 100644 --- a/src/ephy-completion-model.c +++ b/src/ephy-completion-model.c @@ -21,8 +21,8 @@ #include "config.h" #include "ephy-completion-model.h" +#include "ephy-embed-prefs.h" #include "ephy-embed-shell.h" -#include "ephy-favicon-cache.h" #include "ephy-history.h" #include "ephy-history-service.h" #include "ephy-shell.h" @@ -36,7 +36,6 @@ G_DEFINE_TYPE (EphyCompletionModel, ephy_completion_model, GTK_TYPE_LIST_STORE) struct _EphyCompletionModelPrivate { EphyHistoryService *history_service; EphyHistory *legacy_history_service; - EphyFaviconCache *favicon_cache; EphyNode *bookmarks; GSList *search_terms; @@ -99,7 +98,6 @@ ephy_completion_model_init (EphyCompletionModel *model) priv->history_service = EPHY_HISTORY_SERVICE (ephy_embed_shell_get_global_history_service (embed_shell)); priv->legacy_history_service = EPHY_HISTORY (ephy_embed_shell_get_global_history (embed_shell)); - priv->favicon_cache = EPHY_FAVICON_CACHE (ephy_embed_shell_get_favicon_cache (embed_shell)); bookmarks_service = ephy_shell_get_bookmarks (ephy_shell); priv->bookmarks = ephy_bookmarks_get_bookmarks (bookmarks_service); @@ -165,22 +163,69 @@ typedef struct { gboolean is_bookmark; } PotentialRow; +typedef struct { + GtkListStore *model; + GtkTreeRowReference *row_reference; +} IconLoadData; + + +static void +icon_loaded_cb (GObject *source, GAsyncResult *result, gpointer user_data) +{ + GtkTreeIter iter; + IconLoadData *data = (IconLoadData *) user_data; + GdkPixbuf *favicon = webkit_favicon_database_get_favicon_pixbuf_finish (webkit_get_favicon_database (), result, NULL); + + if (favicon) { + /* The completion model might have changed its contents */ + if (gtk_tree_row_reference_valid (data->row_reference)) { + gtk_tree_model_get_iter (GTK_TREE_MODEL (data->model), &iter, + gtk_tree_row_reference_get_path (data->row_reference)); + gtk_list_store_set (data->model, &iter, EPHY_COMPLETION_FAVICON_COL, favicon, -1); + } + } + + g_object_unref (data->model); + gtk_tree_row_reference_free (data->row_reference); + g_slice_free (IconLoadData, data); +} + static void set_row_in_model (EphyCompletionModel *model, int position, PotentialRow *row) { - const char *favicon_location = ephy_history_get_icon (model->priv->legacy_history_service, - row->location); + GtkTreeIter iter; + GdkPixbuf *favicon; + GtkTreePath *path; + IconLoadData *data; + WebKitFaviconDatabase* database = webkit_get_favicon_database (); - gtk_list_store_insert_with_values (GTK_LIST_STORE (model), NULL, position, + gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter, position, EPHY_COMPLETION_TEXT_COL, row->title ? row->title : "", EPHY_COMPLETION_URL_COL, row->location, EPHY_COMPLETION_ACTION_COL, row->location, EPHY_COMPLETION_KEYWORDS_COL, row->keywords ? row->keywords : "", EPHY_COMPLETION_EXTRA_COL, row->is_bookmark, - EPHY_COMPLETION_FAVICON_COL, ephy_favicon_cache_get (model->priv->favicon_cache, - favicon_location), EPHY_COMPLETION_RELEVANCE_COL, row->relevance, -1); + + /* We try first with the try_get_favicon_pixbuf() because if the icon + is in the DB it's faster than the async version. */ + favicon = webkit_favicon_database_try_get_favicon_pixbuf (database, row->location, + FAVICON_SIZE, FAVICON_SIZE); + if (favicon) { + gtk_list_store_set (GTK_LIST_STORE (model), &iter, EPHY_COMPLETION_FAVICON_COL, favicon, -1); + return; + } + + data = g_slice_new (IconLoadData); + data->model = GTK_LIST_STORE (g_object_ref(model)); + path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter); + data->row_reference = gtk_tree_row_reference_new (GTK_TREE_MODEL (model), path); + gtk_tree_path_free (path); + + webkit_favicon_database_get_favicon_pixbuf (webkit_get_favicon_database (), row->location, + FAVICON_SIZE, FAVICON_SIZE, NULL, + icon_loaded_cb, data); } static void diff --git a/src/ephy-history-window.c b/src/ephy-history-window.c index 5ddb0cb2e..39783b573 100644 --- a/src/ephy-history-window.c +++ b/src/ephy-history-window.c @@ -26,7 +26,6 @@ #include "ephy-bookmarks-ui.h" #include "ephy-debug.h" #include "ephy-dnd.h" -#include "ephy-favicon-cache.h" #include "ephy-file-helpers.h" #include "ephy-gui.h" #include "ephy-hosts-store.h" @@ -870,21 +869,22 @@ delete_event_cb (EphyHistoryWindow *editor) static void provide_favicon (EphyNode *node, GValue *value, gpointer user_data) { - EphyFaviconCache *cache; - const char *icon_location; + const char *page_location; GdkPixbuf *pixbuf = NULL; - cache = EPHY_FAVICON_CACHE - (ephy_embed_shell_get_favicon_cache (EPHY_EMBED_SHELL (ephy_shell))); - icon_location = ephy_node_get_property_string - (node, EPHY_NODE_PAGE_PROP_ICON); + page_location = ephy_node_get_property_string + (node, EPHY_NODE_PAGE_PROP_LOCATION); - LOG ("Get favicon for %s", icon_location ? icon_location : "None"); + LOG ("Get favicon for %s", page_location ? page_location : "None"); - if (icon_location) - { - pixbuf = ephy_favicon_cache_get (cache, icon_location); - } + if (page_location) + { + /* No need to use the async version as this function will be + called many times by the treeview. */ + WebKitFaviconDatabase *database = webkit_get_favicon_database (); + pixbuf = webkit_favicon_database_get_favicon_pixbuf (database, page_location, + FAVICON_SIZE, FAVICON_SIZE); + } g_value_init (value, GDK_TYPE_PIXBUF); g_value_take_object (value, pixbuf); diff --git a/src/ephy-shell.c b/src/ephy-shell.c index 6964cefb4..510017a7f 100644 --- a/src/ephy-shell.c +++ b/src/ephy-shell.c @@ -30,7 +30,6 @@ #include "ephy-embed-single.h" #include "ephy-embed-utils.h" #include "ephy-extensions-manager.h" -#include "ephy-favicon-cache.h" #include "ephy-file-helpers.h" #include "ephy-gui.h" #include "ephy-history-window.h" diff --git a/src/pdm-dialog.c b/src/pdm-dialog.c index 4f0139e6d..24d075869 100644 --- a/src/pdm-dialog.c +++ b/src/pdm-dialog.c @@ -33,7 +33,6 @@ #include "ephy-debug.h" #include "ephy-time-helpers.h" #include "ephy-embed-single.h" -#include "ephy-favicon-cache.h" #include "ephy-history-service.h" #include "ephy-password-info.h" @@ -284,7 +283,6 @@ clear_all_dialog_response_cb (GtkDialog *dialog, { EphyEmbedShell *shell; EphyEmbedSingle *single; - EphyFaviconCache *cache; shell = ephy_embed_shell_get_default (); @@ -292,8 +290,7 @@ clear_all_dialog_response_cb (GtkDialog *dialog, ephy_embed_single_clear_cache (single); - cache = EPHY_FAVICON_CACHE (ephy_embed_shell_get_favicon_cache (shell)); - ephy_favicon_cache_clear (cache); + webkit_favicon_database_clear (webkit_get_favicon_database ()); } } gtk_widget_destroy (GTK_WIDGET (dialog)); diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c index 7c3ec5c15..d3c0c09ac 100644 --- a/src/prefs-dialog.c +++ b/src/prefs-dialog.c @@ -31,7 +31,6 @@ #include "ephy-embed-single.h" #include "ephy-embed-utils.h" #include "ephy-encodings.h" -#include "ephy-favicon-cache.h" #include "ephy-file-chooser.h" #include "ephy-file-helpers.h" #include "ephy-gui.h" |