1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00
elinks/src/session/session.h

358 lines
9.2 KiB
C
Raw Normal View History

#ifndef EL__SESSION_SESSION_H
#define EL__SESSION_SESSION_H
#include "bfu/dialog.h"
#include "cache/cache.h"
#include "main/timer.h" /* timer_id_T */
#include "network/state.h"
#include "session/download.h"
#include "session/history.h"
#include "util/lists.h"
#include "viewer/text/vs.h"
#ifdef __cplusplus
extern "C" {
#endif
2021-06-14 15:29:22 -04:00
struct cache_entry;
struct document;
struct document_view;
struct link;
struct location;
struct session_status;
struct term_event;
struct terminal_info;
struct terminal;
struct uri;
struct window;
2007-07-26 20:07:39 -04:00
/** Used by delayed_open() and delayed_goto_uri_frame(). */
struct delayed_open {
struct session *ses;
struct uri *uri;
char *target;
};
struct delayed_rel {
2021-06-14 15:29:22 -04:00
struct cache_entry *cached;
struct document *document;
struct session *ses;
};
enum remote_session_flags {
SES_REMOTE_NEW_TAB = 1,
SES_REMOTE_NEW_WINDOW = 2,
SES_REMOTE_CURRENT_TAB = 4,
SES_REMOTE_PROMPT_URL = 8,
SES_REMOTE_PING = 16,
SES_REMOTE_ADD_BOOKMARK = 32,
SES_REMOTE_INFO_BOX = 64,
2017-05-16 12:37:29 -04:00
SES_REMOTE_RELOAD = 128,
2020-04-25 07:59:40 -04:00
SES_REMOTE_SEARCH = 256,
};
typedef unsigned int remote_session_flags_T;
2007-07-26 20:07:39 -04:00
/** This is generic frame descriptor, meaningful mainly for ses_*_frame*(). */
struct frame {
LIST_HEAD(struct frame);
char *name;
int redirect_cnt;
struct view_state vs;
};
struct iframe {
LIST_HEAD(struct frame);
char *name;
int redirect_cnt;
struct view_state vs;
};
enum kp_mark { KP_MARK_NOTHING, KP_MARK_SET, KP_MARK_GOTO };
2007-07-26 20:07:39 -04:00
/** Use for keyboard prefixes. */
struct kbdprefix {
2007-07-26 20:07:39 -04:00
/** This is the repeat count being inserted by user so far.
* It is stored intermediately per-session. */
int repeat_count;
#ifdef CONFIG_MARKS
2007-07-26 20:07:39 -04:00
/** If the previous key was a mark prefix, this describes what kind
* of action are we supposed to do when we receive the next key. */
enum kp_mark mark;
#endif
};
struct session;
2007-07-26 20:07:39 -04:00
/** This describes, what are we trying to do right now. We pass this around so
* that we can use generic scheduler routines and when the control will get
* back to our subsystem, we will know what are we up to. */
enum task_type {
TASK_NONE,
TASK_FORWARD,
TASK_IMGMAP,
TASK_RELOAD,
TASK_HISTORY,
};
struct session_task {
enum task_type type;
/* TODO: union --pasky */
struct {
char *frame;
2021-07-28 15:22:47 -04:00
char *iframe;
struct location *location;
} target;
};
struct session_status {
unsigned int show_tabs_bar:1;
unsigned int show_status_bar:1;
unsigned int show_title_bar:1;
int force_show_status_bar:2;
int force_show_title_bar:2;
unsigned int set_window_title:1;
char *last_title;
char *window_status;
#ifdef CONFIG_LEDS
unsigned int show_leds:1;
struct led_panel leds;
struct led *ssl_led;
struct led *insert_mode_led;
struct led *ecmascript_led;
struct led *popup_led;
struct led *download_led;
#endif
2007-07-26 20:07:39 -04:00
/** Has the tab been visited yet. */
unsigned int visited:1;
2007-07-26 20:07:39 -04:00
/** Is processing file requests. */
unsigned int processing_file_requests:1;
unsigned int show_tabs_bar_at_top:1;
};
enum insert_mode {
INSERT_MODE_LESS,
INSERT_MODE_ON,
INSERT_MODE_OFF,
};
enum navigate_mode {
NAVIGATE_LINKWISE,
NAVIGATE_CURSOR_ROUTING,
};
2007-07-26 20:07:39 -04:00
/** This is one of the building stones of ELinks architecture --- this structure
* carries information about the specific ELinks session. Each tab (thus, at
* least one per terminal, in the normal case) has its own session. Session
* describes mainly the current browsing and control state, from the currently
* viewed document through the browsing history of this session to the status
* bar information. */
struct session {
LIST_HEAD(struct session);
SMJS: add session object Add session_class, which defines a JSObject wrapper for struct session. Add location_array_class, which defines a JSObject wrapper for struct ses_history. The "history" member of struct session is a struct ses_history, which is a linked list of struct location. Add a pointer from struct session to the session_class object and the location_array object. Add smjs_get_session_object to return a session_class JSObject wrapper for a given struct session. Add smjs_get_session_location_array_object to return a location_array_class JSObject wrapper for a given struct session. Add "session" property to the "elinks" object, which uses smjs_get_session_object to get a JSObject wrapper for smjs_ses. Add smjs_location_array_get_property, which allows indexing a location_array object using a positive number for history forward or a negative number for history backward. Add session_props, session_get_property, session_set_property, session_funcs, smjs_session_goto_url (which implements the "goto" method), and smjs_init_session_interface for session_class. Add session_construct, which creates a new tab and returns the JSObject session_class wrapper. Add session_finalize and smjs_location_array_finalize, which clear the pointers between struct session and the JSObject wrappers in question. Add smjs_detach_session_object, which clears the pointers between a given struct session and the corresponding JSObject wrappers. In destroy_session, call smjs_detach_session_object. Add jsval_to_object helper in ecmascript/spidermonkey/util.h; jsval_to_object is used in smjs_session_goto_url. Modify delayed_goto_uri_frame to allow the target to be NULL. smjs_session_goto_url needs this modification.
2011-11-13 02:12:08 -05:00
#ifdef CONFIG_SCRIPTING_SPIDERMONKEY
struct JSObject *jsobject; /* Instance of session_class */
#endif
2007-07-26 20:07:39 -04:00
/** @name The vital session data
* @{ */
struct window *tab;
/* Session-specific options */
struct option *option;
2007-07-26 20:07:39 -04:00
/** @} @name Browsing history
* @{ */
struct ses_history history;
SMJS: add session object Add session_class, which defines a JSObject wrapper for struct session. Add location_array_class, which defines a JSObject wrapper for struct ses_history. The "history" member of struct session is a struct ses_history, which is a linked list of struct location. Add a pointer from struct session to the session_class object and the location_array object. Add smjs_get_session_object to return a session_class JSObject wrapper for a given struct session. Add smjs_get_session_location_array_object to return a location_array_class JSObject wrapper for a given struct session. Add "session" property to the "elinks" object, which uses smjs_get_session_object to get a JSObject wrapper for smjs_ses. Add smjs_location_array_get_property, which allows indexing a location_array object using a positive number for history forward or a negative number for history backward. Add session_props, session_get_property, session_set_property, session_funcs, smjs_session_goto_url (which implements the "goto" method), and smjs_init_session_interface for session_class. Add session_construct, which creates a new tab and returns the JSObject session_class wrapper. Add session_finalize and smjs_location_array_finalize, which clear the pointers between struct session and the JSObject wrappers in question. Add smjs_detach_session_object, which clears the pointers between a given struct session and the corresponding JSObject wrappers. In destroy_session, call smjs_detach_session_object. Add jsval_to_object helper in ecmascript/spidermonkey/util.h; jsval_to_object is used in smjs_session_goto_url. Modify delayed_goto_uri_frame to allow the target to be NULL. smjs_session_goto_url needs this modification.
2011-11-13 02:12:08 -05:00
#ifdef CONFIG_SCRIPTING_SPIDERMONKEY
struct JSObject *history_jsobject; /* Instance of location_array_class */
#endif
2007-07-26 20:07:39 -04:00
/** @} @name The current document
* @{ */
LIST_OF(struct file_to_load) more_files;
struct download loading;
struct uri *loading_uri;
int reloadlevel;
int redirect_cnt;
struct document_view *doc_view;
LIST_OF(struct document_view) scrn_frames;
2021-07-26 15:28:19 -04:00
LIST_OF(struct document_view) scrn_iframes;
/** The URI from which the next start_download() or resume_download()
* call should download, or NULL if no such call is pending.
2009-07-18 19:08:50 -04:00
*
* When the user requests a download, one of those functions
* is given as a callback to query_file(), which asks the user
* where to save the downloaded file. The URI cannot be given
* to the callback as a parameter because query_file()
* supports only one void * parameter for the callback and
* that one is already used for the struct session *.
* Instead, the URI is saved here before the query_file()
* call. */
struct uri *download_uri;
2007-07-26 20:07:39 -04:00
/** The URI which is the referrer to the current loaded document
* or NULL if there are no referrer.
*
* The @c referrer member's sole purpose is to have the information
* handy when loading URIs. It is not 'filtered' in anyway at this
* level only at the lower ones. */
struct uri *referrer;
2007-07-26 20:07:39 -04:00
/** @} @name The current action-in-progress selector
* @{ */
struct session_task task;
2007-07-26 20:07:39 -04:00
/** @} @name The current browsing state
* @{ */
int search_direction;
struct kbdprefix kbdprefix;
int exit_query;
timer_id_T display_timer;
2007-07-26 20:07:39 -04:00
/** The text input form insert mode. It is a tristate controlled by the
* boolean document.browse.forms.insert_mode option. When disabled we
2007-07-26 20:07:39 -04:00
* use modeless insertion and we always insert stuff into the text
* input field. When enabled it is possible to switch insertion on and
2007-07-26 20:07:39 -04:00
* off using ::ACT_EDIT_ENTER and *_CANCEL. */
enum insert_mode insert_mode;
enum navigate_mode navigate_mode;
char *search_word;
char *last_search_word;
2007-07-26 20:07:39 -04:00
/** The possibly running type queries (what-to-do-with-that-file?) */
LIST_OF(struct type_query) type_queries;
2007-07-26 20:07:39 -04:00
/** The info for status displaying */
struct session_status status;
2007-07-26 20:07:39 -04:00
/** @} */
};
extern LIST_OF(struct session) sessions;
extern remote_session_flags_T remote_session_flags;
2007-07-26 20:07:39 -04:00
/** This returns a pointer to the current location inside of the given session.
* That's nice for encapsulation and already paid out once ;-). */
#define cur_loc(x) ((x)->history.current)
2007-07-27 07:14:00 -04:00
/** Return if we have anything being loaded in this session already.
* @relates session */
static inline int
have_location(struct session *ses) {
return !!cur_loc(ses);
}
2007-07-26 20:07:39 -04:00
/** Swaps the current session referrer with the new one passed as @a referrer.
2007-07-27 07:14:00 -04:00
* @a referrer may be NULL.
* @relates session */
void set_session_referrer(struct session *ses, struct uri *referrer);
void
print_error_dialog(struct session *ses, struct connection_state state,
struct uri *uri, connection_priority_T priority);
void process_file_requests(struct session *);
struct string *encode_session_info(struct string *info,
2007-07-26 15:39:08 -04:00
LIST_OF(struct string_list_item) *url_list);
2007-07-26 20:07:39 -04:00
/** @returns zero if the info was remote sessions or if it failed to
* create any sessions. */
int decode_session_info(struct terminal *term, struct terminal_info *info);
2007-07-26 20:07:39 -04:00
/** Registers a base session and returns its id. Value <= 0 means error. */
int
add_session_info(struct session *ses, struct uri *uri, struct uri *referrer,
cache_mode_T cache_mode, enum task_type task);
void done_saved_session_info(void);
struct session *init_session(struct session *ses, struct terminal *term,
struct uri *uri, int in_background);
void doc_loading_callback(struct download *, struct session *);
void abort_loading(struct session *, int);
void reload_frame(struct session *, char *, cache_mode_T);
void reload(struct session *, cache_mode_T);
void load_frames(struct session *, struct document_view *);
2022-02-25 14:29:32 -05:00
struct frame *ses_find_frame(struct session *, const char *);
2021-07-28 15:22:47 -04:00
struct frame *ses_find_iframe(struct session *, char *);
void free_files(struct session *);
void display_timer(struct session *ses);
2007-07-26 20:07:39 -04:00
/** session_is_loading() is like !!get_current_download() but doesn't take
2007-07-27 07:14:00 -04:00
* session.req_sent into account.
* @relates session */
int session_is_loading(struct session *ses);
2007-07-26 20:07:39 -04:00
struct download *get_current_download(struct session *ses);
2007-07-26 20:07:39 -04:00
/** Information about the current document */
char *get_current_url(struct session *, char *, size_t);
char *get_current_title(struct session *, char *, size_t);
struct link *get_current_session_link(struct session *ses);
struct link *get_current_link_in_view(struct document_view *doc_view);
char *get_current_link_url(struct session *, char *, size_t);
char *get_current_link_name(struct session *, char *, size_t);
2007-07-26 15:39:08 -04:00
extern LIST_OF(struct questions_entry) questions_queue;
void add_questions_entry(void (*callback)(struct session *, void *), void *data);
void check_questions_queue(struct session *ses);
char *get_homepage_url(void);
2007-07-26 20:07:39 -04:00
/** Returns current keyboard repeat count and reset it. */
int eat_kbd_repeat_count(struct session *ses);
/** Set current keyboard repeat count to given value and update link
* highlighting and status bar. */
int set_kbd_repeat_count(struct session *ses, int new_count);
char *get_ui_clipboard_file(void);
#ifdef CONFIG_SCRIPTING
void maybe_pre_format_html(struct cache_entry *cached, struct session *ses);
#endif
#ifdef CONFIG_ECMASCRIPT
void doc_rerender_after_document_update(struct session *ses);
#endif
#ifdef __cplusplus
}
#endif
#endif