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", NULL)
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() */
35 #if defined(CONFIG_ECMASCRIPT_SMJS_HEARTBEAT)
36 struct heartbeat
*heartbeat
;
37 #elif defined(HAVE_JS_SETBRANCHCALLBACK)
41 /* This is a cross-rerenderings accumulator of
42 * @document.onload_snippets (see its description for juicy details).
43 * They enter this list as they continue to appear there, and they
44 * never leave it (so that we can always find from where to look for
45 * any new snippets in document.onload_snippets). Instead, as we
46 * go through the list we maintain a pointer to the last processed
48 LIST_OF(struct string_list_item
) onload_snippets
;
49 struct string_list_item
*current_onload_snippet
;
51 /* ID of the {struct document} where those onload_snippets belong to.
52 * It is kept at 0 until it is definitively hard-attached to a given
53 * final document. Then if we suddenly appear with this structure upon
54 * a document with a different ID, we reset the state and start with a
55 * fresh one (normally, that does not happen since reloading sets
56 * ecmascript_fragile, but it can happen i.e. when the urrent document
57 * is reloaded in another tab and then you just cause the current tab
59 unsigned int onload_snippets_cache_id
;
62 /* Why is the interpreter bound to {struct view_state} instead of {struct
63 * document}? That's easy, because the script won't raid just inside of the
64 * document, but it will also want to generate pop-up boxes, adjust form
65 * contents (which is doc_view-specific) etc. Of course the cons are that we
66 * need to wait with any javascript code execution until we get bound to the
67 * view_state through document_view - that means we are going to re-render the
68 * document if it contains a <script> area full of document.write()s. And why
69 * not bound the interpreter to {struct document_view} then? Because it is
70 * reset for each rerendering, and it sucks to do all the magic to preserve the
71 * interpreter over the rerenderings (we tried). */
73 int ecmascript_check_url(unsigned char *url
, unsigned char *frame
);
74 void ecmascript_free_urls(struct module
*module
);
76 struct ecmascript_interpreter
*ecmascript_get_interpreter(struct view_state
*vs
);
77 void ecmascript_put_interpreter(struct ecmascript_interpreter
*interpreter
);
78 int ecmascript_get_interpreter_count(void);
80 void ecmascript_detach_form_view(struct form_view
*fv
);
81 void ecmascript_detach_form_state(struct form_state
*fs
);
82 void ecmascript_moved_form_state(struct form_state
*fs
);
84 void ecmascript_reset_state(struct view_state
*vs
);
86 void ecmascript_eval(struct ecmascript_interpreter
*interpreter
, struct string
*code
, struct string
*ret
);
87 unsigned char *ecmascript_eval_stringback(struct ecmascript_interpreter
*interpreter
, struct string
*code
);
88 /* Returns -1 if undefined. */
89 int ecmascript_eval_boolback(struct ecmascript_interpreter
*interpreter
, struct string
*code
);
91 /* Takes line with the syntax javascript:<ecmascript code>. Activated when user
92 * follows a link with this synstax. */
93 void ecmascript_protocol_handler(struct session
*ses
, struct uri
*uri
);
95 void ecmascript_timeout_dialog(struct terminal
*term
, int max_exec_time
);
97 void ecmascript_set_action(unsigned char **action
, unsigned char *string
);
99 void ecmascript_set_timeout(struct ecmascript_interpreter
*interpreter
, unsigned char *code
, int timeout
);
101 extern struct module ecmascript_module
;