1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-10-01 03:36:26 -04:00

Add elinks.goto_url_hook.

This commit is contained in:
Miciah Dashiel Butler Masters 2005-12-28 07:06:42 +00:00 committed by Miciah Dashiel Butler Masters
parent c0fd25b368
commit d7c7736008

View File

@ -8,6 +8,7 @@
#include "cache/cache.h"
#include "ecmascript/spidermonkey/util.h"
#include "protocol/uri.h"
#include "main/event.h"
#include "main/module.h"
#include "scripting/smjs/cache_object.h"
@ -17,6 +18,38 @@
#include "session/session.h"
static enum evhook_status
script_hook_goto_url(va_list ap, void *data)
{
unsigned char **url = va_arg(ap, unsigned char **);
struct session *ses = va_arg(ap, struct session *);
enum evhook_status ret = EVENT_HOOK_STATUS_NEXT;
jsval args[1], rval;
if (*url == NULL) return EVENT_HOOK_STATUS_NEXT;
smjs_ses = ses;
args[0] = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx, *url));
if (JS_TRUE == smjs_invoke_elinks_object_method("goto_url_hook",
args, 1, &rval)) {
if (JSVAL_IS_BOOLEAN(rval)
&& JS_FALSE == JSVAL_TO_BOOLEAN(rval)) {
ret = EVENT_HOOK_STATUS_LAST;
} else {
JSString *jsstr = JS_ValueToString(smjs_ctx, rval);
unsigned char *str = JS_GetStringBytes(jsstr);
mem_free_set(url, stracpy(str));
}
}
smjs_ses = NULL;
return ret;
}
static enum evhook_status
script_hook_pre_format_html(va_list ap, void *data)
{
@ -48,6 +81,7 @@ end:
}
struct event_hook_info smjs_scripting_hooks[] = {
{ "goto-url", 0, script_hook_goto_url, NULL },
{ "pre-format-html", 0, script_hook_pre_format_html, NULL },
NULL_EVENT_HOOK_INFO,