1 /* The SpiderMonkey location and history objects implementation. */
13 #include "ecmascript/spidermonkey/util.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/spidermonkey/navigator.h"
26 #include "intl/gettext/libintl.h"
27 #include "main/select.h"
28 #include "osdep/newwin.h"
29 #include "osdep/sysname.h"
30 #include "protocol/http/http.h"
31 #include "protocol/uri.h"
32 #include "session/history.h"
33 #include "session/location.h"
34 #include "session/session.h"
35 #include "session/task.h"
36 #include "terminal/tab.h"
37 #include "terminal/terminal.h"
38 #include "util/conv.h"
39 #include "util/memory.h"
40 #include "util/string.h"
41 #include "viewer/text/draw.h"
42 #include "viewer/text/form.h"
43 #include "viewer/text/link.h"
44 #include "viewer/text/vs.h"
47 static JSBool
navigator_get_property(JSContext
*ctx
, JSObject
*obj
, jsid id
, jsval
*vp
);
49 const JSClass navigator_class
= {
52 JS_PropertyStub
, JS_PropertyStub
,
53 navigator_get_property
, JS_StrictPropertyStub
,
54 JS_EnumerateStub
, JS_ResolveStub
, JS_ConvertStub
, JS_FinalizeStub
57 /* Tinyids of properties. Use negative values to distinguish these
58 * from array indexes (even though this object has no array elements).
59 * ECMAScript code should not use these directly as in navigator[-1];
60 * future versions of ELinks may change the numbers. */
62 JSP_NAVIGATOR_APP_CODENAME
= -1,
63 JSP_NAVIGATOR_APP_NAME
= -2,
64 JSP_NAVIGATOR_APP_VERSION
= -3,
65 JSP_NAVIGATOR_LANGUAGE
= -4,
66 /* JSP_NAVIGATOR_MIME_TYPES = -5, */
67 JSP_NAVIGATOR_PLATFORM
= -6,
68 /* JSP_NAVIGATOR_PLUGINS = -7, */
69 JSP_NAVIGATOR_USER_AGENT
= -8,
71 const JSPropertySpec navigator_props
[] = {
72 { "appCodeName", JSP_NAVIGATOR_APP_CODENAME
, JSPROP_ENUMERATE
| JSPROP_READONLY
},
73 { "appName", JSP_NAVIGATOR_APP_NAME
, JSPROP_ENUMERATE
| JSPROP_READONLY
},
74 { "appVersion", JSP_NAVIGATOR_APP_VERSION
, JSPROP_ENUMERATE
| JSPROP_READONLY
},
75 { "language", JSP_NAVIGATOR_LANGUAGE
, JSPROP_ENUMERATE
| JSPROP_READONLY
},
76 { "platform", JSP_NAVIGATOR_PLATFORM
, JSPROP_ENUMERATE
| JSPROP_READONLY
},
77 { "userAgent", JSP_NAVIGATOR_USER_AGENT
, JSPROP_ENUMERATE
| JSPROP_READONLY
},
82 /* @navigator_class.getProperty */
84 navigator_get_property(JSContext
*ctx
, JSObject
*obj
, jsid id
, jsval
*vp
)
89 undef_to_jsval(ctx
, vp
);
91 switch (JSID_TO_INT(id
)) {
92 case JSP_NAVIGATOR_APP_CODENAME
:
93 string_to_jsval(ctx
, vp
, "Mozilla"); /* More like a constant nowadays. */
95 case JSP_NAVIGATOR_APP_NAME
:
96 /* This evil hack makes the compatibility checking .indexOf()
97 * code find what it's looking for. */
98 string_to_jsval(ctx
, vp
, "ELinks (roughly compatible with Netscape Navigator, Mozilla and Microsoft Internet Explorer)");
100 case JSP_NAVIGATOR_APP_VERSION
:
101 string_to_jsval(ctx
, vp
, VERSION
);
103 case JSP_NAVIGATOR_LANGUAGE
:
105 if (get_opt_bool("protocol.http.accept_ui_language", NULL
))
106 string_to_jsval(ctx
, vp
, language_to_iso639(current_language
));
110 case JSP_NAVIGATOR_PLATFORM
:
111 string_to_jsval(ctx
, vp
, system_name
);
113 case JSP_NAVIGATOR_USER_AGENT
:
115 /* FIXME: Code duplication. */
116 unsigned char *optstr
= get_opt_str("protocol.http.user_agent",
119 if (*optstr
&& strcmp(optstr
, " ")) {
120 unsigned char *ustr
, ts
[64] = "";
121 static unsigned char custr
[256];
122 /* TODO: Somehow get the terminal in which the
123 * document is actually being displayed. */
124 struct terminal
*term
= get_default_terminal();
127 unsigned int tslen
= 0;
129 ulongcat(ts
, &tslen
, term
->width
, 3, 0);
131 ulongcat(ts
, &tslen
, term
->height
, 3, 0);
133 ustr
= subst_user_agent(optstr
, VERSION_STRING
, system_name
, ts
);
136 safe_strncpy(custr
, ustr
, 256);
138 string_to_jsval(ctx
, vp
, custr
);
144 /* Unrecognized integer property ID; someone is using
145 * the object as an array. SMJS builtin classes (e.g.
146 * js_RegExpClass) just return JS_TRUE in this case
147 * and leave *@vp unchanged. Do the same here.
148 * (Actually not quite the same, as we already used
149 * @undef_to_jsval.) */