mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[mujs] navigator
This commit is contained in:
parent
78ad74bfc1
commit
1f09c7c2df
@ -25,6 +25,7 @@
|
||||
#include "document/view.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/mujs.h"
|
||||
#include "ecmascript/mujs/navigator.h"
|
||||
#include "ecmascript/mujs/screen.h"
|
||||
#include "ecmascript/mujs/unibar.h"
|
||||
#include "ecmascript/mujs/window.h"
|
||||
@ -80,6 +81,7 @@ mujs_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
mjs_window_init(interpreter, J);
|
||||
mjs_screen_init(interpreter, J);
|
||||
mjs_unibar_init(interpreter, J);
|
||||
mjs_navigator_init(interpreter, J);
|
||||
|
||||
return J;
|
||||
#if 0
|
||||
|
@ -1,3 +1,3 @@
|
||||
#srcs += files('attr.cpp', 'attributes.cpp', 'collection.cpp', 'console.cpp', 'document.cpp', 'element.cpp', 'form.cpp', 'forms.cpp', 'heartbeat.cpp', 'history.cpp', 'implementation.cpp',
|
||||
#'input.cpp', 'localstorage.cpp', 'location.cpp', 'navigator.cpp', 'nodelist.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp')
|
||||
srcs += files('screen.cpp', 'unibar.cpp', 'window.cpp')
|
||||
srcs += files('navigator.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp')
|
||||
|
180
src/ecmascript/mujs/navigator.cpp
Normal file
180
src/ecmascript/mujs/navigator.cpp
Normal file
@ -0,0 +1,180 @@
|
||||
/* 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 "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/mujs.h"
|
||||
#include "ecmascript/mujs/navigator.h"
|
||||
#include "intl/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"
|
||||
|
||||
|
||||
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(struct ecmascript_interpreter *interpreter, js_State *J)
|
||||
{
|
||||
js_getglobal(J, "Object");
|
||||
js_getproperty(J, -1, "prototype");
|
||||
js_newuserdata(J, "navigator", interpreter, NULL);
|
||||
|
||||
js_newcfunction(J, mjs_navigator_toString, "navigator.prototype.toString", 0);
|
||||
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||
|
||||
js_newcfunction(J, mjs_navigator_get_property_appCodeName, "navigator.prototype.appCodeName", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "appCodeName", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
|
||||
js_newcfunction(J, mjs_navigator_get_property_appName, "navigator.prototype.appName", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "appName", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
|
||||
js_newcfunction(J, mjs_navigator_get_property_appVersion, "navigator.prototype.appVersion", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "appVersion", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
|
||||
js_newcfunction(J, mjs_navigator_get_property_language, "navigator.prototype.language", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "language", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
|
||||
js_newcfunction(J, mjs_navigator_get_property_platform, "navigator.prototype.platform", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "platform", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
|
||||
js_newcfunction(J, mjs_navigator_get_property_userAgent, "navigator.prototype.userAgent", 0);
|
||||
js_pushnull(J);
|
||||
js_defaccessor(J, -3, "userAgent", JS_READONLY | JS_DONTENUM | JS_DONTCONF);
|
||||
|
||||
js_defglobal(J, "navigator", JS_DONTENUM);
|
||||
|
||||
return 0;
|
||||
}
|
10
src/ecmascript/mujs/navigator.h
Normal file
10
src/ecmascript/mujs/navigator.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef EL__ECMASCRIPT_MUJS_NAVIGATOR_H
|
||||
#define EL__ECMASCRIPT_MUJS_NAVIGATOR_H
|
||||
|
||||
#include <mujs.h>
|
||||
|
||||
struct ecmascript_interpreter;
|
||||
|
||||
int mjs_navigator_init(struct ecmascript_interpreter *interpreter, js_State *J);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user