diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2019-05-04 12:18:21 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2019-05-04 12:18:21 +0100 |
commit | 19b45fb494358838be8b3175fde9e3ab55ef5bfa (patch) | |
tree | d872d6c39ffc3d629a9a58610e4730f27184b751 /content/handlers/html/html_script.c | |
parent | 90cabaf8c88782a07cd8bdc448bd21e471eeb072 (diff) | |
download | netsurf-19b45fb494358838be8b3175fde9e3ab55ef5bfa.tar.gz netsurf-19b45fb494358838be8b3175fde9e3ab55ef5bfa.tar.bz2 |
Support script insertion after conversion has begun
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'content/handlers/html/html_script.c')
-rw-r--r-- | content/handlers/html/html_script.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/content/handlers/html/html_script.c b/content/handlers/html/html_script.c index 80992b9dd..b404d2edf 100644 --- a/content/handlers/html/html_script.c +++ b/content/handlers/html/html_script.c @@ -55,7 +55,7 @@ static script_handler_t *select_script_handler(content_type ctype) /* exported internal interface documented in html/html_internal.h */ -nserror html_script_exec(html_content *c) +nserror html_script_exec(html_content *c, bool allow_defer) { unsigned int i; struct html_script *s; @@ -71,7 +71,7 @@ nserror html_script_exec(html_content *c) } if ((s->type == HTML_SCRIPT_ASYNC) || - (s->type == HTML_SCRIPT_DEFER)) { + (allow_defer && (s->type == HTML_SCRIPT_DEFER))) { /* ensure script content is present */ if (s->data.handle == NULL) continue; @@ -200,6 +200,13 @@ convert_script_async_cb(hlcache_handle *script, html_begin_conversion(parent); } + /* if we have already started converting though, then we can handle the + * scripts as they come in. + */ + else if (parent->conversion_begun) { + html_script_exec(parent, false); + } + return NSERROR_OK; } @@ -304,9 +311,11 @@ convert_script_sync_cb(hlcache_handle *script, } /* continue parse */ - err = dom_hubbub_parser_pause(parent->parser, false); - if (err != DOM_HUBBUB_OK) { - NSLOG(netsurf, INFO, "unpause returned 0x%x", err); + if (parent->parser != NULL) { + err = dom_hubbub_parser_pause(parent->parser, false); + if (err != DOM_HUBBUB_OK) { + NSLOG(netsurf, INFO, "unpause returned 0x%x", err); + } } break; @@ -328,9 +337,11 @@ convert_script_sync_cb(hlcache_handle *script, s->already_started = true; /* continue parse */ - err = dom_hubbub_parser_pause(parent->parser, false); - if (err != DOM_HUBBUB_OK) { - NSLOG(netsurf, INFO, "unpause returned 0x%x", err); + if (parent->parser != NULL) { + err = dom_hubbub_parser_pause(parent->parser, false); + if (err != DOM_HUBBUB_OK) { + NSLOG(netsurf, INFO, "unpause returned 0x%x", err); + } } break; @@ -402,6 +413,12 @@ exec_src_script(html_content *c, return DOM_HUBBUB_OK; /* dom error */ } + if (c->parse_completed) { + /* After parse completed, all scripts are essentially async */ + async = true; + defer = false; + } + if (async) { /* asyncronous script */ script_type = HTML_SCRIPT_ASYNC; |