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"
18 #define get_ecmascript_enable() get_opt_bool("ecmascript.enable")
20 struct ecmascript_interpreter
{
21 struct view_state
*vs
;
24 /* Nesting level of calls to backend functions. When this is
25 * nonzero, there are references to backend_data in the C
26 * stack, so it is not safe to free the data yet. */
29 /* Used by document.write() */
32 /* The code evaluated by setTimeout() */
37 /* This is a cross-rerenderings accumulator of
38 * @document.onload_snippets (see its description for juicy details).
39 * They enter this list as they continue to appear there, and they
40 * never leave it (so that we can always find from where to look for
41 * any new snippets in document.onload_snippets). Instead, as we
42 * go through the list we maintain a pointer to the last processed
44 LIST_OF(struct string_list_item
) onload_snippets
;
45 struct string_list_item
*current_onload_snippet
;
47 /* ID of the {struct document} where those onload_snippets belong to.
48 * It is kept at 0 until it is definitively hard-attached to a given
49 * final document. Then if we suddenly appear with this structure upon
50 * a document with a different ID, we reset the state and start with a
51 * fresh one (normally, that does not happen since reloading sets
52 * ecmascript_fragile, but it can happen i.e. when the urrent document
53 * is reloaded in another tab and then you just cause the current tab
55 unsigned int onload_snippets_cache_id
;
58 /* Why is the interpreter bound to {struct view_state} instead of {struct
59 * document}? That's easy, because the script won't raid just inside of the
60 * document, but it will also want to generate pop-up boxes, adjust form
61 * contents (which is doc_view-specific) etc. Of course the cons are that we
62 * need to wait with any javascript code execution until we get bound to the
63 * view_state through document_view - that means we are going to re-render the
64 * document if it contains a <script> area full of document.write()s. And why
65 * not bound the interpreter to {struct document_view} then? Because it is
66 * reset for each rerendering, and it sucks to do all the magic to preserve the
67 * interpreter over the rerenderings (we tried). */
69 int ecmascript_check_url(unsigned char *url
, unsigned char *frame
);
70 void ecmascript_free_urls(struct module
*module
);
72 struct ecmascript_interpreter
*ecmascript_get_interpreter(struct view_state
*vs
);
73 void ecmascript_put_interpreter(struct ecmascript_interpreter
*interpreter
);
75 void ecmascript_detach_form_view(struct form_view
*fv
);
76 void ecmascript_detach_form_state(struct form_state
*fs
);
77 void ecmascript_moved_form_state(struct form_state
*fs
);
79 void ecmascript_reset_state(struct view_state
*vs
);
81 void ecmascript_eval(struct ecmascript_interpreter
*interpreter
, struct string
*code
, struct string
*ret
);
82 unsigned char *ecmascript_eval_stringback(struct ecmascript_interpreter
*interpreter
, struct string
*code
);
83 /* Returns -1 if undefined. */
84 int ecmascript_eval_boolback(struct ecmascript_interpreter
*interpreter
, struct string
*code
);
86 /* Takes line with the syntax javascript:<ecmascript code>. Activated when user
87 * follows a link with this synstax. */
88 void ecmascript_protocol_handler(struct session
*ses
, struct uri
*uri
);
90 void ecmascript_timeout_dialog(struct terminal
*term
, int max_exec_time
);
92 void ecmascript_set_action(unsigned char **action
, unsigned char *string
);
94 void ecmascript_set_timeout(struct ecmascript_interpreter
*interpreter
, unsigned char *code
, int timeout
);
96 extern struct module ecmascript_module
;