[epiphany] Preserve back/forward history when opening links in new tabs/windows.



commit 5e83fc07ff785200e9dd5078ce903fb0b053e526
Author: Xan Lopez <xan gnome org>
Date:   Thu May 28 17:55:53 2009 +0300

    Preserve back/forward history when opening links in new tabs/windows.
    
    Bug #583459.
---
 embed/ephy-embed-utils.h     |    1 +
 embed/webkit/webkit-embed.c  |   31 +++++++++++++++++++++++++++++++
 src/ephy-navigation-action.c |    9 ++++-----
 3 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/embed/ephy-embed-utils.h b/embed/ephy-embed-utils.h
index a5c64bb..e98860e 100644
--- a/embed/ephy-embed-utils.h
+++ b/embed/ephy-embed-utils.h
@@ -36,6 +36,7 @@
 G_BEGIN_DECLS
 
 #define EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED(embed) (WEBKIT_WEB_VIEW (gtk_bin_get_child (GTK_BIN (gtk_bin_get_child (GTK_BIN (embed))))))
+#define EPHY_WEBKIT_BACK_FORWARD_LIMIT 100
 
 char 	   * ephy_embed_utils_link_message_parse  (char *message);
 const char * ephy_embed_utils_get_title_composite (EphyEmbed *embed);
diff --git a/embed/webkit/webkit-embed.c b/embed/webkit/webkit-embed.c
index 481e514..cb6e9dc 100644
--- a/embed/webkit/webkit-embed.c
+++ b/embed/webkit/webkit-embed.c
@@ -858,6 +858,37 @@ impl_shistory_copy (EphyEmbed *source,
                     gboolean copy_forward,
                     gboolean copy_current)
 {
+  WebKitWebView *source_view, *dest_view;
+  WebKitWebBackForwardList* source_bflist, *dest_bflist;
+  WebKitWebHistoryItem *item;
+  GList *items;
+
+  source_view = WEBKIT_EMBED (source)->priv->web_view;
+  dest_view = WEBKIT_EMBED (dest)->priv->web_view;
+
+  source_bflist = webkit_web_view_get_back_forward_list (source_view);
+  dest_bflist = webkit_web_view_get_back_forward_list (dest_view);
+
+  if (copy_back) {
+    items = webkit_web_back_forward_list_get_back_list_with_limit (source_bflist, EPHY_WEBKIT_BACK_FORWARD_LIMIT);
+    /* We want to add the items in the reverse order here, so the
+       history ends up the same */
+    items = g_list_reverse (items);
+    for (; items; items = items->next) {
+      item = (WebKitWebHistoryItem*)items->data;
+      webkit_web_back_forward_list_add_item (dest_bflist, g_object_ref (item));
+    }
+    g_list_free (items);
+  }
+
+  /* The ephy/gecko behavior is to add the current item of the source
+     embed at the end of the back history, so keep doing that */
+  item = webkit_web_back_forward_list_get_current_item (source_bflist);
+  webkit_web_back_forward_list_add_item (dest_bflist, g_object_ref (item));
+
+  /* We ignore the 'copy_current' flag, it's unused in Epiphany */
+  /* We ignore the 'copy_forward' flag, ephy/gecko did nothing with it
+     either AFAICT*/
 }
 
 static void
diff --git a/src/ephy-navigation-action.c b/src/ephy-navigation-action.c
index 1834a13..07f202b 100644
--- a/src/ephy-navigation-action.c
+++ b/src/ephy-navigation-action.c
@@ -39,7 +39,6 @@
 
 #define HISTORY_ITEM_DATA_KEY	  "HistoryItem"
 #define URL_DATA_KEY	          "GoURL"
-#define WEBKIT_BACK_FORWARD_LIMIT 100
 
 #define EPHY_NAVIGATION_ACTION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_NAVIGATION_ACTION, EphyNavigationActionPrivate))
 
@@ -197,10 +196,10 @@ webkit_construct_history_list (WebKitWebView *web_view, WebKitHistoryType hist_t
 
 	if (hist_type == WEBKIT_HISTORY_FORWARD)
 		webkit_items = webkit_web_back_forward_list_get_forward_list_with_limit (web_back_forward_list,
-											 WEBKIT_BACK_FORWARD_LIMIT);
+											 EPHY_WEBKIT_BACK_FORWARD_LIMIT);
 	else
 		webkit_items = webkit_web_back_forward_list_get_back_list_with_limit (web_back_forward_list,
-										      WEBKIT_BACK_FORWARD_LIMIT);
+										      EPHY_WEBKIT_BACK_FORWARD_LIMIT);
 
 	return webkit_items;
 }
@@ -243,8 +242,8 @@ build_back_or_forward_menu (EphyNavigationAction *action)
 
 		item = new_history_menu_item (title ? title : url, url);
 
-		g_object_set_data_full (G_OBJECT (item), HISTORY_ITEM_DATA_KEY, hitem,
-					(GDestroyNotify) g_object_unref);
+		g_object_set_data_full (G_OBJECT (item), HISTORY_ITEM_DATA_KEY,
+					g_object_ref (hitem), g_object_unref);
 
 		g_signal_connect (item, "activate",
 				  G_CALLBACK (activate_back_or_forward_menu_item_cb),



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