diff options
Diffstat (limited to 'content/handlers/javascript/duktape/Document.bnd')
-rw-r--r-- | content/handlers/javascript/duktape/Document.bnd | 144 |
1 files changed, 139 insertions, 5 deletions
diff --git a/content/handlers/javascript/duktape/Document.bnd b/content/handlers/javascript/duktape/Document.bnd index ece417d0d..2f9adc380 100644 --- a/content/handlers/javascript/duktape/Document.bnd +++ b/content/handlers/javascript/duktape/Document.bnd @@ -14,7 +14,7 @@ prologue Document() #include "utils/libdom.h" #include "utils/utils.h" #include "content/hlcache.h" -#include "render/html_internal.h" +#include "html/private.h" #include "content/urldb.h" #define HANDLER_MAGIC MAGIC(HANDLER_MAP) @@ -35,7 +35,7 @@ method Document::write() } duk_concat(ctx, duk_get_top(ctx)); text = duk_safe_to_lstring(ctx, 0, &text_len); - JS_LOG("Writing %*s", (int)text_len, text); + NSLOG(netsurf, DEBUG, "Writing %*s", (int)text_len, text); err = dom_node_get_user_data(priv->parent.node, corestring_dom___ns_key_html_content_data, @@ -70,7 +70,7 @@ method Document::writeln() duk_concat(ctx, duk_get_top(ctx)); text = duk_safe_to_lstring(ctx, 0, &text_len); - JS_LOG("Writeln %*s", (int)text_len, text); + NSLOG(netsurf, DEBUG, "Writeln %*s", (int)text_len, text); err = dom_node_get_user_data(priv->parent.node, corestring_dom___ns_key_html_content_data, &htmlc); @@ -147,6 +147,62 @@ method Document::createElement() return 1; %} +method Document::createElementNS() +%{ + dom_node *newnode; + dom_exception err; + duk_size_t text_len; + duk_size_t ns_len; + const char *ns = duk_safe_to_lstring(ctx, 0, &ns_len); + const char *text = duk_safe_to_lstring(ctx, 0, &text_len); + dom_string *text_str; + dom_string *ns_str; + + err = dom_string_create((const uint8_t*)ns, ns_len, &ns_str); + if (err != DOM_NO_ERR) return 0; /* coerced to undefined */ + + err = dom_string_create((const uint8_t*)text, text_len, &text_str); + if (err != DOM_NO_ERR) { + dom_string_unref(ns_str); + return 0; /* coerced to undefined */ + } + + err = dom_document_create_element_ns(priv->parent.node, + ns_str, + text_str, + &newnode); + if (err != DOM_NO_ERR) { + dom_string_unref(ns_str); + dom_string_unref(text_str); + return 0; /* coerced to undefined */ + } + + dom_string_unref(text_str); + dom_string_unref(ns_str); + + dukky_push_node(ctx, newnode); + + dom_node_unref(newnode); + + return 1; +%} + +method Document::createDocumentFragment() +%{ + struct dom_document_fragment *frag = NULL; + dom_exception err; + + err = dom_document_create_document_fragment(priv->parent.node, &frag); + + if (err != DOM_NO_ERR) return 0; /* coerced to undefined */ + + dukky_push_node(ctx, (dom_node *)frag); + + dom_node_unref(frag); /* The pushed node holds the reference now */ + + return 1; +%} + getter Document::head() %{ struct dom_nodelist *nodes; @@ -290,10 +346,18 @@ method Document::getElementsByTagName() if (nodes == NULL) return 0; /* coerced to undefined */ + dukky_push_generics(ctx, "makeListProxy"); + duk_push_pointer(ctx, nodes); dukky_create_object(ctx, PROTO_NAME(NODELIST), 1); dom_nodelist_unref(nodes); - return 1; + + if (dukky_pcall(ctx, 1, false) != 0) { + NSLOG(dukky, DEBUG, "Unable to construct nodelist?"); + return 0; /* coerced to undefined */ + } + + return 1; /* The Proxy(NodeList) wrapper */ %} getter Document::cookie() @@ -310,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, @@ -320,6 +416,44 @@ getter Document::cookie() return 0; %} +method Document::createEvent () +%{ + /* Create a new event, mark it untrusted since it's new from JS */ + dom_event *evt = NULL; + dom_exception exc; + + exc = dom_event_create(&evt); + if (exc != DOM_NO_ERR) return 0; + exc = dom_event_set_is_trusted(evt, false); + if (exc != DOM_NO_ERR) { dom_event_unref(evt); return 0; } + + dukky_push_event(ctx, evt); + + dom_event_unref(evt); + return 1; +%} + +getter Document::implementation () +%{ + /* Create a new DOMImplementation instance */ + duk_push_this(ctx); + duk_get_prop_string(ctx, -1, MAGIC(DOMImplementation)); + if (duk_is_undefined(ctx, -1)) { + duk_pop(ctx); + + if (dukky_create_object(ctx, + PROTO_NAME(DOMIMPLEMENTATION), + 0) != DUK_EXEC_SUCCESS) { + return duk_error(ctx, + DUK_ERR_ERROR, + "Unable to create dom implementation object"); + } + duk_dup(ctx, -1); + duk_put_prop_string(ctx, -3, MAGIC(DOMImplementation)); + } + return 1; +%} + getter Document::onabort(); setter Document::onabort(); getter Document::onautocompleteerror(); |