gtkwebview: Fix displaying image from memory

Tue, 25 Sep 2018 15:19:56 -0500

author
Mike Ruprecht <cmaiku@gmail.com>
date
Tue, 25 Sep 2018 15:19:56 -0500
changeset 39234
14861f3ffe0c
parent 39233
7888def49437
child 39236
b39bfbb7212f

gtkwebview: Fix displaying image from memory

When the web view was updated to support the newer PurpleImage,
purple_image_get_path() only returned a value if it was created from
a file path. Since then, PurpleImage has been changed to return a
unique identifier, such as from a hash, if a filename is missing.
This identifier isn't an absolute path. g_filename_to_uri() expects
an absolute path and therefore, in the web view code, returns NULL.
This handling code doesn't expect a NULL and fails to display the
image.

The PurpleImage API probably needs another improvement pass. This
patch adds a comment to update the web view when this happens,
although we may be using Talkatu by then. It also checks for the
g_filename_to_uri() return value and handles NULLs.

pidgin/gtkwebview.c file | annotate | diff | comparison | revisions
--- a/pidgin/gtkwebview.c	Tue Sep 25 15:06:32 2018 -0500
+++ b/pidgin/gtkwebview.c	Tue Sep 25 15:19:56 2018 -0500
@@ -194,9 +194,21 @@
 		return;
 
 	if (img != NULL) {
+		/* At the time of this comment, purple_image_get_path()
+		 * always returns something, whether it's the actual
+		 * path or a unique identifier, such as derived from a
+		 * hash. That API will probably be reviewed after which
+		 * this code can probably be simplified.
+		 */
+		gchar *uri = NULL;
+
 		path = purple_image_get_path(img);
+
 		if (path) {
-			gchar *uri = g_filename_to_uri(path, NULL, NULL);
+			uri = g_filename_to_uri(path, NULL, NULL);
+		}
+
+		if (uri != NULL) {
 			webkit_network_request_set_uri(request, uri);
 			g_free(uri);
 		} else {

mercurial