about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJosh Rickmar <jrick@devio.us>2012-08-28 10:31:12 -0400
committerJosh Rickmar <jrick@devio.us>2012-08-28 10:31:12 -0400
commit4c2c92c6e2e88531cd4fc88c045ece8af5009e0b (patch)
tree4c2cb911f99941e1c566b517eb79322306ef7749
parentd2468a775ac9d157fd718b21cfa9e0de572cca81 (diff)
downloadxombrero-4c2c92c6e2e88531cd4fc88c045ece8af5009e0b.tar.gz
Backout the recent back/forward list changes
This changed worked wonders for me but others still saw some problems.
I could not reproduce any of them.  This will bring back some problems
with refresh not working again, but I'll work around that next.
-rw-r--r--about.c7
-rw-r--r--xombrero.c146
2 files changed, 128 insertions, 25 deletions
diff --git a/about.c b/about.c
index cef627b..bc668a1 100644
--- a/about.c
+++ b/about.c
@@ -188,13 +188,8 @@ load_webkit_string(struct tab *t, const char *str, gchar *title)
 		g_signal_handler_disconnect(t->wv, t->progress_handle);
 
 	/* we set this to indicate we want to manually do navaction */
-	if (t->bfl) {
-		if (t->item)
-			g_object_unref(t->item);
+	if (t->bfl)
 		t->item = webkit_web_back_forward_list_get_current_item(t->bfl);
-		if (t->item)
-			g_object_ref(t->item);
-	}
 
 	t->xtp_meaning = XT_XTP_TAB_MEANING_NORMAL;
 	if (title) {
diff --git a/xombrero.c b/xombrero.c
index e3ec499..1535977 100644
--- a/xombrero.c
+++ b/xombrero.c
@@ -2163,7 +2163,7 @@ check_cert_changes(struct tab *t, const char *uri)
 	const char		*errstr = NULL;
 	struct karg		*argsp;
 
-	if (!(warn_cert_changes && uri && g_str_has_prefix(uri, "https://")))
+	if (!(warn_cert_changes && g_str_has_prefix(uri, "https://")))
 		return (0);
 
 	switch (load_compare_cert(uri, &errstr, certs_cache_dir)) {
@@ -2290,8 +2290,113 @@ toplevel_cmd(struct tab *t, struct karg *args)
 }
 
 int
+can_go_back_for_real(struct tab *t)
+{
+	int			i;
+	WebKitWebHistoryItem	*item;
+	const gchar		*uri;
+
+	if (t == NULL)
+		return (FALSE);
+
+	/* rely on webkit to make sure we can go backward when on an about page */
+	uri = get_uri(t);
+	if (uri == NULL || g_str_has_prefix(uri, "about:"))
+		return (webkit_web_view_can_go_back(t->wv));
+
+	/* the back/forwars list is stupid so help determine if we can go back */
+	for (i = 0, item = webkit_web_back_forward_list_get_current_item(t->bfl);
+	    item != NULL;
+	    i--, item = webkit_web_back_forward_list_get_nth_item(t->bfl, i)) {
+		if (strcmp(webkit_web_history_item_get_uri(item), uri))
+			return (TRUE);
+	}
+
+	return (FALSE);
+}
+
+int
+can_go_forward_for_real(struct tab *t)
+{
+	int			i;
+	WebKitWebHistoryItem	*item;
+	const gchar		*uri;
+
+	if (t == NULL)
+		return (FALSE);
+
+	/* rely on webkit to make sure we can go forward when on an about page */
+	uri = get_uri(t);
+	if (uri == NULL || g_str_has_prefix(uri, "about:"))
+		return (webkit_web_view_can_go_forward(t->wv));
+
+	/* the back/forwars list is stupid so help selecting a different item */
+	for (i = 0, item = webkit_web_back_forward_list_get_current_item(t->bfl);
+	    item != NULL;
+	    i++, item = webkit_web_back_forward_list_get_nth_item(t->bfl, i)) {
+		if (strcmp(webkit_web_history_item_get_uri(item), uri))
+			return (TRUE);
+	}
+
+	return (FALSE);
+}
+
+void
+go_back_for_real(struct tab *t)
+{
+	int			i;
+	WebKitWebHistoryItem	*item;
+	const gchar		*uri;
+
+	if (t == NULL)
+		return;
+
+	uri = get_uri(t);
+	if (uri == NULL) {
+		webkit_web_view_go_back(t->wv);
+		return;
+	}
+	/* the back/forwars list is stupid so help selecting a different item */
+	for (i = 0, item = webkit_web_back_forward_list_get_current_item(t->bfl);
+	    item != NULL;
+	    i--, item = webkit_web_back_forward_list_get_nth_item(t->bfl, i)) {
+		if (strcmp(webkit_web_history_item_get_uri(item), uri)) {
+			webkit_web_view_go_to_back_forward_item(t->wv, item);
+			break;
+		}
+	}
+}
+
+void
+go_forward_for_real(struct tab *t)
+{
+	int			i;
+	WebKitWebHistoryItem	*item;
+	const gchar		*uri;
+
+	if (t == NULL)
+		return;
+
+	uri = get_uri(t);
+	if (uri == NULL) {
+		webkit_web_view_go_forward(t->wv);
+		return;
+	}
+	/* the back/forwars list is stupid so help selecting a different item */
+	for (i = 0, item = webkit_web_back_forward_list_get_current_item(t->bfl);
+	    item != NULL;
+	    i++, item = webkit_web_back_forward_list_get_nth_item(t->bfl, i)) {
+		if (strcmp(webkit_web_history_item_get_uri(item), uri)) {
+			webkit_web_view_go_to_back_forward_item(t->wv, item);
+			break;
+		}
+	}
+}
+
+int
 navaction(struct tab *t, struct karg *args)
 {
+	WebKitWebHistoryItem	*item;
 	WebKitWebFrame		*frame;
 
 	DNPRINTF(XT_D_NAV, "navaction: tab %d opcode %d\n",
@@ -2299,18 +2404,26 @@ navaction(struct tab *t, struct karg *args)
 
 	hide_oops(t);
 	set_normal_tab_meaning(t);
+	if (t->item) {
+		if (args->i == XT_NAV_BACK)
+			item = webkit_web_back_forward_list_get_current_item(t->bfl);
+		else
+			item = webkit_web_back_forward_list_get_forward_item(t->bfl);
+		if (item == NULL)
+			return (XT_CB_PASSTHROUGH);
+		webkit_web_view_go_to_back_forward_item(t->wv, item);
+		t->item = NULL;
+		return (XT_CB_PASSTHROUGH);
+	}
 
 	switch (args->i) {
 	case XT_NAV_BACK:
 		marks_clear(t);
-		if (t->item)
-			webkit_web_view_go_to_back_forward_item(t->wv, t->item);
-		else
-			webkit_web_view_go_back(t->wv);
+		go_back_for_real(t);
 		break;
 	case XT_NAV_FORWARD:
 		marks_clear(t);
-		webkit_web_view_go_forward(t->wv);
+		go_forward_for_real(t);
 		break;
 	case XT_NAV_RELOAD:
 		frame = webkit_web_view_get_main_frame(t->wv);
@@ -3892,7 +4005,7 @@ xt_icon_from_file(struct tab *t, char *uri)
 	GdkPixbuf		*pb;
 	char			*file;
 
-	if (uri != NULL && g_str_has_prefix(uri, "file://"))
+	if (g_str_has_prefix(uri, "file://"))
 		file = g_filename_from_uri(uri, NULL, NULL);
 	else
 		file = g_strdup(uri);
@@ -3942,7 +4055,7 @@ set_favicon_from_file(struct tab *t, char *uri)
 	if (t == NULL || uri == NULL)
 		return;
 
-	if (uri != NULL && g_str_has_prefix(uri, "file://"))
+	if (g_str_has_prefix(uri, "file://"))
 		file = g_filename_from_uri(uri, NULL, NULL);
 	else
 		file = g_strdup(uri);
@@ -4312,11 +4425,14 @@ notify_load_status_cb(WebKitWebView* wview, GParamSpec* pspec, struct tab *t)
 		break;
 	}
 
-	gtk_widget_set_sensitive(GTK_WIDGET(t->backward),
-	    t->item || webkit_web_view_can_go_back(t->wv));
+	if (t->item)
+		gtk_widget_set_sensitive(GTK_WIDGET(t->backward), TRUE);
+	else
+		gtk_widget_set_sensitive(GTK_WIDGET(t->backward),
+		    can_go_back_for_real(t));
 
 	gtk_widget_set_sensitive(GTK_WIDGET(t->forward),
-	    webkit_web_view_can_go_forward(t->wv));
+	    can_go_forward_for_real(t));
 }
 
 void
@@ -4836,12 +4952,6 @@ webview_npd_cb(WebKitWebView *wv, WebKitWebFrame *wf,
 		return (TRUE);
 	}
 
-	/* clear t->item, except if we're switching to an about: page */
-	if (t->item && !g_str_has_prefix(uri, "xxxt://")) {
-		g_object_unref(t->item);
-		t->item = NULL;
-	}
-
 	if (!auto_load_images && t->load_images) {
 
 		/* Disable autoloading of images, now that we're done loading
@@ -7364,8 +7474,6 @@ delete_tab(struct tab *t)
 	}
 
 	g_object_unref(t->completion);
-	if (t->item)
-		g_object_unref(t->item);
 
 	gtk_widget_destroy(t->tab_elems.eventbox);
 	gtk_widget_destroy(t->vbox);