1038: Remove remembering last 8 URLs. It did not work.
[elinks.git] / src / ecmascript / see / navigator.c
blob644dad78fd564adb68efc0f43b1939cb1badc5b2
1 /* The SEE navigator objects implementation. */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
11 #include "elinks.h"
13 #include <see/see.h>
15 #include "bfu/dialog.h"
16 #include "cache/cache.h"
17 #include "cookies/cookies.h"
18 #include "dialogs/menu.h"
19 #include "dialogs/status.h"
20 #include "document/html/frames.h"
21 #include "document/document.h"
22 #include "document/forms.h"
23 #include "document/view.h"
24 #include "ecmascript/ecmascript.h"
25 #include "ecmascript/see/input.h"
26 #include "ecmascript/see/navigator.h"
27 #include "ecmascript/see/strings.h"
28 #include "ecmascript/see/window.h"
29 #include "intl/gettext/libintl.h"
30 #include "main/select.h"
31 #include "osdep/newwin.h"
32 #include "osdep/sysname.h"
33 #include "protocol/http/http.h"
34 #include "protocol/uri.h"
35 #include "session/history.h"
36 #include "session/location.h"
37 #include "session/session.h"
38 #include "session/task.h"
39 #include "terminal/tab.h"
40 #include "terminal/terminal.h"
41 #include "util/conv.h"
42 #include "util/memory.h"
43 #include "util/string.h"
44 #include "viewer/text/draw.h"
45 #include "viewer/text/form.h"
46 #include "viewer/text/link.h"
47 #include "viewer/text/vs.h"
49 static void navigator_get(struct SEE_interpreter *, struct SEE_object *, struct SEE_string *, struct SEE_value *);
50 static int navigator_hasproperty(struct SEE_interpreter *, struct SEE_object *, struct SEE_string *);
52 struct SEE_objectclass js_navigator_object_class = {
53 "navigator",
54 navigator_get,
55 SEE_no_put,
56 SEE_no_canput,
57 navigator_hasproperty,
58 SEE_no_delete,
59 SEE_no_defaultvalue,
60 SEE_no_enumerator,
61 NULL,
62 NULL,
63 NULL
66 static void
67 navigator_get(struct SEE_interpreter *interp, struct SEE_object *o,
68 struct SEE_string *p, struct SEE_value *res)
70 struct SEE_string *str;
72 SEE_SET_UNDEFINED(res);
73 if (p == s_appCodeName) {
74 SEE_SET_STRING(res, s_Mozilla);
75 } else if (p == s_appName) {
76 SEE_SET_STRING(res, s_ELinks_);
77 } else if (p == s_appVersion) {
78 str = string_to_SEE_string(interp, VERSION);
79 SEE_SET_STRING(res, str);
80 } else if (p == s_language) {
81 #ifdef CONFIG_NLS
82 if (get_opt_bool("protocol.http.accept_ui_language")) {
83 str = string_to_SEE_string(interp,
84 language_to_iso639(current_language));
85 SEE_SET_STRING(res, str);
87 #endif
88 } else if (p == s_platform) {
89 str = string_to_SEE_string(interp, system_name);
90 SEE_SET_STRING(res, str);
91 } else if (p == s_userAgent) {
92 /* FIXME: Code duplication. */
93 unsigned char *optstr = get_opt_str("protocol.http.user_agent");
95 if (*optstr && strcmp(optstr, " ")) {
96 unsigned char *ustr, ts[64] = "";
97 static unsigned char custr[256];
99 if (!list_empty(terminals)) {
100 unsigned int tslen = 0;
101 struct terminal *term = terminals.prev;
103 ulongcat(ts, &tslen, term->width, 3, 0);
104 ts[tslen++] = 'x';
105 ulongcat(ts, &tslen, term->height, 3, 0);
107 ustr = subst_user_agent(optstr, VERSION_STRING, system_name, ts);
109 if (ustr) {
110 safe_strncpy(custr, ustr, 256);
111 mem_free(ustr);
112 str = string_to_SEE_string(interp, custr);
113 SEE_SET_STRING(res, str);
120 static int
121 navigator_hasproperty(struct SEE_interpreter *interp, struct SEE_object *o,
122 struct SEE_string *p)
124 if (p == s_appCodeName || p == s_appName || p == s_appVersion
125 || p == s_language || p == s_platform || p == s_userAgent)
126 return 1;
127 return 0;
132 void
133 init_js_navigator_object(struct ecmascript_interpreter *interpreter)
135 struct global_object *g = interpreter->backend_data;
136 struct SEE_interpreter *interp = &g->interp;
137 struct SEE_value v;
138 struct SEE_object *navigator;
140 navigator = SEE_NEW(interp, struct SEE_object);
142 navigator->objectclass = &js_navigator_object_class;
143 navigator->Prototype = NULL;
145 SEE_SET_OBJECT(&v, navigator);
146 SEE_OBJECT_PUT(interp, interp->Global, s_navigator, &v, 0);