1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-07-01 02:05:33 +00:00

[mujs] navigator.c

This commit is contained in:
Witold Filipczyk 2023-04-12 18:14:04 +02:00
parent 931cf0d4f3
commit a9fdb49327
5 changed files with 146 additions and 3 deletions

View File

@ -1,6 +1,6 @@
top_builddir=../../../..
include $(top_builddir)/Makefile.config
OBJS = attr.o attributes.o collection.o console.o forms.o history.o implementation.o keyboard.o localstorage.o mapa.obj message.o
OBJS = attr.o attributes.o collection.o console.o forms.o history.o implementation.o keyboard.o localstorage.o mapa.obj message.o navigator.o
include $(top_srcdir)/Makefile.lib

View File

@ -1 +1 @@
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'forms.c', 'history.c', 'implementation.c', 'keyboard.c', 'localstorage.c', 'mapa.cpp', 'message.c')
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'forms.c', 'history.c', 'implementation.c', 'keyboard.c', 'localstorage.c', 'mapa.cpp', 'message.c', 'navigator.c')

View File

@ -0,0 +1,134 @@
/* The mujs navigator object implementation. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "elinks.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/mujs.h"
#include "ecmascript/mujs/navigator.h"
#include "intl/libintl.h"
#include "osdep/sysname.h"
#include "protocol/http/http.h"
#include "util/conv.h"
static void
mjs_navigator_get_property_appCodeName(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "Mozilla");
}
static void
mjs_navigator_get_property_appName(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "ELinks (roughly compatible with Netscape Navigator, Mozilla and Microsoft Internet Explorer)");
}
static void
mjs_navigator_get_property_appVersion(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, VERSION);
}
static void
mjs_navigator_get_property_language(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
#ifdef CONFIG_NLS
if (get_opt_bool("protocol.http.accept_ui_language", NULL)) {
js_pushstring(J, language_to_iso639(current_language));
return;
}
#endif
js_pushundefined(J);
}
static void
mjs_navigator_get_property_platform(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, system_name);
}
static void
mjs_navigator_get_property_userAgent(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
char *optstr;
optstr = get_opt_str("protocol.http.user_agent", NULL);
if (*optstr && strcmp(optstr, " ")) {
char *ustr, ts[64] = "";
static char custr[256];
/* TODO: Somehow get the terminal in which the
* document is actually being displayed. */
struct terminal *term = get_default_terminal();
if (term) {
unsigned int tslen = 0;
ulongcat(ts, &tslen, term->width, 3, 0);
ts[tslen++] = 'x';
ulongcat(ts, &tslen, term->height, 3, 0);
}
ustr = subst_user_agent(optstr, VERSION_STRING, system_name, ts);
if (ustr) {
safe_strncpy(custr, ustr, 256);
mem_free(ustr);
js_pushstring(J, custr);
return;
}
}
js_pushstring(J, system_name);
}
static void
mjs_navigator_toString(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
js_pushstring(J, "[navigator object]");
}
int
mjs_navigator_init(js_State *J)
{
js_newobject(J);
{
addmethod(J, "navigator.toString", mjs_navigator_toString, 0);
addproperty(J, "navigator.appCodeName", mjs_navigator_get_property_appCodeName, NULL);
addproperty(J, "navigator.appName", mjs_navigator_get_property_appName, NULL);
addproperty(J, "navigator.appVersion", mjs_navigator_get_property_appVersion, NULL);
addproperty(J, "navigator.language", mjs_navigator_get_property_language, NULL);
addproperty(J, "navigator.platform", mjs_navigator_get_property_platform, NULL);
addproperty(J, "navigator.userAgent", mjs_navigator_get_property_userAgent, NULL);
}
js_defglobal(J, "navigator", JS_DONTENUM);
return 0;
}

View File

@ -42,7 +42,7 @@
#include "viewer/text/link.h"
#include "viewer/text/vs.h"
#ifndef CONFIG_LIBDOM
static void
mjs_navigator_get_property_appCodeName(js_State *J)
{
@ -157,3 +157,4 @@ mjs_navigator_init(js_State *J)
return 0;
}
#endif

View File

@ -3,6 +3,14 @@
#include <mujs.h>
#ifdef __cplusplus
extern "C" {
#endif
int mjs_navigator_init(js_State *J);
#ifdef __cplusplus
}
#endif
#endif