From db370bfdb7a091bb85a4e2120e641fea0c663734 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Fri, 21 Feb 2020 10:46:21 +0000 Subject: HTML: Complete content state machine after async script The async script completion process needs to complete the content state machine so that browser throbbers eventually stop once async scripts have fetched and run, even if that happens *after* conversion finishes. Signed-off-by: Daniel Silverstone --- content/handlers/html/html.c | 24 +++++++++++++++++++++--- content/handlers/html/html_internal.h | 6 ++++++ content/handlers/html/html_script.c | 4 ++-- 3 files changed, 29 insertions(+), 5 deletions(-) (limited to 'content/handlers/html') diff --git a/content/handlers/html/html.c b/content/handlers/html/html.c index 6e389abe3..c7a9afebd 100644 --- a/content/handlers/html/html.c +++ b/content/handlers/html/html.c @@ -268,13 +268,31 @@ static void html_box_convert_done(html_content *c, bool success) content_set_ready(&c->base); - if (c->base.active == 0) { - content_set_done(&c->base); - } + html_proceed_to_done(c); dom_node_unref(html); } +/* Documented in html_internal.h */ +nserror +html_proceed_to_done(html_content *html) +{ + switch (content__get_status(&html->base)) { + case CONTENT_STATUS_READY: + if (html->base.active == 0) { + content_set_done(&html->base); + return NSERROR_OK; + } + break; + case CONTENT_STATUS_DONE: + return NSERROR_OK; + default: + NSLOG(netsurf, ERROR, "Content status unexpectedly not READY/DONE"); + break; + } + return NSERROR_UNKNOWN; +} + /** process link node */ static bool html_process_link(html_content *c, dom_node *node) diff --git a/content/handlers/html/html_internal.h b/content/handlers/html/html_internal.h index 2ff341038..9b363dc8b 100644 --- a/content/handlers/html/html_internal.h +++ b/content/handlers/html/html_internal.h @@ -396,6 +396,12 @@ nserror html_object_close_objects(html_content *html); nserror html_object_open_objects(html_content *html, struct browser_window *bw); nserror html_object_abort_objects(html_content *html); +/** + * Complete the HTML content state machine *iff* all scripts are finished + */ +nserror html_proceed_to_done(html_content *html); + + /* Events */ /** * Construct an event and fire it at the DOM diff --git a/content/handlers/html/html_script.c b/content/handlers/html/html_script.c index e11e47c56..ed73f50d8 100644 --- a/content/handlers/html/html_script.c +++ b/content/handlers/html/html_script.c @@ -108,7 +108,7 @@ nserror html_script_exec(html_content *c, bool allow_defer) } } - return NSERROR_OK; + return html_proceed_to_done(c); } /* create new html script entry */ @@ -208,7 +208,7 @@ convert_script_async_cb(hlcache_handle *script, * scripts as they come in. */ else if (parent->conversion_begun) { - html_script_exec(parent, false); + return html_script_exec(parent, false); } return NSERROR_OK; -- cgit v1.2.3