1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

Add elinks.follow_url_hook.

This commit is contained in:
Miciah Dashiel Butler Masters 2005-12-28 07:07:21 +00:00 committed by Miciah Dashiel Butler Masters
parent d7c7736008
commit 76d9b9de91

View File

@ -50,6 +50,38 @@ script_hook_goto_url(va_list ap, void *data)
return ret;
}
static enum evhook_status
script_hook_follow_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("follow_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)
{
@ -82,6 +114,7 @@ end:
struct event_hook_info smjs_scripting_hooks[] = {
{ "goto-url", 0, script_hook_goto_url, NULL },
{ "follow-url", 0, script_hook_follow_url, NULL },
{ "pre-format-html", 0, script_hook_pre_format_html, NULL },
NULL_EVENT_HOOK_INFO,