-void
-evalscript(JSContextRef js, char *script, char* scriptname)
-{
- JSStringRef jsscript, jsscriptname;
- JSValueRef exception = NULL;
-
- jsscript = JSStringCreateWithUTF8CString(script);
- jsscriptname = JSStringCreateWithUTF8CString(scriptname);
- JSEvaluateScript(js, jsscript, JSContextGetGlobalObject(js),
- jsscriptname, 0, &exception);
- JSStringRelease(jsscript);
- JSStringRelease(jsscriptname);
-}
-
-void
-runscript(WebKitWebFrame *frame)
-{
- char *script;
- GError *error;
-
- if (g_file_get_contents(scriptfile, &script, NULL, &error)) {
- evalscript(webkit_web_frame_get_global_context(frame), script,
- scriptfile);
- }
-}
-
-void
-clipboard(Client *c, const Arg *arg)
-{
- gboolean paste = *(gboolean *)arg;
-
- if (paste) {
- gtk_clipboard_request_text(gtk_clipboard_get(
- GDK_SELECTION_PRIMARY),
- pasteuri, c);
- } else {
- gtk_clipboard_set_text(gtk_clipboard_get(
- GDK_SELECTION_PRIMARY), c->linkhover
- ? c->linkhover : geturi(c), -1);
- }
-}
-
-char *
-copystr(char **str, const char *src)
-{
- char *tmp;
- tmp = g_strdup(src);
-
- if (str && *str) {
- g_free(*str);
- *str = tmp;
- }
- return tmp;
-}
-
-WebKitWebView *
-createwindow(WebKitWebView *v, WebKitWebFrame *f, Client *c)
-{
- Client *n = newclient();
- return n->view;
-}
-
-gboolean
-decidedownload(WebKitWebView *v, WebKitWebFrame *f, WebKitNetworkRequest *r,
- gchar *m, WebKitWebPolicyDecision *p, Client *c)
-{
- if (!webkit_web_view_can_show_mime_type(v, m)) {
- webkit_web_policy_decision_download(p);
- return TRUE;
- }
- return FALSE;
-}
-
-gboolean
-decidewindow(WebKitWebView *view, WebKitWebFrame *f, WebKitNetworkRequest *r,
- WebKitWebNavigationAction *n, WebKitWebPolicyDecision *p,
- Client *c)
-{
- Arg arg;
-
- if (webkit_web_navigation_action_get_reason(n)
- == WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED) {
- webkit_web_policy_decision_ignore(p);
- arg.v = (void *)webkit_network_request_get_uri(r);
- newwindow(NULL, &arg, 0);
- return TRUE;
- }
- return FALSE;
-}
-
-gboolean
-deletion_interface(WebKitWebView *view, WebKitDOMHTMLElement *arg1, Client *c)
-{
- return FALSE;
-}
-
-void
-destroyclient(Client *c)
-{
- Client *p;
-
- webkit_web_view_stop_loading(c->view);
- gtk_widget_destroy(GTK_WIDGET(c->view));
- gtk_widget_destroy(c->scroll);
- gtk_widget_destroy(c->vbox);
- gtk_widget_destroy(c->win);
-
- for (p = clients; p && p->next != c; p = p->next)
- ;
- if (p)
- p->next = c->next;
- else
- clients = c->next;
- free(c);
- if (clients == NULL)
- gtk_main_quit();
-}
-
-void
-destroywin(GtkWidget* w, Client *c)
-{
- destroyclient(c);
-}
-
-void
-die(const char *errstr, ...)
-{
- va_list ap;
-
- va_start(ap, errstr);
- vfprintf(stderr, errstr, ap);
- va_end(ap);
- exit(EXIT_FAILURE);
-}
-
-void
-find(Client *c, const Arg *arg)
-{
- const char *s;
-
- s = getatom(c, AtomFind);
- gboolean forward = *(gboolean *)arg;
- webkit_web_view_search_text(c->view, s, FALSE, forward, TRUE);
-}
-
-void
-fullscreen(Client *c, const Arg *arg)
-{
- if (c->fullscreen)
- gtk_window_unfullscreen(GTK_WINDOW(c->win));
- else
- gtk_window_fullscreen(GTK_WINDOW(c->win));
- c->fullscreen = !c->fullscreen;
-}
-
-void
-geopolicyrequested(WebKitWebView *v, WebKitWebFrame *f,
- WebKitGeolocationPolicyDecision *d, Client *c)
-{
- if (allowgeolocation)
- webkit_geolocation_policy_allow(d);
- else
- webkit_geolocation_policy_deny(d);
-}
-
-const char *
-getatom(Client *c, int a)
-{
- static char buf[BUFSIZ];
- Atom adummy;
- int idummy;
- unsigned long ldummy;
- unsigned char *p = NULL;
-
- XGetWindowProperty(dpy, c->xid,
- atoms[a], 0L, BUFSIZ, False, XA_STRING,
- &adummy, &idummy, &ldummy, &ldummy, &p);
- if (p)
- strncpy(buf, (char *)p, LENGTH(buf)-1);
- else
- buf[0] = '\0';
- XFree(p);
-
- return buf;
-}
-
-char *
-geturi(Client *c)
-{
- char *uri;
-
- if (!(uri = (char *)webkit_web_view_get_uri(c->view)))
- uri = "about:blank";
- return uri;
-}
-
-const gchar *
-getstyle(const char *uri)