NULL);
}
+void ext_proxy_eval_script(Client *c, char *js)
+{
+ dbus_call(c, "EvalJsNoResult", g_variant_new("(s)", js), NULL);
+}
+
/**
* Request the web extension to focus first editable element.
* Returns whether an focusable element was found or not.
#include "main.h"
const char *ext_proxy_init(void);
+void ext_proxy_eval_script(Client *c, char *js);
void ext_proxy_focus_input(Client *c);
void ext_proxy_set_header(Client *c, const char *headers);
js = g_strdup_printf(
"window.scroll(window.scrollX, %d * (1 + (document.height - window.innerHeight) / 100));",
info->count);
- webkit_web_view_run_javascript(c->webview, js, NULL, NULL, NULL);
+ ext_proxy_eval_script(c, js);
g_free(js);
return RESULT_COMPLETE;
}
/* Without count scroll to the end of the page. */
- webkit_web_view_run_javascript(c->webview, "window.scroll(window.scrollX, document.body.scrollHeight);", NULL, NULL, NULL);
+ ext_proxy_eval_script(c, "window.scroll(window.scrollX, document.body.scrollHeight);");
return RESULT_COMPLETE;
case '0':
- webkit_web_view_run_javascript(c->webview, "window.scroll(0, window.scrollY);", NULL, NULL, NULL);
+ ext_proxy_eval_script(c, "window.scroll(0, window.scrollY);");
return RESULT_COMPLETE;
case '$':
- webkit_web_view_run_javascript(c->webview, "window.scroll(document.body.scrollWidth, window.scrollY);", NULL, NULL, NULL);
+ ext_proxy_eval_script(c, "window.scroll(document.body.scrollWidth, window.scrollY);");
return RESULT_COMPLETE;
default:
if (info->key2 == 'g') {
js = g_strdup_printf(
"window.scroll(window.scrollX, %d * (1 + (document.height - window.innerHeight) / 100));",
info->count);
- webkit_web_view_run_javascript(c->webview, js, NULL, NULL, NULL);
+ ext_proxy_eval_script(c, js);
g_free(js);
return RESULT_COMPLETE;
}
/* Without count gg scrolls to the top of the page. */
- webkit_web_view_run_javascript(c->webview, "window.scroll(window.scrollX, 0);", NULL, NULL, NULL);
+ ext_proxy_eval_script(c, "window.scroll(window.scrollX, 0);");
return RESULT_COMPLETE;
}
return RESULT_ERROR;
}
js = g_strdup_printf("window.scrollBy(%d,%d);", x, y);
- webkit_web_view_run_javascript(c->webview, js, NULL, NULL, NULL);
+ ext_proxy_eval_script(c, js);
g_free(js);
return RESULT_COMPLETE;
static const char introspection_xml[] =
"<node>"
" <interface name='" VB_WEBEXTENSION_INTERFACE "'>"
+ " <method name='EvalJsNoResult'>"
+ " <arg type='s' name='js' direction='in'/>"
+ " </method>"
" <method name='FocusInput'>"
" </method>"
" <signal name='PageCreated'>"
{
char *value;
- if (!g_strcmp0(method, "FocusInput")) {
+ if (!g_strcmp0(method, "EvalJsNoResult")) {
+ g_variant_get(parameters, "(s)", &value);
+ JSGlobalContextRef jsContext;
+
+ jsContext = webkit_frame_get_javascript_context_for_script_world(
+ webkit_web_page_get_main_frame(ext.webpage),
+ webkit_script_world_get_default()
+ );
+ JSValueRef ref = NULL;
+ ext_util_js_eval(jsContext, value, &ref);
+ } else if (!g_strcmp0(method, "FocusInput")) {
ext_dom_focus_input(webkit_web_page_get_dom_document(ext.webpage));
g_dbus_method_invocation_return_value(invocation, NULL);
} else if (!g_strcmp0(method, "SetHeaderSetting")) {
#include "../config.h"
#include "ext-util.h"
+/**
+ * Evaluates given string as script and return if this call succeed or not.
+ */
+gboolean ext_util_js_eval(JSContextRef ctx, const char *script, JSValueRef *result)
+{
+ JSStringRef js_str;
+ JSValueRef exc = NULL, res = NULL;
+
+ js_str = JSStringCreateWithUTF8CString(script);
+ res = JSEvaluateScript(ctx, js_str, JSContextGetGlobalObject(ctx), NULL, 0, &exc);
+ JSStringRelease(js_str);
+
+ if (exc) {
+ *result = exc;
+ return FALSE;
+ }
+
+ *result = res;
+ return TRUE;
+}
+
/**
* Creates a temporary file with given content.
*
#define _EXT_UTIL_H
#include <glib.h>
+#include <JavaScriptCore/JavaScript.h>
gboolean ext_util_create_tmp_file(const char *content, char **file);
+gboolean ext_util_js_eval(JSContextRef ctx, const char *script, JSValueRef *result);
#endif /* end of include guard: _EXT_UTIL_H */