summaryrefslogtreecommitdiff
path: root/browser.c
diff options
context:
space:
mode:
authorPeter Hofmann <scm@uninformativ.de>2015-01-01 09:30:04 +0100
committerPeter Hofmann <scm@uninformativ.de>2015-01-01 09:30:04 +0100
commit6c08b700b523a7444351f9911d3862d3112c4578 (patch)
tree87395bdd4b3eb7716d61820f4a311daaa40787b0 /browser.c
parent7e426ffa6a3da51e9d2957486d495e80e1dea4d8 (diff)
downloadlariza-6c08b700b523a7444351f9911d3862d3112c4578.tar.gz
Automatically recover from WebKit crashes
Diffstat (limited to 'browser.c')
-rw-r--r--browser.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/browser.c b/browser.c
index 0479803..1b12fe1 100644
--- a/browser.c
+++ b/browser.c
@@ -22,6 +22,8 @@ static void changed_download_progress(GObject *, GParamSpec *, gpointer);
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);
@@ -67,6 +69,7 @@ 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 Window embed = 0;
static gchar *fifo_suffix = "main";
@@ -173,6 +176,8 @@ client_new(const gchar *uri)
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 (!initial_wc_setup_done)
{
@@ -336,6 +341,29 @@ changed_uri(GObject *obj, GParamSpec *pspec, gpointer data)
}
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)
{
@@ -479,6 +507,10 @@ grab_environment_configuration(void)
if (e != NULL)
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)
download_dir = g_strdup(e);