]> git.armaanb.net Git - chorizo.git/commitdiff
Automatically recover from WebKit crashes
authorPeter Hofmann <scm@uninformativ.de>
Thu, 1 Jan 2015 08:30:04 +0000 (09:30 +0100)
committerPeter Hofmann <scm@uninformativ.de>
Thu, 1 Jan 2015 08:30:04 +0000 (09:30 +0100)
README
browser.c

diff --git a/README b/README
index b706069d15d615aa0e6489969f19e1ab579f4e84..9ce8511b9fec147eaf7b13692e8a1d74d803cfdc 100644 (file)
--- a/README
+++ b/README
@@ -236,6 +236,17 @@ following environment variables:
         In HTTP requests, WebKit sets the "Accepted-Language" header to
         this value. Defaults to "en-US".
 
+    LARIZA_CRASH_AUTORELOAD_DELAY
+        If/when the WebKit process crashes, lariza's main process will
+        receive a signal and can act accordingly. The default value of
+        this variable is "2", which means that lariza will wait two
+        seconds and then reload each window/tab.
+
+        If you set $LARIZA_CRASH_AUTORELOAD_DELAY to zero or any
+        negative value, then lariza will not automatically reload
+        anything. Note, however, that you can still do this manually by
+        pressing the "reload" hotkey for each window.
+
     LARIZA_DOWNLOAD_DIR
         All downloads are automatically stored in this directory.
         Defaults to "/tmp".
index 04798038e216fcb5487e5c218e4539037712a5e7..1b12fe184134a2b1b023a4d4a8e4e883b65a43a2 100644 (file)
--- 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)
        {
@@ -335,6 +340,29 @@ changed_uri(GObject *obj, GParamSpec *pspec, gpointer data)
        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)
@@ -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);