Request cookiemanager only once at creation
[surf.git] / surf.c
diff --git a/surf.c b/surf.c
index ae2bc81..6950dc5 100644 (file)
--- a/surf.c
+++ b/surf.c
@@ -206,6 +206,9 @@ static void downloadstarted(WebKitWebContext *wc, WebKitDownload *d,
                             Client *c);
 static void responsereceived(WebKitDownload *d, GParamSpec *ps, Client *c);
 static void download(Client *c, WebKitURIResponse *r);
+static void webprocessterminated(WebKitWebView *v,
+                                 WebKitWebProcessTerminationReason r,
+                                 Client *c);
 static void closeview(WebKitWebView *v, Client *c);
 static void destroywin(GtkWidget* w, Client *c);
 
@@ -1076,6 +1079,7 @@ newview(Client *c, WebKitWebView *rv)
        WebKitSettings *settings;
        WebKitUserContentManager *contentmanager;
        WebKitWebContext *context;
+       WebKitCookieManager *cookiemanager;
 
        /* Webview */
        if (rv) {
@@ -1122,6 +1126,8 @@ newview(Client *c, WebKitWebView *rv)
                          "base-data-directory", cachedir,
                          NULL));
 
+               cookiemanager = webkit_web_context_get_cookie_manager(context);
+
                /* rendering process model, can be a shared unique one
                 * or one for each view */
                webkit_web_context_set_process_model(context,
@@ -1136,12 +1142,10 @@ newview(Client *c, WebKitWebView *rv)
                    WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
 
                /* Currently only works with text file to be compatible with curl */
-               webkit_cookie_manager_set_persistent_storage(
-                   webkit_web_context_get_cookie_manager(context), cookiefile,
-                   WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
+               webkit_cookie_manager_set_persistent_storage(cookiemanager,
+                   cookiefile, WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
                /* cookie policy */
-               webkit_cookie_manager_set_accept_policy(
-                   webkit_web_context_get_cookie_manager(context),
+               webkit_cookie_manager_set_accept_policy(cookiemanager,
                    cookiepolicy_get());
                /* languages */
                webkit_web_context_set_preferred_languages(context,
@@ -1187,6 +1191,8 @@ newview(Client *c, WebKitWebView *rv)
                         G_CALLBACK(permissionrequested), c);
        g_signal_connect(G_OBJECT(v), "ready-to-show",
                         G_CALLBACK(showview), c);
+       g_signal_connect(G_OBJECT(v), "web-process-terminated",
+                        G_CALLBACK(webprocessterminated), c);
 
        return v;
 }
@@ -1691,6 +1697,15 @@ download(Client *c, WebKitURIResponse *r)
        spawn(c, &a);
 }
 
+void
+webprocessterminated(WebKitWebView *v, WebKitWebProcessTerminationReason r,
+                     Client *c)
+{
+       fprintf(stderr, "web process terminated: %s\n",
+               r == WEBKIT_WEB_PROCESS_CRASHED ? "crashed" : "no memory");
+       closeview(v, c);
+}
+
 void
 closeview(WebKitWebView *v, Client *c)
 {