Summary Files Commits Branches @commit @diff @stats
path: root / badwolf.c
blob: 86c994b1e0099a6f28567296b9030835f20b9d24 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// BadWolf: Minimalist and privacy-oriented WebKitGTK+ browser
// Copyright © 2019 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
// SPDX-License-Identifier: BSD-3-Clause

#include <gtk/gtk.h>
#include <webkit2/webkit2.h>

static gboolean WebViewCb_close(WebKitWebView *_webView, GtkWidget *window)
{
	gtk_widget_destroy(window);
	return TRUE;
}

static gboolean WebViewCb_notify__uri(WebKitWebView *webView, GtkWidget *location)
{
	const gchar *location_uri;

	location_uri = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(webView));

	gtk_entry_set_text(GTK_ENTRY(location), location_uri);

	return TRUE;
}

int main(int argc, char *argv[])
{
	char *target_url = "about:blank";
	GtkWidget *main_window, *box, *location;
	WebKitWebView *webView;

	if(argv[1]) target_url = argv[1];

	gtk_init(0, 0);

	main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	location    = gtk_entry_new();
	box         = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
	webView     = WEBKIT_WEB_VIEW(webkit_web_view_new());

	gtk_container_add(GTK_CONTAINER(main_window), box);
	gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(location), FALSE, FALSE, 0);
	gtk_box_pack_end(GTK_BOX(box), GTK_WIDGET(webView), TRUE, TRUE, 0);

	gtk_entry_set_text(GTK_ENTRY(location), target_url);

	g_signal_connect(main_window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
	g_signal_connect(webView, "close", G_CALLBACK(WebViewCb_close), main_window);
	g_signal_connect(webView, "notify::uri", G_CALLBACK(WebViewCb_notify__uri), location);

	WebKitSettings *settings = webkit_web_view_get_settings(webView);

	webkit_settings_set_javascript_can_access_clipboard(settings, FALSE);
	webkit_settings_set_enable_developer_extras(settings, TRUE);
	webkit_settings_set_default_charset(settings, "utf-8");

	webkit_web_view_set_settings(webView, settings);

	webkit_web_view_load_uri(webView, target_url);

	gtk_widget_grab_focus(GTK_WIDGET(webView));
	gtk_widget_show_all(main_window);
	gtk_main();
	return 0;
}