From 095a0639d30b2683e028d632379bf7f7ac1ae6ae Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Fri, 2 Aug 2019 12:23:45 +0100 Subject: Document.bnd: Fix cookies getter and implement setter Signed-off-by: Daniel Silverstone --- content/handlers/javascript/duktape/Document.bnd | 34 +++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) 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, -- cgit v1.2.3