summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2019-08-02 12:23:45 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2019-08-02 12:23:45 +0100
commit095a0639d30b2683e028d632379bf7f7ac1ae6ae (patch)
treebbe6abb7bf958b3d00ed198d7f80c8a441dadd07 /content
parentd196dee05b8dc5245da32629bc8f7759cf55a62a (diff)
downloadnetsurf-095a0639d30b2683e028d632379bf7f7ac1ae6ae.tar.gz
netsurf-095a0639d30b2683e028d632379bf7f7ac1ae6ae.tar.bz2
Document.bnd: Fix cookies getter and implement setter
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'content')
-rw-r--r--content/handlers/javascript/duktape/Document.bnd34
1 files changed, 33 insertions, 1 deletions
diff --git a/content/handlers/javascript/duktape/Document.bnd b/content/handlers/javascript/duktape/Document.bnd
index bd0206822..d9bff0a16 100644
--- a/content/handlers/javascript/duktape/Document.bnd
+++ b/content/handlers/javascript/duktape/Document.bnd
@@ -374,7 +374,39 @@ getter Document::cookie()
if (cookie_str != NULL) {
duk_push_string(ctx, cookie_str);
free(cookie_str);
- return 1;
+ } else {
+ duk_push_string(ctx, "");
+ }
+ return 1;
+ } else {
+ NSLOG(netsurf, INFO,
+ "error getting htmlc. parent node:%p htmlc:%p",
+ priv->parent.node, htmlc);
+ }
+ return 0;
+%}
+
+setter Document::cookie()
+%{
+ struct html_content *htmlc;
+ dom_exception err;
+
+ const char * cookie_str = duk_safe_to_string(ctx, 0);
+
+ err = dom_node_get_user_data(priv->parent.node,
+ corestring_dom___ns_key_html_content_data,
+ &htmlc);
+ if ((err == DOM_NO_ERR) && (htmlc != NULL)) {
+ /* At this point we need to get the given cookie string parsed
+ * and inserted into the urldb
+ */
+ bool ok = urldb_set_cookie(cookie_str, /* The cookie string to set */
+ /* The location to set the cookie for */
+ llcache_handle_get_url(htmlc->base.llcache),
+ NULL); /* The referer, which we trust */
+ if (!ok) {
+ NSLOG(netsurf, DEEPDEBUG, "unable to set cookie: %s", cookie_str);
+ /* However there's no useful way to signal that to JS */
}
} else {
NSLOG(netsurf, INFO,