From 4ffa39177deab3403faa8a187c668b722b50edfb Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 7 Feb 2013 18:16:37 +0000 Subject: [PATCH] fix docuemnt/window location to correctly navigate, fixes http://www.avaaz.org/ base page --- javascript/jsapi/htmldocument.bnd | 3 +- javascript/jsapi/location.bnd | 62 +++++++++++++++++++++++++++---- javascript/jsapi/window.bnd | 21 +++++++++++ 3 files changed, 77 insertions(+), 9 deletions(-) diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd index 4aacccf4e..6e7f56528 100644 --- a/javascript/jsapi/htmldocument.bnd +++ b/javascript/jsapi/htmldocument.bnd @@ -76,8 +76,7 @@ getter location %{ jsret = jsapi_new_Location(cx, NULL, NULL, - llcache_handle_get_url(private->htmlc->base.llcache), - private->htmlc); + llcache_handle_get_url(private->htmlc->base.llcache)); %} getter URL %{ diff --git a/javascript/jsapi/location.bnd b/javascript/jsapi/location.bnd index 7fa12d4c4..03687ba18 100644 --- a/javascript/jsapi/location.bnd +++ b/javascript/jsapi/location.bnd @@ -26,6 +26,8 @@ preamble %{ #include "location.h" +struct browser_window *jsapi_get_browser_window(JSContext *cx); + %} binding location { @@ -34,16 +36,50 @@ binding location { interface Location; /* Web IDL interface to generate */ private "nsurl *" url; - private "struct html_content *" htmlc; property unshared href; } operation reload %{ - browser_window_reload(private->htmlc->bw, false); + struct browser_window *bw; + bw = jsapi_get_browser_window(cx); + if (bw != NULL) { + browser_window_reload(bw, false); + } else { + JSLOG("failed to get browser context"); + } %} +/* void Location::assign(DOMString url); */ +operation assign %{ + nsurl *joined; + struct browser_window *bw; + + bw = jsapi_get_browser_window(cx); + if (bw != NULL) { + nsurl_join(private->url, url, &joined); + browser_window_go(bw, nsurl_access(joined), NULL, true); + nsurl_unref(joined); + } else { + JSLOG("failed to get browser context"); + } +%} + +/* void Location::replace(DOMString url); */ +operation replace %{ + nsurl *joined; + struct browser_window *bw; + + bw = jsapi_get_browser_window(cx); + if (bw != NULL) { + nsurl_join(private->url, url, &joined); + browser_window_go(bw, nsurl_access(joined), NULL, false); + nsurl_unref(joined); + } else { + JSLOG("failed to get browser context"); + } +%} getter href %{ char *url_s = NULL; @@ -65,13 +101,25 @@ setter href %{ JSString *url_jsstr = NULL; int url_len = 0; char *url = NULL; + struct browser_window *bw; + nsurl *joined; - url_jsstr = JS_ValueToString(cx, *vp); - if (url_jsstr != NULL) { - JSString_to_char(url_jsstr, url, url_len); - browser_window_go(private->htmlc->bw, url, NULL, false); + bw = jsapi_get_browser_window(cx); + + if (bw != NULL) { + url_jsstr = JS_ValueToString(cx, *vp); + if (url_jsstr != NULL) { + JSString_to_char(url_jsstr, url, url_len); + + nsurl_join(private->url, url, &joined); + + browser_window_go(bw, nsurl_access(joined), NULL, false); + nsurl_unref(joined); + } else { + JSLOG("failed to convert string value"); + } } else { - JSLOG("failed to convert string value"); + JSLOG("failed to get browser context"); } %} diff --git a/javascript/jsapi/window.bnd b/javascript/jsapi/window.bnd index bba1eb7db..b334cc7cc 100644 --- a/javascript/jsapi/window.bnd +++ b/javascript/jsapi/window.bnd @@ -40,6 +40,27 @@ preamble %{ #include "window.h" #include "location.h" +struct browser_window *jsapi_get_browser_window(JSContext *cx); + +%} + +prologue %{ + +struct browser_window *jsapi_get_browser_window(JSContext *cx) +{ + struct jsclass_private *private; + + private = JS_GetInstancePrivate(cx, + JS_GetGlobalObject(cx), + &JSClass_Window, + NULL); + if (private != NULL) { + return private->bw; + } + + return NULL; +} + %} binding window {