}
success = js_eval(
- webkit_web_view_get_main_frame(vb.gui.webview), arg->rhs->str, NULL, &value
+ webkit_web_frame_get_global_context(webkit_web_view_get_main_frame(vb.gui.webview)),
+ arg->rhs->str, NULL, &value
);
if (success) {
vb_echo(VB_MSG_NORMAL, false, "%s", value);
}
if (!hints.obj) {
hints.ctx = webkit_web_frame_get_global_context(frame);
- hints.obj = js_create_object(frame, HINTS_JS);
+ hints.obj = js_create_object(hints.ctx, HINTS_JS);
}
}
/**
* Run scripts out of given file in the given frame.
*/
-gboolean js_eval_file(WebKitWebFrame *frame, const char *file)
+gboolean js_eval_file(JSContextRef ctx, const char *file)
{
char *js = NULL, *value = NULL;
if (g_file_test(file, G_FILE_TEST_IS_REGULAR)
&& g_file_get_contents(file, &js, NULL, NULL)
) {
- gboolean success = js_eval(frame, js, file, &value);
+ gboolean success = js_eval(ctx, js, file, &value);
if (!success) {
g_warning("JavaScript error in %s: %s", file, value);
}
* else with the exception message. In both cases this must be freed by the
* caller if no longer used.
*/
-gboolean js_eval(WebKitWebFrame *frame, const char *script, const char *file,
+gboolean js_eval(JSContextRef ctx, const char *script, const char *file,
char **value)
{
gboolean success;
JSValueRef result = NULL;
- JSContextRef ctx = webkit_web_frame_get_global_context(frame);
success = evaluate_string(ctx, script, file, &result);
*value = js_ref_to_string(ctx, result);
/**
* Creates a JavaScript object in contect of given frame.
*/
-JSObjectRef js_create_object(WebKitWebFrame *frame, const char *script)
+JSObjectRef js_create_object(JSContextRef ctx, const char *script)
{
JSValueRef result = NULL, exc = NULL;
JSObjectRef object;
- JSContextRef ctx = webkit_web_frame_get_global_context(frame);
-
if (!evaluate_string(ctx, script, NULL, &result)) {
return NULL;
}
#include "main.h"
-gboolean js_eval_file(WebKitWebFrame *frame, const char *file);
-gboolean js_eval(WebKitWebFrame *frame, const char *script, const char *file,
+gboolean js_eval_file(JSContextRef ctx, const char *file);
+gboolean js_eval(JSContextRef ctx, const char *script, const char *file,
char **value);
-JSObjectRef js_create_object(WebKitWebFrame *frame, const char *script);
+JSObjectRef js_create_object(JSContextRef ctx, const char *script);
char* js_object_call_function(JSContextRef ctx, JSObjectRef obj,
const char *func, int count, JSValueRef params[]);
char *js_ref_to_string(JSContextRef ctx, JSValueRef ref);
uri = webkit_web_view_get_uri(view);
{
WebKitWebFrame *frame = webkit_web_view_get_main_frame(view);
+ JSContextRef ctx;
/* set the status */
if (g_str_has_prefix(uri, "https://")) {
WebKitWebDataSource *src = webkit_web_frame_get_data_source(frame);
hints_init(frame);
/* run user script file */
- js_eval_file(frame, vb.files[FILES_SCRIPT]);
+ ctx = webkit_web_frame_get_global_context(frame);
+ js_eval_file(ctx, vb.files[FILES_SCRIPT]);
}
/* if we load a page from a submitted form, leafe the insert mode */
{
gboolean result;
char *js, *value = NULL;
+ WebKitWebFrame *frame = webkit_web_view_get_main_frame(vb.gui.webview);
js = g_strdup_printf("var i;for(i=0;i<[%s].length;i++);", pattern);
- result = js_eval(webkit_web_view_get_main_frame(vb.gui.webview), js, NULL, &value);
+ result = js_eval(webkit_web_frame_get_global_context(frame), js, NULL, &value);
g_free(js);
if (!result) {
vb_echo(VB_MSG_ERROR, true, "%s", value);