mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
[ecmascript] Move location_goto to ecmascript.c
This commit is contained in:
parent
46953a35bd
commit
33eab7d910
@ -671,6 +671,52 @@ document_parse(struct document *document)
|
||||
return (void *)docu;
|
||||
}
|
||||
|
||||
static void
|
||||
delayed_goto(void *data)
|
||||
{
|
||||
struct delayed_goto *deg = data;
|
||||
|
||||
assert(deg);
|
||||
if (deg->vs->doc_view
|
||||
&& deg->vs->doc_view == deg->vs->doc_view->session->doc_view) {
|
||||
goto_uri_frame(deg->vs->doc_view->session, deg->uri,
|
||||
deg->vs->doc_view->name,
|
||||
CACHE_MODE_NORMAL);
|
||||
}
|
||||
done_uri(deg->uri);
|
||||
mem_free(deg);
|
||||
}
|
||||
|
||||
void
|
||||
location_goto(struct document_view *doc_view, char *url)
|
||||
{
|
||||
char *new_abs_url;
|
||||
struct uri *new_uri;
|
||||
struct delayed_goto *deg;
|
||||
|
||||
/* Workaround for bug 611. Does not crash, but may lead to infinite loop.*/
|
||||
if (!doc_view) return;
|
||||
new_abs_url = join_urls(doc_view->document->uri,
|
||||
trim_chars(url, ' ', 0));
|
||||
if (!new_abs_url)
|
||||
return;
|
||||
new_uri = get_uri(new_abs_url, 0);
|
||||
mem_free(new_abs_url);
|
||||
if (!new_uri)
|
||||
return;
|
||||
deg = mem_calloc(1, sizeof(*deg));
|
||||
if (!deg) {
|
||||
done_uri(new_uri);
|
||||
return;
|
||||
}
|
||||
assert(doc_view->vs);
|
||||
deg->vs = doc_view->vs;
|
||||
deg->uri = new_uri;
|
||||
/* It does not seem to be very safe inside of frames to
|
||||
* call goto_uri() right away. */
|
||||
register_bottom_half(delayed_goto, deg);
|
||||
}
|
||||
|
||||
struct module ecmascript_module = struct_module(
|
||||
/* name: */ N_("ECMAScript"),
|
||||
/* options: */ ecmascript_options,
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
struct document_view;
|
||||
struct form_state;
|
||||
struct form_view;
|
||||
struct string;
|
||||
@ -78,6 +79,13 @@ struct ecmascript_interpreter {
|
||||
bool changed;
|
||||
};
|
||||
|
||||
struct delayed_goto {
|
||||
/* It might look more convenient to pass doc_view around but it could
|
||||
* disappear during wild dances inside of frames or so. */
|
||||
struct view_state *vs;
|
||||
struct uri *uri;
|
||||
};
|
||||
|
||||
/* Why is the interpreter bound to {struct view_state} instead of {struct
|
||||
* document}? That's easy, because the script won't raid just inside of the
|
||||
* document, but it will also want to generate pop-up boxes, adjust form
|
||||
@ -129,6 +137,7 @@ void toggle_ecmascript(struct session *ses);
|
||||
|
||||
void *document_parse(struct document *document);
|
||||
void free_document(void *doc);
|
||||
void location_goto(struct document_view *doc_view, char *url);
|
||||
|
||||
extern char *console_error_filename;
|
||||
extern char *console_log_filename;
|
||||
|
@ -1138,29 +1138,6 @@ location_toString(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct delayed_goto {
|
||||
/* It might look more convenient to pass doc_view around but it could
|
||||
* disappear during wild dances inside of frames or so. */
|
||||
struct view_state *vs;
|
||||
struct uri *uri;
|
||||
};
|
||||
|
||||
static void
|
||||
delayed_goto(void *data)
|
||||
{
|
||||
struct delayed_goto *deg = data;
|
||||
|
||||
assert(deg);
|
||||
if (deg->vs->doc_view
|
||||
&& deg->vs->doc_view == deg->vs->doc_view->session->doc_view) {
|
||||
goto_uri_frame(deg->vs->doc_view->session, deg->uri,
|
||||
deg->vs->doc_view->name,
|
||||
CACHE_MODE_NORMAL);
|
||||
}
|
||||
done_uri(deg->uri);
|
||||
mem_free(deg);
|
||||
}
|
||||
|
||||
static void
|
||||
location_goto_common(JSContext *ctx, struct document_view *doc_view, JS::HandleValue val)
|
||||
{
|
||||
@ -1171,33 +1148,3 @@ location_goto_common(JSContext *ctx, struct document_view *doc_view, JS::HandleV
|
||||
mem_free(url);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
location_goto(struct document_view *doc_view, char *url)
|
||||
{
|
||||
char *new_abs_url;
|
||||
struct uri *new_uri;
|
||||
struct delayed_goto *deg;
|
||||
|
||||
/* Workaround for bug 611. Does not crash, but may lead to infinite loop.*/
|
||||
if (!doc_view) return;
|
||||
new_abs_url = join_urls(doc_view->document->uri,
|
||||
trim_chars(url, ' ', 0));
|
||||
if (!new_abs_url)
|
||||
return;
|
||||
new_uri = get_uri(new_abs_url, 0);
|
||||
mem_free(new_abs_url);
|
||||
if (!new_uri)
|
||||
return;
|
||||
deg = mem_calloc(1, sizeof(*deg));
|
||||
if (!deg) {
|
||||
done_uri(new_uri);
|
||||
return;
|
||||
}
|
||||
assert(doc_view->vs);
|
||||
deg->vs = doc_view->vs;
|
||||
deg->uri = new_uri;
|
||||
/* It does not seem to be very safe inside of frames to
|
||||
* call goto_uri() right away. */
|
||||
register_bottom_half(delayed_goto, deg);
|
||||
}
|
||||
|
@ -4,8 +4,6 @@
|
||||
|
||||
#include "ecmascript/spidermonkey/util.h"
|
||||
|
||||
struct document_view;
|
||||
|
||||
extern JSClass history_class;
|
||||
extern const spidermonkeyFunctionSpec history_funcs[];
|
||||
|
||||
@ -13,6 +11,4 @@ extern JSClass location_class;
|
||||
extern const spidermonkeyFunctionSpec location_funcs[];
|
||||
extern JSPropertySpec location_props[];
|
||||
|
||||
void location_goto(struct document_view *doc_view, char *url);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user