fix parse completion - working syncronous scripts

This commit is contained in:
Vincent Sanders 2012-07-30 18:18:11 +01:00 committed by Vincent Sanders
parent b0a41606ff
commit 4182685d1e
3 changed files with 72 additions and 37 deletions

View File

@ -301,6 +301,8 @@ html_create_html_data(html_content *c, const http_parameter *params)
c->scripts = NULL; c->scripts = NULL;
c->jscontext = NULL; c->jscontext = NULL;
c->base.active = 1; /* The html content itself is active */
if (lwc_intern_string("*", SLEN("*"), &c->universal) != lwc_error_ok) { if (lwc_intern_string("*", SLEN("*"), &c->universal) != lwc_error_ok) {
msg_data.error = messages_get("NoMemory"); msg_data.error = messages_get("NoMemory");
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data); content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
@ -1933,24 +1935,39 @@ html_find_stylesheets_no_memory:
static bool html_convert(struct content *c) static bool html_convert(struct content *c)
{ {
html_content *htmlc = (html_content *) c; html_content *htmlc = (html_content *) c;
dom_hubbub_error err;
htmlc->base.active--; /* the html fetch is no longer active */
LOG(("%d fetches active", htmlc->base.active));
/* if there are no active fetches in progress no scripts are
* being fetched or they completed already.
*/
if (htmlc->base.active == 0) {
return html_begin_conversion(htmlc);
}
return true;
}
bool
html_begin_conversion(html_content *htmlc)
{
dom_node *html, *head; dom_node *html, *head;
union content_msg_data msg_data; union content_msg_data msg_data;
unsigned long size;
struct form *f; struct form *f;
dom_exception exc; /* returned by libdom functions */ dom_exception exc; /* returned by libdom functions */
dom_string *node_name = NULL; dom_string *node_name = NULL;
dom_hubbub_error error;
/* finish parsing */ /* complete parsing */
content__get_source_data(c, &size); error = dom_hubbub_parser_completed(htmlc->parser);
if (error != DOM_HUBBUB_OK) {
err = dom_hubbub_parser_completed(htmlc->parser);
if (err != DOM_HUBBUB_OK) {
union content_msg_data msg_data; union content_msg_data msg_data;
/** @todo Improve processing of errors */ /** @todo Improve processing of errors */
msg_data.error = messages_get("NoMemory"); msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data); content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
return false; return false;
} }
@ -1960,7 +1977,7 @@ static bool html_convert(struct content *c)
if (htmlc->document == NULL) { if (htmlc->document == NULL) {
LOG(("Parsing failed")); LOG(("Parsing failed"));
msg_data.error = messages_get("ParsingFail"); msg_data.error = messages_get("ParsingFail");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data); content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
return false; return false;
} }
@ -1977,10 +1994,10 @@ static bool html_convert(struct content *c)
encoding = dom_hubbub_parser_get_encoding(htmlc->parser, encoding = dom_hubbub_parser_get_encoding(htmlc->parser,
&htmlc->encoding_source); &htmlc->encoding_source);
htmlc->encoding = talloc_strdup(c, encoding); htmlc->encoding = talloc_strdup(&htmlc->base, encoding);
if (htmlc->encoding == NULL) { if (htmlc->encoding == NULL) {
msg_data.error = messages_get("NoMemory"); msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data); content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
return false; return false;
} }
} }
@ -1988,7 +2005,7 @@ static bool html_convert(struct content *c)
/* Give up processing if we've been aborted */ /* Give up processing if we've been aborted */
if (htmlc->aborted) { if (htmlc->aborted) {
msg_data.error = messages_get("Stopped"); msg_data.error = messages_get("Stopped");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data); content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
return false; return false;
} }
@ -1997,7 +2014,7 @@ static bool html_convert(struct content *c)
if ((exc != DOM_NO_ERR) || (html == NULL)) { if ((exc != DOM_NO_ERR) || (html == NULL)) {
LOG(("error retrieving html element from dom")); LOG(("error retrieving html element from dom"));
msg_data.error = messages_get("ParsingFail"); msg_data.error = messages_get("ParsingFail");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data); content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
return false; return false;
} }
@ -2008,7 +2025,7 @@ static bool html_convert(struct content *c)
corestring_lwc_html))) { corestring_lwc_html))) {
LOG(("root element not html")); LOG(("root element not html"));
msg_data.error = messages_get("ParsingFail"); msg_data.error = messages_get("ParsingFail");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data); content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
dom_node_unref(html); dom_node_unref(html);
return false; return false;
} }
@ -2057,7 +2074,7 @@ static bool html_convert(struct content *c)
if (head != NULL) { if (head != NULL) {
if (html_head(htmlc, head) == false) { if (html_head(htmlc, head) == false) {
msg_data.error = messages_get("NoMemory"); msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data); content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
dom_node_unref(html); dom_node_unref(html);
dom_node_unref(head); dom_node_unref(head);
return false; return false;
@ -2081,7 +2098,7 @@ static bool html_convert(struct content *c)
/* Make all actions absolute */ /* Make all actions absolute */
if (f->action == NULL || f->action[0] == '\0') { if (f->action == NULL || f->action[0] == '\0') {
/* HTML5 4.10.22.3 step 11 */ /* HTML5 4.10.22.3 step 11 */
res = url_join(nsurl_access(content_get_url(c)), res = url_join(nsurl_access(content_get_url(&htmlc->base)),
nsurl_access(htmlc->base_url), &action); nsurl_access(htmlc->base_url), &action);
} else { } else {
res = url_join(f->action, nsurl_access(htmlc->base_url), res = url_join(f->action, nsurl_access(htmlc->base_url),
@ -2090,7 +2107,7 @@ static bool html_convert(struct content *c)
if (res != URL_FUNC_OK) { if (res != URL_FUNC_OK) {
msg_data.error = messages_get("NoMemory"); msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data); content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
dom_node_unref(html); dom_node_unref(html);
dom_node_unref(head); dom_node_unref(head);
return false; return false;
@ -2104,8 +2121,9 @@ static bool html_convert(struct content *c)
f->document_charset = strdup(htmlc->encoding); f->document_charset = strdup(htmlc->encoding);
if (f->document_charset == NULL) { if (f->document_charset == NULL) {
msg_data.error = messages_get("NoMemory"); msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, content_broadcast(&htmlc->base,
msg_data); CONTENT_MSG_ERROR,
msg_data);
dom_node_unref(html); dom_node_unref(html);
dom_node_unref(head); dom_node_unref(head);
return false; return false;
@ -2122,6 +2140,11 @@ static bool html_convert(struct content *c)
} }
dom_node_unref(html); dom_node_unref(html);
if (htmlc->base.active == 0) {
html_finish_conversion(htmlc);
}
return true; return true;
} }

View File

@ -127,12 +127,20 @@ void html__redraw_a_box(struct content *c, struct box *box);
struct browser_window *html_get_browser_window(struct content *c); struct browser_window *html_get_browser_window(struct content *c);
struct search_context *html_get_search(struct content *c); struct search_context *html_get_search(struct content *c);
void html_set_search(struct content *c, struct search_context *s); void html_set_search(struct content *c, struct search_context *s);
/** /**
* Complete conversion of an HTML document * Complete conversion of an HTML document
* *
* \param c Content to convert * \param htmlc Content to convert
*/ */
void html_finish_conversion(html_content *c); void html_finish_conversion(html_content *htmlc);
/**
* Begin conversion of an HTML document
*
* \param htmlc Content to convert
*/
bool html_begin_conversion(html_content *htmlc);
/* in render/html_redraw.c */ /* in render/html_redraw.c */
bool html_redraw(struct content *c, struct content_redraw_data *data, bool html_redraw(struct content *c, struct content_redraw_data *data,

View File

@ -180,8 +180,8 @@ convert_script_async_cb(hlcache_handle *script,
parent->base.active--; parent->base.active--;
LOG(("%d fetches active", parent->base.active)); LOG(("%d fetches active", parent->base.active));
/* script finished loading so try and continue execution */
html_scripts_exec(parent);
break; break;
case CONTENT_MSG_ERROR: case CONTENT_MSG_ERROR:
@ -194,9 +194,6 @@ convert_script_async_cb(hlcache_handle *script,
LOG(("%d fetches active", parent->base.active)); LOG(("%d fetches active", parent->base.active));
content_add_error(&parent->base, "?", 0); content_add_error(&parent->base, "?", 0);
/* script failed loading so try and continue execution */
html_scripts_exec(parent);
break; break;
case CONTENT_MSG_STATUS: case CONTENT_MSG_STATUS:
@ -209,9 +206,6 @@ convert_script_async_cb(hlcache_handle *script,
assert(0); assert(0);
} }
if (parent->base.active == 0)
html_finish_conversion(parent);
return NSERROR_OK; return NSERROR_OK;
} }
@ -248,8 +242,6 @@ convert_script_defer_cb(hlcache_handle *script,
parent->base.active--; parent->base.active--;
LOG(("%d fetches active", parent->base.active)); LOG(("%d fetches active", parent->base.active));
/* script finished loading so try and continue execution */
html_scripts_exec(parent);
break; break;
case CONTENT_MSG_ERROR: case CONTENT_MSG_ERROR:
@ -262,9 +254,6 @@ convert_script_defer_cb(hlcache_handle *script,
LOG(("%d fetches active", parent->base.active)); LOG(("%d fetches active", parent->base.active));
content_add_error(&parent->base, "?", 0); content_add_error(&parent->base, "?", 0);
/* script failed loading so try and continue execution */
html_scripts_exec(parent);
break; break;
case CONTENT_MSG_STATUS: case CONTENT_MSG_STATUS:
@ -277,8 +266,12 @@ convert_script_defer_cb(hlcache_handle *script,
assert(0); assert(0);
} }
if (parent->base.active == 0) /* if there are no active fetches remaining begin post parse
html_finish_conversion(parent); * conversion
*/
if (parent->base.active == 0) {
html_begin_conversion(parent);
}
return NSERROR_OK; return NSERROR_OK;
} }
@ -295,6 +288,7 @@ convert_script_sync_cb(hlcache_handle *script,
unsigned int i; unsigned int i;
struct html_script *s; struct html_script *s;
script_handler_t *script_handler; script_handler_t *script_handler;
dom_hubbub_error err;
/* Find script */ /* Find script */
for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) { for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
@ -330,7 +324,10 @@ convert_script_sync_cb(hlcache_handle *script,
} }
/* continue parse */ /* continue parse */
dom_hubbub_parser_pause(parent->parser, false); err = dom_hubbub_parser_pause(parent->parser, false);
if (err != DOM_HUBBUB_OK) {
LOG(("unpause returned 0x%x", err));
}
break; break;
@ -360,6 +357,13 @@ convert_script_sync_cb(hlcache_handle *script,
assert(0); assert(0);
} }
/* if there are no active fetches remaining begin post parse
* conversion
*/
if (parent->base.active == 0) {
html_begin_conversion(parent);
}
return NSERROR_OK; return NSERROR_OK;
} }