iconv: Bail out of the loop when an illegal sequence of bytes occurs.
[elinks/elinks-j605.git] / src / ecmascript / spidermonkey / unibar.c
blob576c0a7afcf9439bc864bb10f838f59da9854020
1 /* The SpiderMonkey location and history 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 "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/unibar.h"
26 #include "ecmascript/spidermonkey/window.h"
27 #include "intl/gettext/libintl.h"
28 #include "main/select.h"
29 #include "osdep/newwin.h"
30 #include "osdep/sysname.h"
31 #include "protocol/http/http.h"
32 #include "protocol/uri.h"
33 #include "session/history.h"
34 #include "session/location.h"
35 #include "session/session.h"
36 #include "session/task.h"
37 #include "terminal/tab.h"
38 #include "terminal/terminal.h"
39 #include "util/conv.h"
40 #include "util/memory.h"
41 #include "util/string.h"
42 #include "viewer/text/draw.h"
43 #include "viewer/text/form.h"
44 #include "viewer/text/link.h"
45 #include "viewer/text/vs.h"
48 static JSBool unibar_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
49 static JSBool unibar_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
51 /* Each @menubar_class object must have a @window_class parent. */
52 const JSClass menubar_class = {
53 "menubar",
54 JSCLASS_HAS_PRIVATE, /* const char * "t" */
55 JS_PropertyStub, JS_PropertyStub,
56 unibar_get_property, unibar_set_property,
57 JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
59 /* Each @statusbar_class object must have a @window_class parent. */
60 const JSClass statusbar_class = {
61 "statusbar",
62 JSCLASS_HAS_PRIVATE, /* const char * "s" */
63 JS_PropertyStub, JS_PropertyStub,
64 unibar_get_property, unibar_set_property,
65 JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
68 /* Tinyids of properties. Use negative values to distinguish these
69 * from array indexes (even though this object has no array elements).
70 * ECMAScript code should not use these directly as in menubar[-1];
71 * future versions of ELinks may change the numbers. */
72 enum unibar_prop {
73 JSP_UNIBAR_VISIBLE = -1,
75 const JSPropertySpec unibar_props[] = {
76 { "visible", JSP_UNIBAR_VISIBLE, JSPROP_ENUMERATE },
77 { NULL }
81 /* @menubar_class.getProperty, @statusbar_class.getProperty */
82 static JSBool
83 unibar_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
85 JSObject *parent_win; /* instance of @window_class */
86 struct view_state *vs;
87 struct document_view *doc_view;
88 struct session_status *status;
89 unsigned char *bar;
91 /* This can be called if @obj if not itself an instance of either
92 * appropriate class but has one in its prototype chain. Fail
93 * such calls. */
94 if (!JS_InstanceOf(ctx, obj, (JSClass *) &menubar_class, NULL)
95 && !JS_InstanceOf(ctx, obj, (JSClass *) &statusbar_class, NULL))
96 return JS_FALSE;
97 parent_win = JS_GetParent(ctx, obj);
98 assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
99 if_assert_failed return JS_FALSE;
101 vs = JS_GetInstancePrivate(ctx, parent_win,
102 (JSClass *) &window_class, NULL);
103 doc_view = vs->doc_view;
104 status = &doc_view->session->status;
105 bar = JS_GetPrivate(ctx, obj); /* from @menubar_class or @statusbar_class */
107 if (!JSID_IS_INT(id))
108 return JS_TRUE;
110 switch (JSID_TO_INT(id)) {
111 case JSP_UNIBAR_VISIBLE:
112 #define unibar_fetch(bar) \
113 boolean_to_jsval(ctx, vp, status->force_show_##bar##_bar >= 0 \
114 ? status->force_show_##bar##_bar \
115 : status->show_##bar##_bar)
116 switch (*bar) {
117 case 's':
118 unibar_fetch(status);
119 break;
120 case 't':
121 unibar_fetch(title);
122 break;
123 default:
124 boolean_to_jsval(ctx, vp, 0);
125 break;
127 #undef unibar_fetch
128 break;
129 default:
130 /* Unrecognized integer property ID; someone is using
131 * the object as an array. SMJS builtin classes (e.g.
132 * js_RegExpClass) just return JS_TRUE in this case
133 * and leave *@vp unchanged. Do the same here. */
134 break;
137 return JS_TRUE;
140 /* @menubar_class.setProperty, @statusbar_class.setProperty */
141 static JSBool
142 unibar_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
144 JSObject *parent_win; /* instance of @window_class */
145 struct view_state *vs;
146 struct document_view *doc_view;
147 struct session_status *status;
148 unsigned char *bar;
150 /* This can be called if @obj if not itself an instance of either
151 * appropriate class but has one in its prototype chain. Fail
152 * such calls. */
153 if (!JS_InstanceOf(ctx, obj, (JSClass *) &menubar_class, NULL)
154 && !JS_InstanceOf(ctx, obj, (JSClass *) &statusbar_class, NULL))
155 return JS_FALSE;
156 parent_win = JS_GetParent(ctx, obj);
157 assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
158 if_assert_failed return JS_FALSE;
160 vs = JS_GetInstancePrivate(ctx, parent_win,
161 (JSClass *) &window_class, NULL);
162 doc_view = vs->doc_view;
163 status = &doc_view->session->status;
164 bar = JS_GetPrivate(ctx, obj); /* from @menubar_class or @statusbar_class */
166 if (!JSID_IS_INT(id))
167 return JS_TRUE;
169 switch (JSID_TO_INT(id)) {
170 case JSP_UNIBAR_VISIBLE:
171 switch (*bar) {
172 case 's':
173 status->force_show_status_bar = jsval_to_boolean(ctx, vp);
174 break;
175 case 't':
176 status->force_show_title_bar = jsval_to_boolean(ctx, vp);
177 break;
178 default:
179 break;
181 register_bottom_half(update_status, NULL);
182 break;
183 default:
184 /* Unrecognized integer property ID; someone is using
185 * the object as an array. SMJS builtin classes (e.g.
186 * js_RegExpClass) just return JS_TRUE in this case.
187 * Do the same here. */
188 return JS_TRUE;
191 return JS_TRUE;