diff -r dbb565b8d61c surf.c --- a/surf.c Fri Jun 25 09:42:58 2010 +0200 +++ b/surf.c Sat Aug 14 14:38:17 2010 +0200 @@ -23,7 +23,7 @@ #define LENGTH(x) (sizeof x / sizeof x[0]) #define CLEANMASK(mask) (mask & ~(GDK_MOD2_MASK)) -enum { AtomFind, AtomGo, AtomUri, AtomLast }; +enum { AtomFind, AtomGo, AtomUri, AtomScriptFile, AtomLast }; typedef union Arg Arg; union Arg { @@ -145,13 +145,15 @@ } void -runscript(WebKitWebFrame *frame, JSContextRef js) { +runscript(const char * filename, WebKitWebFrame *frame, JSContextRef js) { JSStringRef jsscript; char *script; JSValueRef exception = NULL; GError *error; - if(g_file_get_contents(scriptfile, &script, NULL, &error)) { + if (filename == NULL || filename[0] == '\0') + return; + if(g_file_get_contents(filename, &script, NULL, &error)) { jsscript = JSStringCreateWithUTF8CString(script); JSEvaluateScript(js, jsscript, JSContextGetGlobalObject(js), NULL, 0, &exception); } @@ -370,10 +372,12 @@ switch(webkit_web_view_get_load_status (c->view)) { case WEBKIT_LOAD_COMMITTED: setatom(c, AtomUri, geturi(c)); + PAGE_LOAD_COMMITTED(c); break; case WEBKIT_LOAD_FINISHED: c->progress = 0; update(c); + PAGE_LOAD_FINISHED(c); break; default: break; @@ -390,6 +394,7 @@ return; u = g_strrstr(uri, "://") ? g_strdup(uri) : g_strdup_printf("http://%s", uri); + updatewinid(c); /* prevents endless loop */ if(c->uri && strcmp(u, c->uri) == 0) { reload(c, &a); @@ -490,7 +495,7 @@ gdk_window_add_filter(GTK_WIDGET(c->win)->window, processx, c); webkit_web_view_set_full_content_zoom(c->view, TRUE); frame = webkit_web_view_get_main_frame(c->view); - runscript(frame, webkit_web_frame_get_global_context(frame)); + runscript(scriptfile, frame, webkit_web_frame_get_global_context(frame)); settings = webkit_web_view_get_settings(c->view); if(!(ua = getenv("SURF_USERAGENT"))) ua = useragent; @@ -506,6 +511,7 @@ setatom(c, AtomFind, ""); setatom(c, AtomUri, "about:blank"); + setatom(c, AtomScriptFile, ""); if(NOBACKGROUND) webkit_web_view_set_transparent(c->view, TRUE); @@ -579,6 +585,7 @@ Client *c = (Client *)d; XPropertyEvent *ev; Arg arg; + WebKitWebFrame *frame; if(((XEvent *)e)->type == PropertyNotify) { ev = &((XEvent *)e)->xproperty; @@ -593,6 +600,12 @@ loaduri(c, &arg); return GDK_FILTER_REMOVE; } + else if(ev->atom == atoms[AtomScriptFile]) { + arg.v = getatom(c, AtomScriptFile); + frame = webkit_web_view_get_main_frame(c->view); + runscript(arg.v, frame, webkit_web_frame_get_global_context(frame)); + return GDK_FILTER_REMOVE; + } } } return GDK_FILTER_CONTINUE; @@ -686,6 +699,7 @@ atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False); atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False); atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False); + atoms[AtomScriptFile] = XInternAtom(dpy, "_SURF_SCRIPT", False); /* dirs and files */ cookiefile = buildpath(cookiefile); @@ -779,7 +793,7 @@ void windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame, JSContextRef js, JSObjectRef win, Client *c) { - runscript(frame, js); + runscript(scriptfile, frame, js); } void