2005-09-15 09:58:31 -04:00
|
|
|
/* The SpiderMonkey location and history objects implementation. */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "elinks.h"
|
|
|
|
|
|
|
|
#include "ecmascript/spidermonkey/util.h"
|
|
|
|
|
|
|
|
#include "bfu/dialog.h"
|
|
|
|
#include "cache/cache.h"
|
|
|
|
#include "cookies/cookies.h"
|
|
|
|
#include "dialogs/menu.h"
|
|
|
|
#include "dialogs/status.h"
|
|
|
|
#include "document/html/frames.h"
|
|
|
|
#include "document/document.h"
|
|
|
|
#include "document/forms.h"
|
|
|
|
#include "document/view.h"
|
|
|
|
#include "ecmascript/ecmascript.h"
|
|
|
|
#include "ecmascript/spidermonkey/unibar.h"
|
2006-11-25 01:54:58 -05:00
|
|
|
#include "ecmascript/spidermonkey/window.h"
|
2005-09-15 09:58:31 -04:00
|
|
|
#include "intl/gettext/libintl.h"
|
|
|
|
#include "main/select.h"
|
|
|
|
#include "osdep/newwin.h"
|
|
|
|
#include "osdep/sysname.h"
|
|
|
|
#include "protocol/http/http.h"
|
|
|
|
#include "protocol/uri.h"
|
|
|
|
#include "session/history.h"
|
|
|
|
#include "session/location.h"
|
|
|
|
#include "session/session.h"
|
|
|
|
#include "session/task.h"
|
|
|
|
#include "terminal/tab.h"
|
|
|
|
#include "terminal/terminal.h"
|
|
|
|
#include "util/conv.h"
|
|
|
|
#include "util/memory.h"
|
|
|
|
#include "util/string.h"
|
|
|
|
#include "viewer/text/draw.h"
|
|
|
|
#include "viewer/text/form.h"
|
|
|
|
#include "viewer/text/link.h"
|
|
|
|
#include "viewer/text/vs.h"
|
|
|
|
|
|
|
|
|
2011-04-19 16:41:05 -04:00
|
|
|
static JSBool unibar_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
|
|
|
|
static JSBool unibar_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2006-11-23 16:33:43 -05:00
|
|
|
/* Each @menubar_class object must have a @window_class parent. */
|
2005-09-15 09:58:31 -04:00
|
|
|
const JSClass menubar_class = {
|
|
|
|
"menubar",
|
2006-11-20 14:49:17 -05:00
|
|
|
JSCLASS_HAS_PRIVATE, /* const char * "t" */
|
2005-09-15 09:58:31 -04:00
|
|
|
JS_PropertyStub, JS_PropertyStub,
|
|
|
|
unibar_get_property, unibar_set_property,
|
|
|
|
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
|
|
|
|
};
|
2006-11-23 16:33:43 -05:00
|
|
|
/* Each @statusbar_class object must have a @window_class parent. */
|
2005-09-15 09:58:31 -04:00
|
|
|
const JSClass statusbar_class = {
|
|
|
|
"statusbar",
|
2006-11-20 14:49:17 -05:00
|
|
|
JSCLASS_HAS_PRIVATE, /* const char * "s" */
|
2005-09-15 09:58:31 -04:00
|
|
|
JS_PropertyStub, JS_PropertyStub,
|
|
|
|
unibar_get_property, unibar_set_property,
|
|
|
|
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
|
|
|
|
};
|
|
|
|
|
2006-12-06 16:09:14 -05:00
|
|
|
/* Tinyids of properties. Use negative values to distinguish these
|
|
|
|
* from array indexes (even though this object has no array elements).
|
|
|
|
* ECMAScript code should not use these directly as in menubar[-1];
|
|
|
|
* future versions of ELinks may change the numbers. */
|
|
|
|
enum unibar_prop {
|
|
|
|
JSP_UNIBAR_VISIBLE = -1,
|
|
|
|
};
|
2005-09-15 09:58:31 -04:00
|
|
|
const JSPropertySpec unibar_props[] = {
|
|
|
|
{ "visible", JSP_UNIBAR_VISIBLE, JSPROP_ENUMERATE },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-11-23 16:33:43 -05:00
|
|
|
/* @menubar_class.getProperty, @statusbar_class.getProperty */
|
2005-09-15 09:58:31 -04:00
|
|
|
static JSBool
|
2011-04-19 16:41:05 -04:00
|
|
|
unibar_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
2006-11-24 01:50:12 -05:00
|
|
|
JSObject *parent_win; /* instance of @window_class */
|
|
|
|
struct view_state *vs;
|
|
|
|
struct document_view *doc_view;
|
|
|
|
struct session_status *status;
|
|
|
|
unsigned char *bar;
|
|
|
|
|
2006-12-03 04:14:22 -05:00
|
|
|
/* This can be called if @obj if not itself an instance of either
|
|
|
|
* appropriate class but has one in its prototype chain. Fail
|
|
|
|
* such calls. */
|
|
|
|
if (!JS_InstanceOf(ctx, obj, (JSClass *) &menubar_class, NULL)
|
|
|
|
&& !JS_InstanceOf(ctx, obj, (JSClass *) &statusbar_class, NULL))
|
|
|
|
return JS_FALSE;
|
2006-11-24 01:50:12 -05:00
|
|
|
parent_win = JS_GetParent(ctx, obj);
|
2006-11-25 01:54:58 -05:00
|
|
|
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
|
|
|
|
if_assert_failed return JS_FALSE;
|
|
|
|
|
2007-05-27 11:32:53 -04:00
|
|
|
vs = JS_GetInstancePrivate(ctx, parent_win,
|
|
|
|
(JSClass *) &window_class, NULL);
|
2006-11-24 01:50:12 -05:00
|
|
|
doc_view = vs->doc_view;
|
|
|
|
status = &doc_view->session->status;
|
|
|
|
bar = JS_GetPrivate(ctx, obj); /* from @menubar_class or @statusbar_class */
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2011-04-19 16:41:05 -04:00
|
|
|
if (!JSID_IS_INT(id))
|
2005-09-15 09:58:31 -04:00
|
|
|
return JS_TRUE;
|
|
|
|
|
2011-04-19 16:41:05 -04:00
|
|
|
switch (JSID_TO_INT(id)) {
|
2005-09-15 09:58:31 -04:00
|
|
|
case JSP_UNIBAR_VISIBLE:
|
|
|
|
#define unibar_fetch(bar) \
|
|
|
|
boolean_to_jsval(ctx, vp, status->force_show_##bar##_bar >= 0 \
|
|
|
|
? status->force_show_##bar##_bar \
|
|
|
|
: status->show_##bar##_bar)
|
|
|
|
switch (*bar) {
|
|
|
|
case 's':
|
|
|
|
unibar_fetch(status);
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
unibar_fetch(title);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
boolean_to_jsval(ctx, vp, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#undef unibar_fetch
|
|
|
|
break;
|
|
|
|
default:
|
2007-05-27 11:36:31 -04:00
|
|
|
/* Unrecognized integer property ID; someone is using
|
|
|
|
* the object as an array. SMJS builtin classes (e.g.
|
2006-12-03 05:07:07 -05:00
|
|
|
* js_RegExpClass) just return JS_TRUE in this case
|
|
|
|
* and leave *@vp unchanged. Do the same here. */
|
2005-09-15 09:58:31 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2006-11-23 16:33:43 -05:00
|
|
|
/* @menubar_class.setProperty, @statusbar_class.setProperty */
|
2005-09-15 09:58:31 -04:00
|
|
|
static JSBool
|
2011-04-19 16:41:05 -04:00
|
|
|
unibar_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
|
2005-09-15 09:58:31 -04:00
|
|
|
{
|
2006-11-24 01:50:12 -05:00
|
|
|
JSObject *parent_win; /* instance of @window_class */
|
|
|
|
struct view_state *vs;
|
|
|
|
struct document_view *doc_view;
|
|
|
|
struct session_status *status;
|
|
|
|
unsigned char *bar;
|
|
|
|
|
2006-12-03 04:14:22 -05:00
|
|
|
/* This can be called if @obj if not itself an instance of either
|
|
|
|
* appropriate class but has one in its prototype chain. Fail
|
|
|
|
* such calls. */
|
|
|
|
if (!JS_InstanceOf(ctx, obj, (JSClass *) &menubar_class, NULL)
|
|
|
|
&& !JS_InstanceOf(ctx, obj, (JSClass *) &statusbar_class, NULL))
|
|
|
|
return JS_FALSE;
|
2006-11-24 01:50:12 -05:00
|
|
|
parent_win = JS_GetParent(ctx, obj);
|
2006-11-25 01:54:58 -05:00
|
|
|
assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
|
|
|
|
if_assert_failed return JS_FALSE;
|
|
|
|
|
2007-05-27 11:32:53 -04:00
|
|
|
vs = JS_GetInstancePrivate(ctx, parent_win,
|
|
|
|
(JSClass *) &window_class, NULL);
|
2006-11-24 01:50:12 -05:00
|
|
|
doc_view = vs->doc_view;
|
|
|
|
status = &doc_view->session->status;
|
|
|
|
bar = JS_GetPrivate(ctx, obj); /* from @menubar_class or @statusbar_class */
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2011-04-19 16:41:05 -04:00
|
|
|
if (!JSID_IS_INT(id))
|
2005-09-15 09:58:31 -04:00
|
|
|
return JS_TRUE;
|
|
|
|
|
2011-04-19 16:41:05 -04:00
|
|
|
switch (JSID_TO_INT(id)) {
|
2005-09-15 09:58:31 -04:00
|
|
|
case JSP_UNIBAR_VISIBLE:
|
|
|
|
switch (*bar) {
|
|
|
|
case 's':
|
|
|
|
status->force_show_status_bar = jsval_to_boolean(ctx, vp);
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
status->force_show_title_bar = jsval_to_boolean(ctx, vp);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
register_bottom_half(update_status, NULL);
|
|
|
|
break;
|
|
|
|
default:
|
2007-05-27 11:36:31 -04:00
|
|
|
/* Unrecognized integer property ID; someone is using
|
|
|
|
* the object as an array. SMJS builtin classes (e.g.
|
2006-12-03 05:07:07 -05:00
|
|
|
* js_RegExpClass) just return JS_TRUE in this case.
|
|
|
|
* Do the same here. */
|
2005-09-15 09:58:31 -04:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|