summaryrefslogtreecommitdiff
path: root/render/html_script.c
diff options
context:
space:
mode:
Diffstat (limited to 'render/html_script.c')
-rw-r--r--render/html_script.c98
1 files changed, 56 insertions, 42 deletions
diff --git a/render/html_script.c b/render/html_script.c
index 37b0564d7..c73a4806d 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -96,7 +96,7 @@ nserror html_script_exec(html_content *c)
s->already_started = true;
- }
+ }
}
}
@@ -105,8 +105,8 @@ nserror html_script_exec(html_content *c)
/* create new html script entry */
static struct html_script *
-html_process_new_script(html_content *c,
- dom_string *mimetype,
+html_process_new_script(html_content *c,
+ dom_string *mimetype,
enum html_script_type type)
{
struct html_script *nscript;
@@ -165,18 +165,24 @@ convert_script_async_cb(hlcache_handle *script,
break;
case CONTENT_MSG_DONE:
- LOG("script %d done '%s'", i, nsurl_access(hlcache_handle_get_url(script)));
+ NSLOG(netsurf, INFO, "script %d done '%s'", i,
+ nsurl_access(hlcache_handle_get_url(script)));
parent->base.active--;
- LOG("%d fetches active", parent->base.active);
+ NSLOG(netsurf, INFO, "%d fetches active", parent->base.active);
break;
case CONTENT_MSG_ERROR:
- LOG("script %s failed: %s", nsurl_access(hlcache_handle_get_url(script)), event->data.error);
+ NSLOG(netsurf, INFO, "script %s failed: %s",
+ nsurl_access(hlcache_handle_get_url(script)),
+ event->data.error);
+ /* fall through */
+
+ case CONTENT_MSG_ERRORCODE:
hlcache_handle_release(script);
s->data.handle = NULL;
parent->base.active--;
- LOG("%d fetches active", parent->base.active);
+ NSLOG(netsurf, INFO, "%d fetches active", parent->base.active);
content_add_error(&parent->base, "?", 0);
break;
@@ -218,18 +224,24 @@ convert_script_defer_cb(hlcache_handle *script,
switch (event->type) {
case CONTENT_MSG_DONE:
- LOG("script %d done '%s'", i, nsurl_access(hlcache_handle_get_url(script)));
+ NSLOG(netsurf, INFO, "script %d done '%s'", i,
+ nsurl_access(hlcache_handle_get_url(script)));
parent->base.active--;
- LOG("%d fetches active", parent->base.active);
+ NSLOG(netsurf, INFO, "%d fetches active", parent->base.active);
break;
case CONTENT_MSG_ERROR:
- LOG("script %s failed: %s", nsurl_access(hlcache_handle_get_url(script)), event->data.error);
+ NSLOG(netsurf, INFO, "script %s failed: %s",
+ nsurl_access(hlcache_handle_get_url(script)),
+ event->data.error);
+ /* fall through */
+
+ case CONTENT_MSG_ERRORCODE:
hlcache_handle_release(script);
s->data.handle = NULL;
parent->base.active--;
- LOG("%d fetches active", parent->base.active);
+ NSLOG(netsurf, INFO, "%d fetches active", parent->base.active);
content_add_error(&parent->base, "?", 0);
break;
@@ -272,9 +284,10 @@ convert_script_sync_cb(hlcache_handle *script,
switch (event->type) {
case CONTENT_MSG_DONE:
- LOG("script %d done '%s'", i, nsurl_access(hlcache_handle_get_url(script)));
+ NSLOG(netsurf, INFO, "script %d done '%s'", i,
+ nsurl_access(hlcache_handle_get_url(script)));
parent->base.active--;
- LOG("%d fetches active", parent->base.active);
+ NSLOG(netsurf, INFO, "%d fetches active", parent->base.active);
s->already_started = true;
@@ -291,19 +304,23 @@ convert_script_sync_cb(hlcache_handle *script,
/* continue parse */
err = dom_hubbub_parser_pause(parent->parser, false);
if (err != DOM_HUBBUB_OK) {
- LOG("unpause returned 0x%x", err);
- }
+ NSLOG(netsurf, INFO, "unpause returned 0x%x", err);
+ }
break;
case CONTENT_MSG_ERROR:
- LOG("script %s failed: %s", nsurl_access(hlcache_handle_get_url(script)), event->data.error);
+ NSLOG(netsurf, INFO, "script %s failed: %s",
+ nsurl_access(hlcache_handle_get_url(script)),
+ event->data.error);
+ /* fall through */
+ case CONTENT_MSG_ERRORCODE:
hlcache_handle_release(script);
s->data.handle = NULL;
parent->base.active--;
- LOG("%d fetches active", parent->base.active);
+ NSLOG(netsurf, INFO, "%d fetches active", parent->base.active);
content_add_error(&parent->base, "?", 0);
s->already_started = true;
@@ -311,8 +328,8 @@ convert_script_sync_cb(hlcache_handle *script,
/* continue parse */
err = dom_hubbub_parser_pause(parent->parser, false);
if (err != DOM_HUBBUB_OK) {
- LOG("unpause returned 0x%x", err);
- }
+ NSLOG(netsurf, INFO, "unpause returned 0x%x", err);
+ }
break;
@@ -343,7 +360,6 @@ exec_src_script(html_content *c,
nsurl *joined;
hlcache_child_context child;
struct html_script *nscript;
- union content_msg_data msg_data;
bool async;
bool defer;
enum html_script_type script_type;
@@ -354,21 +370,21 @@ exec_src_script(html_content *c,
/* src url */
ns_error = nsurl_join(c->base_url, dom_string_data(src), &joined);
if (ns_error != NSERROR_OK) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ content_broadcast_errorcode(&c->base, NSERROR_NOMEM);
return DOM_HUBBUB_NOMEM;
}
- LOG("script %i '%s'", c->scripts_count, nsurl_access(joined));
+ NSLOG(netsurf, INFO, "script %i '%s'", c->scripts_count,
+ nsurl_access(joined));
/* there are three ways to process the script tag at this point:
*
* Syncronously pause the parent parse and continue after
* the script has downloaded and executed. (default)
- * Async Start the script downloading and execute it when it
- * becomes available.
- * Defered Start the script downloading and execute it when
- * the page has completed parsing, may be set along
+ * Async Start the script downloading and execute it when it
+ * becomes available.
+ * Defered Start the script downloading and execute it when
+ * the page has completed parsing, may be set along
* with async where it is ignored.
*/
@@ -377,7 +393,7 @@ exec_src_script(html_content *c,
* value or the attribute name itself are valid. However
* various browsers interpret this in various ways the most
* compatible approach is to be liberal and accept any
- * value. Note setting the values to "false" still makes them true!
+ * value. Note setting the values to "false" still makes them true!
*/
exc = dom_element_has_attribute(node, corestring_dom_async, &async);
if (exc != DOM_NO_ERR) {
@@ -390,7 +406,7 @@ exec_src_script(html_content *c,
script_cb = convert_script_async_cb;
} else {
- exc = dom_element_has_attribute(node,
+ exc = dom_element_has_attribute(node,
corestring_dom_defer, &defer);
if (exc != DOM_NO_ERR) {
return DOM_HUBBUB_OK; /* dom error */
@@ -410,8 +426,7 @@ exec_src_script(html_content *c,
nscript = html_process_new_script(c, mimetype, script_type);
if (nscript == NULL) {
nsurl_unref(joined);
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ content_broadcast_errorcode(&c->base, NSERROR_NOMEM);
return DOM_HUBBUB_NOMEM;
}
@@ -434,15 +449,15 @@ exec_src_script(html_content *c,
if (ns_error != NSERROR_OK) {
/* @todo Deal with fetch error better. currently assume
- * fetch never became active
+ * fetch never became active
*/
/* mark duff script fetch as already started */
- nscript->already_started = true;
- LOG("Fetch failed with error %d", ns_error);
+ nscript->already_started = true;
+ NSLOG(netsurf, INFO, "Fetch failed with error %d", ns_error);
} else {
/* update base content active fetch count */
- c->base.active++;
- LOG("%d fetches active", c->base.active);
+ c->base.active++;
+ NSLOG(netsurf, INFO, "%d fetches active", c->base.active);
switch (script_type) {
case HTML_SCRIPT_SYNC:
@@ -465,7 +480,6 @@ exec_src_script(html_content *c,
static dom_hubbub_error
exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
{
- union content_msg_data msg_data;
dom_string *script;
dom_exception exc; /* returned by libdom functions */
struct lwc_string_s *lwcmimetype;
@@ -482,8 +496,7 @@ exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
if (nscript == NULL) {
dom_string_unref(script);
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ content_broadcast_errorcode(&c->base, NSERROR_NOMEM);
return DOM_HUBBUB_NOMEM;
}
@@ -526,15 +539,16 @@ html_process_script(void *ctx, dom_node *node)
union content_msg_data msg_data;
msg_data.jscontext = &c->jscontext;
- content_broadcast(&c->base, CONTENT_MSG_GETCTX, msg_data);
- LOG("javascript context %p ", c->jscontext);
+ content_broadcast(&c->base, CONTENT_MSG_GETCTX, &msg_data);
+ NSLOG(netsurf, INFO, "javascript context %p ", c->jscontext);
if (c->jscontext == NULL) {
/* no context and it could not be created, abort */
return DOM_HUBBUB_OK;
}
}
- LOG("content %p parser %p node %p", c, c->parser, node);
+ NSLOG(netsurf, INFO, "content %p parser %p node %p", c, c->parser,
+ node);
exc = dom_element_get_attribute(node, corestring_dom_type, &mimetype);
if (exc != DOM_NO_ERR || mimetype == NULL) {