From d42586bb4a2fb45cad1fcc2cf7f6b49a423770cd Mon Sep 17 00:00:00 2001 From: Xan Lopez Date: Tue, 13 Mar 2012 18:57:56 +0100 Subject: history: remember visit types Instead of hardcoding all visits as 'TYPED' properly distinguish between bookmarks, following links and typing URIs in the entry. We'll use this to compute the frecency of history items. --- embed/ephy-embed-private.h | 11 +++++++++++ embed/ephy-embed.c | 20 +++++++++++++------ embed/ephy-web-view.c | 37 ++++++++++++++++++++++++++++++++++++ lib/history/ephy-history-service.c | 15 +++++++++------ lib/history/ephy-history-service.h | 5 +++-- lib/history/ephy-history-types.h | 3 +++ src/bookmarks/ephy-bookmark-action.c | 2 ++ src/ephy-link.h | 4 +++- src/ephy-location-controller.c | 4 ++-- src/ephy-private.h | 1 + src/ephy-window.c | 10 ++++++++++ 11 files changed, 95 insertions(+), 17 deletions(-) diff --git a/embed/ephy-embed-private.h b/embed/ephy-embed-private.h index 17c6ad857..34ba6bcb1 100644 --- a/embed/ephy-embed-private.h +++ b/embed/ephy-embed-private.h @@ -22,9 +22,14 @@ #error "Only can be included directly." #endif +#include "ephy-history-types.h" +#include "ephy-web-view.h" + #ifndef EPHY_EMBED_PRIVATE_H #define EPHY_EMBED_PRIVATE_H +G_BEGIN_DECLS + /* EphyWebView */ #define EPHY_WEB_VIEW_NON_SEARCH_REGEX "(" \ @@ -39,6 +44,12 @@ "^file:.*$" \ ")" +void ephy_web_view_set_visit_type (EphyWebView *view, + EphyHistoryPageVisitType visit_type); + +EphyHistoryPageVisitType ephy_web_view_get_visit_type (EphyWebView *view); + +G_END_DECLS #endif diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c index 205f2573b..f1c4c87d5 100644 --- a/embed/ephy-embed.c +++ b/embed/ephy-embed.c @@ -31,6 +31,7 @@ #include "ephy-download.h" #include "ephy-embed-event.h" #include "ephy-embed-prefs.h" +#include "ephy-embed-private.h" #include "ephy-embed-shell.h" #include "ephy-embed-single.h" #include "ephy-embed-utils.h" @@ -316,32 +317,39 @@ remove_from_destroy_list_cb (GtkWidget *widget, EphyEmbed *embed) } static void -load_status_changed_cb (WebKitWebView *view, +load_status_changed_cb (WebKitWebView *web_view, GParamSpec *spec, EphyEmbed *embed) { - WebKitLoadStatus status = webkit_web_view_get_load_status (view); + WebKitLoadStatus status = webkit_web_view_get_load_status (web_view); if (status == WEBKIT_LOAD_COMMITTED) { const gchar* uri; char *history_uri; + EphyHistoryPageVisitType visit_type; + EphyWebView *view = EPHY_WEB_VIEW (web_view); - uri = webkit_web_view_get_uri (view); + uri = webkit_web_view_get_uri (web_view); ephy_embed_destroy_top_widgets (embed); restore_zoom_level (embed, uri); - if (ephy_web_view_is_loading_homepage (EPHY_WEB_VIEW (view))) + if (ephy_web_view_is_loading_homepage (view)) return; - /* TODO: move the normaliztion down to the history service? */ + /* TODO: move the normalization down to the history service? */ if (g_str_has_prefix (uri, EPHY_ABOUT_SCHEME)) history_uri = g_strdup_printf ("about:%s", uri + EPHY_ABOUT_SCHEME_LEN + 1); else history_uri = g_strdup (uri); - ephy_history_service_visit_url (embed->priv->history_service, history_uri); + visit_type = ephy_web_view_get_visit_type (view); + + ephy_history_service_visit_url (embed->priv->history_service, + history_uri, + visit_type); + g_free (history_uri); } } diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c index de26f42d6..3314e4271 100644 --- a/embed/ephy-web-view.c +++ b/embed/ephy-web-view.c @@ -104,6 +104,8 @@ struct _EphyWebViewPrivate { GSList *shown_popups; GtkWidget *password_info_bar; + + EphyHistoryPageVisitType visit_type; }; typedef struct { @@ -1949,6 +1951,9 @@ load_status_cb (WebKitWebView *web_view, if (uri) soup_uri_free (uri); + /* Reset visit type. */ + priv->visit_type = EPHY_PAGE_VISIT_NONE; + break; } case WEBKIT_LOAD_FAILED: @@ -3694,6 +3699,8 @@ ephy_web_view_load_homepage (EphyWebView *view) { g_signal_emit_by_name (view, "loading-homepage"); + ephy_web_view_set_visit_type (view, + EPHY_PAGE_VISIT_HOMEPAGE); ephy_web_view_load_url (view, "about:blank"); } @@ -3740,3 +3747,33 @@ ephy_web_view_is_loading_homepage (EphyWebView *view) return view->priv->loading_homepage; } + +/** + * ephy_web_view_get_visit_type: + * @view: an #EphyWebView + * + * Returns: the @view #EphyWebViewVisitType + **/ +EphyHistoryPageVisitType +ephy_web_view_get_visit_type (EphyWebView *view) +{ + g_return_val_if_fail (EPHY_IS_WEB_VIEW (view), 0); + + return view->priv->visit_type; +} + +/** + * ephy_web_view_set_visit_type: + * @view: an #EphyWebView + * @visit_type: an #EphyHistoryPageVisitType + * + * Sets the @visit_type for @view, so that the URI can be + * properly weighted in the history backend. + **/ +void +ephy_web_view_set_visit_type (EphyWebView *view, EphyHistoryPageVisitType visit_type) +{ + g_return_if_fail (EPHY_IS_WEB_VIEW (view)); + + view->priv->visit_type = visit_type; +} diff --git a/lib/history/ephy-history-service.c b/lib/history/ephy-history-service.c index f7b468b9e..d618547e5 100644 --- a/lib/history/ephy-history-service.c +++ b/lib/history/ephy-history-service.c @@ -21,6 +21,7 @@ #include "ephy-history-service-private.h" #include "ephy-history-types.h" +#include "ephy-history-type-builtins.h" #include "ephy-sqlite-connection.h" typedef gboolean (*EphyHistoryServiceMethod) (EphyHistoryService *self, gpointer data, gpointer *result); @@ -125,13 +126,13 @@ ephy_history_service_finalize (GObject *self) } static gboolean -impl_visit_url (EphyHistoryService *self, const char *url) +impl_visit_url (EphyHistoryService *self, const char *url, EphyHistoryPageVisitType visit_type) { EphyHistoryPageVisit *visit; visit = ephy_history_page_visit_new (url, time (NULL), - EPHY_PAGE_VISIT_TYPED); + visit_type); ephy_history_service_add_visit (self, visit, NULL, NULL, NULL); ephy_history_page_visit_free (visit); @@ -158,8 +159,9 @@ ephy_history_service_class_init (EphyHistoryServiceClass *klass) g_signal_accumulator_true_handled, NULL, g_cclosure_marshal_generic, G_TYPE_BOOLEAN, - 1, - G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE); + 2, + G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE, + EPHY_TYPE_HISTORY_PAGE_VISIT_TYPE); signals[CLEARED] = g_signal_new ("cleared", @@ -1008,14 +1010,15 @@ ephy_history_service_find_urls (EphyHistoryService *self, void ephy_history_service_visit_url (EphyHistoryService *self, - const char *url) + const char *url, + EphyHistoryPageVisitType visit_type) { gboolean result; g_return_if_fail (EPHY_IS_HISTORY_SERVICE (self)); g_return_if_fail (url != NULL); - g_signal_emit (self, signals[VISIT_URL], 0, url, &result); + g_signal_emit (self, signals[VISIT_URL], 0, url, visit_type, &result); } void diff --git a/lib/history/ephy-history-service.h b/lib/history/ephy-history-service.h index c2e2093db..233f443bf 100644 --- a/lib/history/ephy-history-service.h +++ b/lib/history/ephy-history-service.h @@ -53,7 +53,8 @@ struct _EphyHistoryServiceClass { /* Signals */ gboolean (* visit_url) (EphyHistoryService *self, - const char *url); + const char *url, + EphyHistoryPageVisitType visit_type); }; GType ephy_history_service_get_type (void); @@ -73,7 +74,7 @@ void ephy_history_service_delete_host (EphyHisto void ephy_history_service_get_url (EphyHistoryService *self, const char *url, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data); void ephy_history_service_delete_urls (EphyHistoryService *self, GList *urls, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data); void ephy_history_service_find_urls (EphyHistoryService *self, gint64 from, gint64 to, guint limit, gint host, GList *substring_list, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data); -void ephy_history_service_visit_url (EphyHistoryService *self, const char *orig_url); +void ephy_history_service_visit_url (EphyHistoryService *self, const char *orig_url, EphyHistoryPageVisitType visit_type); void ephy_history_service_clear (EphyHistoryService *self, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data); void ephy_history_service_find_hosts (EphyHistoryService *self, gint64 from, gint64 to, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data); diff --git a/lib/history/ephy-history-types.h b/lib/history/ephy-history-types.h index 4ff836fc6..28e762d4e 100644 --- a/lib/history/ephy-history-types.h +++ b/lib/history/ephy-history-types.h @@ -30,6 +30,7 @@ G_BEGIN_DECLS * src/chrome/common/page_transition_types.h in the Chromium source code. */ typedef enum { + EPHY_PAGE_VISIT_NONE, EPHY_PAGE_VISIT_LINK, EPHY_PAGE_VISIT_TYPED, EPHY_PAGE_VISIT_MANUAL_SUBFRAME, @@ -37,6 +38,8 @@ typedef enum { EPHY_PAGE_VISIT_STARTUP, EPHY_PAGE_VISIT_FORM_SUBMISSION, EPHY_PAGE_VISIT_FORM_RELOAD, + EPHY_PAGE_VISIT_BOOKMARK, + EPHY_PAGE_VISIT_HOMEPAGE } EphyHistoryPageVisitType; typedef enum { diff --git a/src/bookmarks/ephy-bookmark-action.c b/src/bookmarks/ephy-bookmark-action.c index 29c568486..814fadd7e 100644 --- a/src/bookmarks/ephy-bookmark-action.c +++ b/src/bookmarks/ephy-bookmark-action.c @@ -183,6 +183,8 @@ ephy_bookmark_action_activate (EphyBookmarkAction *action, } g_return_if_fail (address != NULL); + flags |= EPHY_LINK_BOOKMARK; + ephy_link_open (EPHY_LINK (action), address, NULL, flags); g_free (address); diff --git a/src/ephy-link.h b/src/ephy-link.h index 65bad41b4..58c542fb9 100644 --- a/src/ephy-link.h +++ b/src/ephy-link.h @@ -47,7 +47,9 @@ typedef enum EPHY_LINK_NEW_TAB = 1 << 1, EPHY_LINK_JUMP_TO = 1 << 2, EPHY_LINK_NEW_TAB_APPEND_AFTER = 1 << 3, - EPHY_LINK_HOME_PAGE = 1 << 4 + EPHY_LINK_HOME_PAGE = 1 << 4, + EPHY_LINK_TYPED = 1 << 5, + EPHY_LINK_BOOKMARK = 1 << 6 } EphyLinkFlags; struct _EphyLinkIface diff --git a/src/ephy-location-controller.c b/src/ephy-location-controller.c index 5908967a4..8ebdc74b4 100644 --- a/src/ephy-location-controller.c +++ b/src/ephy-location-controller.c @@ -127,7 +127,7 @@ action_activated_cb (GtkEntryCompletion *completion, if (url == NULL) return; ephy_link_open (EPHY_LINK (controller), url, NULL, - ephy_link_flags_from_current_event ()); + ephy_link_flags_from_current_event () | EPHY_LINK_TYPED); g_free (url); } @@ -159,7 +159,7 @@ entry_activate_cb (GtkEntry *entry, g_return_if_fail (address != NULL); ephy_link_open (EPHY_LINK (controller), g_strstrip (address), NULL, - ephy_link_flags_from_current_event ()); + ephy_link_flags_from_current_event () | EPHY_LINK_TYPED); g_free (address); } diff --git a/src/ephy-private.h b/src/ephy-private.h index ee2514ea1..1f3b0390a 100644 --- a/src/ephy-private.h +++ b/src/ephy-private.h @@ -27,6 +27,7 @@ #include "ephy-embed.h" #include "ephy-embed-event.h" +#include "ephy-embed-private.h" #include "ephy-location-controller.h" #include "ephy-window.h" diff --git a/src/ephy-window.c b/src/ephy-window.c index d3cbfeb91..90d4b95cb 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -544,6 +544,13 @@ ephy_window_open_link (EphyLink *link, embed = window->priv->active_embed; } + if (flags & EPHY_LINK_BOOKMARK) + ephy_web_view_set_visit_type (ephy_embed_get_web_view (embed), + EPHY_PAGE_VISIT_BOOKMARK); + else if (flags & EPHY_LINK_TYPED) + ephy_web_view_set_visit_type (ephy_embed_get_web_view (embed), + EPHY_PAGE_VISIT_TYPED); + if (flags & (EPHY_LINK_JUMP_TO | EPHY_LINK_NEW_TAB | EPHY_LINK_NEW_WINDOW | @@ -2175,6 +2182,9 @@ policy_decision_required_cb (WebKitWebView *web_view, flags = EPHY_NEW_TAB_OPEN_PAGE; + ephy_web_view_set_visit_type (EPHY_WEB_VIEW (web_view), + EPHY_PAGE_VISIT_LINK); + /* New tab in new window for control+shift+click */ if (button == 1 && state == (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) -- cgit v1.2.3