static void changed_load_progress(GObject *, GParamSpec *, gpointer);
static void changed_title(GObject *, GParamSpec *, gpointer);
static void changed_uri(GObject *, GParamSpec *, gpointer);
+static gboolean crashed_web_view(WebKitWebView *, gpointer);
+static gboolean crashed_web_view_reload(gpointer);
static gboolean decide_policy(WebKitWebView *, WebKitPolicyDecision *,
WebKitPolicyDecisionType, gpointer);
static gboolean download_handle(WebKitDownload *, gchar *, gpointer);
static void download_handle_start(WebKitWebView *, WebKitDownload *, gpointer);
-static gboolean download_reset_indicator(gpointer);
static void downloadmanager_cancel(GtkToolButton *, gpointer data);
static void downloadmanager_setup(void);
static gchar *ensure_uri_scheme(const gchar *);
static gboolean remote_msg(GIOChannel *, GIOCondition, gpointer);
static void search(gpointer, gint);
static Window tabbed_launch(void);
+static void trust_user_certs(WebKitWebContext *);
static void usage(void);
GtkWidget *location;
GtkWidget *progress;
GtkWidget *scroll;
- GtkWidget *status;
GtkWidget *top_box;
GtkWidget *vbox;
GtkWidget *web_view;
} dm;
-static gchar *accepted_language = "en-US";
+static const gchar *accepted_language[2] = { NULL, NULL };
static gint clients = 0;
static gboolean cooperative_alone = TRUE;
static gboolean cooperative_instances = TRUE;
static int cooperative_pipe_fp = 0;
+static int crash_autoreload_delay = 2;
static gchar *download_dir = "/tmp";
-static gint downloads_indicated = 0;
static Window embed = 0;
static gchar *fifo_suffix = "main";
static gdouble global_zoom = 1.0;
static gchar *home_uri = "about:blank";
+static gboolean initial_wc_setup_done = FALSE;
static GHashTable *keywords = NULL;
-static gboolean language_is_set = FALSE;
static gchar *search_text = NULL;
-static gboolean show_all_requests = FALSE;
static gboolean tabbed_automagic = TRUE;
static gchar *user_agent = NULL;
+static gchar *web_extensions_dir = NULL;
void
c->web_view = webkit_web_view_new();
wc = webkit_web_view_get_context(WEBKIT_WEB_VIEW(c->web_view));
- /* XXX I really do want to enable this option. However, I get
- * reproducible crashes with it enabled. I've seen bug reports from
- * 2010 about this... WebKit crashes in libpixman, so maybe it's not
- * a WebKit issue.
- * Yeah, well. I'll turn it off for now. */
- /*webkit_web_view_set_full_content_zoom(WEBKIT_WEB_VIEW(c->web_view), TRUE);*/
-
webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), global_zoom);
g_signal_connect(G_OBJECT(c->web_view), "notify::title",
G_CALLBACK(changed_title), c);
G_CALLBACK(client_destroy_request), c);
g_signal_connect(G_OBJECT(c->web_view), "decide-policy",
G_CALLBACK(decide_policy), NULL);
- g_signal_connect(G_OBJECT(wc), "download-started",
- G_CALLBACK(download_handle_start), c);
g_signal_connect(G_OBJECT(c->web_view), "key-press-event",
G_CALLBACK(key_web_view), c);
g_signal_connect(G_OBJECT(c->web_view), "button-press-event",
G_CALLBACK(key_web_view), c);
g_signal_connect(G_OBJECT(c->web_view), "mouse-target-changed",
G_CALLBACK(hover_web_view), c);
+ g_signal_connect(G_OBJECT(c->web_view), "web-process-crashed",
+ G_CALLBACK(crashed_web_view), c);
- if (!language_is_set)
+ if (!initial_wc_setup_done)
{
- /* XXX make this pretty */
- const gchar *languages[2];
- languages[0] = accepted_language;
- languages[1] = NULL;
- webkit_web_context_set_preferred_languages(wc, languages);
- language_is_set = TRUE;
+ if (accepted_language[0] != NULL)
+ webkit_web_context_set_preferred_languages(wc, accepted_language);
+
+ g_signal_connect(G_OBJECT(wc), "download-started",
+ G_CALLBACK(download_handle_start), NULL);
+
+ trust_user_certs(wc);
+
+ initial_wc_setup_done = TRUE;
}
if (user_agent != NULL)
gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), 0);
gtk_widget_set_size_request(c->progress, 100, -1);
- c->status = gtk_level_bar_new();
- gtk_level_bar_set_value(GTK_LEVEL_BAR(c->status), 0);
- gtk_widget_set_size_request(c->status, 20, -1);
-
c->top_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_box_pack_start(GTK_BOX(c->top_box), c->status, FALSE, FALSE, 2);
- gtk_box_pack_start(GTK_BOX(c->top_box), c->location, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(c->top_box), c->location, TRUE, TRUE, 2);
gtk_box_pack_start(GTK_BOX(c->top_box), c->progress, FALSE, FALSE, 2);
c->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
if (uri != NULL)
{
f = ensure_uri_scheme(uri);
- if (show_all_requests)
- fprintf(stderr, "====> %s\n", uri);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
g_free(f);
}
gtk_entry_set_text(GTK_ENTRY(c->location), (t == NULL ? __NAME__ : t));
}
+gboolean
+crashed_web_view(WebKitWebView *web_view, gpointer data)
+{
+ fprintf(stderr, __NAME__": WebView crashed!\n");
+ if (crash_autoreload_delay >= 1)
+ {
+ fprintf(stderr, __NAME__": Reloading WebView in %d seconds.\n",
+ crash_autoreload_delay);
+ g_timeout_add_seconds(crash_autoreload_delay, crashed_web_view_reload,
+ web_view);
+ }
+
+ return TRUE;
+}
+
+gboolean
+crashed_web_view_reload(gpointer data)
+{
+ webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(data));
+
+ return G_SOURCE_REMOVE;
+}
+
gboolean
decide_policy(WebKitWebView *web_view, WebKitPolicyDecision *decision,
WebKitPolicyDecisionType type, gpointer data)
gboolean
download_handle(WebKitDownload *download, gchar *suggested_filename, gpointer data)
{
- struct Client *c = (struct Client *)data;
gchar *path, *path2 = NULL, *uri;
GtkToolItem *tb;
int suffix = 1;
webkit_download_set_destination(download, uri);
g_free(uri);
- gtk_level_bar_set_value(GTK_LEVEL_BAR(c->status), 1);
- downloads_indicated++;
- g_timeout_add(500, download_reset_indicator, c);
-
- tb = gtk_tool_button_new_from_stock(GTK_STOCK_DELETE);
+ tb = gtk_tool_button_new(NULL, NULL);
+ gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(tb), "gtk-delete");
gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), suggested_filename);
gtk_toolbar_insert(GTK_TOOLBAR(dm.toolbar), tb, 0);
- gtk_widget_show_all(dm.toolbar);
+ gtk_widget_show_all(dm.win);
g_signal_connect(G_OBJECT(download), "notify::estimated-progress",
G_CALLBACK(changed_download_progress), tb);
return FALSE;
}
-gboolean
-download_reset_indicator(gpointer data)
-{
- struct Client *c = (struct Client *)data;
-
- downloads_indicated--;
- if (downloads_indicated == 0)
- gtk_level_bar_set_value(GTK_LEVEL_BAR(c->status), 0);
-
- return FALSE;
-}
-
void
downloadmanager_cancel(GtkToolButton *tb, gpointer data)
{
dm.scroll = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dm.scroll),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(dm.scroll),
- dm.toolbar);
+ gtk_container_add(GTK_CONTAINER(dm.scroll), dm.toolbar);
gtk_container_add(GTK_CONTAINER(dm.win), dm.scroll);
}
e = g_getenv(__NAME_UPPERCASE__"_ACCEPTED_LANGUAGE");
if (e != NULL)
- accepted_language = g_strdup(e);
+ accepted_language[0] = g_strdup(e);
+
+ e = g_getenv(__NAME_UPPERCASE__"_CRASH_AUTORELOAD_DELAY");
+ if (e != NULL)
+ crash_autoreload_delay = atoi(e);
e = g_getenv(__NAME_UPPERCASE__"_DOWNLOAD_DIR");
if (e != NULL)
if (e != NULL)
user_agent = g_strdup(e);
+ e = g_getenv(__NAME_UPPERCASE__"_WEB_EXTENSIONS_DIR");
+ if (e != NULL)
+ web_extensions_dir = g_strdup(e);
+ else
+ web_extensions_dir = g_build_filename(g_get_user_data_dir(), __NAME__,
+ "web_extensions", NULL);
+
e = g_getenv(__NAME_UPPERCASE__"_ZOOM");
if (e != NULL)
global_zoom = atof(e);
struct Client *c = (struct Client *)data;
const gchar *t;
gchar *f;
+ WebKitWebContext *wc = webkit_web_view_get_context(WEBKIT_WEB_VIEW(c->web_view));
if (event->type == GDK_KEY_PRESS)
{
gtk_entry_set_text(GTK_ENTRY(c->location), "/");
gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
return TRUE;
+ case GDK_KEY_c: /* reload trusted certs (left hand) */
+ trust_user_certs(wc);
+ return TRUE;
}
}
else
else if (!keywords_try_search(WEBKIT_WEB_VIEW(c->web_view), t))
{
f = ensure_uri_scheme(t);
- if (show_all_requests)
- fprintf(stderr, "====> %s\n", f);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
g_free(f);
}
key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data)
{
struct Client *c = (struct Client *)data;
+ gdouble dx, dy;
gchar *f;
gfloat z;
- gboolean b;
+ WebKitWebContext *wc = webkit_web_view_get_context(WEBKIT_WEB_VIEW(c->web_view));
if (event->type == GDK_KEY_PRESS)
{
return TRUE;
case GDK_KEY_w: /* home (left hand) */
f = ensure_uri_scheme(home_uri);
- if (show_all_requests)
- fprintf(stderr, "====> %s\n", f);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
g_free(f);
return TRUE;
case GDK_KEY_e: /* new tab (left hand) */
f = ensure_uri_scheme(home_uri);
- if (show_all_requests)
- fprintf(stderr, "====> %s\n", f);
client_new(f);
g_free(f);
return TRUE;
webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(
c->web_view));
return TRUE;
-#if 0
- case GDK_KEY_s: /* toggle source view (left hand) */
- b = webkit_web_view_get_view_source_mode(WEBKIT_WEB_VIEW(
- c->web_view));
- b = !b;
- webkit_web_view_set_view_source_mode(WEBKIT_WEB_VIEW(
- c->web_view), b);
- webkit_web_view_reload(WEBKIT_WEB_VIEW(c->web_view));
- return TRUE;
-#endif
case GDK_KEY_d: /* download manager (left hand) */
gtk_widget_show_all(dm.win);
return TRUE;
gtk_entry_set_text(GTK_ENTRY(c->location), "/");
gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
return TRUE;
+ case GDK_KEY_c: /* reload trusted certs (left hand) */
+ trust_user_certs(wc);
+ return TRUE;
}
}
else if (((GdkEventKey *)event)->keyval == GDK_KEY_Escape)
if (((GdkEventScroll *)event)->state & GDK_MOD1_MASK ||
((GdkEventScroll *)event)->state & GDK_CONTROL_MASK)
{
- switch (((GdkEventScroll *)event)->direction)
- {
- case GDK_SCROLL_UP:
- z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(c->web_view));
- z += 0.1;
- webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), z);
- return TRUE;
- case GDK_SCROLL_DOWN:
- z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(c->web_view));
- z -= 0.1;
- webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), z);
- return TRUE;
- default:
- break;
- }
+ gdk_event_get_scroll_deltas(event, &dx, &dy);
+ z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(c->web_view));
+ z += -dy * 0.1;
+ z = dx != 0 ? global_zoom : z;
+ webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), z);
+ return TRUE;
}
}
if (val != NULL)
{
uri = g_strdup_printf((gchar *)val, tokens[1]);
- if (show_all_requests)
- fprintf(stderr, "====> %s\n", uri);
webkit_web_view_load_uri(web_view, uri);
g_free(uri);
ret = TRUE;
return plug_into;
}
+void
+trust_user_certs(WebKitWebContext *wc)
+{
+ GTlsCertificate *cert;
+ const gchar *basedir, *file, *absfile;
+ GDir *dir;
+
+ basedir = g_build_filename(g_get_user_config_dir(), __NAME__, "certs", NULL);
+ dir = g_dir_open(basedir, 0, NULL);
+ if (dir != NULL)
+ {
+ file = g_dir_read_name(dir);
+ while (file != NULL)
+ {
+ absfile = g_build_filename(g_get_user_config_dir(), __NAME__, "certs",
+ file, NULL);
+ cert = g_tls_certificate_new_from_file(absfile, NULL);
+ if (cert == NULL)
+ fprintf(stderr, __NAME__": Could not load trusted cert '%s'\n", file);
+ else
+ webkit_web_context_allow_tls_certificate_for_host(wc, cert, file);
+ file = g_dir_read_name(dir);
+ }
+ g_dir_close(dir);
+ }
+}
+
void
usage(void)
{
grab_environment_configuration();
- while ((opt = getopt(argc, argv, "e:rCT")) != -1)
+ while ((opt = getopt(argc, argv, "e:CT")) != -1)
{
switch (opt)
{
embed = atol(optarg);
tabbed_automagic = FALSE;
break;
- case 'r':
- show_all_requests = TRUE;
- break;
case 'C':
cooperative_instances = FALSE;
break;
if (tabbed_automagic && !(cooperative_instances && !cooperative_alone))
embed = tabbed_launch();
+ if (!cooperative_instances || cooperative_alone)
+ webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(),
+ web_extensions_dir);
+
if (optind >= argc)
client_new(home_uri);
else