mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Merge script_hook_goto_url and script_hook_follow_url
Combine the two into the new script_hook_url and use the hook data field to store the name of the appropriate ECMAScript routine.
This commit is contained in:
parent
c776fab903
commit
d5fe12b5f4
@ -22,7 +22,7 @@
|
||||
|
||||
|
||||
static enum evhook_status
|
||||
script_hook_goto_url(va_list ap, void *data)
|
||||
script_hook_url(va_list ap, void *data)
|
||||
{
|
||||
unsigned char **url = va_arg(ap, unsigned char **);
|
||||
struct session *ses = va_arg(ap, struct session *);
|
||||
@ -35,40 +35,7 @@ script_hook_goto_url(va_list ap, void *data)
|
||||
|
||||
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)) {
|
||||
if (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_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 (JS_TRUE == smjs_invoke_elinks_object_method(data, args, 1, &rval)) {
|
||||
if (JSVAL_IS_BOOLEAN(rval)) {
|
||||
if (JS_FALSE == JSVAL_TO_BOOLEAN(rval))
|
||||
ret = EVENT_HOOK_STATUS_LAST;
|
||||
@ -123,8 +90,8 @@ end:
|
||||
}
|
||||
|
||||
struct event_hook_info smjs_scripting_hooks[] = {
|
||||
{ "goto-url", 0, script_hook_goto_url, NULL },
|
||||
{ "follow-url", 0, script_hook_follow_url, NULL },
|
||||
{ "goto-url", 0, script_hook_url, "goto_url_hook" },
|
||||
{ "follow-url", 0, script_hook_url, "follow_url_hook" },
|
||||
{ "pre-format-html", 0, script_hook_pre_format_html, NULL },
|
||||
|
||||
NULL_EVENT_HOOK_INFO,
|
||||
|
Loading…
Reference in New Issue
Block a user