mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-03-05 14:51:47 +03:00
Improve location implementation to be more complete
This commit is contained in:
parent
63dba3a061
commit
46945f6362
@ -10,7 +10,10 @@
|
||||
*/
|
||||
|
||||
class Location {
|
||||
private "nsurl *" url;
|
||||
private "nsurl *" url;
|
||||
prologue %{
|
||||
#include "desktop/browser.h"
|
||||
%};
|
||||
}
|
||||
|
||||
init Location("nsurl *" url)
|
||||
@ -24,6 +27,80 @@ fini Location()
|
||||
nsurl_unref(priv->url);
|
||||
%}
|
||||
|
||||
method Location::reload()
|
||||
%{
|
||||
/* retrieve the private data from the root object (window) */
|
||||
duk_push_global_object(ctx);
|
||||
duk_get_prop_string(ctx, -1, PRIVATE_MAGIC);
|
||||
window_private_t *priv_win = duk_get_pointer(ctx, -1);
|
||||
duk_pop(ctx);
|
||||
|
||||
if (priv_win->win != NULL) {
|
||||
browser_window_reload(priv_win->win, false);
|
||||
} else {
|
||||
LOG("failed to get browser context");
|
||||
}
|
||||
return 0;
|
||||
%}
|
||||
|
||||
method Location::assign()
|
||||
%{
|
||||
/* retrieve the private data from the root object (window) */
|
||||
duk_push_global_object(ctx);
|
||||
duk_get_prop_string(ctx, -1, PRIVATE_MAGIC);
|
||||
window_private_t *priv_win = duk_get_pointer(ctx, -1);
|
||||
duk_pop(ctx);
|
||||
|
||||
if (priv_win == NULL || priv_win->win == NULL) {
|
||||
LOG("failed to get browser context");
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsurl *joined;
|
||||
duk_size_t slen;
|
||||
const char *url = duk_safe_to_lstring(ctx, 0, &slen);
|
||||
|
||||
nsurl_join(priv->url, url, &joined);
|
||||
browser_window_navigate(priv_win->win,
|
||||
joined,
|
||||
NULL,
|
||||
BW_NAVIGATE_HISTORY,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
nsurl_unref(joined);
|
||||
return 0;
|
||||
%}
|
||||
|
||||
method Location::replace()
|
||||
%{
|
||||
/* retrieve the private data from the root object (window) */
|
||||
duk_push_global_object(ctx);
|
||||
duk_get_prop_string(ctx, -1, PRIVATE_MAGIC);
|
||||
window_private_t *priv_win = duk_get_pointer(ctx, -1);
|
||||
duk_pop(ctx);
|
||||
|
||||
if (priv_win == NULL || priv_win->win == NULL) {
|
||||
LOG("failed to get browser context");
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsurl *joined;
|
||||
duk_size_t slen;
|
||||
const char *url = duk_safe_to_lstring(ctx, 0, &slen);
|
||||
|
||||
nsurl_join(priv->url, url, &joined);
|
||||
browser_window_navigate(priv_win->win,
|
||||
joined,
|
||||
NULL,
|
||||
BW_NAVIGATE_NONE,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
nsurl_unref(joined);
|
||||
return 0;
|
||||
%}
|
||||
|
||||
getter Location::href()
|
||||
%{
|
||||
char *url_s = NULL;
|
||||
@ -36,11 +113,60 @@ getter Location::href()
|
||||
|
||||
duk_push_lstring(ctx, url_s, url_l);
|
||||
|
||||
free(url_s);
|
||||
if (url_s != NULL) {
|
||||
free(url_s);
|
||||
}
|
||||
|
||||
return 1;
|
||||
%}
|
||||
|
||||
setter Location::href()
|
||||
%{
|
||||
/* retrieve the private data from the root object (window) */
|
||||
duk_push_global_object(ctx);
|
||||
duk_get_prop_string(ctx, -1, PRIVATE_MAGIC);
|
||||
window_private_t *priv_win = duk_get_pointer(ctx, -1);
|
||||
duk_pop(ctx);
|
||||
|
||||
if (priv_win == NULL || priv_win->win == NULL) {
|
||||
LOG("failed to get browser context");
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsurl *joined;
|
||||
duk_size_t slen;
|
||||
const char *url = duk_safe_to_lstring(ctx, 0, &slen);
|
||||
|
||||
nsurl_join(priv->url, url, &joined);
|
||||
browser_window_navigate(priv_win->win,
|
||||
joined,
|
||||
NULL,
|
||||
BW_NAVIGATE_HISTORY,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
nsurl_unref(joined);
|
||||
return 0;
|
||||
%}
|
||||
|
||||
getter Location::origin()
|
||||
%{
|
||||
char *url_s = NULL;
|
||||
size_t url_l;
|
||||
|
||||
nsurl_get(priv->url, NSURL_SCHEME | NSURL_HOST | NSURL_PORT, &url_s, &url_l);
|
||||
|
||||
/* if url_s is NULL duk_push_lstring pushes an empty string
|
||||
* which is correct for this API
|
||||
*/
|
||||
duk_push_lstring(ctx, url_s, url_l);
|
||||
|
||||
if (url_s != NULL) {
|
||||
free(url_s);
|
||||
}
|
||||
|
||||
return 1;
|
||||
%}
|
||||
|
||||
getter Location::protocol()
|
||||
%{
|
||||
@ -48,13 +174,15 @@ getter Location::protocol()
|
||||
size_t url_l;
|
||||
|
||||
nsurl_get(priv->url, NSURL_SCHEME, &url_s, &url_l);
|
||||
if (url_s == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* if url_s is NULL duk_push_lstring pushes an empty string
|
||||
* which is correct for this API
|
||||
*/
|
||||
duk_push_lstring(ctx, url_s, url_l);
|
||||
|
||||
free(url_s);
|
||||
if (url_s != NULL) {
|
||||
free(url_s);
|
||||
}
|
||||
|
||||
return 1;
|
||||
%}
|
||||
@ -66,13 +194,15 @@ getter Location::username()
|
||||
size_t url_l;
|
||||
|
||||
nsurl_get(priv->url, NSURL_USERNAME, &url_s, &url_l);
|
||||
if (url_s == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* if url_s is NULL duk_push_lstring pushes an empty string
|
||||
* which is correct for this API
|
||||
*/
|
||||
duk_push_lstring(ctx, url_s, url_l);
|
||||
|
||||
free(url_s);
|
||||
if (url_s != NULL) {
|
||||
free(url_s);
|
||||
}
|
||||
|
||||
return 1;
|
||||
%}
|
||||
@ -84,13 +214,15 @@ getter Location::password()
|
||||
size_t url_l;
|
||||
|
||||
nsurl_get(priv->url, NSURL_PASSWORD, &url_s, &url_l);
|
||||
if (url_s == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* if url_s is NULL duk_push_lstring pushes an empty string
|
||||
* which is correct for this API
|
||||
*/
|
||||
duk_push_lstring(ctx, url_s, url_l);
|
||||
|
||||
free(url_s);
|
||||
if (url_s != NULL) {
|
||||
free(url_s);
|
||||
}
|
||||
|
||||
return 1;
|
||||
%}
|
||||
@ -102,13 +234,15 @@ getter Location::host()
|
||||
size_t url_l;
|
||||
|
||||
nsurl_get(priv->url, NSURL_HOST, &url_s, &url_l);
|
||||
if (url_s == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* if url_s is NULL duk_push_lstring pushes an empty string
|
||||
* which is correct for this API
|
||||
*/
|
||||
duk_push_lstring(ctx, url_s, url_l);
|
||||
|
||||
free(url_s);
|
||||
if (url_s != NULL) {
|
||||
free(url_s);
|
||||
}
|
||||
|
||||
return 1;
|
||||
%}
|
||||
@ -119,32 +253,37 @@ getter Location::hostname()
|
||||
char *url_s = NULL;
|
||||
size_t url_l;
|
||||
|
||||
nsurl_get(priv->url, NSURL_COMPLETE, &url_s, &url_l);
|
||||
if (url_s == NULL) {
|
||||
return 0;
|
||||
}
|
||||
nsurl_get(priv->url, NSURL_HOST, &url_s, &url_l);
|
||||
|
||||
/* if url_s is NULL duk_push_lstring pushes an empty string
|
||||
* which is correct for this API
|
||||
*/
|
||||
duk_push_lstring(ctx, url_s, url_l);
|
||||
|
||||
free(url_s);
|
||||
if (url_s != NULL) {
|
||||
free(url_s);
|
||||
}
|
||||
|
||||
return 1;
|
||||
%}
|
||||
|
||||
|
||||
|
||||
getter Location::port()
|
||||
%{
|
||||
char *url_s = NULL;
|
||||
size_t url_l;
|
||||
|
||||
nsurl_get(priv->url, NSURL_PORT, &url_s, &url_l);
|
||||
if (url_s == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* if url_s is NULL duk_push_lstring pushes an empty string
|
||||
* which is correct for this API
|
||||
*/
|
||||
duk_push_lstring(ctx, url_s, url_l);
|
||||
|
||||
free(url_s);
|
||||
if (url_s != NULL) {
|
||||
free(url_s);
|
||||
}
|
||||
|
||||
return 1;
|
||||
%}
|
||||
@ -156,13 +295,15 @@ getter Location::pathname()
|
||||
size_t url_l;
|
||||
|
||||
nsurl_get(priv->url, NSURL_PATH, &url_s, &url_l);
|
||||
if (url_s == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* if url_s is NULL duk_push_lstring pushes an empty string
|
||||
* which is correct for this API
|
||||
*/
|
||||
duk_push_lstring(ctx, url_s, url_l);
|
||||
|
||||
free(url_s);
|
||||
if (url_s != NULL) {
|
||||
free(url_s);
|
||||
}
|
||||
|
||||
return 1;
|
||||
%}
|
||||
@ -174,13 +315,15 @@ getter Location::search()
|
||||
size_t url_l;
|
||||
|
||||
nsurl_get(priv->url, NSURL_QUERY, &url_s, &url_l);
|
||||
if (url_s == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* if url_s is NULL duk_push_lstring pushes an empty string
|
||||
* which is correct for this API
|
||||
*/
|
||||
duk_push_lstring(ctx, url_s, url_l);
|
||||
|
||||
free(url_s);
|
||||
if (url_s != NULL) {
|
||||
free(url_s);
|
||||
}
|
||||
|
||||
return 1;
|
||||
%}
|
||||
@ -192,13 +335,15 @@ getter Location::hash()
|
||||
size_t url_l;
|
||||
|
||||
nsurl_get(priv->url, NSURL_FRAGMENT, &url_s, &url_l);
|
||||
if (url_s == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* if url_s is NULL duk_push_lstring pushes an empty string
|
||||
* which is correct for this API
|
||||
*/
|
||||
duk_push_lstring(ctx, url_s, url_l);
|
||||
|
||||
free(url_s);
|
||||
if (url_s != NULL) {
|
||||
free(url_s);
|
||||
}
|
||||
|
||||
return 1;
|
||||
%}
|
||||
|
@ -12,14 +12,6 @@
|
||||
<li><a href="core.infinite.html">Infinite loop</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h2>Window</h2>
|
||||
<ul>
|
||||
<li><a href="window.lately.html">location</a></li>
|
||||
<li><a href="window-enumerate.html">enumerate</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h2>Document write</h2>
|
||||
<ul>
|
||||
<li><a href="inline-doc-write-simple.html">Simple document write</a></li>
|
||||
@ -31,6 +23,20 @@
|
||||
<li><a href="inline-innerhtml.html">Inline script innerHtml test</a></li>
|
||||
</ul>
|
||||
|
||||
<h2>Window</h2>
|
||||
<ul>
|
||||
<li><a href="window.lately.html">lately</a></li>
|
||||
<li><a href="window-enumerate.html">enumerate</a></li>
|
||||
</ul>
|
||||
|
||||
<h2>Location</h2>
|
||||
<ul>
|
||||
<li><a href="location-enumerate.html">Enumerate members</a></li>
|
||||
<li><a href="location-assign.html">assign</a> should navigate to enumeration with page in history</li>
|
||||
<li><a href="location-replace.html">replace</a> should navigate to enumeration without page in history.</li>
|
||||
<li><a href="location-href.html">href</a> should navigate to enumeration with page in history</li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h2>DOM tests</h2>
|
||||
|
||||
|
13
test/js/location-assign.html
Normal file
13
test/js/location-assign.html
Normal file
@ -0,0 +1,13 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>location interface assign</title>
|
||||
<link rel="stylesheet" type="text/css" href="tst.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>location interface assign</h1>
|
||||
|
||||
<script>
|
||||
location.assign("location-enumerate.html");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
13
test/js/location-href.html
Normal file
13
test/js/location-href.html
Normal file
@ -0,0 +1,13 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>location interface href</title>
|
||||
<link rel="stylesheet" type="text/css" href="tst.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>location interface href</h1>
|
||||
|
||||
<script>
|
||||
location.href = "location-enumerate.html";
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
13
test/js/location-replace.html
Normal file
13
test/js/location-replace.html
Normal file
@ -0,0 +1,13 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>location interface replace</title>
|
||||
<link rel="stylesheet" type="text/css" href="tst.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>location interface replace</h1>
|
||||
|
||||
<script>
|
||||
location.replace("location-enumerate.html");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user