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
, jsval id
, jsval
*vp
);
49 const JSClass navigator_class
= {
52 JS_PropertyStub
, JS_PropertyStub
,
53 navigator_get_property
, JS_PropertyStub
,
54 JS_EnumerateStub
, JS_ResolveStub
, JS_ConvertStub
, JS_FinalizeStub
58 JSP_NAVIGATOR_APP_CODENAME
,
59 JSP_NAVIGATOR_APP_NAME
,
60 JSP_NAVIGATOR_APP_VERSION
,
61 JSP_NAVIGATOR_LANGUAGE
,
62 /* JSP_NAVIGATOR_MIME_TYPES, */
63 JSP_NAVIGATOR_PLATFORM
,
64 /* JSP_NAVIGATOR_PLUGINS, */
65 JSP_NAVIGATOR_USER_AGENT
,
67 const JSPropertySpec navigator_props
[] = {
68 { "appCodeName", JSP_NAVIGATOR_APP_CODENAME
, JSPROP_ENUMERATE
| JSPROP_READONLY
},
69 { "appName", JSP_NAVIGATOR_APP_NAME
, JSPROP_ENUMERATE
| JSPROP_READONLY
},
70 { "appVersion", JSP_NAVIGATOR_APP_VERSION
, JSPROP_ENUMERATE
| JSPROP_READONLY
},
71 { "language", JSP_NAVIGATOR_LANGUAGE
, JSPROP_ENUMERATE
| JSPROP_READONLY
},
72 { "platform", JSP_NAVIGATOR_PLATFORM
, JSPROP_ENUMERATE
| JSPROP_READONLY
},
73 { "userAgent", JSP_NAVIGATOR_USER_AGENT
, JSPROP_ENUMERATE
| JSPROP_READONLY
},
78 /* @navigator_class.getProperty */
80 navigator_get_property(JSContext
*ctx
, JSObject
*obj
, jsval id
, jsval
*vp
)
82 if (!JSVAL_IS_INT(id
))
85 undef_to_jsval(ctx
, vp
);
87 switch (JSVAL_TO_INT(id
)) {
88 case JSP_NAVIGATOR_APP_CODENAME
:
89 string_to_jsval(ctx
, vp
, "Mozilla"); /* More like a constant nowadays. */
91 case JSP_NAVIGATOR_APP_NAME
:
92 /* This evil hack makes the compatibility checking .indexOf()
93 * code find what it's looking for. */
94 string_to_jsval(ctx
, vp
, "ELinks (roughly compatible with Netscape Navigator, Mozilla and Microsoft Internet Explorer)");
96 case JSP_NAVIGATOR_APP_VERSION
:
97 string_to_jsval(ctx
, vp
, VERSION
);
99 case JSP_NAVIGATOR_LANGUAGE
:
101 if (get_opt_bool("protocol.http.accept_ui_language"))
102 string_to_jsval(ctx
, vp
, language_to_iso639(current_language
));
106 case JSP_NAVIGATOR_PLATFORM
:
107 string_to_jsval(ctx
, vp
, system_name
);
109 case JSP_NAVIGATOR_USER_AGENT
:
111 /* FIXME: Code duplication. */
112 unsigned char *optstr
= get_opt_str("protocol.http.user_agent");
114 if (*optstr
&& strcmp(optstr
, " ")) {
115 unsigned char *ustr
, ts
[64] = "";
116 static unsigned char custr
[256];
118 if (!list_empty(terminals
)) {
119 unsigned int tslen
= 0;
120 struct terminal
*term
= terminals
.prev
;
122 ulongcat(ts
, &tslen
, term
->width
, 3, 0);
124 ulongcat(ts
, &tslen
, term
->height
, 3, 0);
126 ustr
= subst_user_agent(optstr
, VERSION_STRING
, system_name
, ts
);
129 safe_strncpy(custr
, ustr
, 256);
131 string_to_jsval(ctx
, vp
, custr
);
137 /* Unrecognized integer property ID; someone is using
138 * the object as an array. SMJS builtin classes (e.g.
139 * js_RegExpClass) just return JS_TRUE in this case
140 * and leave *@vp unchanged. Do the same here.
141 * (Actually not quite the same, as we already used
142 * @undef_to_jsval.) */