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/navigator.h"
|
|
|
|
#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 navigator_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
const JSClass navigator_class = {
|
|
|
|
"navigator",
|
|
|
|
JSCLASS_HAS_PRIVATE,
|
|
|
|
JS_PropertyStub, JS_PropertyStub,
|
2011-04-19 16:41:05 -04:00
|
|
|
navigator_get_property, JS_StrictPropertyStub,
|
2005-09-15 09:58:31 -04:00
|
|
|
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 navigator[-1];
|
|
|
|
* future versions of ELinks may change the numbers. */
|
2005-09-15 09:58:31 -04:00
|
|
|
enum navigator_prop {
|
2006-12-06 16:09:14 -05:00
|
|
|
JSP_NAVIGATOR_APP_CODENAME = -1,
|
|
|
|
JSP_NAVIGATOR_APP_NAME = -2,
|
|
|
|
JSP_NAVIGATOR_APP_VERSION = -3,
|
|
|
|
JSP_NAVIGATOR_LANGUAGE = -4,
|
|
|
|
/* JSP_NAVIGATOR_MIME_TYPES = -5, */
|
|
|
|
JSP_NAVIGATOR_PLATFORM = -6,
|
|
|
|
/* JSP_NAVIGATOR_PLUGINS = -7, */
|
|
|
|
JSP_NAVIGATOR_USER_AGENT = -8,
|
2005-09-15 09:58:31 -04:00
|
|
|
};
|
|
|
|
const JSPropertySpec navigator_props[] = {
|
|
|
|
{ "appCodeName", JSP_NAVIGATOR_APP_CODENAME, JSPROP_ENUMERATE | JSPROP_READONLY },
|
|
|
|
{ "appName", JSP_NAVIGATOR_APP_NAME, JSPROP_ENUMERATE | JSPROP_READONLY },
|
|
|
|
{ "appVersion", JSP_NAVIGATOR_APP_VERSION, JSPROP_ENUMERATE | JSPROP_READONLY },
|
|
|
|
{ "language", JSP_NAVIGATOR_LANGUAGE, JSPROP_ENUMERATE | JSPROP_READONLY },
|
|
|
|
{ "platform", JSP_NAVIGATOR_PLATFORM, JSPROP_ENUMERATE | JSPROP_READONLY },
|
|
|
|
{ "userAgent", JSP_NAVIGATOR_USER_AGENT, JSPROP_ENUMERATE | JSPROP_READONLY },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-11-23 16:33:43 -05:00
|
|
|
/* @navigator_class.getProperty */
|
2005-09-15 09:58:31 -04:00
|
|
|
static JSBool
|
2011-04-19 16:41:05 -04:00
|
|
|
navigator_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
|
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;
|
|
|
|
|
|
|
|
undef_to_jsval(ctx, vp);
|
|
|
|
|
2011-04-19 16:41:05 -04:00
|
|
|
switch (JSID_TO_INT(id)) {
|
2005-09-15 09:58:31 -04:00
|
|
|
case JSP_NAVIGATOR_APP_CODENAME:
|
|
|
|
string_to_jsval(ctx, vp, "Mozilla"); /* More like a constant nowadays. */
|
|
|
|
break;
|
|
|
|
case JSP_NAVIGATOR_APP_NAME:
|
|
|
|
/* This evil hack makes the compatibility checking .indexOf()
|
|
|
|
* code find what it's looking for. */
|
|
|
|
string_to_jsval(ctx, vp, "ELinks (roughly compatible with Netscape Navigator, Mozilla and Microsoft Internet Explorer)");
|
|
|
|
break;
|
|
|
|
case JSP_NAVIGATOR_APP_VERSION:
|
|
|
|
string_to_jsval(ctx, vp, VERSION);
|
|
|
|
break;
|
|
|
|
case JSP_NAVIGATOR_LANGUAGE:
|
|
|
|
#ifdef CONFIG_NLS
|
2007-08-28 12:41:18 -04:00
|
|
|
if (get_opt_bool("protocol.http.accept_ui_language", NULL))
|
2005-09-15 09:58:31 -04:00
|
|
|
string_to_jsval(ctx, vp, language_to_iso639(current_language));
|
|
|
|
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case JSP_NAVIGATOR_PLATFORM:
|
|
|
|
string_to_jsval(ctx, vp, system_name);
|
|
|
|
break;
|
|
|
|
case JSP_NAVIGATOR_USER_AGENT:
|
|
|
|
{
|
|
|
|
/* FIXME: Code duplication. */
|
2007-08-28 12:41:18 -04:00
|
|
|
unsigned char *optstr = get_opt_str("protocol.http.user_agent",
|
|
|
|
NULL);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
if (*optstr && strcmp(optstr, " ")) {
|
|
|
|
unsigned char *ustr, ts[64] = "";
|
|
|
|
static unsigned char custr[256];
|
bug 1054: Don't abort downloads when closing a terminal.
Except if they have external handlers.
When ELinks receives an event from a terminal, move that terminal to
the beginning of the global "terminals" list, so that the terminals
are always sorted according to the time of the most recent use. Note,
this affects the numbering of bookmark folders in session snapshots.
Add get_default_terminal(), which returns the most recently used
terminal that is still open. Use that in various places that
previously used terminals.prev or terminals.next. Four functions
fetch the size of the terminal for User-Agent headers, and
get_default_terminal() is not really right, but neither was the
original code; add TODO comments in those functions.
When the user chooses "Background and Notify", associate the download
with the terminal where the dialog box is. So any later messages will
then appear in that terminal, if it is still open. However, don't
change the terminal if the download has an external handler.
When a download gets some data, don't immediately check the associated
terminal. Instead, wait for the download to end. Then, if the
terminal of the download has been closed, use get_default_terminal()
instead. If there is no default terminal either, just skip any
message boxes.
2008-10-15 04:05:43 -04:00
|
|
|
/* TODO: Somehow get the terminal in which the
|
|
|
|
* document is actually being displayed. */
|
|
|
|
struct terminal *term = get_default_terminal();
|
2005-09-15 09:58:31 -04:00
|
|
|
|
bug 1054: Don't abort downloads when closing a terminal.
Except if they have external handlers.
When ELinks receives an event from a terminal, move that terminal to
the beginning of the global "terminals" list, so that the terminals
are always sorted according to the time of the most recent use. Note,
this affects the numbering of bookmark folders in session snapshots.
Add get_default_terminal(), which returns the most recently used
terminal that is still open. Use that in various places that
previously used terminals.prev or terminals.next. Four functions
fetch the size of the terminal for User-Agent headers, and
get_default_terminal() is not really right, but neither was the
original code; add TODO comments in those functions.
When the user chooses "Background and Notify", associate the download
with the terminal where the dialog box is. So any later messages will
then appear in that terminal, if it is still open. However, don't
change the terminal if the download has an external handler.
When a download gets some data, don't immediately check the associated
terminal. Instead, wait for the download to end. Then, if the
terminal of the download has been closed, use get_default_terminal()
instead. If there is no default terminal either, just skip any
message boxes.
2008-10-15 04:05:43 -04:00
|
|
|
if (term) {
|
2005-09-15 09:58:31 -04:00
|
|
|
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);
|
|
|
|
string_to_jsval(ctx, vp, custr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
* (Actually not quite the same, as we already used
|
|
|
|
* @undef_to_jsval.) */
|
2005-09-15 09:58:31 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|