[Commits] [SCM] claws branch, master, updated. 3.15.0-64-gb320c50

Colin colin at claws-mail.org
Sat Jun 3 22:01:04 CEST 2017


The branch, master has been updated
       via  b320c5095cd51213520d8011ae4969e97c8f7436 (commit)
      from  b7157747860b26cbb69295a4cc62a2493bd1d7e2 (commit)

Summary of changes:
 src/plugins/fancy/fancy_viewer.c |  119 +++++++++++++++++++++++++-------------
 src/plugins/fancy/fancy_viewer.h |    2 +
 2 files changed, 81 insertions(+), 40 deletions(-)


- Log -----------------------------------------------------------------
commit b320c5095cd51213520d8011ae4969e97c8f7436
Author: Colin Leroy <colin at colino.net>
Date:   Sat Jun 3 21:57:08 2017 +0200

    Fix Fancy showing a previous email in some cases.
    
    The problem seemed to be due to something returning
    "application/x-extension-html" instead of "text/html"
    as MIME types for some emails, stopping rendering.
    Using _load_string instead of _load_uri fixes it.
    Also, remove some outdated conditionals now we require
    Webkit 1.1.14, and replace some deprecated callbacks
    with the more recent ones.

diff --git a/src/plugins/fancy/fancy_viewer.c b/src/plugins/fancy/fancy_viewer.c
index 3e818f8..079a18e 100644
--- a/src/plugins/fancy/fancy_viewer.c
+++ b/src/plugins/fancy/fancy_viewer.c
@@ -42,12 +42,9 @@ static void
 over_link_cb (WebKitWebView *view, const gchar *wtf, const gchar *link,
 	      FancyViewer *viewer, void *wtfa);
 
-static void
-load_progress_cb (WebKitWebView *view, gint progress, FancyViewer *viewer);
 
-static WebKitNavigationResponse
-navigation_requested_cb (WebKitWebView *view, WebKitWebFrame *frame,
-			 WebKitNetworkRequest *netreq, FancyViewer *viewer);
+static void
+load_progress_cb(WebKitWebView *view, GParamSpec* pspec, FancyViewer *viewer);
 
 static MimeViewerFactory fancy_viewer_factory;
 
@@ -199,15 +196,6 @@ static void fancy_set_defaults(FancyViewer *viewer)
 	fancy_apply_prefs(viewer);
 }
 
-static void fancy_load_uri(FancyViewer *viewer, const gchar *uri)
-{
-#if WEBKIT_CHECK_VERSION(1,1,1)
-	webkit_web_view_load_uri(viewer->view, uri);
-#else
-	webkit_web_view_open(viewer->view, uri);
-#endif
-}
-
 static gboolean fancy_show_mimepart_real(MimeViewer *_viewer)
 {
 	FancyViewer *viewer = (FancyViewer *) _viewer;
@@ -240,6 +228,7 @@ static gboolean fancy_show_mimepart_real(MimeViewer *_viewer)
 	}
 	else {
 		const gchar *charset = NULL;
+		gchar *contents = NULL;
 		if (messageview && messageview->forced_charset)
 			charset = _viewer->mimeview->messageview->forced_charset;
 		else
@@ -248,14 +237,20 @@ static gboolean fancy_show_mimepart_real(MimeViewer *_viewer)
 			charset = conv_get_locale_charset_str();
 		debug_print("using %s charset\n", charset);
 		g_object_set(viewer->settings, "default-encoding", charset, NULL);
-		gchar *tmp = g_filename_to_uri(viewer->filename, NULL, NULL);
+		
+		contents = file_read_to_str_no_recode(viewer->filename);
+		
 		debug_print("zoom_level: %i\n", fancy_prefs.zoom_level);
 		webkit_web_view_set_zoom_level(viewer->view, (fancy_prefs.zoom_level / 100.0));
 
 		fancy_set_defaults(viewer);
-		fancy_load_uri(viewer, tmp);
 
-		g_free(tmp);
+		webkit_web_view_load_string(viewer->view,
+					    contents,
+					    "text/html",
+					    charset,
+					    NULL);
+		g_free(contents);
 	}
 	viewer->loading = FALSE;
 	return FALSE;
