mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Add elinks.location property to get and set the current URL.
This commit is contained in:
parent
b13d35dc5a
commit
f46cdd8f03
@ -7,13 +7,52 @@
|
|||||||
#include "elinks.h"
|
#include "elinks.h"
|
||||||
|
|
||||||
#include "ecmascript/spidermonkey/util.h"
|
#include "ecmascript/spidermonkey/util.h"
|
||||||
|
#include "protocol/uri.h"
|
||||||
#include "scripting/scripting.h"
|
#include "scripting/scripting.h"
|
||||||
#include "scripting/smjs/core.h"
|
#include "scripting/smjs/core.h"
|
||||||
#include "scripting/smjs/elinks_object.h"
|
#include "scripting/smjs/elinks_object.h"
|
||||||
#include "scripting/smjs/global_object.h"
|
#include "scripting/smjs/global_object.h"
|
||||||
#include "scripting/smjs/keybinding.h"
|
#include "scripting/smjs/keybinding.h"
|
||||||
|
#include "session/location.h"
|
||||||
|
#include "session/session.h"
|
||||||
|
#include "session/task.h"
|
||||||
|
|
||||||
|
|
||||||
|
static JSBool
|
||||||
|
elinks_get_location(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
|
||||||
|
{
|
||||||
|
struct uri *uri;
|
||||||
|
|
||||||
|
if (!smjs_ses) return JS_FALSE;
|
||||||
|
|
||||||
|
uri = have_location(smjs_ses) ? cur_loc(smjs_ses)->vs.uri
|
||||||
|
: smjs_ses->loading_uri;
|
||||||
|
if (!uri) return JS_FALSE;
|
||||||
|
|
||||||
|
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx, struri(uri)));
|
||||||
|
|
||||||
|
return JS_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSBool
|
||||||
|
elinks_set_location(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
|
||||||
|
{
|
||||||
|
JSString *jsstr;
|
||||||
|
unsigned char *url;
|
||||||
|
|
||||||
|
if (!smjs_ses) return JS_FALSE;
|
||||||
|
|
||||||
|
jsstr = JS_ValueToString(smjs_ctx, *vp);
|
||||||
|
if (!jsstr) return JS_FALSE;
|
||||||
|
|
||||||
|
url = JS_GetStringBytes(jsstr);
|
||||||
|
if (!url) return JS_FALSE;
|
||||||
|
|
||||||
|
goto_url(smjs_ses, url);
|
||||||
|
|
||||||
|
return JS_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static JSBool
|
static JSBool
|
||||||
elinks_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
elinks_alert(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||||
{
|
{
|
||||||
@ -49,12 +88,20 @@ static const JSFunctionSpec elinks_funcs[] = {
|
|||||||
static JSObject *
|
static JSObject *
|
||||||
smjs_get_elinks_object(void)
|
smjs_get_elinks_object(void)
|
||||||
{
|
{
|
||||||
|
JSObject *jsobj;
|
||||||
|
|
||||||
assert(smjs_ctx);
|
assert(smjs_ctx);
|
||||||
assert(smjs_global_object);
|
assert(smjs_global_object);
|
||||||
|
|
||||||
return JS_InitClass(smjs_ctx, smjs_global_object, NULL,
|
jsobj = JS_InitClass(smjs_ctx, smjs_global_object, NULL,
|
||||||
(JSClass *) &elinks_class, NULL, 0, NULL,
|
(JSClass *) &elinks_class, NULL, 0, NULL,
|
||||||
(JSFunctionSpec *) elinks_funcs, NULL, NULL);
|
(JSFunctionSpec *) elinks_funcs, NULL, NULL);
|
||||||
|
|
||||||
|
JS_DefineProperty(smjs_ctx, jsobj, "location", JSVAL_NULL,
|
||||||
|
elinks_get_location, elinks_set_location,
|
||||||
|
JSPROP_ENUMERATE | JSPROP_PERMANENT);
|
||||||
|
|
||||||
|
return jsobj;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user