about summary refs log tree commit diff stats
path: root/xxxterm.c
diff options
context:
space:
mode:
authorStevan Andjelkovic <stevan.andjelkovic@strath.ac.uk>2011-12-30 19:26:18 +0100
committerStevan Andjelkovic <stevan.andjelkovic@strath.ac.uk>2011-12-30 19:26:18 +0100
commit095704d173040308b7ad5985c94e3b167af62be3 (patch)
treecd1542854ab3229a37b812a749ad6f0f124c7181 /xxxterm.c
parent660a5dd434a29ab6a20ca49c31fca3565bdca74d (diff)
downloadxombrero-095704d173040308b7ad5985c94e3b167af62be3.tar.gz
FS#201 - option to not load images on webpages
Code from Elias Norberg (xyzzy)

ok marco@
Diffstat (limited to 'xxxterm.c')
-rw-r--r--xxxterm.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/xxxterm.c b/xxxterm.c
index f4ccd2e..9149e34 100644
--- a/xxxterm.c
+++ b/xxxterm.c
@@ -163,6 +163,7 @@ TAILQ_HEAD(command_list, command_entry);
 #define XT_TAB_SHOW		(6)
 #define XT_TAB_HIDE		(7)
 #define XT_TAB_NEXTSTYLE	(8)
+#define XT_TAB_LOAD_IMAGES	(9)
 
 #define XT_NAV_INVALID		(0)
 #define XT_NAV_BACK		(1)
@@ -2598,6 +2599,28 @@ tabaction(struct tab *t, struct karg *args)
 			g_free(u);
 		}
 		break;
+	case XT_TAB_LOAD_IMAGES:
+
+		if (!auto_load_images) {
+
+			/* Enable auto-load images (this will load all
+			 * previously unloaded images). */
+			g_object_set(G_OBJECT(t->settings),
+			    "auto-load-images", TRUE, (char *)NULL);
+			webkit_web_view_set_settings(t->wv, t->settings);
+
+			webkit_web_view_reload(t->wv);
+
+			/* Webkit triggers an event when we change the setting,
+			 * so we can't disable the auto-loading at once.
+			 *
+			 * Unfortunately, webkit does not tell us when it's done.
+			 * Instead, we wait until the next request, and then
+			 * disable autoloading again.
+			 */
+			t->load_images = TRUE;
+		}
+		break;
 	default:
 		rv = XT_CB_PASSTHROUGH;
 		goto done;
@@ -3293,6 +3316,7 @@ struct cmd {
 	{ "buffers",		0,	buffers,		0,			0 },
 	{ "ls",			0,	buffers,		0,			0 },
 	{ "encoding",		0,	set_encoding,		0,			XT_USERARG },
+	{ "loadimages",		0,	tabaction,		XT_TAB_LOAD_IMAGES,	0 },
 
 	/* command aliases (handy when -S flag is used) */
 	{ "promptopen",		0,	command,		XT_CMD_OPEN,		0 },
@@ -4297,6 +4321,17 @@ webview_npd_cb(WebKitWebView *wv, WebKitWebFrame *wf,
 
 	uri = (char *)webkit_network_request_get_uri(request);
 
+	if (!auto_load_images && t->load_images) {
+
+		/* Disable autoloading of images, now that we're done loading
+		 * them. */
+		g_object_set(G_OBJECT(t->settings),
+		    "auto-load-images", FALSE, (char *)NULL);
+		webkit_web_view_set_settings(t->wv, t->settings);
+
+		t->load_images = FALSE;
+	}
+
 	/* if this is an xtp url, we don't load anything else */
 	if (parse_xtp_url(t, uri))
 		    return (TRUE);
@@ -5978,6 +6013,8 @@ setup_webkit(struct tab *t)
 	    "enable-developer-extras", TRUE, (char *)NULL);
 	g_object_set(G_OBJECT(t->wv),
 	    "full-content-zoom", TRUE, (char *)NULL);
+	g_object_set(G_OBJECT(t->settings),
+	    "auto-load-images", auto_load_images, (char *)NULL);
 
 	webkit_web_view_set_settings(t->wv, t->settings);
 }
@@ -6075,6 +6112,7 @@ create_browser(struct tab *t)
 		t->user_agent = g_strdup(user_agent->value);
 
 	t->stylesheet = g_strdup_printf("file://%s/style.css", resource_dir);
+	t->load_images = auto_load_images;
 
 	adjustment =
 	    gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(w));