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/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
, jsval id
, jsval
*vp
);
49 static JSBool
unibar_set_property(JSContext
*ctx
, JSObject
*obj
, jsval id
, jsval
*vp
);
51 /* Each @menubar_class object must have a @window_class parent. */
52 const JSClass menubar_class
= {
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
= {
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 enum unibar_prop
{ JSP_UNIBAR_VISIBLE
};
69 const JSPropertySpec unibar_props
[] = {
70 { "visible", JSP_UNIBAR_VISIBLE
, JSPROP_ENUMERATE
},
75 /* @menubar_class.getProperty, @statusbar_class.getProperty */
77 unibar_get_property(JSContext
*ctx
, JSObject
*obj
, jsval id
, jsval
*vp
)
79 JSObject
*parent_win
; /* instance of @window_class */
80 struct view_state
*vs
;
81 struct document_view
*doc_view
;
82 struct session_status
*status
;
85 /* This can be called if @obj if not itself an instance of either
86 * appropriate class but has one in its prototype chain. Fail
88 if (!JS_InstanceOf(ctx
, obj
, (JSClass
*) &menubar_class
, NULL
)
89 && !JS_InstanceOf(ctx
, obj
, (JSClass
*) &statusbar_class
, NULL
))
91 parent_win
= JS_GetParent(ctx
, obj
);
92 assert(JS_InstanceOf(ctx
, parent_win
, (JSClass
*) &window_class
, NULL
));
93 if_assert_failed
return JS_FALSE
;
95 vs
= JS_GetInstancePrivate(ctx
, parent_win
,
96 (JSClass
*) &window_class
, NULL
);
97 doc_view
= vs
->doc_view
;
98 status
= &doc_view
->session
->status
;
99 bar
= JS_GetPrivate(ctx
, obj
); /* from @menubar_class or @statusbar_class */
101 if (!JSVAL_IS_INT(id
))
104 switch (JSVAL_TO_INT(id
)) {
105 case JSP_UNIBAR_VISIBLE
:
106 #define unibar_fetch(bar) \
107 boolean_to_jsval(ctx, vp, status->force_show_##bar##_bar >= 0 \
108 ? status->force_show_##bar##_bar \
109 : status->show_##bar##_bar)
112 unibar_fetch(status
);
118 boolean_to_jsval(ctx
, vp
, 0);
124 /* Unrecognized integer property ID; someone is using
125 * the object as an array. SMJS builtin classes (e.g.
126 * js_RegExpClass) just return JS_TRUE in this case
127 * and leave *@vp unchanged. Do the same here. */
134 /* @menubar_class.setProperty, @statusbar_class.setProperty */
136 unibar_set_property(JSContext
*ctx
, JSObject
*obj
, jsval id
, jsval
*vp
)
138 JSObject
*parent_win
; /* instance of @window_class */
139 struct view_state
*vs
;
140 struct document_view
*doc_view
;
141 struct session_status
*status
;
144 /* This can be called if @obj if not itself an instance of either
145 * appropriate class but has one in its prototype chain. Fail
147 if (!JS_InstanceOf(ctx
, obj
, (JSClass
*) &menubar_class
, NULL
)
148 && !JS_InstanceOf(ctx
, obj
, (JSClass
*) &statusbar_class
, NULL
))
150 parent_win
= JS_GetParent(ctx
, obj
);
151 assert(JS_InstanceOf(ctx
, parent_win
, (JSClass
*) &window_class
, NULL
));
152 if_assert_failed
return JS_FALSE
;
154 vs
= JS_GetInstancePrivate(ctx
, parent_win
,
155 (JSClass
*) &window_class
, NULL
);
156 doc_view
= vs
->doc_view
;
157 status
= &doc_view
->session
->status
;
158 bar
= JS_GetPrivate(ctx
, obj
); /* from @menubar_class or @statusbar_class */
160 if (!JSVAL_IS_INT(id
))
163 switch (JSVAL_TO_INT(id
)) {
164 case JSP_UNIBAR_VISIBLE
:
167 status
->force_show_status_bar
= jsval_to_boolean(ctx
, vp
);
170 status
->force_show_title_bar
= jsval_to_boolean(ctx
, vp
);
175 register_bottom_half(update_status
, NULL
);
178 /* Unrecognized integer property ID; someone is using
179 * the object as an array. SMJS builtin classes (e.g.
180 * js_RegExpClass) just return JS_TRUE in this case.
181 * Do the same here. */