@@ -349,7 +344,7 @@ static void fancy_clear_viewer(MimeViewer *_viewer)
 	viewer->cur_link = NULL;
 	fancy_set_defaults(viewer);
 
-	fancy_load_uri(viewer, "about:blank");
+	webkit_web_view_load_uri(viewer->view, "about:blank");
 
 	debug_print("fancy_clear_viewer\n");
 	fancy_prefs.zoom_level = webkit_web_view_get_zoom_level(viewer->view) * 100;
@@ -368,25 +363,35 @@ static void fancy_destroy_viewer(MimeViewer *_viewer)
 	g_free(viewer);
 }
 
-static WebKitNavigationResponse
-navigation_requested_cb(WebKitWebView *view, WebKitWebFrame *frame,
-						WebKitNetworkRequest *netreq, FancyViewer *viewer)
+static gboolean
+navigation_policy_cb (WebKitWebView             *web_view,
+		      WebKitWebFrame            *frame,
+		      WebKitNetworkRequest      *request,
+		      WebKitWebNavigationAction *navigation_action,
+		      WebKitWebPolicyDecision   *policy_decision,
+		      FancyViewer		*viewer)
 {
-	const gchar *uri = webkit_network_request_get_uri(netreq);
+	const gchar *uri = webkit_network_request_get_uri(request);
 
 	debug_print("navigation requested to %s\n", uri);
 
 	if (!strncmp(uri, "mailto:", 7)) {
+		debug_print("Opening message window\n");
 		compose_new(NULL, uri + 7, NULL);
-		return WEBKIT_NAVIGATION_RESPONSE_IGNORE;
-	} else if (!strncmp(uri, "file://", 7)) {
-		return WEBKIT_NAVIGATION_RESPONSE_ACCEPT;
-	} else if (viewer->override_prefs_remote_content)
-		return WEBKIT_NAVIGATION_RESPONSE_ACCEPT;
-	else {
+		webkit_web_policy_decision_ignore(policy_decision);
+	} else if (!strncmp(uri, "file://", 7) || !strcmp(uri, "about:blank")) {
+		debug_print("local navigation request ACCEPTED\n");
+		webkit_web_policy_decision_use(policy_decision);
+	} else if (viewer->override_prefs_remote_content) {
+		debug_print("remote navigation request ACCEPTED\n");
+		webkit_web_policy_decision_use(policy_decision);
+	} else {
+		debug_print("remote navigation request IGNORED\n");
 		fancy_show_notice(viewer, _("Remote content loading is disabled."));
-		return WEBKIT_NAVIGATION_RESPONSE_IGNORE;
+		webkit_web_policy_decision_ignore(policy_decision);
 	}
+
+	return true;
 }
 
 static void resource_request_starting_cb(WebKitWebView		*view,
@@ -560,17 +565,33 @@ static void over_link_cb(WebKitWebView *view, const gchar *wtf,
 	}
 }
 
-static void load_progress_cb(WebKitWebView *view, gint progress,
+static void load_progress_cb(WebKitWebView *view, GParamSpec* pspec,
 			     FancyViewer *viewer)
 {
-	gdouble pbar;
-	gchar *label = g_strdup_printf("%d%% Loading...", progress);
-	pbar = (gdouble) progress / 100;
+	WebKitLoadStatus status = webkit_web_view_get_load_status(viewer->view);
+	gdouble pbar = webkit_web_view_get_progress(viewer->view);
+	const gchar *uri = webkit_web_view_get_uri(viewer->view);
+
+	gchar *label = g_strdup_printf("%d%% Loading...", (gint)(pbar * 100));
 	gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(viewer->progress), pbar);
 	gtk_progress_bar_set_text(GTK_PROGRESS_BAR(viewer->progress),
 				  (const gchar*)label);
 	g_free(label);
+
+	switch (status) {
+		case WEBKIT_LOAD_PROVISIONAL:
+		case WEBKIT_LOAD_COMMITTED:
+		case WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT:
+			break;
+		case WEBKIT_LOAD_FAILED:
+			debug_print("Load failed: %s\n", uri);
+			break;
+		case WEBKIT_LOAD_FINISHED:
+			debug_print("Load finished: %s\n", uri);
+			break;
+	}
 }
