about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--settings.c19
-rw-r--r--xxxterm.14
-rw-r--r--xxxterm.c38
-rw-r--r--xxxterm.conf1
-rw-r--r--xxxterm.h2
5 files changed, 63 insertions, 1 deletions
diff --git a/settings.c b/settings.c
index 9ff0137..a8da3d5 100644
--- a/settings.c
+++ b/settings.c
@@ -91,6 +91,7 @@ int		autofocus_onload = 0;
 int		js_autorun_enabled = 1;
 int		edit_mode = XT_EM_HYBRID;
 int		userstyle_global = 0;
+int		auto_load_images = 1;
 
 char		*cmd_font_name = NULL;
 char		*oops_font_name = NULL;
@@ -119,6 +120,7 @@ int		set_tab_style(struct settings *, char *);
 int		set_edit_mode(struct settings *, char *);
 int		set_work_dir(struct settings *, char *);
 int		set_ua_roundrobin(char *);
+int		set_auto_load_images(char *value);
 
 void		walk_mime_type(struct settings *, void (*)(struct settings *,
 		    char *, void *), void *);
@@ -306,7 +308,8 @@ struct settings		rs[] = {
 	{ "window_maximize",		XT_S_INT, 0,		&window_maximize, NULL, NULL },
 	{ "work_dir",			XT_S_STR, 0, NULL, NULL,&s_work_dir },
 	{ "xterm_workaround",		XT_S_INT, 0,		&xterm_workaround, NULL, NULL },
-	{ "user_agent_roundrobin",	XT_S_INT, 0,	&user_agent_roundrobin, NULL, NULL, NULL, set_ua_roundrobin },
+	{ "user_agent_roundrobin",	XT_S_INT, 0,		&user_agent_roundrobin, NULL, NULL, NULL, set_ua_roundrobin },
+	{ "auto_load_images",		XT_S_INT, 0, 		&auto_load_images, NULL, NULL, NULL, set_auto_load_images },
 
 	/* font settings */
 	{ "cmd_font",			XT_S_STR, 0, NULL, &cmd_font_name, NULL },
@@ -978,6 +981,20 @@ set_ua_roundrobin(char *value)
 	return (0);
 }
 
+int
+set_auto_load_images(char *value)
+{
+	struct tab *t;
+
+	auto_load_images = atoi(value);
+	TAILQ_FOREACH(t, &tabs, entry) {
+		g_object_set(G_OBJECT(t->settings),
+		    "auto-load-images", auto_load_images, (char *)NULL);
+		webkit_web_view_set_settings(t->wv, t->settings);
+	}
+	return (0);
+}
+
 void
 setup_proxy(char *uri)
 {
diff --git a/xxxterm.1 b/xxxterm.1
index afab5c3..b9c2b14 100644
--- a/xxxterm.1
+++ b/xxxterm.1
@@ -508,6 +508,8 @@ Shows all session entries in the JS whitelist.
 Toggle Java Script execution for the current FQDN.
 .It Cm js toggle domain
 Toggle Java Script execution for the current top level domain.
+.It Cm loadimages
+If auto_load_images is disabled, load all images for current site.
 .It Cm open , op , o URL
 Open URL.
 .It Cm plugin
@@ -911,6 +913,8 @@ Unfortunately enabling this does allow for some limited tracking on the web.
 .It Cm append_next
 When set a new tab is appended after the current tab instead of being appended
 as the last tab.
+.It Cm auto_load_images
+If disabled, images will not be loaded automatically.
 .It Cm autofocus_onload
 When set a tab that is loaded will attempt to autofocus the default input
 entry.
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));
diff --git a/xxxterm.conf b/xxxterm.conf
index 79a609a..10bda14 100644
--- a/xxxterm.conf
+++ b/xxxterm.conf
@@ -37,6 +37,7 @@
 # autofocus_onload	= 1
 # encoding		= UTF-8
 # js_autorun_enabled	= 0
+# auto_load_images	= 1
 
 #
 # default_script points to a script executed by the run_script command.
diff --git a/xxxterm.h b/xxxterm.h
index df76489..3558ed0 100644
--- a/xxxterm.h
+++ b/xxxterm.h
@@ -226,6 +226,7 @@ struct tab {
 	/* settings */
 	WebKitWebSettings	*settings;
 	gchar			*user_agent;
+	gboolean		load_images;
 
 	/* marks */
 	double			mark[XT_NOMARKS];
@@ -548,6 +549,7 @@ extern char	*statusbar_font_name;
 extern char	*tabbar_font_name;
 extern int	edit_mode;
 extern int	userstyle_global;
+extern int	auto_load_images;
 
 /* globals */
 extern char		*version;