netsurf/javascript/jsapi/location.bnd

158 lines
3.5 KiB
Plaintext
Raw Normal View History

2012-11-02 03:30:28 +04:00
/* Binding to generate Location interface
*
* Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* Released under the terms of the MIT License,
* http://www.opensource.org/licenses/mit-license
*/
webidlfile "html.idl";
hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>";
hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
hdrcomment "Released under the terms of the MIT License,";
hdrcomment " http://www.opensource.org/licenses/mit-license";
preamble %{
#include "desktop/browser.h"
#include "utils/config.h"
#include "utils/log.h"
#include "javascript/jsapi.h"
#include "render/html_internal.h"
#include "location.h"
2012-11-02 03:30:28 +04:00
%}
binding location {
2012-11-19 21:23:24 +04:00
type js_libdom; /* the binding type */
interface Location; /* Web IDL interface to generate */
private "nsurl *" url;
private "struct html_content *" htmlc;
property unshared href;
2012-11-02 03:30:28 +04:00
}
operation reload %{
browser_window_reload(private->htmlc->bw, false);
2012-11-02 03:30:28 +04:00
%}
getter href %{
char *url_s = NULL;
size_t url_l;
if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx,vp))) {
/* already created - return it */
return JS_TRUE;
}
nsurl_get(private->url, NSURL_COMPLETE, &url_s, &url_l);
if (url_s != NULL) {
jsret = JS_NewStringCopyN(cx, url_s, url_l);
free(url_s);
}
%}
2013-02-01 00:28:49 +04:00
setter href %{
JSString *url_jsstr = NULL;
int url_len = 0;
char *url = NULL;
url_jsstr = JS_ValueToString(cx, *vp);
2013-02-01 00:28:49 +04:00
if (url_jsstr != NULL) {
JSString_to_char(url_jsstr, url, url_len);
browser_window_go(private->htmlc->bw, url, NULL, false);
} else {
JSLOG("failed to convert string value");
}
%}
getter protocol %{
lwc_string *component;
component = nsurl_get_component(private->url, NSURL_SCHEME);
if (component != NULL) {
jsret = JS_NewStringCopyN(cx,
lwc_string_data(component),
lwc_string_length(component));
2012-11-22 02:08:18 +04:00
lwc_string_unref(component);
}
%}
getter host %{
lwc_string *component;
component = nsurl_get_component(private->url, NSURL_HOST);
if (component != NULL) {
jsret = JS_NewStringCopyN(cx,
lwc_string_data(component),
lwc_string_length(component));
2012-11-22 02:08:18 +04:00
lwc_string_unref(component);
}
%}
getter hostname %{
lwc_string *component;
component = nsurl_get_component(private->url, NSURL_HOST);
if (component != NULL) {
jsret = JS_NewStringCopyN(cx,
lwc_string_data(component),
lwc_string_length(component));
2012-11-22 02:08:18 +04:00
lwc_string_unref(component);
}
%}
getter port %{
lwc_string *component;
component = nsurl_get_component(private->url, NSURL_PORT);
if (component != NULL) {
jsret = JS_NewStringCopyN(cx,
lwc_string_data(component),
lwc_string_length(component));
2012-11-22 02:08:18 +04:00
lwc_string_unref(component);
}
%}
getter pathname %{
lwc_string *component;
component = nsurl_get_component(private->url, NSURL_PATH);
if (component != NULL) {
jsret = JS_NewStringCopyN(cx,
lwc_string_data(component),
lwc_string_length(component));
2012-11-22 02:08:18 +04:00
lwc_string_unref(component);
}
%}
getter search %{
lwc_string *component;
component = nsurl_get_component(private->url, NSURL_QUERY);
if (component != NULL) {
jsret = JS_NewStringCopyN(cx,
lwc_string_data(component),
lwc_string_length(component));
2012-11-22 02:08:18 +04:00
lwc_string_unref(component);
}
%}
getter hash %{
lwc_string *component;
component = nsurl_get_component(private->url, NSURL_FRAGMENT);
if (component != NULL) {
jsret = JS_NewStringCopyN(cx,
lwc_string_data(component),
lwc_string_length(component));
2012-11-22 02:08:18 +04:00
lwc_string_unref(component);
}
%}