diff options
author | Sergio Villar Senin <svillar@igalia.com> | 2011-02-22 01:38:59 +0800 |
---|---|---|
committer | Sergio Villar Senin <svillar@igalia.com> | 2011-02-25 02:42:21 +0800 |
commit | 7b24139e069c3de30cdafe983cfb6eb90c097362 (patch) | |
tree | 7df2a83c73bb2820eae1f7f09fd770142ece4bcc /lib | |
parent | da765e7da76ec0614499023f4ef9945279a19e0c (diff) | |
download | gsoc2013-epiphany-7b24139e069c3de30cdafe983cfb6eb90c097362.tar gsoc2013-epiphany-7b24139e069c3de30cdafe983cfb6eb90c097362.tar.gz gsoc2013-epiphany-7b24139e069c3de30cdafe983cfb6eb90c097362.tar.bz2 gsoc2013-epiphany-7b24139e069c3de30cdafe983cfb6eb90c097362.tar.lz gsoc2013-epiphany-7b24139e069c3de30cdafe983cfb6eb90c097362.tar.xz gsoc2013-epiphany-7b24139e069c3de30cdafe983cfb6eb90c097362.tar.zst gsoc2013-epiphany-7b24139e069c3de30cdafe983cfb6eb90c097362.zip |
ephy-location-entry: add DNS prefetching
Proactively perform DNS lookups when the user sets the cursor over an
autocompleted entry in the location bar. This way the prefetching is likely to
already have been resolved by the time the user actually clicks on the entry.
https://bugzilla.gnome.org/show_bug.cgi?id=606087
Diffstat (limited to 'lib')
-rw-r--r-- | lib/widgets/ephy-location-entry.c | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c index 8624363b1..0ad827757 100644 --- a/lib/widgets/ephy-location-entry.c +++ b/lib/widgets/ephy-location-entry.c @@ -36,6 +36,7 @@ #include <glib/gi18n.h> #include <gdk/gdkkeysyms.h> #include <gtk/gtk.h> +#include <webkit/webkit.h> #include <string.h> @@ -72,6 +73,8 @@ struct _EphyLocationEntryPrivate guint hash; + gulong dns_prefetch_handler; + guint user_changed : 1; guint can_redo : 1; guint block_update : 1; @@ -1008,7 +1011,8 @@ ephy_location_entry_init (EphyLocationEntry *le) p->saved_text = NULL; p->search_terms = NULL; p->show_lock = FALSE; - + p->dns_prefetch_handler = 0; + ephy_location_entry_construct_contents (le); gtk_tool_item_set_expand (GTK_TOOL_ITEM (le), TRUE); @@ -1020,29 +1024,74 @@ ephy_location_entry_new (void) return GTK_WIDGET (g_object_new (EPHY_TYPE_LOCATION_ENTRY, NULL)); } +typedef struct { + SoupURI *uri; + EphyLocationEntry *entry; +} PrefetchHelper; + +static void +free_prefetch_helper (PrefetchHelper *helper) +{ + soup_uri_free (helper->uri); + g_object_unref (helper->entry); + g_slice_free (PrefetchHelper, helper); +} + +static gboolean +do_dns_prefetch (PrefetchHelper *helper) +{ + SoupSession *session = webkit_get_default_session (); + + soup_session_prepare_for_uri (session, helper->uri); + + helper->entry->priv->dns_prefetch_handler = 0; + + return FALSE; +} + +static void +schedule_dns_prefetch (EphyLocationEntry *entry, guint interval, const gchar *url) +{ + PrefetchHelper *helper; + + if (entry->priv->dns_prefetch_handler) + g_source_remove (entry->priv->dns_prefetch_handler); + + helper = g_slice_new0 (PrefetchHelper); + helper->entry = g_object_ref (entry); + helper->uri = soup_uri_new (url); + + entry->priv->dns_prefetch_handler = + g_timeout_add_full (G_PRIORITY_DEFAULT, interval, + (GSourceFunc) do_dns_prefetch, helper, + (GDestroyNotify) free_prefetch_helper); +} + static gboolean cursor_on_match_cb (GtkEntryCompletion *completion, GtkTreeModel *model, GtkTreeIter *iter, EphyLocationEntry *le) { - char *item = NULL; + char *url = NULL; GtkWidget *entry; gtk_tree_model_get (model, iter, le->priv->url_col, - &item, -1); + &url, -1); entry = gtk_entry_completion_get_entry (completion); /* Prevent the update so we keep the highlight from our input. * See textcell_data_func(). */ le->priv->block_update = TRUE; - gtk_entry_set_text (GTK_ENTRY (entry), item); + gtk_entry_set_text (GTK_ENTRY (entry), url); gtk_editable_set_position (GTK_EDITABLE (entry), -1); le->priv->block_update = FALSE; - g_free (item); + schedule_dns_prefetch (le, 250, (const gchar*) url); + + g_free (url); return TRUE; } |