ECMAScript: Probably superfluous kill_timer. Removed unused include.
[elinks.git] / src / ecmascript / ecmascript.h
blob47063bb91563c51c04651cfd864f84837f6b9dfd
1 #ifndef EL__ECMASCRIPT_ECMASCRIPT_H
2 #define EL__ECMASCRIPT_ECMASCRIPT_H
4 /* This is a trivial ECMAScript driver. All your base are belong to pasky. */
5 /* In the future you will get DOM, a complete ECMAScript interface and free
6 * plasm displays for everyone. */
8 #include "main/module.h"
9 #include "util/time.h"
11 struct string;
12 struct terminal;
13 struct uri;
14 struct view_state;
16 #define get_ecmascript_enable() get_opt_bool("ecmascript.enable")
18 struct ecmascript_interpreter {
19 struct view_state *vs;
20 void *backend_data;
21 /* Used by document.write() */
22 struct string *ret;
24 /* The code evaluated by setTimeout() */
25 struct string code;
27 time_t exec_start;
29 /* This is a cross-rerenderings accumulator of
30 * @document.onload_snippets (see its description for juicy details).
31 * They enter this list as they continue to appear there, and they
32 * never leave it (so that we can always find from where to look for
33 * any new snippets in document.onload_snippets). Instead, as we
34 * go through the list we maintain a pointer to the last processed
35 * entry. */
36 struct list_head onload_snippets; /* -> struct string_list_item */
37 struct string_list_item *current_onload_snippet;
39 /* ID of the {struct document} where those onload_snippets belong to.
40 * It is kept at 0 until it is definitively hard-attached to a given
41 * final document. Then if we suddenly appear with this structure upon
42 * a document with a different ID, we reset the state and start with a
43 * fresh one (normally, that does not happen since reloading sets
44 * ecmascript_fragile, but it can happen i.e. when the urrent document
45 * is reloaded in another tab and then you just cause the current tab
46 * to redraw. */
47 unsigned int onload_snippets_owner;
50 /* Why is the interpreter bound to {struct view_state} instead of {struct
51 * document}? That's easy, because the script won't raid just inside of the
52 * document, but it will also want to generate pop-up boxes, adjust form
53 * contents (which is doc_view-specific) etc. Of course the cons are that we
54 * need to wait with any javascript code execution until we get bound to the
55 * view_state through document_view - that means we are going to re-render the
56 * document if it contains a <script> area full of document.write()s. And why
57 * not bound the interpreter to {struct document_view} then? Because it is
58 * reset for each rerendering, and it sucks to do all the magic to preserve the
59 * interpreter over the rerenderings (we tried). */
61 int ecmascript_check_url(unsigned char *url, unsigned char *frame);
62 void ecmascript_free_urls(struct module *module);
64 struct ecmascript_interpreter *ecmascript_get_interpreter(struct view_state*vs);
65 void ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter);
67 void ecmascript_reset_state(struct view_state *vs);
69 void ecmascript_eval(struct ecmascript_interpreter *interpreter, struct string *code, struct string *ret);
70 unsigned char *ecmascript_eval_stringback(struct ecmascript_interpreter *interpreter, struct string *code);
71 /* Returns -1 if undefined. */
72 int ecmascript_eval_boolback(struct ecmascript_interpreter *interpreter, struct string *code);
74 /* Takes line with the syntax javascript:<ecmascript code>. Activated when user
75 * follows a link with this synstax. */
76 void ecmascript_protocol_handler(struct session *ses, struct uri *uri);
78 void ecmascript_timeout_dialog(struct terminal *term, int max_exec_time);
80 void ecmascript_set_action(unsigned char **action, unsigned char *string);
82 void ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, unsigned char *code, int timeout);
84 extern struct module ecmascript_module;
86 #endif