2005-09-15 09:58:31 -04:00
|
|
|
/* Base ECMAScript file. Mostly a proxy for specific library backends. */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2020-10-27 09:53:24 -04:00
|
|
|
#include <stdio.h>
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
#include "elinks.h"
|
|
|
|
|
2020-12-07 16:36:24 -05:00
|
|
|
#include "config/home.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "config/options.h"
|
2021-09-20 12:40:01 -04:00
|
|
|
#include "dialogs/status.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "document/document.h"
|
2021-07-20 04:05:58 -04:00
|
|
|
#include "document/renderer.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "document/view.h"
|
2021-07-20 04:05:58 -04:00
|
|
|
#include "document/xml/renderer.h"
|
|
|
|
#include "document/xml/renderer2.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "ecmascript/ecmascript.h"
|
2021-10-17 12:17:48 -04:00
|
|
|
#ifdef CONFIG_QUICKJS
|
|
|
|
#include "ecmascript/quickjs.h"
|
|
|
|
#else
|
2006-01-27 04:08:19 -05:00
|
|
|
#include "ecmascript/spidermonkey.h"
|
2021-10-17 12:17:48 -04:00
|
|
|
#endif
|
2021-12-01 13:27:50 -05:00
|
|
|
#include "ecmascript/timer.h"
|
2021-08-08 15:25:08 -04:00
|
|
|
#include "intl/libintl.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "main/module.h"
|
2021-07-20 04:05:58 -04:00
|
|
|
#include "main/select.h"
|
2006-10-24 13:10:10 -04:00
|
|
|
#include "main/timer.h"
|
2006-07-09 07:02:44 -04:00
|
|
|
#include "osdep/osdep.h"
|
2006-03-21 12:45:40 -05:00
|
|
|
#include "protocol/protocol.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "protocol/uri.h"
|
|
|
|
#include "session/session.h"
|
|
|
|
#include "session/task.h"
|
|
|
|
#include "terminal/terminal.h"
|
|
|
|
#include "terminal/window.h"
|
|
|
|
#include "util/conv.h"
|
2006-03-21 12:45:40 -05:00
|
|
|
#include "util/string.h"
|
2021-07-20 04:11:26 -04:00
|
|
|
#include "viewer/text/draw.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "viewer/text/view.h" /* current_frame() */
|
|
|
|
#include "viewer/text/form.h" /* <-ecmascript_reset_state() */
|
|
|
|
#include "viewer/text/vs.h"
|
|
|
|
|
2021-10-17 12:17:48 -04:00
|
|
|
#include <libxml/tree.h>
|
|
|
|
#include <libxml/HTMLparser.h>
|
|
|
|
#include <libxml++/libxml++.h>
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2021-12-01 13:27:50 -05:00
|
|
|
#include <map>
|
|
|
|
|
|
|
|
std::map<struct timer *, bool> map_timer;
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
/* TODO: We should have some kind of ACL for the scripts - i.e. ability to
|
|
|
|
* disallow the scripts to open new windows (or so that the windows are always
|
|
|
|
* directed to tabs, this particular option would be a tristate), disallow
|
|
|
|
* messing with your menubar/statusbar visibility, disallow changing the
|
|
|
|
* statusbar content etc. --pasky */
|
|
|
|
|
bug 764: Initialize the right member of union option_value
INIT_OPTION used to initialize union option_value at compile time by
casting the default value to LIST_OF(struct option) *, which is the
type of the first member. On sparc64 and other big-endian systems
where sizeof(int) < sizeof(struct list_head *), this tended to leave
option->value.number as zero, thus messing up OPT_INT and OPT_BOOL
at least. OPT_LONG however tended to work right.
This would be easy to fix with C99 designated initializers,
but doc/hacking.txt says ELinks must be kept C89 compatible.
Another solution would be to make register_options() read the
value from option->value.tree (the first member), cast it back
to the right type, and write it to the appropriate member;
but that would still require somewhat dubious conversions
between integers, data pointers, and function pointers.
So here's a rather more invasive solution. Add struct option_init,
which is somewhat similar to struct option but has non-overlapping
members for different types of values, to ensure nothing is lost
in compile-time conversions. Move unsigned char *path from struct
option_info to struct option_init, and replace struct option_info
with a union that contains struct option_init and struct option.
Now, this union can be initialized with no portability problems,
and register_options() then moves the values from struct option_init
to their final places in struct option.
In my x86 ELinks build with plenty of options configured in, this
change bloated the text section by 340 bytes but compressed the data
section by 2784 bytes, presumably because union option_info is a
pointer smaller than struct option_info was.
(cherry picked from elinks-0.12 commit e5f6592ee20780a61f70feeb1f9e17631b9c5835)
Conflicts:
src/protocol/fsp/fsp.c: All options had been removed in 0.13.GIT.
src/protocol/smb/smb2.c: Ditto.
2009-08-15 15:39:07 -04:00
|
|
|
static union option_info ecmascript_options[] = {
|
2022-03-02 12:30:25 -05:00
|
|
|
INIT_OPT_TREE("", N_("ECMAScript"),
|
|
|
|
"ecmascript", OPT_ZERO,
|
2005-09-15 09:58:31 -04:00
|
|
|
N_("ECMAScript options.")),
|
|
|
|
|
2022-03-02 12:30:25 -05:00
|
|
|
INIT_OPT_BOOL("ecmascript", N_("Enable"),
|
|
|
|
"enable", OPT_ZERO, 0,
|
2005-09-15 09:58:31 -04:00
|
|
|
N_("Whether to run those scripts inside of documents.")),
|
|
|
|
|
2022-03-02 12:30:25 -05:00
|
|
|
INIT_OPT_BOOL("ecmascript", N_("Console log"),
|
|
|
|
"enable_console_log", OPT_ZERO, 0,
|
2021-02-22 10:05:55 -05:00
|
|
|
N_("When enabled logs will be appended to ~/.elinks/console.log.")),
|
|
|
|
|
2022-03-02 12:30:25 -05:00
|
|
|
INIT_OPT_BOOL("ecmascript", N_("Script error reporting"),
|
|
|
|
"error_reporting", OPT_ZERO, 0,
|
2005-09-15 09:58:31 -04:00
|
|
|
N_("Open a message box when a script reports an error.")),
|
|
|
|
|
2022-03-02 12:30:25 -05:00
|
|
|
INIT_OPT_BOOL("ecmascript", N_("Ignore <noscript> content"),
|
|
|
|
"ignore_noscript", OPT_ZERO, 0,
|
Rewrap lines in option documentation.
Documentation strings of most options used to contain a "\n" at the
end of each source line. When the option manager displayed these
strings, it treated each "\n" as a hard newline. On 80x24 terminals
however, the option description window has only 60 columes available
for the text (with the default setup.h), and the hard newlines were
further apart, so the option manager wrapped the text a second time,
resulting in rather ugly output where long lones are interleaved with
short ones. This could also cause the text to take up too much
vertical space and not fit in the window.
Replace most of those hard newlines with spaces so that the option
manager (or perhaps BFU) will take care of the wrapping. At the same
time, rewrap the strings in source code so that the source lines are
at most 79 columns wide.
In some options though, there is a list of possible values and their
meanings. In those lists, if the description of one value does not
fit in one line, then continuation lines should be indented. The
option manager and BFU are not currently able to do that. So, keep
the hard newlines in those lists, but rewrap them to 60 columns so
that they are less likely to require further wrapping at runtime.
2009-03-07 13:48:38 -05:00
|
|
|
N_("Whether to ignore content enclosed by the <noscript> tag "
|
|
|
|
"when ECMAScript is enabled.")),
|
2005-10-23 17:59:05 -04:00
|
|
|
|
2022-03-02 12:30:25 -05:00
|
|
|
INIT_OPT_INT("ecmascript", N_("Maximum execution time"),
|
|
|
|
"max_exec_time", OPT_ZERO, 1, 3600, 5,
|
2005-09-15 09:58:31 -04:00
|
|
|
N_("Maximum execution time in seconds for a script.")),
|
|
|
|
|
2022-03-02 12:30:25 -05:00
|
|
|
INIT_OPT_BOOL("ecmascript", N_("Pop-up window blocking"),
|
|
|
|
"block_window_opening", OPT_ZERO, 0,
|
2005-09-15 09:58:31 -04:00
|
|
|
N_("Whether to disallow scripts to open new windows or tabs.")),
|
|
|
|
|
|
|
|
NULL_OPTION_INFO,
|
|
|
|
};
|
|
|
|
|
2008-09-06 16:18:10 -04:00
|
|
|
static int interpreter_count;
|
|
|
|
|
2020-12-07 16:36:24 -05:00
|
|
|
static INIT_LIST_OF(struct string_list_item, allowed_urls);
|
2021-05-07 05:29:33 -04:00
|
|
|
static INIT_LIST_OF(struct string_list_item, disallowed_urls);
|
2020-12-07 16:36:24 -05:00
|
|
|
|
2021-09-07 11:31:45 -04:00
|
|
|
char *console_error_filename;
|
2021-02-22 09:55:12 -05:00
|
|
|
char *console_log_filename;
|
|
|
|
|
2021-02-22 17:27:19 -05:00
|
|
|
char *local_storage_filename;
|
|
|
|
|
|
|
|
int local_storage_ready;
|
|
|
|
|
2020-12-07 16:36:24 -05:00
|
|
|
static int
|
2021-01-02 10:20:27 -05:00
|
|
|
is_prefix(char *prefix, char *url, int dl)
|
2020-12-07 16:36:24 -05:00
|
|
|
{
|
|
|
|
return memcmp(prefix, url, dl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
read_url_list(void)
|
|
|
|
{
|
|
|
|
char line[4096];
|
2021-01-02 10:20:27 -05:00
|
|
|
char *filename;
|
2020-12-07 16:36:24 -05:00
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
if (!elinks_home) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
filename = straconcat(elinks_home, STRING_DIR_SEP, ALLOWED_ECMASCRIPT_URL_PREFIXES, NULL);
|
|
|
|
|
2021-05-07 05:29:33 -04:00
|
|
|
if (filename) {
|
|
|
|
|
|
|
|
f = fopen(filename, "r");
|
|
|
|
|
|
|
|
if (f) {
|
|
|
|
while (fgets(line, 4096, f)) {
|
|
|
|
add_to_string_list(&allowed_urls, line, strlen(line) - 1);
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
mem_free(filename);
|
2020-12-07 16:36:24 -05:00
|
|
|
}
|
|
|
|
|
2021-05-07 05:29:33 -04:00
|
|
|
filename = straconcat(elinks_home, STRING_DIR_SEP, DISALLOWED_ECMASCRIPT_URL_PREFIXES, NULL);
|
2020-12-07 16:36:24 -05:00
|
|
|
|
2021-05-07 05:29:33 -04:00
|
|
|
if (filename) {
|
|
|
|
|
|
|
|
f = fopen(filename, "r");
|
|
|
|
|
|
|
|
if (f) {
|
|
|
|
while (fgets(line, 4096, f)) {
|
|
|
|
add_to_string_list(&disallowed_urls, line, strlen(line) - 1);
|
|
|
|
}
|
|
|
|
fclose(f);
|
2020-12-07 16:36:24 -05:00
|
|
|
}
|
2021-05-07 05:29:33 -04:00
|
|
|
mem_free(filename);
|
2020-12-07 16:36:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-20 12:40:01 -04:00
|
|
|
static int ecmascript_enabled;
|
2021-09-19 13:40:01 -04:00
|
|
|
|
|
|
|
void
|
2021-09-20 12:40:01 -04:00
|
|
|
toggle_ecmascript(struct session *ses)
|
2021-09-19 13:40:01 -04:00
|
|
|
{
|
|
|
|
ecmascript_enabled = !ecmascript_enabled;
|
2021-09-20 12:40:01 -04:00
|
|
|
|
|
|
|
if (ecmascript_enabled) {
|
|
|
|
mem_free_set(&ses->status.window_status, stracpy(_("Ecmascript enabled", ses->tab->term)));
|
|
|
|
} else {
|
|
|
|
mem_free_set(&ses->status.window_status, stracpy(_("Ecmascript disabled", ses->tab->term)));
|
|
|
|
}
|
2021-09-21 13:04:25 -04:00
|
|
|
print_screen_status(ses);
|
2021-09-19 13:40:01 -04:00
|
|
|
}
|
|
|
|
|
2020-12-07 16:36:24 -05:00
|
|
|
int
|
|
|
|
get_ecmascript_enable(struct ecmascript_interpreter *interpreter)
|
|
|
|
{
|
|
|
|
struct string_list_item *item;
|
2021-01-02 10:20:27 -05:00
|
|
|
char *url;
|
2020-12-07 16:36:24 -05:00
|
|
|
|
2021-09-19 13:40:01 -04:00
|
|
|
if (!ecmascript_enabled || !get_opt_bool("ecmascript.enable", NULL)
|
2020-12-07 16:36:24 -05:00
|
|
|
|| !interpreter || !interpreter->vs || !interpreter->vs->doc_view
|
|
|
|
|| !interpreter->vs->doc_view->document || !interpreter->vs->doc_view->document->uri) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-05-07 05:29:33 -04:00
|
|
|
if (list_empty(allowed_urls) && list_empty(disallowed_urls)) {
|
2020-12-09 10:13:20 -05:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-12-07 16:36:24 -05:00
|
|
|
url = get_uri_string(interpreter->vs->doc_view->document->uri, URI_PUBLIC);
|
|
|
|
if (!url) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-05-07 05:29:33 -04:00
|
|
|
foreach(item, disallowed_urls) {
|
|
|
|
struct string *string = &item->string;
|
|
|
|
|
|
|
|
if (string->length <= 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!is_prefix(string->source, url, string->length)) {
|
|
|
|
mem_free(url);
|
|
|
|
move_to_top_of_list(disallowed_urls, item);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-07 16:36:24 -05:00
|
|
|
foreach(item, allowed_urls) {
|
|
|
|
struct string *string = &item->string;
|
|
|
|
|
|
|
|
if (string->length <= 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!is_prefix(string->source, url, string->length)) {
|
|
|
|
mem_free(url);
|
2020-12-11 12:51:53 -05:00
|
|
|
move_to_top_of_list(allowed_urls, item);
|
2020-12-07 16:36:24 -05:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mem_free(url);
|
2021-05-07 05:29:33 -04:00
|
|
|
return list_empty(allowed_urls);
|
2020-12-07 16:36:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-27 04:08:19 -05:00
|
|
|
struct ecmascript_interpreter *
|
|
|
|
ecmascript_get_interpreter(struct view_state *vs)
|
|
|
|
{
|
|
|
|
struct ecmascript_interpreter *interpreter;
|
|
|
|
|
|
|
|
assert(vs);
|
|
|
|
|
2022-01-16 15:08:50 -05:00
|
|
|
interpreter = (struct ecmascript_interpreter *)mem_calloc(1, sizeof(*interpreter));
|
2006-01-27 04:08:19 -05:00
|
|
|
if (!interpreter)
|
|
|
|
return NULL;
|
|
|
|
|
2008-09-06 16:18:10 -04:00
|
|
|
++interpreter_count;
|
|
|
|
|
2006-01-27 04:08:19 -05:00
|
|
|
interpreter->vs = vs;
|
2007-06-21 04:31:12 -04:00
|
|
|
interpreter->vs->ecmascript_fragile = 0;
|
2006-01-27 04:08:19 -05:00
|
|
|
init_list(interpreter->onload_snippets);
|
2009-06-27 17:18:05 -04:00
|
|
|
/* The following backend call reads interpreter->vs. */
|
|
|
|
if (
|
2021-10-17 12:17:48 -04:00
|
|
|
#ifdef CONFIG_QUICKJS
|
|
|
|
!quickjs_get_interpreter(interpreter)
|
|
|
|
#else
|
2009-06-27 17:18:05 -04:00
|
|
|
!spidermonkey_get_interpreter(interpreter)
|
2021-10-17 12:17:48 -04:00
|
|
|
#endif
|
2009-06-27 17:18:05 -04:00
|
|
|
) {
|
|
|
|
/* Undo what was done above. */
|
|
|
|
interpreter->vs->ecmascript_fragile = 1;
|
|
|
|
mem_free(interpreter);
|
2009-07-11 09:47:33 -04:00
|
|
|
--interpreter_count;
|
2009-06-27 17:18:05 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2022-01-04 11:14:49 -05:00
|
|
|
|
2022-01-09 11:12:31 -05:00
|
|
|
(void)init_string(&interpreter->code);
|
2006-01-27 04:08:19 -05:00
|
|
|
return interpreter;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter)
|
|
|
|
{
|
|
|
|
assert(interpreter);
|
2007-06-21 14:34:36 -04:00
|
|
|
assert(interpreter->backend_nesting == 0);
|
2007-07-02 14:43:30 -04:00
|
|
|
/* If the assertion fails, it is better to leak the
|
|
|
|
* interpreter than to corrupt memory. */
|
|
|
|
if_assert_failed return;
|
2021-10-17 12:17:48 -04:00
|
|
|
#ifdef CONFIG_QUICKJS
|
|
|
|
quickjs_put_interpreter(interpreter);
|
|
|
|
#else
|
2006-01-27 04:08:19 -05:00
|
|
|
spidermonkey_put_interpreter(interpreter);
|
2021-10-17 12:17:48 -04:00
|
|
|
#endif
|
2006-01-27 04:08:19 -05:00
|
|
|
free_string_list(&interpreter->onload_snippets);
|
2006-10-23 16:45:55 -04:00
|
|
|
done_string(&interpreter->code);
|
2006-10-24 13:10:10 -04:00
|
|
|
/* Is it superfluous? */
|
|
|
|
if (interpreter->vs->doc_view)
|
|
|
|
kill_timer(&interpreter->vs->doc_view->document->timeout);
|
2006-01-27 04:08:19 -05:00
|
|
|
interpreter->vs->ecmascript = NULL;
|
2007-05-21 06:50:27 -04:00
|
|
|
interpreter->vs->ecmascript_fragile = 1;
|
2006-01-27 04:08:19 -05:00
|
|
|
mem_free(interpreter);
|
2008-09-06 16:18:10 -04:00
|
|
|
--interpreter_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ecmascript_get_interpreter_count(void)
|
|
|
|
{
|
|
|
|
return interpreter_count;
|
2006-01-27 04:08:19 -05:00
|
|
|
}
|
|
|
|
|
2021-07-20 04:05:58 -04:00
|
|
|
static void
|
|
|
|
delayed_reload(void *data)
|
|
|
|
{
|
2022-01-30 07:58:34 -05:00
|
|
|
struct delayed_rel *rel = (struct delayed_rel *)data;
|
2021-07-20 04:05:58 -04:00
|
|
|
|
|
|
|
assert(rel);
|
|
|
|
reset_document(rel->document);
|
|
|
|
render_xhtml_document(rel->cached, rel->document, NULL);
|
|
|
|
sort_links(rel->document);
|
2021-07-20 04:11:26 -04:00
|
|
|
draw_formatted(rel->ses, 0);
|
2021-07-20 04:05:58 -04:00
|
|
|
mem_free(rel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
check_for_rerender(struct ecmascript_interpreter *interpreter, const char* text)
|
|
|
|
{
|
2021-10-07 12:27:21 -04:00
|
|
|
#ifdef ECMASCRIPT_DEBUG
|
|
|
|
fprintf(stderr, "%s:%s %s %d\n", __FILE__, __FUNCTION__, text, interpreter->changed);
|
|
|
|
#endif
|
2021-07-20 04:05:58 -04:00
|
|
|
if (interpreter->changed) {
|
|
|
|
struct document_view *doc_view = interpreter->vs->doc_view;
|
|
|
|
struct document *document = doc_view->document;
|
|
|
|
struct session *ses = doc_view->session;
|
|
|
|
struct cache_entry *cached = document->cached;
|
|
|
|
|
|
|
|
//fprintf(stderr, "%s\n", text);
|
|
|
|
|
|
|
|
if (document->dom) {
|
|
|
|
interpreter->changed = false;
|
|
|
|
|
2022-01-16 15:08:50 -05:00
|
|
|
struct delayed_rel *rel = (struct delayed_rel *)mem_calloc(1, sizeof(*rel));
|
2021-07-20 04:05:58 -04:00
|
|
|
|
|
|
|
if (rel) {
|
|
|
|
rel->cached = cached;
|
|
|
|
rel->document = document;
|
|
|
|
rel->ses = ses;
|
|
|
|
object_lock(document);
|
|
|
|
register_bottom_half(delayed_reload, rel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-27 04:08:19 -05:00
|
|
|
void
|
|
|
|
ecmascript_eval(struct ecmascript_interpreter *interpreter,
|
2019-04-21 06:27:40 -04:00
|
|
|
struct string *code, struct string *ret)
|
2006-01-27 04:08:19 -05:00
|
|
|
{
|
2020-12-07 16:36:24 -05:00
|
|
|
if (!get_ecmascript_enable(interpreter))
|
2006-01-27 04:08:19 -05:00
|
|
|
return;
|
|
|
|
assert(interpreter);
|
2007-06-21 14:34:36 -04:00
|
|
|
interpreter->backend_nesting++;
|
2021-10-17 12:17:48 -04:00
|
|
|
#ifdef CONFIG_QUICKJS
|
|
|
|
quickjs_eval(interpreter, code, ret);
|
|
|
|
#else
|
2006-01-27 06:07:45 -05:00
|
|
|
spidermonkey_eval(interpreter, code, ret);
|
2021-10-17 12:17:48 -04:00
|
|
|
#endif
|
2007-06-21 14:34:36 -04:00
|
|
|
interpreter->backend_nesting--;
|
2006-01-27 04:08:19 -05:00
|
|
|
}
|
|
|
|
|
2021-11-12 15:53:31 -05:00
|
|
|
#ifdef CONFIG_QUICKJS
|
|
|
|
static void
|
|
|
|
ecmascript_call_function(struct ecmascript_interpreter *interpreter,
|
|
|
|
JSValueConst fun, struct string *ret)
|
|
|
|
#else
|
2020-11-22 10:42:23 -05:00
|
|
|
static void
|
|
|
|
ecmascript_call_function(struct ecmascript_interpreter *interpreter,
|
|
|
|
JS::HandleValue fun, struct string *ret)
|
2021-11-12 15:53:31 -05:00
|
|
|
#endif
|
2020-11-22 10:42:23 -05:00
|
|
|
{
|
2020-12-07 16:36:24 -05:00
|
|
|
if (!get_ecmascript_enable(interpreter))
|
2020-11-22 10:42:23 -05:00
|
|
|
return;
|
|
|
|
assert(interpreter);
|
|
|
|
interpreter->backend_nesting++;
|
2021-10-17 12:17:48 -04:00
|
|
|
#ifdef CONFIG_QUICKJS
|
|
|
|
quickjs_call_function(interpreter, fun, ret);
|
|
|
|
#else
|
2020-11-22 10:42:23 -05:00
|
|
|
spidermonkey_call_function(interpreter, fun, ret);
|
2021-10-17 12:17:48 -04:00
|
|
|
#endif
|
2020-11-22 10:42:23 -05:00
|
|
|
interpreter->backend_nesting--;
|
|
|
|
}
|
|
|
|
|
2021-01-02 10:20:27 -05:00
|
|
|
char *
|
2006-01-27 04:08:19 -05:00
|
|
|
ecmascript_eval_stringback(struct ecmascript_interpreter *interpreter,
|
2019-04-21 06:27:40 -04:00
|
|
|
struct string *code)
|
2006-01-27 04:08:19 -05:00
|
|
|
{
|
2021-01-02 10:20:27 -05:00
|
|
|
char *result;
|
2007-06-21 14:34:36 -04:00
|
|
|
|
2020-12-07 16:36:24 -05:00
|
|
|
if (!get_ecmascript_enable(interpreter))
|
2006-01-27 04:08:19 -05:00
|
|
|
return NULL;
|
|
|
|
assert(interpreter);
|
2007-06-21 14:34:36 -04:00
|
|
|
interpreter->backend_nesting++;
|
2021-10-17 12:17:48 -04:00
|
|
|
#ifdef CONFIG_QUICKJS
|
|
|
|
result = quickjs_eval_stringback(interpreter, code);
|
|
|
|
#else
|
2007-06-21 14:34:36 -04:00
|
|
|
result = spidermonkey_eval_stringback(interpreter, code);
|
2021-10-17 12:17:48 -04:00
|
|
|
#endif
|
2007-06-21 14:34:36 -04:00
|
|
|
interpreter->backend_nesting--;
|
2021-07-20 04:05:58 -04:00
|
|
|
|
|
|
|
check_for_rerender(interpreter, "stringback");
|
|
|
|
|
2007-06-21 14:34:36 -04:00
|
|
|
return result;
|
2006-01-27 04:08:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ecmascript_eval_boolback(struct ecmascript_interpreter *interpreter,
|
2019-04-21 06:27:40 -04:00
|
|
|
struct string *code)
|
2006-01-27 04:08:19 -05:00
|
|
|
{
|
2007-06-21 14:34:36 -04:00
|
|
|
int result;
|
|
|
|
|
2020-12-07 16:36:24 -05:00
|
|
|
if (!get_ecmascript_enable(interpreter))
|
2006-01-27 04:08:19 -05:00
|
|
|
return -1;
|
|
|
|
assert(interpreter);
|
2007-06-21 14:34:36 -04:00
|
|
|
interpreter->backend_nesting++;
|
2021-10-17 12:17:48 -04:00
|
|
|
#ifdef CONFIG_QUICKJS
|
|
|
|
result = quickjs_eval_boolback(interpreter, code);
|
|
|
|
#else
|
2007-06-21 14:34:36 -04:00
|
|
|
result = spidermonkey_eval_boolback(interpreter, code);
|
2021-10-17 12:17:48 -04:00
|
|
|
#endif
|
2007-06-21 14:34:36 -04:00
|
|
|
interpreter->backend_nesting--;
|
2021-07-20 04:05:58 -04:00
|
|
|
|
|
|
|
check_for_rerender(interpreter, "boolback");
|
|
|
|
|
2007-06-21 14:34:36 -04:00
|
|
|
return result;
|
2006-01-27 04:08:19 -05:00
|
|
|
}
|
|
|
|
|
2008-07-18 12:43:30 -04:00
|
|
|
void
|
|
|
|
ecmascript_detach_form_view(struct form_view *fv)
|
|
|
|
{
|
2021-10-17 12:17:48 -04:00
|
|
|
#ifdef CONFIG_QUICKJS
|
2021-11-11 14:43:59 -05:00
|
|
|
quickjs_detach_form_view(fv);
|
2021-10-17 12:17:48 -04:00
|
|
|
#else
|
2008-07-18 12:43:30 -04:00
|
|
|
spidermonkey_detach_form_view(fv);
|
2021-10-17 12:17:48 -04:00
|
|
|
#endif
|
2008-07-18 12:43:30 -04:00
|
|
|
}
|
|
|
|
|
2008-07-18 12:16:34 -04:00
|
|
|
void ecmascript_detach_form_state(struct form_state *fs)
|
|
|
|
{
|
2021-10-17 12:17:48 -04:00
|
|
|
#ifdef CONFIG_QUICKJS
|
2021-11-11 14:43:59 -05:00
|
|
|
quickjs_detach_form_state(fs);
|
2021-10-17 12:17:48 -04:00
|
|
|
#else
|
2008-07-18 12:16:34 -04:00
|
|
|
spidermonkey_detach_form_state(fs);
|
2021-10-17 12:17:48 -04:00
|
|
|
#endif
|
2008-07-18 12:16:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ecmascript_moved_form_state(struct form_state *fs)
|
|
|
|
{
|
2021-10-17 12:17:48 -04:00
|
|
|
#ifdef CONFIG_QUICKJS
|
2021-11-11 14:43:59 -05:00
|
|
|
quickjs_moved_form_state(fs);
|
2021-10-17 12:17:48 -04:00
|
|
|
#else
|
2008-07-18 12:16:34 -04:00
|
|
|
spidermonkey_moved_form_state(fs);
|
2021-10-17 12:17:48 -04:00
|
|
|
#endif
|
2008-07-18 12:16:34 -04:00
|
|
|
}
|
2006-01-27 04:08:19 -05:00
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
void
|
|
|
|
ecmascript_reset_state(struct view_state *vs)
|
|
|
|
{
|
|
|
|
struct form_view *fv;
|
|
|
|
int i;
|
|
|
|
|
2008-07-18 12:16:34 -04:00
|
|
|
/* Normally, if vs->ecmascript == NULL, the associated
|
|
|
|
* ecmascript_obj pointers are also NULL. However, they might
|
|
|
|
* be non-NULL if the ECMAScript objects have been lazily
|
|
|
|
* created because of scripts running in sibling HTML frames. */
|
2008-07-18 12:43:30 -04:00
|
|
|
foreach (fv, vs->forms)
|
|
|
|
ecmascript_detach_form_view(fv);
|
2008-07-18 12:16:34 -04:00
|
|
|
for (i = 0; i < vs->form_info_len; i++)
|
|
|
|
ecmascript_detach_form_state(&vs->form_info[i]);
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
vs->ecmascript_fragile = 0;
|
|
|
|
if (vs->ecmascript)
|
|
|
|
ecmascript_put_interpreter(vs->ecmascript);
|
|
|
|
|
|
|
|
vs->ecmascript = ecmascript_get_interpreter(vs);
|
|
|
|
if (!vs->ecmascript)
|
|
|
|
vs->ecmascript_fragile = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ecmascript_protocol_handler(struct session *ses, struct uri *uri)
|
|
|
|
{
|
|
|
|
struct document_view *doc_view = current_frame(ses);
|
2022-01-17 11:07:46 -05:00
|
|
|
struct string current_url = INIT_STRING(struri(uri), (int)strlen(struri(uri)));
|
2021-01-02 10:20:27 -05:00
|
|
|
char *redirect_url, *redirect_abs_url;
|
2005-09-15 09:58:31 -04:00
|
|
|
struct uri *redirect_uri;
|
|
|
|
|
|
|
|
if (!doc_view) /* Blank initial document. TODO: Start at about:blank? */
|
|
|
|
return;
|
|
|
|
assert(doc_view->vs);
|
|
|
|
if (doc_view->vs->ecmascript_fragile)
|
|
|
|
ecmascript_reset_state(doc_view->vs);
|
|
|
|
if (!doc_view->vs->ecmascript)
|
|
|
|
return;
|
|
|
|
|
|
|
|
redirect_url = ecmascript_eval_stringback(doc_view->vs->ecmascript,
|
|
|
|
¤t_url);
|
|
|
|
if (!redirect_url)
|
|
|
|
return;
|
|
|
|
/* XXX: This code snippet is duplicated over here,
|
|
|
|
* location_set_property(), html_a() and who knows where else. */
|
|
|
|
redirect_abs_url = join_urls(doc_view->document->uri,
|
|
|
|
trim_chars(redirect_url, ' ', 0));
|
|
|
|
mem_free(redirect_url);
|
|
|
|
if (!redirect_abs_url)
|
|
|
|
return;
|
2022-01-14 14:52:17 -05:00
|
|
|
redirect_uri = get_uri(redirect_abs_url, URI_NONE);
|
2005-09-15 09:58:31 -04:00
|
|
|
mem_free(redirect_abs_url);
|
|
|
|
if (!redirect_uri)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* XXX: Is that safe to do at this point? --pasky */
|
|
|
|
goto_uri_frame(ses, redirect_uri, doc_view->name,
|
|
|
|
CACHE_MODE_NORMAL);
|
|
|
|
done_uri(redirect_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-10 13:17:29 -05:00
|
|
|
void
|
|
|
|
ecmascript_timeout_dialog(struct terminal *term, int max_exec_time)
|
|
|
|
{
|
|
|
|
info_box(term, MSGBOX_FREE_TEXT,
|
|
|
|
N_("JavaScript Emergency"), ALIGN_LEFT,
|
|
|
|
msg_text(term,
|
|
|
|
N_("A script embedded in the current document was running\n"
|
|
|
|
"for more than %d seconds. This probably means there is\n"
|
|
|
|
"a bug in the script and it could have halted the whole\n"
|
|
|
|
"ELinks, so the script execution was interrupted."),
|
|
|
|
max_exec_time));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-03-21 12:45:40 -05:00
|
|
|
void
|
2021-01-02 10:20:27 -05:00
|
|
|
ecmascript_set_action(char **action, char *string)
|
2006-03-21 12:45:40 -05:00
|
|
|
{
|
|
|
|
struct uri *protocol;
|
|
|
|
|
|
|
|
trim_chars(string, ' ', NULL);
|
|
|
|
protocol = get_uri(string, URI_PROTOCOL);
|
|
|
|
|
|
|
|
if (protocol) { /* full uri with protocol */
|
|
|
|
done_uri(protocol);
|
|
|
|
mem_free_set(action, string);
|
|
|
|
} else {
|
2006-07-09 07:02:44 -04:00
|
|
|
if (dir_sep(string[0])) { /* absolute uri, TODO: disk drive under WIN32 */
|
2006-03-21 12:45:40 -05:00
|
|
|
struct uri *uri = get_uri(*action, URI_HTTP_REFERRER_HOST);
|
|
|
|
|
|
|
|
if (uri->protocol == PROTOCOL_FILE) {
|
2021-01-02 10:20:27 -05:00
|
|
|
mem_free_set(action, straconcat(struri(uri), string, (char *) NULL));
|
2006-03-21 12:45:40 -05:00
|
|
|
}
|
|
|
|
else
|
2021-01-02 10:20:27 -05:00
|
|
|
mem_free_set(action, straconcat(struri(uri), string + 1, (char *) NULL));
|
2006-03-21 12:45:40 -05:00
|
|
|
done_uri(uri);
|
|
|
|
mem_free(string);
|
|
|
|
} else { /* relative uri */
|
2022-01-18 14:42:29 -05:00
|
|
|
char *last_slash = strrchr(*action, '/');
|
2021-01-02 10:20:27 -05:00
|
|
|
char *new_action;
|
2006-03-21 12:45:40 -05:00
|
|
|
|
|
|
|
if (last_slash) *(last_slash + 1) = '\0';
|
2007-03-11 06:59:11 -04:00
|
|
|
new_action = straconcat(*action, string,
|
2021-01-02 10:20:27 -05:00
|
|
|
(char *) NULL);
|
2006-03-21 12:45:40 -05:00
|
|
|
mem_free_set(action, new_action);
|
|
|
|
mem_free(string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-02 11:35:03 -05:00
|
|
|
/* Timer callback for @interpreter->vs->doc_view->document->timeout.
|
|
|
|
* As explained in @install_timer, this function must erase the
|
|
|
|
* expired timer ID from all variables. */
|
2006-10-23 16:45:55 -04:00
|
|
|
static void
|
|
|
|
ecmascript_timeout_handler(void *i)
|
|
|
|
{
|
2022-01-30 07:58:34 -05:00
|
|
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)i;
|
2006-10-23 16:45:55 -04:00
|
|
|
|
2007-03-11 06:22:02 -04:00
|
|
|
assertm(interpreter->vs->doc_view != NULL,
|
|
|
|
"setTimeout: vs with no document (e_f %d)",
|
|
|
|
interpreter->vs->ecmascript_fragile);
|
2006-11-04 07:20:29 -05:00
|
|
|
interpreter->vs->doc_view->document->timeout = TIMER_ID_UNDEF;
|
2006-12-02 11:35:03 -05:00
|
|
|
/* The expired timer ID has now been erased. */
|
2006-11-03 14:18:31 -05:00
|
|
|
|
2006-10-23 16:45:55 -04:00
|
|
|
ecmascript_eval(interpreter, &interpreter->code, NULL);
|
2021-07-20 04:05:58 -04:00
|
|
|
check_for_rerender(interpreter, "handler");
|
2006-10-23 16:45:55 -04:00
|
|
|
}
|
|
|
|
|
2021-11-12 15:53:31 -05:00
|
|
|
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS)
|
2020-11-22 10:42:23 -05:00
|
|
|
/* Timer callback for @interpreter->vs->doc_view->document->timeout.
|
|
|
|
* As explained in @install_timer, this function must erase the
|
|
|
|
* expired timer ID from all variables. */
|
|
|
|
static void
|
|
|
|
ecmascript_timeout_handler2(void *i)
|
|
|
|
{
|
2022-01-30 07:58:34 -05:00
|
|
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)i;
|
2020-11-22 10:42:23 -05:00
|
|
|
|
|
|
|
assertm(interpreter->vs->doc_view != NULL,
|
|
|
|
"setTimeout: vs with no document (e_f %d)",
|
|
|
|
interpreter->vs->ecmascript_fragile);
|
|
|
|
interpreter->vs->doc_view->document->timeout = TIMER_ID_UNDEF;
|
|
|
|
/* The expired timer ID has now been erased. */
|
|
|
|
|
|
|
|
ecmascript_call_function(interpreter, interpreter->fun, NULL);
|
2021-07-20 04:05:58 -04:00
|
|
|
check_for_rerender(interpreter, "handler2");
|
2020-11-22 10:42:23 -05:00
|
|
|
}
|
2021-10-17 12:17:48 -04:00
|
|
|
#endif
|
2020-11-22 10:42:23 -05:00
|
|
|
|
2021-12-01 14:47:25 -05:00
|
|
|
timer_id_T
|
2021-01-02 10:20:27 -05:00
|
|
|
ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, char *code, int timeout)
|
2006-10-23 16:45:55 -04:00
|
|
|
{
|
2006-10-24 10:47:41 -04:00
|
|
|
assert(interpreter && interpreter->vs->doc_view->document);
|
2021-12-01 14:47:25 -05:00
|
|
|
if (!code) return nullptr;
|
2022-01-04 11:14:49 -05:00
|
|
|
if (interpreter->code.source) {
|
|
|
|
done_string(&interpreter->code);
|
|
|
|
}
|
|
|
|
if (!init_string(&interpreter->code)) {
|
|
|
|
mem_free(code);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2006-10-23 16:45:55 -04:00
|
|
|
add_to_string(&interpreter->code, code);
|
|
|
|
mem_free(code);
|
2021-12-02 11:02:00 -05:00
|
|
|
if (found_in_map_timer(interpreter->vs->doc_view->document->timeout)) {
|
2021-12-01 14:47:25 -05:00
|
|
|
kill_timer(&interpreter->vs->doc_view->document->timeout);
|
|
|
|
}
|
2006-10-24 10:47:41 -04:00
|
|
|
install_timer(&interpreter->vs->doc_view->document->timeout, timeout, ecmascript_timeout_handler, interpreter);
|
2021-12-01 14:47:25 -05:00
|
|
|
|
|
|
|
return interpreter->vs->doc_view->document->timeout;
|
2006-10-23 16:45:55 -04:00
|
|
|
}
|
|
|
|
|
2021-10-17 12:17:48 -04:00
|
|
|
#ifdef CONFIG_ECMASCRIPT_SMJS
|
2021-12-01 14:47:25 -05:00
|
|
|
timer_id_T
|
2020-11-22 10:42:23 -05:00
|
|
|
ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, JS::HandleValue f, int timeout)
|
|
|
|
{
|
|
|
|
assert(interpreter && interpreter->vs->doc_view->document);
|
2022-01-04 11:14:49 -05:00
|
|
|
if (interpreter->code.source) {
|
|
|
|
done_string(&interpreter->code);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!init_string(&interpreter->code)) {
|
|
|
|
return TIMER_ID_UNDEF;
|
|
|
|
}
|
2021-12-02 11:02:00 -05:00
|
|
|
if (found_in_map_timer(interpreter->vs->doc_view->document->timeout)) {
|
2021-12-01 14:47:25 -05:00
|
|
|
kill_timer(&interpreter->vs->doc_view->document->timeout);
|
|
|
|
}
|
2020-11-22 10:42:23 -05:00
|
|
|
JS::RootedValue fun((JSContext *)interpreter->backend_data, f);
|
|
|
|
interpreter->fun = fun;
|
|
|
|
install_timer(&interpreter->vs->doc_view->document->timeout, timeout, ecmascript_timeout_handler2, interpreter);
|
2021-12-01 14:47:25 -05:00
|
|
|
|
|
|
|
return interpreter->vs->doc_view->document->timeout;
|
2020-11-22 10:42:23 -05:00
|
|
|
}
|
2021-10-17 12:17:48 -04:00
|
|
|
#endif
|
2020-11-22 10:42:23 -05:00
|
|
|
|
2021-10-31 15:48:10 -04:00
|
|
|
#ifdef CONFIG_QUICKJS
|
2021-12-01 13:27:50 -05:00
|
|
|
timer_id_T
|
2021-11-12 15:53:31 -05:00
|
|
|
ecmascript_set_timeout2q(struct ecmascript_interpreter *interpreter, JSValueConst fun, int timeout)
|
2021-10-31 15:48:10 -04:00
|
|
|
{
|
|
|
|
assert(interpreter && interpreter->vs->doc_view->document);
|
2022-01-04 11:14:49 -05:00
|
|
|
if (interpreter->code.source) {
|
|
|
|
done_string(&interpreter->code);
|
|
|
|
}
|
|
|
|
if (!init_string(&interpreter->code)) {
|
|
|
|
return TIMER_ID_UNDEF;
|
|
|
|
}
|
2021-12-02 11:02:00 -05:00
|
|
|
if (found_in_map_timer(interpreter->vs->doc_view->document->timeout)) {
|
2021-12-01 13:27:50 -05:00
|
|
|
kill_timer(&interpreter->vs->doc_view->document->timeout);
|
|
|
|
}
|
2021-10-31 15:48:10 -04:00
|
|
|
interpreter->fun = fun;
|
|
|
|
install_timer(&interpreter->vs->doc_view->document->timeout, timeout, ecmascript_timeout_handler2, interpreter);
|
2021-12-01 13:27:50 -05:00
|
|
|
|
|
|
|
return interpreter->vs->doc_view->document->timeout;
|
2021-10-31 15:48:10 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-12-08 14:54:14 -05:00
|
|
|
static void
|
|
|
|
init_ecmascript_module(struct module *module)
|
|
|
|
{
|
|
|
|
read_url_list();
|
2021-02-22 09:55:12 -05:00
|
|
|
|
|
|
|
if (elinks_home) {
|
2021-09-07 11:31:45 -04:00
|
|
|
/* ecmascript console log */
|
2021-02-22 09:55:12 -05:00
|
|
|
console_log_filename = straconcat(elinks_home, "/console.log", NULL);
|
2021-09-07 11:31:45 -04:00
|
|
|
console_error_filename = straconcat(elinks_home, "/console.err", NULL);
|
|
|
|
/* ecmascript local storage db location */
|
2021-02-22 17:27:19 -05:00
|
|
|
local_storage_filename = straconcat(elinks_home, "/elinks_ls.db", NULL);
|
|
|
|
}
|
2021-09-20 12:40:01 -04:00
|
|
|
ecmascript_enabled = get_opt_bool("ecmascript.enable", NULL);
|
2020-12-08 14:54:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
done_ecmascript_module(struct module *module)
|
|
|
|
{
|
|
|
|
free_string_list(&allowed_urls);
|
2021-02-22 09:55:12 -05:00
|
|
|
mem_free_if(console_log_filename);
|
2021-02-22 17:27:19 -05:00
|
|
|
mem_free_if(local_storage_filename);
|
2020-12-08 14:54:14 -05:00
|
|
|
}
|
2020-11-22 10:42:23 -05:00
|
|
|
|
2006-01-16 08:14:14 -05:00
|
|
|
static struct module *ecmascript_modules[] = {
|
2011-05-11 05:31:15 -04:00
|
|
|
#ifdef CONFIG_ECMASCRIPT_SMJS
|
2006-01-16 08:14:14 -05:00
|
|
|
&spidermonkey_module,
|
2021-10-17 12:17:48 -04:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_QUICKJS
|
|
|
|
&quickjs_module,
|
2006-01-16 08:14:14 -05:00
|
|
|
#endif
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2021-10-17 12:17:48 -04:00
|
|
|
void
|
|
|
|
free_document(void *doc)
|
|
|
|
{
|
|
|
|
if (!doc) {
|
|
|
|
return;
|
|
|
|
}
|
2022-01-30 07:58:34 -05:00
|
|
|
xmlpp::Document *docu = static_cast<xmlpp::Document *>(doc);
|
2021-10-17 12:17:48 -04:00
|
|
|
delete docu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
document_parse(struct document *document)
|
|
|
|
{
|
|
|
|
#ifdef ECMASCRIPT_DEBUG
|
|
|
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
|
|
|
#endif
|
|
|
|
struct cache_entry *cached = document->cached;
|
|
|
|
struct fragment *f = get_cache_fragment(cached);
|
|
|
|
|
|
|
|
if (!f || !f->length) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct string str;
|
2022-01-04 11:14:49 -05:00
|
|
|
if (!init_string(&str)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2021-10-17 12:17:48 -04:00
|
|
|
|
|
|
|
add_bytes_to_string(&str, f->data, f->length);
|
|
|
|
|
|
|
|
// Parse HTML and create a DOM tree
|
|
|
|
xmlDoc* doc = htmlReadDoc((xmlChar*)str.source, NULL, get_cp_mime_name(document->cp),
|
|
|
|
HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING);
|
|
|
|
// Encapsulate raw libxml document in a libxml++ wrapper
|
|
|
|
xmlpp::Document *docu = new xmlpp::Document(doc);
|
|
|
|
done_string(&str);
|
|
|
|
|
|
|
|
return (void *)docu;
|
|
|
|
}
|
|
|
|
|
2021-10-22 04:44:37 -04:00
|
|
|
static void
|
|
|
|
delayed_goto(void *data)
|
|
|
|
{
|
2022-01-30 07:58:34 -05:00
|
|
|
struct delayed_goto *deg = (struct delayed_goto *)data;
|
2021-10-22 04:44:37 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-01-14 13:48:40 -05:00
|
|
|
void
|
|
|
|
location_goto_const(struct document_view *doc_view, const char *url)
|
|
|
|
{
|
|
|
|
char *url2 = stracpy(url);
|
|
|
|
|
|
|
|
if (url2) {
|
|
|
|
location_goto(doc_view, url2);
|
|
|
|
mem_free(url2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-22 04:44:37 -04:00
|
|
|
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;
|
2022-01-14 14:52:17 -05:00
|
|
|
new_uri = get_uri(new_abs_url, URI_NONE);
|
2021-10-22 04:44:37 -04:00
|
|
|
mem_free(new_abs_url);
|
|
|
|
if (!new_uri)
|
|
|
|
return;
|
2022-01-16 15:08:50 -05:00
|
|
|
deg = (struct delayed_goto *)mem_calloc(1, sizeof(*deg));
|
2021-10-22 04:44:37 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
struct module ecmascript_module = struct_module(
|
|
|
|
/* name: */ N_("ECMAScript"),
|
|
|
|
/* options: */ ecmascript_options,
|
|
|
|
/* events: */ NULL,
|
2006-01-16 08:14:14 -05:00
|
|
|
/* submodules: */ ecmascript_modules,
|
2005-09-15 09:58:31 -04:00
|
|
|
/* data: */ NULL,
|
2020-12-08 14:54:14 -05:00
|
|
|
/* init: */ init_ecmascript_module,
|
|
|
|
/* done: */ done_ecmascript_module
|
2005-09-15 09:58:31 -04:00
|
|
|
);
|