-void
-mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers,
- Client *c)
-{
- WebKitHitTestResultContext hc;
-
- /* Keep the hit test to know where is the pointer on the next click */
- c->mousepos = h;
-
- hc = webkit_hit_test_result_get_context(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;
- updatetitle(c);
-}
-
-void
-loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c)
-{
- switch (e) {
- case WEBKIT_LOAD_STARTED:
- c->tlsflags = G_TLS_CERTIFICATE_VALIDATE_ALL + 1;
- break;
- case WEBKIT_LOAD_REDIRECTED:
- setatom(c, AtomUri, geturi(c));
- break;
- case WEBKIT_LOAD_COMMITTED:
- if (!webkit_web_view_get_tls_info(c->view, NULL, &(c->tlsflags)))
- c->tlsflags = G_TLS_CERTIFICATE_VALIDATE_ALL + 1;
-
- setatom(c, AtomUri, geturi(c));
-
- if (enablestyle)
- setstyle(c, getstyle(geturi(c)));
- 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
-loaduri(Client *c, const Arg *arg)
-{
- char *u = NULL, *rp;
- const char *uri = (char *)arg->v;
- Arg a = { .b = FALSE };
- struct stat st;
-
- if (strcmp(uri, "") == 0)
- return;
-
- /* In case it's a file path. */
- if (stat(uri, &st) == 0) {
- rp = realpath(uri, NULL);
- u = g_strdup_printf("file://%s", rp);
- free(rp);
- } else {
- u = g_strrstr(uri, "://") ? g_strdup(uri)
- : g_strdup_printf("http://%s", uri);
- }
-
- setatom(c, AtomUri, uri);
-
- /* prevents endless loop */
- if (strcmp(u, geturi(c)) == 0) {
- reload(c, &a);
- } else {
- webkit_web_view_load_uri(c->view, u);
- c->progress = 0;
- c->title = copystr(&c->title, u);
- updatetitle(c);
- }
- g_free(u);
-}
-
-void
-navigate(Client *c, const Arg *a)
-{
- if (a->i < 0)
- webkit_web_view_go_back(c->view);
- else if (a->i > 0)
- webkit_web_view_go_forward(c->view);
-}
-
-Client *
-newclient(Client *rc)
-{
- Client *c;
- gdouble dpi;
-
- if (!(c = calloc(1, sizeof(Client))))
- die("Cannot malloc!\n");
-
- c->title = NULL;
- c->progress = 100;
-
- c->next = clients;
- clients = c;
-
- c->view = newview(c, rc ? rc->view : NULL);
- c->tlsflags = G_TLS_CERTIFICATE_VALIDATE_ALL + 1;
-
- return c;
-}
-
-WebKitWebView *
-newview(Client *c, WebKitWebView *rv)
-{
- WebKitWebView *v;
- WebKitSettings *settings;
- WebKitUserContentManager *contentmanager;
- WebKitWebContext *context;
- char *ua;
-
- /* Webview */
- if (rv) {
- v = WEBKIT_WEB_VIEW(
- webkit_web_view_new_with_related_view(rv));
- } else {
- settings = webkit_settings_new_with_settings(
- "auto-load-images", loadimages,
- "default-font-size", defaultfontsize,
- "enable-caret-browsing", enablecaretbrowsing,
- "enable-developer-extras", enableinspector,
- "enable-dns-prefetching", enablednsprefetching,
- "enable-frame-flattening", enableframeflattening,
- "enable-html5-database", enablecache,
- "enable-html5-local-storage", enablecache,
- "enable-javascript", enablescripts,
- "enable-plugins", enableplugins,
- NULL);
- if (!(ua = getenv("SURF_USERAGENT")))
- ua = useragent;
- webkit_settings_set_user_agent(settings, ua);
- /* Have a look at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html
- * for more interesting settings */
-
- contentmanager = webkit_user_content_manager_new();
-
- context = webkit_web_context_new_with_website_data_manager(
- webkit_website_data_manager_new(
- "base-cache-directory", cachedir,
- "base-data-directory", cachedir,
- NULL));
-
- /* rendering process model, can be a shared unique one or one for each
- * view */
- webkit_web_context_set_process_model(context,
- WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
- /* ssl */
- webkit_web_context_set_tls_errors_policy(context, strictssl ?
- WEBKIT_TLS_ERRORS_POLICY_FAIL : WEBKIT_TLS_ERRORS_POLICY_IGNORE);
- /* disk cache */
- webkit_web_context_set_cache_model(context, enablecache ?
- WEBKIT_CACHE_MODEL_WEB_BROWSER : 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);
- /* cookie policy */
- webkit_cookie_manager_set_accept_policy(
- webkit_web_context_get_cookie_manager(context),
- cookiepolicy_get());