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"
|
2012-12-20 21:00:06 +04:00
|
|
|
#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 */
|
|
|
|
|
2012-11-21 22:51:44 +04:00
|
|
|
private "nsurl *" url;
|
2012-12-07 19:50:24 +04:00
|
|
|
private "struct html_content *" htmlc;
|
|
|
|
|
|
|
|
property unshared href;
|
2012-11-23 17:48:11 +04:00
|
|
|
|
2012-11-02 03:30:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
operation reload %{
|
2012-12-07 19:50:24 +04:00
|
|
|
browser_window_reload(private->htmlc->bw, false);
|
2012-11-02 03:30:28 +04:00
|
|
|
%}
|
2012-11-21 22:51:44 +04:00
|
|
|
|
|
|
|
|
|
|
|
getter href %{
|
|
|
|
char *url_s = NULL;
|
|
|
|
size_t url_l;
|
2012-12-07 19:50:24 +04:00
|
|
|
|
|
|
|
if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx,vp))) {
|
|
|
|
/* already created - return it */
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-11-21 22:51:44 +04:00
|
|
|
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;
|
|
|
|
|
2013-02-01 02:53:20 +04:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
%}
|
|
|
|
|
2012-11-21 22:51:44 +04:00
|
|
|
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);
|
2012-11-21 22:51:44 +04:00
|
|
|
}
|
|
|
|
%}
|
|
|
|
|
|
|
|
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);
|
2012-11-21 22:51:44 +04:00
|
|
|
}
|
|
|
|
%}
|
|
|
|
|
|
|
|
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);
|
2012-11-21 22:51:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
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);
|
2012-11-21 22:51:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
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);
|
2012-11-21 22:51:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
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);
|
2012-11-21 22:51:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
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);
|
2012-11-21 22:51:44 +04:00
|
|
|
}
|
|
|
|
%}
|