+
 static void stop_loading_cb(GtkWidget *widget, GdkEvent *ev,
 							FancyViewer *viewer)
 {
@@ -594,11 +615,8 @@ static void search_the_web_cb(GtkWidget *widget, FancyViewer *viewer)
 		gchar *tmp = webkit_web_view_get_selected_text(viewer->view);
 #endif
 		search = g_strconcat(GOOGLE_SEARCH, tmp, NULL);
-#if WEBKIT_CHECK_VERSION(1,1,1)
+
 		webkit_web_view_load_uri(viewer->view, search);
-#else
-		webkit_web_view_open(viewer->view, search);
-#endif
 		g_free(search);
 		g_free(tmp);
 	}
@@ -893,6 +911,17 @@ static void zoom_out_cb(GtkWidget *widget, GdkEvent *ev, FancyViewer *viewer)
 	webkit_web_view_zoom_out(viewer->view);
 }
 
+#if WEBKIT_CHECK_VERSION (1,7,5)
+static void resource_load_failed_cb(WebKitWebView     *web_view,
+				    WebKitWebFrame    *web_frame,
+				    WebKitWebResource *web_resource,
+				    GError            *error,
+				    FancyViewer	      *viewer)
+{
+	debug_print("Loading error: %s\n", error->message);
+}
+#endif
+
 static MimeViewer *fancy_viewer_create(void)
 {
 	FancyViewer    *viewer;
@@ -1009,10 +1038,15 @@ static MimeViewer *fancy_viewer_create(void)
 			 G_CALLBACK(load_finished_cb), viewer);
 	g_signal_connect(G_OBJECT(viewer->view), "hovering-over-link",
 			 G_CALLBACK(over_link_cb), viewer);
-	g_signal_connect(G_OBJECT(viewer->view), "load-progress-changed",
+
+	g_signal_connect(G_OBJECT(viewer->view), "notify::progress",
+			 G_CALLBACK(load_progress_cb), viewer);
+	g_signal_connect(G_OBJECT(viewer->view), "notify::load-status",
 			 G_CALLBACK(load_progress_cb), viewer);
-	g_signal_connect(G_OBJECT(viewer->view), "navigation-requested",
-			 G_CALLBACK(navigation_requested_cb), viewer);
+
+	g_signal_connect(G_OBJECT(viewer->view), "navigation-policy-decision-requested",
+			 G_CALLBACK(navigation_policy_cb), viewer);
+
 	g_signal_connect(G_OBJECT(viewer->view), "resource-request-starting",
 			G_CALLBACK(resource_request_starting_cb), viewer);
 	g_signal_connect(G_OBJECT(viewer->view), "populate-popup",
@@ -1034,6 +1068,11 @@ static MimeViewer *fancy_viewer_create(void)
 	g_signal_connect(G_OBJECT(viewer->view), "key_press_event",
 			 G_CALLBACK(keypress_events_cb), viewer);
 
+#if WEBKIT_CHECK_VERSION (1,7,5)
+	g_signal_connect(G_OBJECT(viewer->view), "resource-load-failed",
+			 G_CALLBACK(resource_load_failed_cb), viewer);
+#endif
+
 	viewer->filename = NULL;
 	return (MimeViewer *) viewer;
 }
diff --git a/src/plugins/fancy/fancy_viewer.h b/src/plugins/fancy/fancy_viewer.h
index 4d751b7..952b337 100644
--- a/src/plugins/fancy/fancy_viewer.h
+++ b/src/plugins/fancy/fancy_viewer.h
@@ -33,6 +33,8 @@
 #include <webkit/webkitversion.h>
 #include <webkit/webkitwebframe.h>
 #include <webkit/webkitnetworkrequest.h>
+#include <webkit/webkitwebnavigationaction.h>
+#include <webkit/webkitwebpolicydecision.h>
 #if WEBKIT_CHECK_VERSION (1,3,10)
 #include <webkit/webkitglobals.h>
 #endif

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list