Adapt JavaScript functions
Removed eval(), evalscript() is now sufficient and can directly execute passed JavaScript string.
This commit is contained in:
parent
72905b8bfc
commit
d9cecc8932
1 changed files with 17 additions and 25 deletions
42
surf.c
42
surf.c
|
@ -124,7 +124,8 @@ static void closeview(WebKitWebView *v, Client *c);
|
||||||
static void destroyclient(Client *c);
|
static void destroyclient(Client *c);
|
||||||
static void destroywin(GtkWidget* w, Client *c);
|
static void destroywin(GtkWidget* w, Client *c);
|
||||||
static void die(const char *errstr, ...);
|
static void die(const char *errstr, ...);
|
||||||
static void eval(Client *c, const Arg *arg);
|
static void evalscript(Client *c, const char *jsstr, ...);
|
||||||
|
static void runscript(Client *c);
|
||||||
static void find(Client *c, const Arg *arg);
|
static void find(Client *c, const Arg *arg);
|
||||||
static void fullscreen(Client *c, const Arg *arg);
|
static void fullscreen(Client *c, const Arg *arg);
|
||||||
static gboolean permissionrequested(WebKitWebView *v,
|
static gboolean permissionrequested(WebKitWebView *v,
|
||||||
|
@ -336,29 +337,28 @@ cookiepolicy_set(const WebKitCookieAcceptPolicy ep)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
evalscript(JSContextRef js, char *script, char* scriptname)
|
evalscript(Client *c, const char *jsstr, ...)
|
||||||
{
|
{
|
||||||
JSStringRef jsscript, jsscriptname;
|
va_list ap;
|
||||||
JSValueRef exception = NULL;
|
gchar *script;
|
||||||
|
|
||||||
jsscript = JSStringCreateWithUTF8CString(script);
|
va_start(ap, jsstr);
|
||||||
jsscriptname = JSStringCreateWithUTF8CString(scriptname);
|
script = g_strdup_vprintf(jsstr, ap);
|
||||||
JSEvaluateScript(js, jsscript, JSContextGetGlobalObject(js),
|
va_end(ap);
|
||||||
jsscriptname, 0, &exception);
|
|
||||||
JSStringRelease(jsscript);
|
webkit_web_view_run_javascript(c->view, script, NULL, NULL, NULL);
|
||||||
JSStringRelease(jsscriptname);
|
g_free(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
runscript(WebKitWebFrame *frame)
|
runscript(Client *c)
|
||||||
{
|
{
|
||||||
char *script;
|
gchar *script;
|
||||||
GError *error;
|
gsize l;
|
||||||
|
|
||||||
if (g_file_get_contents(scriptfile, &script, NULL, &error)) {
|
if (g_file_get_contents(scriptfile, &script, &l, NULL) && l)
|
||||||
evalscript(webkit_web_frame_get_global_context(frame), script,
|
evalscript(c, script);
|
||||||
scriptfile);
|
g_free(script);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1318,14 +1318,6 @@ spawn(Client *c, const Arg *arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
eval(Client *c, const Arg *arg)
|
|
||||||
{
|
|
||||||
WebKitWebFrame *frame = webkit_web_view_get_main_frame(c->view);
|
|
||||||
evalscript(webkit_web_frame_get_global_context(frame),
|
|
||||||
((char **)arg->v)[0], "");
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
stop(Client *c, const Arg *arg)
|
stop(Client *c, const Arg *arg)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue