+ gtk_window_set_default_size(GTK_WINDOW(w), winsize[0], winsize[1]);
+ }
+
+ g_signal_connect(G_OBJECT(w), "destroy",
+ G_CALLBACK(destroywin), c);
+ g_signal_connect(G_OBJECT(w), "enter-notify-event",
+ G_CALLBACK(winevent), c);
+ g_signal_connect(G_OBJECT(w), "key-press-event",
+ G_CALLBACK(winevent), c);
+ g_signal_connect(G_OBJECT(w), "leave-notify-event",
+ G_CALLBACK(winevent), c);
+ g_signal_connect(G_OBJECT(w), "window-state-event",
+ G_CALLBACK(winevent), c);
+
+ return w;
+}
+
+gboolean
+loadfailedtls(WebKitWebView *v, gchar *uri, GTlsCertificate *cert,
+ GTlsCertificateFlags err, Client *c)
+{
+ GString *errmsg = g_string_new(NULL);
+ gchar *html, *pem;
+
+ c->failedcert = g_object_ref(cert);
+ c->tlserr = err;
+ c->errorpage = 1;
+
+ if (err & G_TLS_CERTIFICATE_UNKNOWN_CA)
+ g_string_append(errmsg,
+ "The signing certificate authority is not known.<br>");
+ if (err & G_TLS_CERTIFICATE_BAD_IDENTITY)
+ g_string_append(errmsg,
+ "The certificate does not match the expected identity "
+ "of the site that it was retrieved from.<br>");
+ if (err & G_TLS_CERTIFICATE_NOT_ACTIVATED)
+ g_string_append(errmsg,
+ "The certificate's activation time "
+ "is still in the future.<br>");
+ if (err & G_TLS_CERTIFICATE_EXPIRED)
+ g_string_append(errmsg, "The certificate has expired.<br>");
+ if (err & G_TLS_CERTIFICATE_REVOKED)
+ g_string_append(errmsg,
+ "The certificate has been revoked according to "
+ "the GTlsConnection's certificate revocation list.<br>");
+ if (err & G_TLS_CERTIFICATE_INSECURE)
+ g_string_append(errmsg,
+ "The certificate's algorithm is considered insecure.<br>");
+ if (err & G_TLS_CERTIFICATE_GENERIC_ERROR)
+ g_string_append(errmsg,
+ "Some error occurred validating the certificate.<br>");
+
+ g_object_get(cert, "certificate-pem", &pem, NULL);
+ html = g_strdup_printf("<p>Could not validate TLS for “%s”<br>%s</p>"
+ "<p>You can inspect the following certificate "
+ "with Ctrl+Shift+x (default keybinding).</p>"
+ "<p><pre>%s</pre></p>", uri, errmsg->str, pem);
+ g_free(pem);
+ g_string_free(errmsg, TRUE);
+
+ webkit_web_view_load_alternate_html(c->view, html, uri, NULL);
+ g_free(html);
+
+ return TRUE;
+}
+
+void
+loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c)
+{
+ const char *title = geturi(c);
+
+ switch (e) {
+ case WEBKIT_LOAD_STARTED:
+ curconfig = defconfig;
+ setatom(c, AtomUri, title);
+ c->title = title;
+ c->https = c->insecure = 0;
+ seturiparameters(c, geturi(c));
+ if (c->errorpage)
+ c->errorpage = 0;
+ else
+ g_clear_object(&c->failedcert);
+ break;
+ case WEBKIT_LOAD_REDIRECTED:
+ setatom(c, AtomUri, title);
+ c->title = title;
+ seturiparameters(c, geturi(c));
+ break;
+ case WEBKIT_LOAD_COMMITTED:
+ c->https = webkit_web_view_get_tls_info(c->view, &c->cert,
+ &c->tlserr);
+ break;
+ case WEBKIT_LOAD_FINISHED:
+ /* Disabled until we write some WebKitWebExtension for
+ * manipulating the DOM directly.
+ evalscript(c, "document.documentElement.style.overflow = '%s'",
+ enablescrollbars ? "auto" : "hidden");
+ */
+ runscript(c);
+ break;
+ }
+ updatetitle(c);
+}
+
+void
+progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c)
+{
+ c->progress = webkit_web_view_get_estimated_load_progress(c->view) *
+ 100;
+ updatetitle(c);
+}
+
+void
+titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c)
+{
+ c->title = webkit_web_view_get_title(c->view);
+ updatetitle(c);
+}
+
+void
+mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers,
+ Client *c)
+{
+ WebKitHitTestResultContext hc = webkit_hit_test_result_get_context(h);
+
+ /* Keep the hit test to know where is the pointer on the next click */
+ c->mousepos = h;
+
+ if (hc & OnLink)
+ c->targeturi = webkit_hit_test_result_get_link_uri(h);
+ else if (hc & OnImg)
+ c->targeturi = webkit_hit_test_result_get_image_uri(h);
+ else if (hc & OnMedia)
+ c->targeturi = webkit_hit_test_result_get_media_uri(h);
+ else
+ c->targeturi = NULL;
+
+ c->overtitle = c->targeturi;
+ updatetitle(c);
+}
+
+gboolean
+permissionrequested(WebKitWebView *v, WebKitPermissionRequest *r, Client *c)
+{
+ if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(r)) {
+ if (curconfig[Geolocation].val.b)
+ webkit_permission_request_allow(r);
+ else
+ webkit_permission_request_deny(r);
+ return TRUE;