libdom: branch master updated. 6aedb99d8efddb2e3d7db18560ea671424ad8854
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libdom.git/shortlog/6aedb99d8efddb2e3d7db1...
...commit http://git.netsurf-browser.org/libdom.git/commit/6aedb99d8efddb2e3d7db185...
...tree http://git.netsurf-browser.org/libdom.git/tree/6aedb99d8efddb2e3d7db18560...
The branch, master has been updated
via 6aedb99d8efddb2e3d7db18560ea671424ad8854 (commit)
from aceae56f9efb6cbf82c399de3b6c360d3650d15c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libdom.git/commitdiff/6aedb99d8efddb2e3d7d...
commit 6aedb99d8efddb2e3d7db18560ea671424ad8854
Author: Vincent Sanders <vince(a)netsurf-browser.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
fix error handling return from script completion calback
diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c
index 6299da5..9423c2c 100644
--- a/bindings/hubbub/parser.c
+++ b/bindings/hubbub/parser.c
@@ -633,11 +633,16 @@ static hubbub_error complete_script(void *parser, void *script)
dom_hubbub_error err;
err = dom_parser->script(dom_parser->mctx, (struct dom_node *)script);
- if (err != DOM_HUBBUB_OK) {
- return HUBBUB_UNKNOWN;
+
+ if (err == DOM_HUBBUB_OK) {
+ return HUBBUB_OK;
}
- return HUBBUB_OK;
+ if ((err & DOM_HUBBUB_HUBBUB_ERR) != 0) {
+ return err & (~DOM_HUBBUB_HUBBUB_ERR);
+ }
+
+ return HUBBUB_UNKNOWN;
}
static hubbub_tree_handler tree_handler = {
-----------------------------------------------------------------------
Summary of changes:
bindings/hubbub/parser.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c
index 6299da5..9423c2c 100644
--- a/bindings/hubbub/parser.c
+++ b/bindings/hubbub/parser.c
@@ -633,11 +633,16 @@ static hubbub_error complete_script(void *parser, void *script)
dom_hubbub_error err;
err = dom_parser->script(dom_parser->mctx, (struct dom_node *)script);
- if (err != DOM_HUBBUB_OK) {
- return HUBBUB_UNKNOWN;
+
+ if (err == DOM_HUBBUB_OK) {
+ return HUBBUB_OK;
}
- return HUBBUB_OK;
+ if ((err & DOM_HUBBUB_HUBBUB_ERR) != 0) {
+ return err & (~DOM_HUBBUB_HUBBUB_ERR);
+ }
+
+ return HUBBUB_UNKNOWN;
}
static hubbub_tree_handler tree_handler = {
--
Document Object Model library
10 years, 6 months
netsurf: branch vince/script-async created. 4182685d1e90e082407a8e40a0b1db76cf9fbea2
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/4182685d1e90e082407a8...
...commit http://git.netsurf-browser.org/netsurf.git/commit/4182685d1e90e082407a8e4...
...tree http://git.netsurf-browser.org/netsurf.git/tree/4182685d1e90e082407a8e40a...
The branch, vince/script-async has been created
at 4182685d1e90e082407a8e40a0b1db76cf9fbea2 (commit)
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/4182685d1e90e082407...
commit 4182685d1e90e082407a8e40a0b1db76cf9fbea2
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
fix parse completion - working syncronous scripts
diff --git a/render/html.c b/render/html.c
index 95f7553..4263a06 100644
--- a/render/html.c
+++ b/render/html.c
@@ -301,6 +301,8 @@ html_create_html_data(html_content *c, const http_parameter *params)
c->scripts = NULL;
c->jscontext = NULL;
+ c->base.active = 1; /* The html content itself is active */
+
if (lwc_intern_string("*", SLEN("*"), &c->universal) != lwc_error_ok) {
msg_data.error = messages_get("NoMemory");
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)
{
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;
union content_msg_data msg_data;
- unsigned long size;
struct form *f;
dom_exception exc; /* returned by libdom functions */
dom_string *node_name = NULL;
+ dom_hubbub_error error;
- /* finish parsing */
- content__get_source_data(c, &size);
-
- err = dom_hubbub_parser_completed(htmlc->parser);
- if (err != DOM_HUBBUB_OK) {
+ /* complete parsing */
+ error = dom_hubbub_parser_completed(htmlc->parser);
+ if (error != DOM_HUBBUB_OK) {
union content_msg_data msg_data;
/** @todo Improve processing of errors */
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;
}
@@ -1960,7 +1977,7 @@ static bool html_convert(struct content *c)
if (htmlc->document == NULL) {
LOG(("Parsing failed"));
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;
}
@@ -1977,10 +1994,10 @@ static bool html_convert(struct content *c)
encoding = dom_hubbub_parser_get_encoding(htmlc->parser,
&htmlc->encoding_source);
- htmlc->encoding = talloc_strdup(c, encoding);
+ htmlc->encoding = talloc_strdup(&htmlc->base, encoding);
if (htmlc->encoding == NULL) {
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;
}
}
@@ -1988,7 +2005,7 @@ static bool html_convert(struct content *c)
/* Give up processing if we've been aborted */
if (htmlc->aborted) {
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;
}
@@ -1997,7 +2014,7 @@ static bool html_convert(struct content *c)
if ((exc != DOM_NO_ERR) || (html == NULL)) {
LOG(("error retrieving html element from dom"));
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;
}
@@ -2008,7 +2025,7 @@ static bool html_convert(struct content *c)
corestring_lwc_html))) {
LOG(("root element not html"));
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);
return false;
}
@@ -2057,7 +2074,7 @@ static bool html_convert(struct content *c)
if (head != NULL) {
if (html_head(htmlc, head) == false) {
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(head);
return false;
@@ -2081,7 +2098,7 @@ static bool html_convert(struct content *c)
/* Make all actions absolute */
if (f->action == NULL || f->action[0] == '\0') {
/* 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);
} else {
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) {
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(head);
return false;
@@ -2104,8 +2121,9 @@ static bool html_convert(struct content *c)
f->document_charset = strdup(htmlc->encoding);
if (f->document_charset == NULL) {
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(head);
return false;
@@ -2122,6 +2140,11 @@ static bool html_convert(struct content *c)
}
dom_node_unref(html);
+
+ if (htmlc->base.active == 0) {
+ html_finish_conversion(htmlc);
+ }
+
return true;
}
diff --git a/render/html_internal.h b/render/html_internal.h
index 3eabe1c..0f20cc1 100644
--- a/render/html_internal.h
+++ b/render/html_internal.h
@@ -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 search_context *html_get_search(struct content *c);
void html_set_search(struct content *c, struct search_context *s);
+
/**
* Complete conversion of an HTML document
*
- * \param c Content to convert
+ * \param htmlc Content to convert
+ */
+void html_finish_conversion(html_content *htmlc);
+
+/**
+ * Begin conversion of an HTML document
+ *
+ * \param htmlc Content to convert
*/
-void html_finish_conversion(html_content *c);
+bool html_begin_conversion(html_content *htmlc);
/* in render/html_redraw.c */
bool html_redraw(struct content *c, struct content_redraw_data *data,
diff --git a/render/html_script.c b/render/html_script.c
index 1e2c1b3..7222f80 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -180,8 +180,8 @@ convert_script_async_cb(hlcache_handle *script,
parent->base.active--;
LOG(("%d fetches active", parent->base.active));
- /* script finished loading so try and continue execution */
- html_scripts_exec(parent);
+
+
break;
case CONTENT_MSG_ERROR:
@@ -194,9 +194,6 @@ convert_script_async_cb(hlcache_handle *script,
LOG(("%d fetches active", parent->base.active));
content_add_error(&parent->base, "?", 0);
- /* script failed loading so try and continue execution */
- html_scripts_exec(parent);
-
break;
case CONTENT_MSG_STATUS:
@@ -209,9 +206,6 @@ convert_script_async_cb(hlcache_handle *script,
assert(0);
}
- if (parent->base.active == 0)
- html_finish_conversion(parent);
-
return NSERROR_OK;
}
@@ -248,8 +242,6 @@ convert_script_defer_cb(hlcache_handle *script,
parent->base.active--;
LOG(("%d fetches active", parent->base.active));
- /* script finished loading so try and continue execution */
- html_scripts_exec(parent);
break;
case CONTENT_MSG_ERROR:
@@ -262,9 +254,6 @@ convert_script_defer_cb(hlcache_handle *script,
LOG(("%d fetches active", parent->base.active));
content_add_error(&parent->base, "?", 0);
- /* script failed loading so try and continue execution */
- html_scripts_exec(parent);
-
break;
case CONTENT_MSG_STATUS:
@@ -277,8 +266,12 @@ convert_script_defer_cb(hlcache_handle *script,
assert(0);
}
- if (parent->base.active == 0)
- html_finish_conversion(parent);
+ /* if there are no active fetches remaining begin post parse
+ * conversion
+ */
+ if (parent->base.active == 0) {
+ html_begin_conversion(parent);
+ }
return NSERROR_OK;
}
@@ -295,6 +288,7 @@ convert_script_sync_cb(hlcache_handle *script,
unsigned int i;
struct html_script *s;
script_handler_t *script_handler;
+ dom_hubbub_error err;
/* Find script */
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 */
- 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;
@@ -360,6 +357,13 @@ convert_script_sync_cb(hlcache_handle *script,
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;
}
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/b0a41606ffe3b2cff04...
commit b0a41606ffe3b2cff04c68e0ae0aec96816cb857
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
extend html data processing to deal with paused parse
diff --git a/render/html.c b/render/html.c
index 2367529..95f7553 100644
--- a/render/html.c
+++ b/render/html.c
@@ -412,12 +412,10 @@ html_create(const content_handler *handler,
-/**
- * Process data for CONTENT_HTML.
- */
-
static bool
-html_process_data(struct content *c, const char *data, unsigned int size)
+html_process_encoding_change(struct content *c,
+ const char *data,
+ unsigned int size)
{
html_content *html = (html_content *) c;
dom_hubbub_error error;
@@ -425,23 +423,6 @@ html_process_data(struct content *c, const char *data, unsigned int size)
const char *source_data;
unsigned long source_size;
- error = dom_hubbub_parser_parse_chunk(html->parser, (const uint8_t *) data, size);
-
- if (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE)) {
- goto encoding_change;
- } else if (error != DOM_HUBBUB_OK) {
- union content_msg_data msg_data;
-
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
-
- return false;
- }
-
- return true;
-
-encoding_change:
-
/* Retrieve new encoding */
encoding = dom_hubbub_parser_get_encoding(html->parser,
&html->encoding_source);
@@ -464,11 +445,11 @@ encoding_change:
/* Create new binding, using the new encoding */
html->parser = dom_hubbub_parser_create(html->encoding,
- true,
- nsoption_bool(enable_javascript),
- NULL,
- html_process_script,
- html);
+ true,
+ nsoption_bool(enable_javascript),
+ NULL,
+ html_process_script,
+ html);
if (html->parser == NULL) {
/* Ok, we don't support the declared encoding. Bailing out
* isn't exactly user-friendly, so fall back to Windows-1252 */
@@ -506,10 +487,50 @@ encoding_change:
source_data = content__get_source_data(c, &source_size);
- /* Recurse to reprocess all the data. This is safe because
+ /* Reprocess all the data. This is safe because
* the encoding is now specified at parser start which means
* it cannot be changed again. */
- return html_process_data(c, source_data, source_size);
+ error = dom_hubbub_parser_parse_chunk(html->parser, (const uint8_t *)source_data, source_size);
+
+ if ((error == DOM_HUBBUB_OK) ||
+ (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED))) {
+ return true;
+ }
+
+ union content_msg_data msg_data;
+
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+
+ return false;
+
+}
+
+/**
+ * Process data for CONTENT_HTML.
+ */
+
+static bool
+html_process_data(struct content *c, const char *data, unsigned int size)
+{
+ html_content *html = (html_content *) c;
+ dom_hubbub_error error;
+ union content_msg_data msg_data;
+
+ error = dom_hubbub_parser_parse_chunk(html->parser, (const uint8_t *) data, size);
+
+ if ((error == DOM_HUBBUB_OK) ||
+ (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED))) {
+ return true;
+ } else if (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE)) {
+ return html_process_encoding_change(c, data, size);
+ }
+
+ /** @todo better error handling and reporting */
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+
+ return false;
}
@@ -1927,7 +1948,7 @@ static bool html_convert(struct content *c)
if (err != DOM_HUBBUB_OK) {
union content_msg_data msg_data;
- /** @todo Improve precessing of errors */
+ /** @todo Improve processing of errors */
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
@@ -2093,6 +2114,7 @@ static bool html_convert(struct content *c)
}
dom_node_unref(head);
+
/* get stylesheets */
if (html_find_stylesheets(htmlc, html) == false) {
dom_node_unref(html);
diff --git a/render/html_script.c b/render/html_script.c
index 932efa4..1e2c1b3 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -294,10 +294,11 @@ convert_script_sync_cb(hlcache_handle *script,
html_content *parent = pw;
unsigned int i;
struct html_script *s;
+ script_handler_t *script_handler;
/* Find script */
for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
- if (s->type == HTML_SCRIPT_ASYNC && s->data.handle == script)
+ if (s->type == HTML_SCRIPT_SYNC && s->data.handle == script)
break;
}
@@ -318,16 +319,19 @@ convert_script_sync_cb(hlcache_handle *script,
s->already_started = true;
- script_handler = select_script_handler(
- content_get_type(s->data.handle));
+ /* attempt to execute script */
+ script_handler = select_script_handler(content_get_type(s->data.handle));
if (script_handler != NULL) {
- /* script fetch is done and supported type */
-
+ /* script has a handler */
const char *data;
unsigned long size;
data = content_get_source_data(s->data.handle, &size );
- script_handler(c->jscontext, data, size);
+ script_handler(parent->jscontext, data, size);
}
+
+ /* continue parse */
+ dom_hubbub_parser_pause(parent->parser, false);
+
break;
case CONTENT_MSG_ERROR:
@@ -338,6 +342,7 @@ convert_script_sync_cb(hlcache_handle *script,
hlcache_handle_release(script);
s->data.handle = NULL;
parent->base.active--;
+
LOG(("%d fetches active", parent->base.active));
content_add_error(&parent->base, "?", 0);
@@ -355,9 +360,6 @@ convert_script_sync_cb(hlcache_handle *script,
assert(0);
}
- if (parent->base.active == 0)
- html_finish_conversion(parent);
-
return NSERROR_OK;
}
@@ -385,8 +387,11 @@ 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) {
- goto html_process_script_no_memory;
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return DOM_HUBBUB_NOMEM;
}
+
LOG(("script %i '%s'", c->scripts_count, nsurl_access(joined)));
/* there are three ways to process the script tag at this point:
@@ -438,7 +443,9 @@ exec_src_script(html_content *c,
nscript = html_process_new_script(c, mimetype, script_type);
if (nscript == NULL) {
nsurl_unref(joined);
- goto html_process_script_no_memory;
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return DOM_HUBBUB_NOMEM;
}
/* set up child fetch encoding and quirks */
@@ -469,6 +476,7 @@ exec_src_script(html_content *c,
/* update base content active fetch count */
c->base.active++;
LOG(("%d fetches active", c->base.active));
+
switch (script_type) {
case HTML_SCRIPT_SYNC:
ret = DOM_HUBBUB_PAUSED;
@@ -480,16 +488,11 @@ exec_src_script(html_content *c,
break;
default:
- assert(true);
+ assert(0);
}
}
return ret;
-
-html_process_script_no_memory:
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
- return DOM_HUBBUB_NOMEM;
}
static dom_hubbub_error
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/db76dd3b1abd3295097...
commit db76dd3b1abd32950971c38b3a8fb915471fb3d2
Author: Vincent Sanders <vince(a)netsurf-browser.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
extend completion types
diff --git a/render/html_script.c b/render/html_script.c
index e3075f6..932efa4 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -115,7 +115,9 @@ static bool html_scripts_exec(html_content *c)
/* create new html script entry */
static struct html_script *
-html_process_new_script(html_content *c, enum html_script_type type)
+html_process_new_script(html_content *c,
+ dom_string *mimetype,
+ enum html_script_type type)
{
struct html_script *nscript;
/* add space for new script entry */
@@ -140,13 +142,14 @@ html_process_new_script(html_content *c, enum html_script_type type)
nscript->type = type;
+ nscript->mimetype = dom_string_ref(mimetype); /* reference mimetype */
+
return nscript;
}
/**
* Callback for asyncronous scripts
*/
-
static nserror
convert_script_async_cb(hlcache_handle *script,
const hlcache_event *event,
@@ -213,6 +216,152 @@ convert_script_async_cb(hlcache_handle *script,
}
/**
+ * Callback for defer scripts
+ */
+static nserror
+convert_script_defer_cb(hlcache_handle *script,
+ const hlcache_event *event,
+ void *pw)
+{
+ html_content *parent = pw;
+ unsigned int i;
+ struct html_script *s;
+
+ /* Find script */
+ for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
+ if (s->type == HTML_SCRIPT_ASYNC && s->data.handle == script)
+ break;
+ }
+
+ assert(i != parent->scripts_count);
+
+ switch (event->type) {
+ case CONTENT_MSG_LOADING:
+ break;
+
+ case CONTENT_MSG_READY:
+ break;
+
+ case CONTENT_MSG_DONE:
+ LOG(("script %d done '%s'", i,
+ nsurl_access(hlcache_handle_get_url(script))));
+ parent->base.active--;
+ LOG(("%d fetches active", parent->base.active));
+
+ /* script finished loading so try and continue execution */
+ html_scripts_exec(parent);
+ break;
+
+ case CONTENT_MSG_ERROR:
+ LOG(("script %s failed: %s",
+ nsurl_access(hlcache_handle_get_url(script)),
+ event->data.error));
+ hlcache_handle_release(script);
+ s->data.handle = NULL;
+ parent->base.active--;
+ LOG(("%d fetches active", parent->base.active));
+ content_add_error(&parent->base, "?", 0);
+
+ /* script failed loading so try and continue execution */
+ html_scripts_exec(parent);
+
+ break;
+
+ case CONTENT_MSG_STATUS:
+ html_set_status(parent, content_get_status_message(script));
+ content_broadcast(&parent->base, CONTENT_MSG_STATUS,
+ event->data);
+ break;
+
+ default:
+ assert(0);
+ }
+
+ if (parent->base.active == 0)
+ html_finish_conversion(parent);
+
+ return NSERROR_OK;
+}
+
+/**
+ * Callback for syncronous scripts
+ */
+static nserror
+convert_script_sync_cb(hlcache_handle *script,
+ const hlcache_event *event,
+ void *pw)
+{
+ html_content *parent = pw;
+ unsigned int i;
+ struct html_script *s;
+
+ /* Find script */
+ for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
+ if (s->type == HTML_SCRIPT_ASYNC && s->data.handle == script)
+ break;
+ }
+
+ assert(i != parent->scripts_count);
+
+ switch (event->type) {
+ case CONTENT_MSG_LOADING:
+ break;
+
+ case CONTENT_MSG_READY:
+ break;
+
+ case CONTENT_MSG_DONE:
+ LOG(("script %d done '%s'", i,
+ nsurl_access(hlcache_handle_get_url(script))));
+ parent->base.active--;
+ LOG(("%d fetches active", parent->base.active));
+
+ s->already_started = true;
+
+ script_handler = select_script_handler(
+ content_get_type(s->data.handle));
+ if (script_handler != NULL) {
+ /* script fetch is done and supported type */
+
+ const char *data;
+ unsigned long size;
+ data = content_get_source_data(s->data.handle, &size );
+ script_handler(c->jscontext, data, size);
+ }
+ break;
+
+ case CONTENT_MSG_ERROR:
+ LOG(("script %s failed: %s",
+ nsurl_access(hlcache_handle_get_url(script)),
+ event->data.error));
+
+ hlcache_handle_release(script);
+ s->data.handle = NULL;
+ parent->base.active--;
+ LOG(("%d fetches active", parent->base.active));
+ content_add_error(&parent->base, "?", 0);
+
+ s->already_started = true;
+
+ break;
+
+ case CONTENT_MSG_STATUS:
+ html_set_status(parent, content_get_status_message(script));
+ content_broadcast(&parent->base, CONTENT_MSG_STATUS,
+ event->data);
+ break;
+
+ default:
+ assert(0);
+ }
+
+ if (parent->base.active == 0)
+ html_finish_conversion(parent);
+
+ return NSERROR_OK;
+}
+
+/**
* process a script with a src tag
*/
static dom_hubbub_error
@@ -226,26 +375,73 @@ exec_src_script(html_content *c,
hlcache_child_context child;
struct html_script *nscript;
union content_msg_data msg_data;
+ bool async;
+ bool defer;
+ enum html_script_type script_type;
+ hlcache_handle_callback script_cb;
+ dom_hubbub_error ret = DOM_HUBBUB_OK;
+ dom_exception exc; /* returned by libdom functions */
- //exc = dom_element_has_attribute(node, html_dom_string_async, &async);
-
- nscript = html_process_new_script(c, HTML_SCRIPT_SYNC);
- if (nscript == NULL) {
- dom_string_unref(mimetype);
- goto html_process_script_no_memory;
- }
-
- /* charset (encoding) */
+ /* src url */
ns_error = nsurl_join(c->base_url, dom_string_data(src), &joined);
if (ns_error != NSERROR_OK) {
- dom_string_unref(mimetype);
goto html_process_script_no_memory;
}
+ LOG(("script %i '%s'", c->scripts_count, nsurl_access(joined)));
- nscript->mimetype = mimetype; /* keep reference to mimetype */
+ /* 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
+ * with async where it is ignored.
+ */
+
+ /* we interpret the presence of the async and defer attribute
+ * as true and ignore its value, technically only the empty
+ * 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!
+ */
+ exc = dom_element_has_attribute(node, corestring_dom_async, &async);
+ if (exc != DOM_NO_ERR) {
+ return DOM_HUBBUB_OK; /* dom error */
+ }
- LOG(("script %i '%s'", c->scripts_count, nsurl_access(joined)));
+ if (async) {
+ /* asyncronous script */
+ script_type = HTML_SCRIPT_ASYNC;
+ script_cb = convert_script_async_cb;
+ } else {
+ exc = dom_element_has_attribute(node,
+ corestring_dom_defer, &defer);
+ if (exc != DOM_NO_ERR) {
+ return DOM_HUBBUB_OK; /* dom error */
+ }
+
+ if (defer) {
+ /* defered script */
+ script_type = HTML_SCRIPT_DEFER;
+ script_cb = convert_script_defer_cb;
+ } else {
+ /* syncronous script */
+ script_type = HTML_SCRIPT_SYNC;
+ script_cb = convert_script_sync_cb;
+ }
+ }
+
+ nscript = html_process_new_script(c, mimetype, script_type);
+ if (nscript == NULL) {
+ nsurl_unref(joined);
+ goto html_process_script_no_memory;
+ }
+
+ /* set up child fetch encoding and quirks */
child.charset = c->encoding;
child.quirks = c->base.quirks;
@@ -253,25 +449,42 @@ exec_src_script(html_content *c,
0,
content_get_url(&c->base),
NULL,
- convert_script_async_cb,
+ script_cb,
c,
&child,
CONTENT_SCRIPT,
&nscript->data.handle);
+
nsurl_unref(joined);
if (ns_error != NSERROR_OK) {
- goto html_process_script_no_memory;
- }
-
- c->base.active++; /* ensure base content knows the fetch is active */
- LOG(("%d fetches active", c->base.active));
+ /* @todo Deal with fetch error better. currently assume
+ * fetch never became active
+ */
+ /* mark duff script fetch as already started */
+ nscript->already_started = true;
+ LOG(("Fetch failed with error %d",ns_error));
+ } else {
+ /* update base content active fetch count */
+ c->base.active++;
+ LOG(("%d fetches active", c->base.active));
+ switch (script_type) {
+ case HTML_SCRIPT_SYNC:
+ ret = DOM_HUBBUB_PAUSED;
+
+ case HTML_SCRIPT_ASYNC:
+ break;
- html_scripts_exec(c);
+ case HTML_SCRIPT_DEFER:
+ break;
- return DOM_HUBBUB_OK;
+ default:
+ assert(true);
+ }
+ }
+ return ret;
html_process_script_no_memory:
msg_data.error = messages_get("NoMemory");
@@ -292,13 +505,11 @@ exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
/* does not appear to be a src so script is inline content */
exc = dom_node_get_text_content(node, &script);
if ((exc != DOM_NO_ERR) || (script == NULL)) {
- dom_string_unref(mimetype);
return DOM_HUBBUB_OK; /* no contents, skip */
}
- nscript = html_process_new_script(c, HTML_SCRIPT_INLINE);
+ nscript = html_process_new_script(c, mimetype, HTML_SCRIPT_INLINE);
if (nscript == NULL) {
- dom_string_unref(mimetype);
dom_string_unref(script);
msg_data.error = messages_get("NoMemory");
@@ -308,11 +519,8 @@ exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
}
nscript->data.string = script;
- nscript->mimetype = mimetype;
nscript->already_started = true;
- /* charset (encoding) */
-
/* ensure script handler for content type */
dom_string_intern(mimetype, &lwcmimetype);
script_handler = select_script_handler(content_factory_type_from_mime_type(lwcmimetype));
@@ -368,6 +576,8 @@ html_process_script(void *ctx, dom_node *node)
dom_string_unref(src);
}
+ dom_string_unref(mimetype);
+
return err;
}
diff --git a/utils/corestrings.c b/utils/corestrings.c
index 396e86e..af87ce2 100644
--- a/utils/corestrings.c
+++ b/utils/corestrings.c
@@ -112,6 +112,7 @@ lwc_string *corestring_lwc__top;
dom_string *corestring_dom_a;
dom_string *corestring_dom_align;
dom_string *corestring_dom_area;
+dom_string *corestring_dom_async;
dom_string *corestring_dom_background;
dom_string *corestring_dom_bgcolor;
dom_string *corestring_dom_border;
@@ -122,6 +123,7 @@ dom_string *corestring_dom_color;
dom_string *corestring_dom_cols;
dom_string *corestring_dom_content;
dom_string *corestring_dom_coords;
+dom_string *corestring_dom_defer;
dom_string *corestring_dom_height;
dom_string *corestring_dom_href;
dom_string *corestring_dom_hreflang;
@@ -258,6 +260,7 @@ void corestrings_fini(void)
CSS_DOM_STRING_UNREF(a);
CSS_DOM_STRING_UNREF(align);
CSS_DOM_STRING_UNREF(area);
+ CSS_DOM_STRING_UNREF(async);
CSS_DOM_STRING_UNREF(background);
CSS_DOM_STRING_UNREF(bgcolor);
CSS_DOM_STRING_UNREF(border);
@@ -268,6 +271,7 @@ void corestrings_fini(void)
CSS_DOM_STRING_UNREF(cols);
CSS_DOM_STRING_UNREF(content);
CSS_DOM_STRING_UNREF(coords);
+ CSS_DOM_STRING_UNREF(defer);
CSS_DOM_STRING_UNREF(height);
CSS_DOM_STRING_UNREF(href);
CSS_DOM_STRING_UNREF(hreflang);
@@ -431,6 +435,7 @@ nserror corestrings_init(void)
CSS_DOM_STRING_INTERN(a);
CSS_DOM_STRING_INTERN(align);
CSS_DOM_STRING_INTERN(area);
+ CSS_DOM_STRING_INTERN(async);
CSS_DOM_STRING_INTERN(background);
CSS_DOM_STRING_INTERN(bgcolor);
CSS_DOM_STRING_INTERN(border);
@@ -441,6 +446,7 @@ nserror corestrings_init(void)
CSS_DOM_STRING_INTERN(cols);
CSS_DOM_STRING_INTERN(content);
CSS_DOM_STRING_INTERN(coords);
+ CSS_DOM_STRING_INTERN(defer);
CSS_DOM_STRING_INTERN(height);
CSS_DOM_STRING_INTERN(href);
CSS_DOM_STRING_INTERN(hreflang);
diff --git a/utils/corestrings.h b/utils/corestrings.h
index a3bda16..1bcf8ae 100644
--- a/utils/corestrings.h
+++ b/utils/corestrings.h
@@ -118,6 +118,7 @@ struct dom_string;
extern struct dom_string *corestring_dom_a;
extern struct dom_string *corestring_dom_align;
extern struct dom_string *corestring_dom_area;
+extern struct dom_string *corestring_dom_async;
extern struct dom_string *corestring_dom_background;
extern struct dom_string *corestring_dom_bgcolor;
extern struct dom_string *corestring_dom_border;
@@ -128,6 +129,7 @@ extern struct dom_string *corestring_dom_color;
extern struct dom_string *corestring_dom_cols;
extern struct dom_string *corestring_dom_content;
extern struct dom_string *corestring_dom_coords;
+extern struct dom_string *corestring_dom_defer;
extern struct dom_string *corestring_dom_height;
extern struct dom_string *corestring_dom_href;
extern struct dom_string *corestring_dom_hreflang;
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/06608c1bf0b1046520e...
commit 06608c1bf0b1046520e184fdc063c83ead2184af
Author: Vincent Sanders <vince(a)netsurf-browser.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
extend script enumeration to include asyncronous and deferred scripts
diff --git a/render/html.c b/render/html.c
index 759c244..2367529 100644
--- a/render/html.c
+++ b/render/html.c
@@ -2433,21 +2433,7 @@ static void html_destroy(struct content *c)
}
/* Free scripts */
- for (i = 0; i != html->scripts_count; i++) {
- if (html->scripts[i].mimetype != NULL) {
- dom_string_unref(html->scripts[i].mimetype);
- }
- if (html->scripts[i].type == HTML_SCRIPT_EXTERNAL &&
- html->scripts[i].data.external != NULL) {
- hlcache_handle_release(
- html->scripts[i].data.external);
- } else if (html->scripts[i].type ==
- HTML_SCRIPT_INTERNAL &&
- html->scripts[i].data.internal != NULL) {
- dom_string_unref(html->scripts[i].data.internal);
- }
- }
- free(html->scripts);
+ html_free_scripts(html);
/* Free objects */
html_destroy_objects(html);
diff --git a/render/html.h b/render/html.h
index 64548f8..dcbc1a3 100644
--- a/render/html.h
+++ b/render/html.h
@@ -66,10 +66,13 @@ struct html_stylesheet {
*/
struct html_script {
/** Type of script */
- enum html_script_type { HTML_SCRIPT_EXTERNAL, HTML_SCRIPT_INTERNAL } type;
+ enum html_script_type { HTML_SCRIPT_INLINE,
+ HTML_SCRIPT_SYNC,
+ HTML_SCRIPT_DEFER,
+ HTML_SCRIPT_ASYNC } type;
union {
- struct hlcache_handle *external;
- struct dom_string *internal;
+ struct hlcache_handle *handle;
+ struct dom_string *string;
} data; /**< Script data */
struct dom_string *mimetype;
struct dom_string *encoding;
@@ -175,9 +178,9 @@ struct content_html_frames *html_get_frameset(struct hlcache_handle *h);
struct content_html_iframe *html_get_iframe(struct hlcache_handle *h);
nsurl *html_get_base_url(struct hlcache_handle *h);
const char *html_get_base_target(struct hlcache_handle *h);
-struct html_stylesheet *html_get_stylesheets(struct hlcache_handle *h,
+struct html_stylesheet *html_get_stylesheets(struct hlcache_handle *h,
unsigned int *n);
-struct content_html_object *html_get_objects(struct hlcache_handle *h,
+struct content_html_object *html_get_objects(struct hlcache_handle *h,
unsigned int *n);
bool html_get_id_offset(struct hlcache_handle *h, lwc_string *frag_id,
int *x, int *y);
diff --git a/render/html_internal.h b/render/html_internal.h
index ad032f7..3eabe1c 100644
--- a/render/html_internal.h
+++ b/render/html_internal.h
@@ -149,6 +149,7 @@ void html_overflow_scroll_callback(void *client_data,
/* in render/html_script.c */
dom_hubbub_error html_process_script(void *ctx, dom_node *node);
+void html_free_scripts(html_content *html);
/* in render/html_forms.c */
struct form *html_forms_get_forms(const char *docenc, dom_html_document *doc);
diff --git a/render/html_script.c b/render/html_script.c
index fb51256..e3075f6 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -69,32 +69,32 @@ static bool html_scripts_exec(html_content *c)
continue;
}
- assert((s->type == HTML_SCRIPT_EXTERNAL) ||
- (s->type == HTML_SCRIPT_INTERNAL));
+ assert((s->type == HTML_SCRIPT_SYNC) ||
+ (s->type == HTML_SCRIPT_INLINE));
- if (s->type == HTML_SCRIPT_EXTERNAL) {
+ if (s->type == HTML_SCRIPT_SYNC) {
/* ensure script content is present */
- if (s->data.external == NULL)
+ if (s->data.handle == NULL)
continue;
/* ensure script content fetch status is not an error */
- if (content_get_status(s->data.external) ==
+ if (content_get_status(s->data.handle) ==
CONTENT_STATUS_ERROR)
continue;
/* ensure script handler for content type */
script_handler = select_script_handler(
- content_get_type(s->data.external));
+ content_get_type(s->data.handle));
if (script_handler == NULL)
continue; /* unsupported type */
- if (content_get_status(s->data.external) ==
+ if (content_get_status(s->data.handle) ==
CONTENT_STATUS_DONE) {
/* external script is now available */
const char *data;
unsigned long size;
data = content_get_source_data(
- s->data.external, &size );
+ s->data.handle, &size );
script_handler(c->jscontext, data, size);
s->already_started = true;
@@ -158,8 +158,7 @@ convert_script_async_cb(hlcache_handle *script,
/* Find script */
for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
- if (s->type == HTML_SCRIPT_EXTERNAL &&
- s->data.external == script)
+ if (s->type == HTML_SCRIPT_ASYNC && s->data.handle == script)
break;
}
@@ -187,7 +186,7 @@ convert_script_async_cb(hlcache_handle *script,
nsurl_access(hlcache_handle_get_url(script)),
event->data.error));
hlcache_handle_release(script);
- s->data.external = NULL;
+ s->data.handle = NULL;
parent->base.active--;
LOG(("%d fetches active", parent->base.active));
content_add_error(&parent->base, "?", 0);
@@ -213,13 +212,13 @@ convert_script_async_cb(hlcache_handle *script,
return NSERROR_OK;
}
-/**
- * process a script with a src tag
+/**
+ * process a script with a src tag
*/
static dom_hubbub_error
-exec_src_script(html_content *c,
- dom_node *node,
- dom_string *mimetype,
+exec_src_script(html_content *c,
+ dom_node *node,
+ dom_string *mimetype,
dom_string *src)
{
nserror ns_error;
@@ -230,7 +229,7 @@ exec_src_script(html_content *c,
//exc = dom_element_has_attribute(node, html_dom_string_async, &async);
- nscript = html_process_new_script(c, HTML_STYLESHEET_EXTERNAL);
+ nscript = html_process_new_script(c, HTML_SCRIPT_SYNC);
if (nscript == NULL) {
dom_string_unref(mimetype);
goto html_process_script_no_memory;
@@ -258,7 +257,7 @@ exec_src_script(html_content *c,
c,
&child,
CONTENT_SCRIPT,
- &nscript->data.external);
+ &nscript->data.handle);
nsurl_unref(joined);
@@ -297,7 +296,7 @@ exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
return DOM_HUBBUB_OK; /* no contents, skip */
}
- nscript = html_process_new_script(c, HTML_STYLESHEET_INTERNAL);
+ nscript = html_process_new_script(c, HTML_SCRIPT_INLINE);
if (nscript == NULL) {
dom_string_unref(mimetype);
dom_string_unref(script);
@@ -308,7 +307,7 @@ exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
}
- nscript->data.internal = script;
+ nscript->data.string = script;
nscript->mimetype = mimetype;
nscript->already_started = true;
@@ -328,7 +327,7 @@ exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
}
-/**
+/**
* process script node parser callback
*
*
@@ -354,7 +353,7 @@ html_process_script(void *ctx, dom_node *node)
}
}
- LOG(("content %p parser %p node %p",c,c->parser, node));
+ LOG(("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) {
@@ -371,3 +370,27 @@ html_process_script(void *ctx, dom_node *node)
return err;
}
+
+void html_free_scripts(html_content *html)
+{
+ unsigned int i;
+
+ for (i = 0; i != html->scripts_count; i++) {
+ if (html->scripts[i].mimetype != NULL) {
+ dom_string_unref(html->scripts[i].mimetype);
+ }
+
+ if ((html->scripts[i].type == HTML_SCRIPT_INLINE) &&
+ (html->scripts[i].data.string != NULL)) {
+
+ dom_string_unref(html->scripts[i].data.string);
+
+ } else if ((html->scripts[i].type == HTML_SCRIPT_SYNC) &&
+ (html->scripts[i].data.handle != NULL)) {
+
+ hlcache_handle_release(html->scripts[i].data.handle);
+
+ }
+ }
+ free(html->scripts);
+}
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/4f0e70b50d2446ed3ba...
commit 4f0e70b50d2446ed3ba14bd51d61c80088226d91
Author: Vincent Sanders <vince(a)netsurf-browser.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
split up the script processing
diff --git a/render/html_script.c b/render/html_script.c
index 5fd8c8a..fb51256 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -144,11 +144,11 @@ html_process_new_script(html_content *c, enum html_script_type type)
}
/**
- * Callback for fetchcache() for linked stylesheets.
+ * Callback for asyncronous scripts
*/
static nserror
-html_convert_script_callback(hlcache_handle *script,
+convert_script_async_cb(hlcache_handle *script,
const hlcache_event *event,
void *pw)
{
@@ -213,7 +213,123 @@ html_convert_script_callback(hlcache_handle *script,
return NSERROR_OK;
}
-/** process script node
+/**
+ * process a script with a src tag
+ */
+static dom_hubbub_error
+exec_src_script(html_content *c,
+ dom_node *node,
+ dom_string *mimetype,
+ dom_string *src)
+{
+ nserror ns_error;
+ nsurl *joined;
+ hlcache_child_context child;
+ struct html_script *nscript;
+ union content_msg_data msg_data;
+
+ //exc = dom_element_has_attribute(node, html_dom_string_async, &async);
+
+ nscript = html_process_new_script(c, HTML_STYLESHEET_EXTERNAL);
+ if (nscript == NULL) {
+ dom_string_unref(mimetype);
+ goto html_process_script_no_memory;
+ }
+
+ /* charset (encoding) */
+ ns_error = nsurl_join(c->base_url, dom_string_data(src), &joined);
+ if (ns_error != NSERROR_OK) {
+ dom_string_unref(mimetype);
+ goto html_process_script_no_memory;
+ }
+
+ nscript->mimetype = mimetype; /* keep reference to mimetype */
+
+ LOG(("script %i '%s'", c->scripts_count, nsurl_access(joined)));
+
+ child.charset = c->encoding;
+ child.quirks = c->base.quirks;
+
+ ns_error = hlcache_handle_retrieve(joined,
+ 0,
+ content_get_url(&c->base),
+ NULL,
+ convert_script_async_cb,
+ c,
+ &child,
+ CONTENT_SCRIPT,
+ &nscript->data.external);
+
+ nsurl_unref(joined);
+
+ if (ns_error != NSERROR_OK) {
+ goto html_process_script_no_memory;
+ }
+
+ c->base.active++; /* ensure base content knows the fetch is active */
+ LOG(("%d fetches active", c->base.active));
+
+ html_scripts_exec(c);
+
+ return DOM_HUBBUB_OK;
+
+
+html_process_script_no_memory:
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return DOM_HUBBUB_NOMEM;
+}
+
+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;
+ script_handler_t *script_handler;
+ struct html_script *nscript;
+
+ /* does not appear to be a src so script is inline content */
+ exc = dom_node_get_text_content(node, &script);
+ if ((exc != DOM_NO_ERR) || (script == NULL)) {
+ dom_string_unref(mimetype);
+ return DOM_HUBBUB_OK; /* no contents, skip */
+ }
+
+ nscript = html_process_new_script(c, HTML_STYLESHEET_INTERNAL);
+ if (nscript == NULL) {
+ dom_string_unref(mimetype);
+ dom_string_unref(script);
+
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return DOM_HUBBUB_NOMEM;
+
+ }
+
+ nscript->data.internal = script;
+ nscript->mimetype = mimetype;
+ nscript->already_started = true;
+
+ /* charset (encoding) */
+
+ /* ensure script handler for content type */
+ dom_string_intern(mimetype, &lwcmimetype);
+ script_handler = select_script_handler(content_factory_type_from_mime_type(lwcmimetype));
+ lwc_string_unref(lwcmimetype);
+
+ if (script_handler != NULL) {
+ script_handler(c->jscontext,
+ dom_string_data(script),
+ dom_string_byte_length(script));
+ }
+ return DOM_HUBBUB_OK;
+}
+
+
+/**
+ * process script node parser callback
*
*
*/
@@ -222,9 +338,8 @@ html_process_script(void *ctx, dom_node *node)
{
html_content *c = (html_content *)ctx;
dom_exception exc; /* returned by libdom functions */
- dom_string *src, *script, *mimetype;
- struct html_script *nscript;
- union content_msg_data msg_data;
+ dom_string *src, *mimetype;
+ dom_hubbub_error err = DOM_HUBBUB_OK;
/* ensure javascript context is available */
if (c->jscontext == NULL) {
@@ -248,97 +363,11 @@ html_process_script(void *ctx, dom_node *node)
exc = dom_element_get_attribute(node, corestring_dom_src, &src);
if (exc != DOM_NO_ERR || src == NULL) {
- struct lwc_string_s *lwcmimetype;
- script_handler_t *script_handler;
-
- /* does not appear to be a src so script is inline content */
- exc = dom_node_get_text_content(node, &script);
- if ((exc != DOM_NO_ERR) || (script == NULL)) {
- dom_string_unref(mimetype);
- return DOM_HUBBUB_OK; /* no contents, skip */
- }
-
- nscript = html_process_new_script(c, HTML_STYLESHEET_INTERNAL);
- if (nscript == NULL) {
- dom_string_unref(mimetype);
- dom_string_unref(script);
- goto html_process_script_no_memory;
- }
-
- nscript->data.internal = script;
- nscript->mimetype = mimetype;
- nscript->already_started = true;
-
- /* charset (encoding) */
-
- /* ensure script handler for content type */
- dom_string_intern(mimetype, &lwcmimetype);
- script_handler = select_script_handler(content_factory_type_from_mime_type(lwcmimetype));
- lwc_string_unref(lwcmimetype);
-
- if (script_handler != NULL) {
- script_handler(c->jscontext,
- dom_string_data(script),
- dom_string_byte_length(script));
- }
-
-
+ err = exec_inline_script(c, node, mimetype);
} else {
- /* script with a src tag */
- nserror ns_error;
- nsurl *joined;
- hlcache_child_context child;
-
-
- nscript = html_process_new_script(c, HTML_STYLESHEET_EXTERNAL);
- if (nscript == NULL) {
- dom_string_unref(src);
- dom_string_unref(mimetype);
- goto html_process_script_no_memory;
- }
-
- /* charset (encoding) */
-
- ns_error = nsurl_join(c->base_url, dom_string_data(src), &joined);
+ err = exec_src_script(c, node, mimetype, src);
dom_string_unref(src);
- if (ns_error != NSERROR_OK) {
- dom_string_unref(mimetype);
- goto html_process_script_no_memory;
- }
-
- nscript->mimetype = mimetype; /* keep reference to mimetype */
-
- LOG(("script %i '%s'", c->scripts_count, nsurl_access(joined)));
-
- child.charset = c->encoding;
- child.quirks = c->base.quirks;
-
- ns_error = hlcache_handle_retrieve(joined,
- 0,
- content_get_url(&c->base),
- NULL,
- html_convert_script_callback,
- c,
- &child,
- CONTENT_SCRIPT,
- &nscript->data.external);
-
- nsurl_unref(joined);
-
- if (ns_error != NSERROR_OK) {
- goto html_process_script_no_memory;
- }
-
- c->base.active++; /* ensure base content knows the fetch is active */
- LOG(("%d fetches active", c->base.active));
-
}
- html_scripts_exec(c);
-
- return DOM_HUBBUB_OK;
-html_process_script_no_memory:
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
- return DOM_HUBBUB_NOMEM;
+ return err;
}
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/f207f14be1e95d0c1fa...
commit f207f14be1e95d0c1fa1866decf2c07a119ba8fe
Author: Vincent Sanders <vince(a)netsurf-browser.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
simple script tests
diff --git a/test/js/assorted.html b/test/js/assorted.html
new file mode 100644
index 0000000..bb3d477
--- /dev/null
+++ b/test/js/assorted.html
@@ -0,0 +1,34 @@
+<html>
+<head><title>moo</title></head>
+<body>
+<script>
+var tree = (this ===window)
+console.log(tree);
+var string = "50";
+
+console.log(string + 100); // 50100
+console.log(+string + 100); // 150
+
+string = parseInt(string, 10);
+console.log(string + 100); // 150
+var binary = parseInt("110010", 2);
+console.log(binary); // 50
+
+function doSomething(param) {
+ param = param.toUpperCase(); // param is now a local variable
+ console.log(param);
+}
+var string = "test";
+
+/* note that string will be passed in by reference */
+doSomething(string); // TEST
+console.log(string); // test
+
+document.write("<p>Hello World!<p>");
+</script>
+<p>one</p>
+<script>document.write("<scr" +"ipt>document.write(\"Goodbye Cruel World\");</scri" + "pt>");</script>
+</script>
+<p>hi</p>
+</body>
+</html>
diff --git a/test/js/index.html b/test/js/index.html
new file mode 100644
index 0000000..22f602e
--- /dev/null
+++ b/test/js/index.html
@@ -0,0 +1,17 @@
+<html>
+<head>
+<title>Script Tests</title>
+<link rel="stylesheet" type="text/css" href="tst.css">
+</head>
+<body>
+<h1>Script Tests</h1>
+<ul>
+<li><a href="assorted.html">Assorted</a></li>
+<li><a href="inline-doc-write-simple.html">Simple docuemnt write</a></li>
+<li><a href="inline-doc-write.html">Script within inline script</a></li>
+<li><a href="sync-script.html">External syncronous script (with css)</a></li>
+
+
+</ul>
+</body>
+</html>
diff --git a/test/js/inline-doc-write-simple.html b/test/js/inline-doc-write-simple.html
new file mode 100644
index 0000000..17ad8ee
--- /dev/null
+++ b/test/js/inline-doc-write-simple.html
@@ -0,0 +1,11 @@
+<html>
+<head><title>Inline Script Simple Document Write</title></head>
+<body>
+<h1>Inline Script Simple Document Write</h1>
+<p>Before</p>
+<script>
+document.write("<p>Hello World!<p>");
+</script>
+<p>Afterwards</p>
+</body>
+</html>
diff --git a/test/js/inline-doc-write.html b/test/js/inline-doc-write.html
new file mode 100644
index 0000000..290256d
--- /dev/null
+++ b/test/js/inline-doc-write.html
@@ -0,0 +1,13 @@
+<html>
+<head>
+<title>Inline Docuemnt Write Test</title>
+<link rel="stylesheet" type="text/css" href="tst.css">
+</head>
+<body>
+<h1>Inline Document Write Test</h1>
+<p>Before</p>
+<script>document.write("<scr" +"ipt>document.write(\"Goodbye Cruel World\");</scri" + "pt>");</script>
+</script>
+<p>Afterwards</p>
+</body>
+</html>
diff --git a/test/js/sync-script.html b/test/js/sync-script.html
new file mode 100644
index 0000000..e234fb4
--- /dev/null
+++ b/test/js/sync-script.html
@@ -0,0 +1,12 @@
+<html>
+<head>
+<title>Sync script Test</title>
+<link rel="stylesheet" type="text/css" href="tst.css">
+</head>
+<body>
+<h1>Sync script Test</h1>
+<p>Before</p>
+<script src="tst.js"></script>
+<p>Afterwards</p>
+</body>
+</html>
diff --git a/test/js/tst.css b/test/js/tst.css
new file mode 100644
index 0000000..6069f24
--- /dev/null
+++ b/test/js/tst.css
@@ -0,0 +1 @@
+h1 { color:red; }
diff --git a/test/js/tst.js b/test/js/tst.js
new file mode 100644
index 0000000..10e3b9c
--- /dev/null
+++ b/test/js/tst.js
@@ -0,0 +1 @@
+document.write("<script>document.write(\"Hello World\");</script>");
-----------------------------------------------------------------------
--
NetSurf Browser
10 years, 6 months
netsurf: branch vince/script-async created. 9e3465134380d4a0d742cf97f5c8e10b7c315d5e
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/9e3465134380d4a0d742c...
...commit http://git.netsurf-browser.org/netsurf.git/commit/9e3465134380d4a0d742cf9...
...tree http://git.netsurf-browser.org/netsurf.git/tree/9e3465134380d4a0d742cf97f...
The branch, vince/script-async has been created
at 9e3465134380d4a0d742cf97f5c8e10b7c315d5e (commit)
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/9e3465134380d4a0d74...
commit 9e3465134380d4a0d742cf97f5c8e10b7c315d5e
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
fix parse completion - working syncronous scripts
diff --git a/render/html.c b/render/html.c
index 95f7553..4263a06 100644
--- a/render/html.c
+++ b/render/html.c
@@ -301,6 +301,8 @@ html_create_html_data(html_content *c, const http_parameter *params)
c->scripts = NULL;
c->jscontext = NULL;
+ c->base.active = 1; /* The html content itself is active */
+
if (lwc_intern_string("*", SLEN("*"), &c->universal) != lwc_error_ok) {
msg_data.error = messages_get("NoMemory");
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)
{
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;
union content_msg_data msg_data;
- unsigned long size;
struct form *f;
dom_exception exc; /* returned by libdom functions */
dom_string *node_name = NULL;
+ dom_hubbub_error error;
- /* finish parsing */
- content__get_source_data(c, &size);
-
- err = dom_hubbub_parser_completed(htmlc->parser);
- if (err != DOM_HUBBUB_OK) {
+ /* complete parsing */
+ error = dom_hubbub_parser_completed(htmlc->parser);
+ if (error != DOM_HUBBUB_OK) {
union content_msg_data msg_data;
/** @todo Improve processing of errors */
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;
}
@@ -1960,7 +1977,7 @@ static bool html_convert(struct content *c)
if (htmlc->document == NULL) {
LOG(("Parsing failed"));
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;
}
@@ -1977,10 +1994,10 @@ static bool html_convert(struct content *c)
encoding = dom_hubbub_parser_get_encoding(htmlc->parser,
&htmlc->encoding_source);
- htmlc->encoding = talloc_strdup(c, encoding);
+ htmlc->encoding = talloc_strdup(&htmlc->base, encoding);
if (htmlc->encoding == NULL) {
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;
}
}
@@ -1988,7 +2005,7 @@ static bool html_convert(struct content *c)
/* Give up processing if we've been aborted */
if (htmlc->aborted) {
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;
}
@@ -1997,7 +2014,7 @@ static bool html_convert(struct content *c)
if ((exc != DOM_NO_ERR) || (html == NULL)) {
LOG(("error retrieving html element from dom"));
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;
}
@@ -2008,7 +2025,7 @@ static bool html_convert(struct content *c)
corestring_lwc_html))) {
LOG(("root element not html"));
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);
return false;
}
@@ -2057,7 +2074,7 @@ static bool html_convert(struct content *c)
if (head != NULL) {
if (html_head(htmlc, head) == false) {
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(head);
return false;
@@ -2081,7 +2098,7 @@ static bool html_convert(struct content *c)
/* Make all actions absolute */
if (f->action == NULL || f->action[0] == '\0') {
/* 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);
} else {
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) {
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(head);
return false;
@@ -2104,8 +2121,9 @@ static bool html_convert(struct content *c)
f->document_charset = strdup(htmlc->encoding);
if (f->document_charset == NULL) {
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(head);
return false;
@@ -2122,6 +2140,11 @@ static bool html_convert(struct content *c)
}
dom_node_unref(html);
+
+ if (htmlc->base.active == 0) {
+ html_finish_conversion(htmlc);
+ }
+
return true;
}
diff --git a/render/html_internal.h b/render/html_internal.h
index 3eabe1c..0f20cc1 100644
--- a/render/html_internal.h
+++ b/render/html_internal.h
@@ -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 search_context *html_get_search(struct content *c);
void html_set_search(struct content *c, struct search_context *s);
+
/**
* Complete conversion of an HTML document
*
- * \param c Content to convert
+ * \param htmlc Content to convert
+ */
+void html_finish_conversion(html_content *htmlc);
+
+/**
+ * Begin conversion of an HTML document
+ *
+ * \param htmlc Content to convert
*/
-void html_finish_conversion(html_content *c);
+bool html_begin_conversion(html_content *htmlc);
/* in render/html_redraw.c */
bool html_redraw(struct content *c, struct content_redraw_data *data,
diff --git a/render/html_script.c b/render/html_script.c
index 1e2c1b3..7222f80 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -180,8 +180,8 @@ convert_script_async_cb(hlcache_handle *script,
parent->base.active--;
LOG(("%d fetches active", parent->base.active));
- /* script finished loading so try and continue execution */
- html_scripts_exec(parent);
+
+
break;
case CONTENT_MSG_ERROR:
@@ -194,9 +194,6 @@ convert_script_async_cb(hlcache_handle *script,
LOG(("%d fetches active", parent->base.active));
content_add_error(&parent->base, "?", 0);
- /* script failed loading so try and continue execution */
- html_scripts_exec(parent);
-
break;
case CONTENT_MSG_STATUS:
@@ -209,9 +206,6 @@ convert_script_async_cb(hlcache_handle *script,
assert(0);
}
- if (parent->base.active == 0)
- html_finish_conversion(parent);
-
return NSERROR_OK;
}
@@ -248,8 +242,6 @@ convert_script_defer_cb(hlcache_handle *script,
parent->base.active--;
LOG(("%d fetches active", parent->base.active));
- /* script finished loading so try and continue execution */
- html_scripts_exec(parent);
break;
case CONTENT_MSG_ERROR:
@@ -262,9 +254,6 @@ convert_script_defer_cb(hlcache_handle *script,
LOG(("%d fetches active", parent->base.active));
content_add_error(&parent->base, "?", 0);
- /* script failed loading so try and continue execution */
- html_scripts_exec(parent);
-
break;
case CONTENT_MSG_STATUS:
@@ -277,8 +266,12 @@ convert_script_defer_cb(hlcache_handle *script,
assert(0);
}
- if (parent->base.active == 0)
- html_finish_conversion(parent);
+ /* if there are no active fetches remaining begin post parse
+ * conversion
+ */
+ if (parent->base.active == 0) {
+ html_begin_conversion(parent);
+ }
return NSERROR_OK;
}
@@ -295,6 +288,7 @@ convert_script_sync_cb(hlcache_handle *script,
unsigned int i;
struct html_script *s;
script_handler_t *script_handler;
+ dom_hubbub_error err;
/* Find script */
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 */
- 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;
@@ -360,6 +357,13 @@ convert_script_sync_cb(hlcache_handle *script,
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;
}
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/feb661a116cb599999a...
commit feb661a116cb599999a68167c79760be6455a158
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
make html data processing deal with paused
diff --git a/render/html.c b/render/html.c
index 2367529..95f7553 100644
--- a/render/html.c
+++ b/render/html.c
@@ -412,12 +412,10 @@ html_create(const content_handler *handler,
-/**
- * Process data for CONTENT_HTML.
- */
-
static bool
-html_process_data(struct content *c, const char *data, unsigned int size)
+html_process_encoding_change(struct content *c,
+ const char *data,
+ unsigned int size)
{
html_content *html = (html_content *) c;
dom_hubbub_error error;
@@ -425,23 +423,6 @@ html_process_data(struct content *c, const char *data, unsigned int size)
const char *source_data;
unsigned long source_size;
- error = dom_hubbub_parser_parse_chunk(html->parser, (const uint8_t *) data, size);
-
- if (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE)) {
- goto encoding_change;
- } else if (error != DOM_HUBBUB_OK) {
- union content_msg_data msg_data;
-
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
-
- return false;
- }
-
- return true;
-
-encoding_change:
-
/* Retrieve new encoding */
encoding = dom_hubbub_parser_get_encoding(html->parser,
&html->encoding_source);
@@ -464,11 +445,11 @@ encoding_change:
/* Create new binding, using the new encoding */
html->parser = dom_hubbub_parser_create(html->encoding,
- true,
- nsoption_bool(enable_javascript),
- NULL,
- html_process_script,
- html);
+ true,
+ nsoption_bool(enable_javascript),
+ NULL,
+ html_process_script,
+ html);
if (html->parser == NULL) {
/* Ok, we don't support the declared encoding. Bailing out
* isn't exactly user-friendly, so fall back to Windows-1252 */
@@ -506,10 +487,50 @@ encoding_change:
source_data = content__get_source_data(c, &source_size);
- /* Recurse to reprocess all the data. This is safe because
+ /* Reprocess all the data. This is safe because
* the encoding is now specified at parser start which means
* it cannot be changed again. */
- return html_process_data(c, source_data, source_size);
+ error = dom_hubbub_parser_parse_chunk(html->parser, (const uint8_t *)source_data, source_size);
+
+ if ((error == DOM_HUBBUB_OK) ||
+ (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED))) {
+ return true;
+ }
+
+ union content_msg_data msg_data;
+
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+
+ return false;
+
+}
+
+/**
+ * Process data for CONTENT_HTML.
+ */
+
+static bool
+html_process_data(struct content *c, const char *data, unsigned int size)
+{
+ html_content *html = (html_content *) c;
+ dom_hubbub_error error;
+ union content_msg_data msg_data;
+
+ error = dom_hubbub_parser_parse_chunk(html->parser, (const uint8_t *) data, size);
+
+ if ((error == DOM_HUBBUB_OK) ||
+ (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED))) {
+ return true;
+ } else if (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE)) {
+ return html_process_encoding_change(c, data, size);
+ }
+
+ /** @todo better error handling and reporting */
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+
+ return false;
}
@@ -1927,7 +1948,7 @@ static bool html_convert(struct content *c)
if (err != DOM_HUBBUB_OK) {
union content_msg_data msg_data;
- /** @todo Improve precessing of errors */
+ /** @todo Improve processing of errors */
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
@@ -2093,6 +2114,7 @@ static bool html_convert(struct content *c)
}
dom_node_unref(head);
+
/* get stylesheets */
if (html_find_stylesheets(htmlc, html) == false) {
dom_node_unref(html);
diff --git a/render/html_script.c b/render/html_script.c
index 932efa4..1e2c1b3 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -294,10 +294,11 @@ convert_script_sync_cb(hlcache_handle *script,
html_content *parent = pw;
unsigned int i;
struct html_script *s;
+ script_handler_t *script_handler;
/* Find script */
for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
- if (s->type == HTML_SCRIPT_ASYNC && s->data.handle == script)
+ if (s->type == HTML_SCRIPT_SYNC && s->data.handle == script)
break;
}
@@ -318,16 +319,19 @@ convert_script_sync_cb(hlcache_handle *script,
s->already_started = true;
- script_handler = select_script_handler(
- content_get_type(s->data.handle));
+ /* attempt to execute script */
+ script_handler = select_script_handler(content_get_type(s->data.handle));
if (script_handler != NULL) {
- /* script fetch is done and supported type */
-
+ /* script has a handler */
const char *data;
unsigned long size;
data = content_get_source_data(s->data.handle, &size );
- script_handler(c->jscontext, data, size);
+ script_handler(parent->jscontext, data, size);
}
+
+ /* continue parse */
+ dom_hubbub_parser_pause(parent->parser, false);
+
break;
case CONTENT_MSG_ERROR:
@@ -338,6 +342,7 @@ convert_script_sync_cb(hlcache_handle *script,
hlcache_handle_release(script);
s->data.handle = NULL;
parent->base.active--;
+
LOG(("%d fetches active", parent->base.active));
content_add_error(&parent->base, "?", 0);
@@ -355,9 +360,6 @@ convert_script_sync_cb(hlcache_handle *script,
assert(0);
}
- if (parent->base.active == 0)
- html_finish_conversion(parent);
-
return NSERROR_OK;
}
@@ -385,8 +387,11 @@ 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) {
- goto html_process_script_no_memory;
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return DOM_HUBBUB_NOMEM;
}
+
LOG(("script %i '%s'", c->scripts_count, nsurl_access(joined)));
/* there are three ways to process the script tag at this point:
@@ -438,7 +443,9 @@ exec_src_script(html_content *c,
nscript = html_process_new_script(c, mimetype, script_type);
if (nscript == NULL) {
nsurl_unref(joined);
- goto html_process_script_no_memory;
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return DOM_HUBBUB_NOMEM;
}
/* set up child fetch encoding and quirks */
@@ -469,6 +476,7 @@ exec_src_script(html_content *c,
/* update base content active fetch count */
c->base.active++;
LOG(("%d fetches active", c->base.active));
+
switch (script_type) {
case HTML_SCRIPT_SYNC:
ret = DOM_HUBBUB_PAUSED;
@@ -480,16 +488,11 @@ exec_src_script(html_content *c,
break;
default:
- assert(true);
+ assert(0);
}
}
return ret;
-
-html_process_script_no_memory:
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
- return DOM_HUBBUB_NOMEM;
}
static dom_hubbub_error
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/5c0df673a80f96ea269...
commit 5c0df673a80f96ea269760e836534cf5d003b00c
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
add differnt completion types
diff --git a/render/html_script.c b/render/html_script.c
index 379fb39..932efa4 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -115,7 +115,9 @@ static bool html_scripts_exec(html_content *c)
/* create new html script entry */
static struct html_script *
-html_process_new_script(html_content *c, enum html_script_type type)
+html_process_new_script(html_content *c,
+ dom_string *mimetype,
+ enum html_script_type type)
{
struct html_script *nscript;
/* add space for new script entry */
@@ -140,13 +142,14 @@ html_process_new_script(html_content *c, enum html_script_type type)
nscript->type = type;
+ nscript->mimetype = dom_string_ref(mimetype); /* reference mimetype */
+
return nscript;
}
/**
* Callback for asyncronous scripts
*/
-
static nserror
convert_script_async_cb(hlcache_handle *script,
const hlcache_event *event,
@@ -213,6 +216,152 @@ convert_script_async_cb(hlcache_handle *script,
}
/**
+ * Callback for defer scripts
+ */
+static nserror
+convert_script_defer_cb(hlcache_handle *script,
+ const hlcache_event *event,
+ void *pw)
+{
+ html_content *parent = pw;
+ unsigned int i;
+ struct html_script *s;
+
+ /* Find script */
+ for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
+ if (s->type == HTML_SCRIPT_ASYNC && s->data.handle == script)
+ break;
+ }
+
+ assert(i != parent->scripts_count);
+
+ switch (event->type) {
+ case CONTENT_MSG_LOADING:
+ break;
+
+ case CONTENT_MSG_READY:
+ break;
+
+ case CONTENT_MSG_DONE:
+ LOG(("script %d done '%s'", i,
+ nsurl_access(hlcache_handle_get_url(script))));
+ parent->base.active--;
+ LOG(("%d fetches active", parent->base.active));
+
+ /* script finished loading so try and continue execution */
+ html_scripts_exec(parent);
+ break;
+
+ case CONTENT_MSG_ERROR:
+ LOG(("script %s failed: %s",
+ nsurl_access(hlcache_handle_get_url(script)),
+ event->data.error));
+ hlcache_handle_release(script);
+ s->data.handle = NULL;
+ parent->base.active--;
+ LOG(("%d fetches active", parent->base.active));
+ content_add_error(&parent->base, "?", 0);
+
+ /* script failed loading so try and continue execution */
+ html_scripts_exec(parent);
+
+ break;
+
+ case CONTENT_MSG_STATUS:
+ html_set_status(parent, content_get_status_message(script));
+ content_broadcast(&parent->base, CONTENT_MSG_STATUS,
+ event->data);
+ break;
+
+ default:
+ assert(0);
+ }
+
+ if (parent->base.active == 0)
+ html_finish_conversion(parent);
+
+ return NSERROR_OK;
+}
+
+/**
+ * Callback for syncronous scripts
+ */
+static nserror
+convert_script_sync_cb(hlcache_handle *script,
+ const hlcache_event *event,
+ void *pw)
+{
+ html_content *parent = pw;
+ unsigned int i;
+ struct html_script *s;
+
+ /* Find script */
+ for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
+ if (s->type == HTML_SCRIPT_ASYNC && s->data.handle == script)
+ break;
+ }
+
+ assert(i != parent->scripts_count);
+
+ switch (event->type) {
+ case CONTENT_MSG_LOADING:
+ break;
+
+ case CONTENT_MSG_READY:
+ break;
+
+ case CONTENT_MSG_DONE:
+ LOG(("script %d done '%s'", i,
+ nsurl_access(hlcache_handle_get_url(script))));
+ parent->base.active--;
+ LOG(("%d fetches active", parent->base.active));
+
+ s->already_started = true;
+
+ script_handler = select_script_handler(
+ content_get_type(s->data.handle));
+ if (script_handler != NULL) {
+ /* script fetch is done and supported type */
+
+ const char *data;
+ unsigned long size;
+ data = content_get_source_data(s->data.handle, &size );
+ script_handler(c->jscontext, data, size);
+ }
+ break;
+
+ case CONTENT_MSG_ERROR:
+ LOG(("script %s failed: %s",
+ nsurl_access(hlcache_handle_get_url(script)),
+ event->data.error));
+
+ hlcache_handle_release(script);
+ s->data.handle = NULL;
+ parent->base.active--;
+ LOG(("%d fetches active", parent->base.active));
+ content_add_error(&parent->base, "?", 0);
+
+ s->already_started = true;
+
+ break;
+
+ case CONTENT_MSG_STATUS:
+ html_set_status(parent, content_get_status_message(script));
+ content_broadcast(&parent->base, CONTENT_MSG_STATUS,
+ event->data);
+ break;
+
+ default:
+ assert(0);
+ }
+
+ if (parent->base.active == 0)
+ html_finish_conversion(parent);
+
+ return NSERROR_OK;
+}
+
+/**
* process a script with a src tag
*/
static dom_hubbub_error
@@ -226,15 +375,29 @@ exec_src_script(html_content *c,
hlcache_child_context child;
struct html_script *nscript;
union content_msg_data msg_data;
+ bool async;
+ bool defer;
+ enum html_script_type script_type;
+ hlcache_handle_callback script_cb;
+ dom_hubbub_error ret = DOM_HUBBUB_OK;
+ dom_exception exc; /* returned by libdom functions */
- /* there are three ways to precess the script tag at this point:
+ /* src url */
+ ns_error = nsurl_join(c->base_url, dom_string_data(src), &joined);
+ if (ns_error != NSERROR_OK) {
+ goto html_process_script_no_memory;
+ }
+ LOG(("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)
- * Defered Start the script downloading and execute it when
- * the page has completed parsing
* 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.
*/
/* we interpret the presence of the async and defer attribute
@@ -242,28 +405,43 @@ 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
+ * value. Note setting the values to "false" still makes them true!
*/
- exc = dom_element_has_attribute(node, html_dom_string_async, &async);
- exc = dom_element_has_attribute(node, html_dom_string_async, &defer);
+ exc = dom_element_has_attribute(node, corestring_dom_async, &async);
+ if (exc != DOM_NO_ERR) {
+ return DOM_HUBBUB_OK; /* dom error */
+ }
- nscript = html_process_new_script(c, HTML_SCRIPT_SYNC);
- if (nscript == NULL) {
- dom_string_unref(mimetype);
- goto html_process_script_no_memory;
+ if (async) {
+ /* asyncronous script */
+ script_type = HTML_SCRIPT_ASYNC;
+ script_cb = convert_script_async_cb;
+
+ } else {
+ exc = dom_element_has_attribute(node,
+ corestring_dom_defer, &defer);
+ if (exc != DOM_NO_ERR) {
+ return DOM_HUBBUB_OK; /* dom error */
+ }
+
+ if (defer) {
+ /* defered script */
+ script_type = HTML_SCRIPT_DEFER;
+ script_cb = convert_script_defer_cb;
+ } else {
+ /* syncronous script */
+ script_type = HTML_SCRIPT_SYNC;
+ script_cb = convert_script_sync_cb;
+ }
}
- /* charset (encoding) */
- ns_error = nsurl_join(c->base_url, dom_string_data(src), &joined);
- if (ns_error != NSERROR_OK) {
- dom_string_unref(mimetype);
+ nscript = html_process_new_script(c, mimetype, script_type);
+ if (nscript == NULL) {
+ nsurl_unref(joined);
goto html_process_script_no_memory;
}
- nscript->mimetype = mimetype; /* keep reference to mimetype */
-
- LOG(("script %i '%s'", c->scripts_count, nsurl_access(joined)));
-
+ /* set up child fetch encoding and quirks */
child.charset = c->encoding;
child.quirks = c->base.quirks;
@@ -271,25 +449,42 @@ exec_src_script(html_content *c,
0,
content_get_url(&c->base),
NULL,
- convert_script_async_cb,
+ script_cb,
c,
&child,
CONTENT_SCRIPT,
&nscript->data.handle);
+
nsurl_unref(joined);
if (ns_error != NSERROR_OK) {
- goto html_process_script_no_memory;
- }
-
- c->base.active++; /* ensure base content knows the fetch is active */
- LOG(("%d fetches active", c->base.active));
+ /* @todo Deal with fetch error better. currently assume
+ * fetch never became active
+ */
+ /* mark duff script fetch as already started */
+ nscript->already_started = true;
+ LOG(("Fetch failed with error %d",ns_error));
+ } else {
+ /* update base content active fetch count */
+ c->base.active++;
+ LOG(("%d fetches active", c->base.active));
+ switch (script_type) {
+ case HTML_SCRIPT_SYNC:
+ ret = DOM_HUBBUB_PAUSED;
+
+ case HTML_SCRIPT_ASYNC:
+ break;
- html_scripts_exec(c);
+ case HTML_SCRIPT_DEFER:
+ break;
- return DOM_HUBBUB_OK;
+ default:
+ assert(true);
+ }
+ }
+ return ret;
html_process_script_no_memory:
msg_data.error = messages_get("NoMemory");
@@ -310,13 +505,11 @@ exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
/* does not appear to be a src so script is inline content */
exc = dom_node_get_text_content(node, &script);
if ((exc != DOM_NO_ERR) || (script == NULL)) {
- dom_string_unref(mimetype);
return DOM_HUBBUB_OK; /* no contents, skip */
}
- nscript = html_process_new_script(c, HTML_SCRIPT_INLINE);
+ nscript = html_process_new_script(c, mimetype, HTML_SCRIPT_INLINE);
if (nscript == NULL) {
- dom_string_unref(mimetype);
dom_string_unref(script);
msg_data.error = messages_get("NoMemory");
@@ -326,11 +519,8 @@ exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
}
nscript->data.string = script;
- nscript->mimetype = mimetype;
nscript->already_started = true;
- /* charset (encoding) */
-
/* ensure script handler for content type */
dom_string_intern(mimetype, &lwcmimetype);
script_handler = select_script_handler(content_factory_type_from_mime_type(lwcmimetype));
@@ -386,6 +576,8 @@ html_process_script(void *ctx, dom_node *node)
dom_string_unref(src);
}
+ dom_string_unref(mimetype);
+
return err;
}
diff --git a/utils/corestrings.c b/utils/corestrings.c
index 396e86e..af87ce2 100644
--- a/utils/corestrings.c
+++ b/utils/corestrings.c
@@ -112,6 +112,7 @@ lwc_string *corestring_lwc__top;
dom_string *corestring_dom_a;
dom_string *corestring_dom_align;
dom_string *corestring_dom_area;
+dom_string *corestring_dom_async;
dom_string *corestring_dom_background;
dom_string *corestring_dom_bgcolor;
dom_string *corestring_dom_border;
@@ -122,6 +123,7 @@ dom_string *corestring_dom_color;
dom_string *corestring_dom_cols;
dom_string *corestring_dom_content;
dom_string *corestring_dom_coords;
+dom_string *corestring_dom_defer;
dom_string *corestring_dom_height;
dom_string *corestring_dom_href;
dom_string *corestring_dom_hreflang;
@@ -258,6 +260,7 @@ void corestrings_fini(void)
CSS_DOM_STRING_UNREF(a);
CSS_DOM_STRING_UNREF(align);
CSS_DOM_STRING_UNREF(area);
+ CSS_DOM_STRING_UNREF(async);
CSS_DOM_STRING_UNREF(background);
CSS_DOM_STRING_UNREF(bgcolor);
CSS_DOM_STRING_UNREF(border);
@@ -268,6 +271,7 @@ void corestrings_fini(void)
CSS_DOM_STRING_UNREF(cols);
CSS_DOM_STRING_UNREF(content);
CSS_DOM_STRING_UNREF(coords);
+ CSS_DOM_STRING_UNREF(defer);
CSS_DOM_STRING_UNREF(height);
CSS_DOM_STRING_UNREF(href);
CSS_DOM_STRING_UNREF(hreflang);
@@ -431,6 +435,7 @@ nserror corestrings_init(void)
CSS_DOM_STRING_INTERN(a);
CSS_DOM_STRING_INTERN(align);
CSS_DOM_STRING_INTERN(area);
+ CSS_DOM_STRING_INTERN(async);
CSS_DOM_STRING_INTERN(background);
CSS_DOM_STRING_INTERN(bgcolor);
CSS_DOM_STRING_INTERN(border);
@@ -441,6 +446,7 @@ nserror corestrings_init(void)
CSS_DOM_STRING_INTERN(cols);
CSS_DOM_STRING_INTERN(content);
CSS_DOM_STRING_INTERN(coords);
+ CSS_DOM_STRING_INTERN(defer);
CSS_DOM_STRING_INTERN(height);
CSS_DOM_STRING_INTERN(href);
CSS_DOM_STRING_INTERN(hreflang);
diff --git a/utils/corestrings.h b/utils/corestrings.h
index a3bda16..1bcf8ae 100644
--- a/utils/corestrings.h
+++ b/utils/corestrings.h
@@ -118,6 +118,7 @@ struct dom_string;
extern struct dom_string *corestring_dom_a;
extern struct dom_string *corestring_dom_align;
extern struct dom_string *corestring_dom_area;
+extern struct dom_string *corestring_dom_async;
extern struct dom_string *corestring_dom_background;
extern struct dom_string *corestring_dom_bgcolor;
extern struct dom_string *corestring_dom_border;
@@ -128,6 +129,7 @@ extern struct dom_string *corestring_dom_color;
extern struct dom_string *corestring_dom_cols;
extern struct dom_string *corestring_dom_content;
extern struct dom_string *corestring_dom_coords;
+extern struct dom_string *corestring_dom_defer;
extern struct dom_string *corestring_dom_height;
extern struct dom_string *corestring_dom_href;
extern struct dom_string *corestring_dom_hreflang;
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/bf0d4f529a96ea235b4...
commit bf0d4f529a96ea235b41df8467f9acd0bf855991
Author: Vincent Sanders <vince(a)netsurf-browser.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
current wip on adding syncronous interpretation
diff --git a/render/html_script.c b/render/html_script.c
index e3075f6..379fb39 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -227,7 +227,25 @@ exec_src_script(html_content *c,
struct html_script *nscript;
union content_msg_data msg_data;
- //exc = dom_element_has_attribute(node, html_dom_string_async, &async);
+ /* there are three ways to precess the script tag at this point:
+
+ * Syncronously pause the parent parse and continue after
+ * the script has downloaded and executed. (default)
+ * Defered Start the script downloading and execute it when
+ * the page has completed parsing
+ * Async Start the script downloading and execute it when it
+ * becomes available.
+ */
+
+ /* we interpret the presence of the async and defer attribute
+ * as true and ignore its value, technically only the empty
+ * 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
+ */
+ exc = dom_element_has_attribute(node, html_dom_string_async, &async);
+ exc = dom_element_has_attribute(node, html_dom_string_async, &defer);
nscript = html_process_new_script(c, HTML_SCRIPT_SYNC);
if (nscript == NULL) {
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/27c07f594983d010a2e...
commit 27c07f594983d010a2e9216ac33af83bba7aa4ef
Author: Vincent Sanders <vince(a)netsurf-browser.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
rename and extend script enum to represent the four types we require
diff --git a/render/html.c b/render/html.c
index 759c244..2367529 100644
--- a/render/html.c
+++ b/render/html.c
@@ -2433,21 +2433,7 @@ static void html_destroy(struct content *c)
}
/* Free scripts */
- for (i = 0; i != html->scripts_count; i++) {
- if (html->scripts[i].mimetype != NULL) {
- dom_string_unref(html->scripts[i].mimetype);
- }
- if (html->scripts[i].type == HTML_SCRIPT_EXTERNAL &&
- html->scripts[i].data.external != NULL) {
- hlcache_handle_release(
- html->scripts[i].data.external);
- } else if (html->scripts[i].type ==
- HTML_SCRIPT_INTERNAL &&
- html->scripts[i].data.internal != NULL) {
- dom_string_unref(html->scripts[i].data.internal);
- }
- }
- free(html->scripts);
+ html_free_scripts(html);
/* Free objects */
html_destroy_objects(html);
diff --git a/render/html.h b/render/html.h
index 64548f8..dcbc1a3 100644
--- a/render/html.h
+++ b/render/html.h
@@ -66,10 +66,13 @@ struct html_stylesheet {
*/
struct html_script {
/** Type of script */
- enum html_script_type { HTML_SCRIPT_EXTERNAL, HTML_SCRIPT_INTERNAL } type;
+ enum html_script_type { HTML_SCRIPT_INLINE,
+ HTML_SCRIPT_SYNC,
+ HTML_SCRIPT_DEFER,
+ HTML_SCRIPT_ASYNC } type;
union {
- struct hlcache_handle *external;
- struct dom_string *internal;
+ struct hlcache_handle *handle;
+ struct dom_string *string;
} data; /**< Script data */
struct dom_string *mimetype;
struct dom_string *encoding;
@@ -175,9 +178,9 @@ struct content_html_frames *html_get_frameset(struct hlcache_handle *h);
struct content_html_iframe *html_get_iframe(struct hlcache_handle *h);
nsurl *html_get_base_url(struct hlcache_handle *h);
const char *html_get_base_target(struct hlcache_handle *h);
-struct html_stylesheet *html_get_stylesheets(struct hlcache_handle *h,
+struct html_stylesheet *html_get_stylesheets(struct hlcache_handle *h,
unsigned int *n);
-struct content_html_object *html_get_objects(struct hlcache_handle *h,
+struct content_html_object *html_get_objects(struct hlcache_handle *h,
unsigned int *n);
bool html_get_id_offset(struct hlcache_handle *h, lwc_string *frag_id,
int *x, int *y);
diff --git a/render/html_internal.h b/render/html_internal.h
index ad032f7..3eabe1c 100644
--- a/render/html_internal.h
+++ b/render/html_internal.h
@@ -149,6 +149,7 @@ void html_overflow_scroll_callback(void *client_data,
/* in render/html_script.c */
dom_hubbub_error html_process_script(void *ctx, dom_node *node);
+void html_free_scripts(html_content *html);
/* in render/html_forms.c */
struct form *html_forms_get_forms(const char *docenc, dom_html_document *doc);
diff --git a/render/html_script.c b/render/html_script.c
index fb51256..e3075f6 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -69,32 +69,32 @@ static bool html_scripts_exec(html_content *c)
continue;
}
- assert((s->type == HTML_SCRIPT_EXTERNAL) ||
- (s->type == HTML_SCRIPT_INTERNAL));
+ assert((s->type == HTML_SCRIPT_SYNC) ||
+ (s->type == HTML_SCRIPT_INLINE));
- if (s->type == HTML_SCRIPT_EXTERNAL) {
+ if (s->type == HTML_SCRIPT_SYNC) {
/* ensure script content is present */
- if (s->data.external == NULL)
+ if (s->data.handle == NULL)
continue;
/* ensure script content fetch status is not an error */
- if (content_get_status(s->data.external) ==
+ if (content_get_status(s->data.handle) ==
CONTENT_STATUS_ERROR)
continue;
/* ensure script handler for content type */
script_handler = select_script_handler(
- content_get_type(s->data.external));
+ content_get_type(s->data.handle));
if (script_handler == NULL)
continue; /* unsupported type */
- if (content_get_status(s->data.external) ==
+ if (content_get_status(s->data.handle) ==
CONTENT_STATUS_DONE) {
/* external script is now available */
const char *data;
unsigned long size;
data = content_get_source_data(
- s->data.external, &size );
+ s->data.handle, &size );
script_handler(c->jscontext, data, size);
s->already_started = true;
@@ -158,8 +158,7 @@ convert_script_async_cb(hlcache_handle *script,
/* Find script */
for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
- if (s->type == HTML_SCRIPT_EXTERNAL &&
- s->data.external == script)
+ if (s->type == HTML_SCRIPT_ASYNC && s->data.handle == script)
break;
}
@@ -187,7 +186,7 @@ convert_script_async_cb(hlcache_handle *script,
nsurl_access(hlcache_handle_get_url(script)),
event->data.error));
hlcache_handle_release(script);
- s->data.external = NULL;
+ s->data.handle = NULL;
parent->base.active--;
LOG(("%d fetches active", parent->base.active));
content_add_error(&parent->base, "?", 0);
@@ -213,13 +212,13 @@ convert_script_async_cb(hlcache_handle *script,
return NSERROR_OK;
}
-/**
- * process a script with a src tag
+/**
+ * process a script with a src tag
*/
static dom_hubbub_error
-exec_src_script(html_content *c,
- dom_node *node,
- dom_string *mimetype,
+exec_src_script(html_content *c,
+ dom_node *node,
+ dom_string *mimetype,
dom_string *src)
{
nserror ns_error;
@@ -230,7 +229,7 @@ exec_src_script(html_content *c,
//exc = dom_element_has_attribute(node, html_dom_string_async, &async);
- nscript = html_process_new_script(c, HTML_STYLESHEET_EXTERNAL);
+ nscript = html_process_new_script(c, HTML_SCRIPT_SYNC);
if (nscript == NULL) {
dom_string_unref(mimetype);
goto html_process_script_no_memory;
@@ -258,7 +257,7 @@ exec_src_script(html_content *c,
c,
&child,
CONTENT_SCRIPT,
- &nscript->data.external);
+ &nscript->data.handle);
nsurl_unref(joined);
@@ -297,7 +296,7 @@ exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
return DOM_HUBBUB_OK; /* no contents, skip */
}
- nscript = html_process_new_script(c, HTML_STYLESHEET_INTERNAL);
+ nscript = html_process_new_script(c, HTML_SCRIPT_INLINE);
if (nscript == NULL) {
dom_string_unref(mimetype);
dom_string_unref(script);
@@ -308,7 +307,7 @@ exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
}
- nscript->data.internal = script;
+ nscript->data.string = script;
nscript->mimetype = mimetype;
nscript->already_started = true;
@@ -328,7 +327,7 @@ exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
}
-/**
+/**
* process script node parser callback
*
*
@@ -354,7 +353,7 @@ html_process_script(void *ctx, dom_node *node)
}
}
- LOG(("content %p parser %p node %p",c,c->parser, node));
+ LOG(("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) {
@@ -371,3 +370,27 @@ html_process_script(void *ctx, dom_node *node)
return err;
}
+
+void html_free_scripts(html_content *html)
+{
+ unsigned int i;
+
+ for (i = 0; i != html->scripts_count; i++) {
+ if (html->scripts[i].mimetype != NULL) {
+ dom_string_unref(html->scripts[i].mimetype);
+ }
+
+ if ((html->scripts[i].type == HTML_SCRIPT_INLINE) &&
+ (html->scripts[i].data.string != NULL)) {
+
+ dom_string_unref(html->scripts[i].data.string);
+
+ } else if ((html->scripts[i].type == HTML_SCRIPT_SYNC) &&
+ (html->scripts[i].data.handle != NULL)) {
+
+ hlcache_handle_release(html->scripts[i].data.handle);
+
+ }
+ }
+ free(html->scripts);
+}
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/e490ccc88dc3e48f35d...
commit e490ccc88dc3e48f35ddd014b6a02c5fefd18e04
Author: Vincent Sanders <vince(a)netsurf-browser.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
split up the script processing
diff --git a/render/html_script.c b/render/html_script.c
index 5fd8c8a..fb51256 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -144,11 +144,11 @@ html_process_new_script(html_content *c, enum html_script_type type)
}
/**
- * Callback for fetchcache() for linked stylesheets.
+ * Callback for asyncronous scripts
*/
static nserror
-html_convert_script_callback(hlcache_handle *script,
+convert_script_async_cb(hlcache_handle *script,
const hlcache_event *event,
void *pw)
{
@@ -213,7 +213,123 @@ html_convert_script_callback(hlcache_handle *script,
return NSERROR_OK;
}
-/** process script node
+/**
+ * process a script with a src tag
+ */
+static dom_hubbub_error
+exec_src_script(html_content *c,
+ dom_node *node,
+ dom_string *mimetype,
+ dom_string *src)
+{
+ nserror ns_error;
+ nsurl *joined;
+ hlcache_child_context child;
+ struct html_script *nscript;
+ union content_msg_data msg_data;
+
+ //exc = dom_element_has_attribute(node, html_dom_string_async, &async);
+
+ nscript = html_process_new_script(c, HTML_STYLESHEET_EXTERNAL);
+ if (nscript == NULL) {
+ dom_string_unref(mimetype);
+ goto html_process_script_no_memory;
+ }
+
+ /* charset (encoding) */
+ ns_error = nsurl_join(c->base_url, dom_string_data(src), &joined);
+ if (ns_error != NSERROR_OK) {
+ dom_string_unref(mimetype);
+ goto html_process_script_no_memory;
+ }
+
+ nscript->mimetype = mimetype; /* keep reference to mimetype */
+
+ LOG(("script %i '%s'", c->scripts_count, nsurl_access(joined)));
+
+ child.charset = c->encoding;
+ child.quirks = c->base.quirks;
+
+ ns_error = hlcache_handle_retrieve(joined,
+ 0,
+ content_get_url(&c->base),
+ NULL,
+ convert_script_async_cb,
+ c,
+ &child,
+ CONTENT_SCRIPT,
+ &nscript->data.external);
+
+ nsurl_unref(joined);
+
+ if (ns_error != NSERROR_OK) {
+ goto html_process_script_no_memory;
+ }
+
+ c->base.active++; /* ensure base content knows the fetch is active */
+ LOG(("%d fetches active", c->base.active));
+
+ html_scripts_exec(c);
+
+ return DOM_HUBBUB_OK;
+
+
+html_process_script_no_memory:
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return DOM_HUBBUB_NOMEM;
+}
+
+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;
+ script_handler_t *script_handler;
+ struct html_script *nscript;
+
+ /* does not appear to be a src so script is inline content */
+ exc = dom_node_get_text_content(node, &script);
+ if ((exc != DOM_NO_ERR) || (script == NULL)) {
+ dom_string_unref(mimetype);
+ return DOM_HUBBUB_OK; /* no contents, skip */
+ }
+
+ nscript = html_process_new_script(c, HTML_STYLESHEET_INTERNAL);
+ if (nscript == NULL) {
+ dom_string_unref(mimetype);
+ dom_string_unref(script);
+
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return DOM_HUBBUB_NOMEM;
+
+ }
+
+ nscript->data.internal = script;
+ nscript->mimetype = mimetype;
+ nscript->already_started = true;
+
+ /* charset (encoding) */
+
+ /* ensure script handler for content type */
+ dom_string_intern(mimetype, &lwcmimetype);
+ script_handler = select_script_handler(content_factory_type_from_mime_type(lwcmimetype));
+ lwc_string_unref(lwcmimetype);
+
+ if (script_handler != NULL) {
+ script_handler(c->jscontext,
+ dom_string_data(script),
+ dom_string_byte_length(script));
+ }
+ return DOM_HUBBUB_OK;
+}
+
+
+/**
+ * process script node parser callback
*
*
*/
@@ -222,9 +338,8 @@ html_process_script(void *ctx, dom_node *node)
{
html_content *c = (html_content *)ctx;
dom_exception exc; /* returned by libdom functions */
- dom_string *src, *script, *mimetype;
- struct html_script *nscript;
- union content_msg_data msg_data;
+ dom_string *src, *mimetype;
+ dom_hubbub_error err = DOM_HUBBUB_OK;
/* ensure javascript context is available */
if (c->jscontext == NULL) {
@@ -248,97 +363,11 @@ html_process_script(void *ctx, dom_node *node)
exc = dom_element_get_attribute(node, corestring_dom_src, &src);
if (exc != DOM_NO_ERR || src == NULL) {
- struct lwc_string_s *lwcmimetype;
- script_handler_t *script_handler;
-
- /* does not appear to be a src so script is inline content */
- exc = dom_node_get_text_content(node, &script);
- if ((exc != DOM_NO_ERR) || (script == NULL)) {
- dom_string_unref(mimetype);
- return DOM_HUBBUB_OK; /* no contents, skip */
- }
-
- nscript = html_process_new_script(c, HTML_STYLESHEET_INTERNAL);
- if (nscript == NULL) {
- dom_string_unref(mimetype);
- dom_string_unref(script);
- goto html_process_script_no_memory;
- }
-
- nscript->data.internal = script;
- nscript->mimetype = mimetype;
- nscript->already_started = true;
-
- /* charset (encoding) */
-
- /* ensure script handler for content type */
- dom_string_intern(mimetype, &lwcmimetype);
- script_handler = select_script_handler(content_factory_type_from_mime_type(lwcmimetype));
- lwc_string_unref(lwcmimetype);
-
- if (script_handler != NULL) {
- script_handler(c->jscontext,
- dom_string_data(script),
- dom_string_byte_length(script));
- }
-
-
+ err = exec_inline_script(c, node, mimetype);
} else {
- /* script with a src tag */
- nserror ns_error;
- nsurl *joined;
- hlcache_child_context child;
-
-
- nscript = html_process_new_script(c, HTML_STYLESHEET_EXTERNAL);
- if (nscript == NULL) {
- dom_string_unref(src);
- dom_string_unref(mimetype);
- goto html_process_script_no_memory;
- }
-
- /* charset (encoding) */
-
- ns_error = nsurl_join(c->base_url, dom_string_data(src), &joined);
+ err = exec_src_script(c, node, mimetype, src);
dom_string_unref(src);
- if (ns_error != NSERROR_OK) {
- dom_string_unref(mimetype);
- goto html_process_script_no_memory;
- }
-
- nscript->mimetype = mimetype; /* keep reference to mimetype */
-
- LOG(("script %i '%s'", c->scripts_count, nsurl_access(joined)));
-
- child.charset = c->encoding;
- child.quirks = c->base.quirks;
-
- ns_error = hlcache_handle_retrieve(joined,
- 0,
- content_get_url(&c->base),
- NULL,
- html_convert_script_callback,
- c,
- &child,
- CONTENT_SCRIPT,
- &nscript->data.external);
-
- nsurl_unref(joined);
-
- if (ns_error != NSERROR_OK) {
- goto html_process_script_no_memory;
- }
-
- c->base.active++; /* ensure base content knows the fetch is active */
- LOG(("%d fetches active", c->base.active));
-
}
- html_scripts_exec(c);
-
- return DOM_HUBBUB_OK;
-html_process_script_no_memory:
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
- return DOM_HUBBUB_NOMEM;
+ return err;
}
-----------------------------------------------------------------------
--
NetSurf Browser
10 years, 6 months
libdom: branch chris/amiga-hubbub-lib-compat updated. a86f8f40dd3153346c9d4e96f65d71da1573a783
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libdom.git/shortlog/a86f8f40dd3153346c9d4e...
...commit http://git.netsurf-browser.org/libdom.git/commit/a86f8f40dd3153346c9d4e96...
...tree http://git.netsurf-browser.org/libdom.git/tree/a86f8f40dd3153346c9d4e96f6...
The branch, chris/amiga-hubbub-lib-compat has been updated
via a86f8f40dd3153346c9d4e96f65d71da1573a783 (commit)
via 3193d4f4daa362f83a4b45c0e4a3e5e3539c9663 (commit)
via 387ad01f061d415bbc24e4ba546e660ae33ff01a (commit)
via af0e4892995a00aa35f7c288bfba45bdd507dc4c (commit)
via 8bef33b1005ea97359a71786a84912c42edf97bb (commit)
from d316c5d1a09406b63cc5b5754726007882e6360d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libdom.git/commitdiff/a86f8f40dd3153346c9d...
commit a86f8f40dd3153346c9d4e96f65d71da1573a783
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
test
diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c
index 9bbf131..a64b640 100644
--- a/bindings/hubbub/parser.c
+++ b/bindings/hubbub/parser.c
@@ -658,7 +658,7 @@ static hubbub_tree_handler tree_handler = {
add_attributes,
set_quirks_mode,
change_encoding,
- NULL,
+ NULL, /* test */
complete_script
};
-----------------------------------------------------------------------
Summary of changes:
bindings/hubbub/parser.c | 23 ++++++++++++++++++++++-
bindings/hubbub/parser.h | 10 ++++++++++
2 files changed, 32 insertions(+), 1 deletions(-)
diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c
index cc98335..a64b640 100644
--- a/bindings/hubbub/parser.c
+++ b/bindings/hubbub/parser.c
@@ -658,7 +658,7 @@ static hubbub_tree_handler tree_handler = {
add_attributes,
set_quirks_mode,
change_encoding,
- NULL,
+ NULL, /* test */
complete_script
};
@@ -911,3 +911,24 @@ const char *dom_hubbub_parser_get_encoding(dom_hubbub_parser *parser,
return parser->encoding != NULL ? parser->encoding
: "Windows-1252";
}
+
+/**
+ * Set the Parse pause state.
+ *
+ * \param parser The parser object
+ * \param pause The pause state to set.
+ * \return DOM_HUBBUB_OK on success,
+ * DOM_HUBBUB_HUBBUB_ERR | <hubbub_error> on failure
+ */
+dom_hubbub_error dom_hubbub_parser_pause(dom_hubbub_parser *parser, bool pause)
+{
+ hubbub_error err;
+ hubbub_parser_optparams params;
+
+ params.pause_parse = pause;
+ err = hubbub_parser_setopt(parser->parser, HUBBUB_PARSER_PAUSE, ¶ms);
+ if (err != HUBBUB_OK)
+ return DOM_HUBBUB_HUBBUB_ERR | err;
+
+ return DOM_HUBBUB_OK;
+}
diff --git a/bindings/hubbub/parser.h b/bindings/hubbub/parser.h
index 7af0dd0..16b02a8 100644
--- a/bindings/hubbub/parser.h
+++ b/bindings/hubbub/parser.h
@@ -77,4 +77,14 @@ dom_document *dom_hubbub_parser_get_document(dom_hubbub_parser *parser);
const char *dom_hubbub_parser_get_encoding(dom_hubbub_parser *parser,
dom_hubbub_encoding_source *source);
+/**
+ * Set the Parse pause state.
+ *
+ * \param parser The parser object
+ * \param pause The pause state to set.
+ * \return DOM_HUBBUB_OK on success,
+ * DOM_HUBBUB_HUBBUB_ERR | <hubbub_error> on failure
+ */
+dom_hubbub_error dom_hubbub_parser_pause(dom_hubbub_parser *parser, bool pause);
+
#endif
--
Document Object Model library
10 years, 6 months
libdom: branch master updated. aceae56f9efb6cbf82c399de3b6c360d3650d15c
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libdom.git/shortlog/aceae56f9efb6cbf82c399...
...commit http://git.netsurf-browser.org/libdom.git/commit/aceae56f9efb6cbf82c399de...
...tree http://git.netsurf-browser.org/libdom.git/tree/aceae56f9efb6cbf82c399de3b...
The branch, master has been updated
via aceae56f9efb6cbf82c399de3b6c360d3650d15c (commit)
from 3193d4f4daa362f83a4b45c0e4a3e5e3539c9663 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libdom.git/commitdiff/aceae56f9efb6cbf82c3...
commit aceae56f9efb6cbf82c399de3b6c360d3650d15c
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Fix master
diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c
index 9bbf131..6299da5 100644
--- a/bindings/hubbub/parser.c
+++ b/bindings/hubbub/parser.c
@@ -658,8 +658,8 @@ static hubbub_tree_handler tree_handler = {
add_attributes,
set_quirks_mode,
change_encoding,
- NULL,
- complete_script
+ complete_script,
+ NULL
};
/**
-----------------------------------------------------------------------
Summary of changes:
bindings/hubbub/parser.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c
index 9bbf131..6299da5 100644
--- a/bindings/hubbub/parser.c
+++ b/bindings/hubbub/parser.c
@@ -658,8 +658,8 @@ static hubbub_tree_handler tree_handler = {
add_attributes,
set_quirks_mode,
change_encoding,
- NULL,
- complete_script
+ complete_script,
+ NULL
};
/**
--
Document Object Model library
10 years, 6 months
libdom: branch master updated. 3193d4f4daa362f83a4b45c0e4a3e5e3539c9663
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libdom.git/shortlog/3193d4f4daa362f83a4b45...
...commit http://git.netsurf-browser.org/libdom.git/commit/3193d4f4daa362f83a4b45c0...
...tree http://git.netsurf-browser.org/libdom.git/tree/3193d4f4daa362f83a4b45c0e4...
The branch, master has been updated
via 3193d4f4daa362f83a4b45c0e4a3e5e3539c9663 (commit)
from 387ad01f061d415bbc24e4ba546e660ae33ff01a (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libdom.git/commitdiff/3193d4f4daa362f83a4b...
commit 3193d4f4daa362f83a4b45c0e4a3e5e3539c9663
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Change back for branch only
diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c
index 6299da5..9bbf131 100644
--- a/bindings/hubbub/parser.c
+++ b/bindings/hubbub/parser.c
@@ -658,8 +658,8 @@ static hubbub_tree_handler tree_handler = {
add_attributes,
set_quirks_mode,
change_encoding,
- complete_script,
- NULL
+ NULL,
+ complete_script
};
/**
-----------------------------------------------------------------------
Summary of changes:
bindings/hubbub/parser.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c
index 6299da5..9bbf131 100644
--- a/bindings/hubbub/parser.c
+++ b/bindings/hubbub/parser.c
@@ -658,8 +658,8 @@ static hubbub_tree_handler tree_handler = {
add_attributes,
set_quirks_mode,
change_encoding,
- complete_script,
- NULL
+ NULL,
+ complete_script
};
/**
--
Document Object Model library
10 years, 6 months
libdom: branch master updated. 387ad01f061d415bbc24e4ba546e660ae33ff01a
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libdom.git/shortlog/387ad01f061d415bbc24e4...
...commit http://git.netsurf-browser.org/libdom.git/commit/387ad01f061d415bbc24e4ba...
...tree http://git.netsurf-browser.org/libdom.git/tree/387ad01f061d415bbc24e4ba54...
The branch, master has been updated
via 387ad01f061d415bbc24e4ba546e660ae33ff01a (commit)
from af0e4892995a00aa35f7c288bfba45bdd507dc4c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libdom.git/commitdiff/387ad01f061d415bbc24...
commit 387ad01f061d415bbc24e4ba546e660ae33ff01a
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Resynchronise hubbub binding with master
diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c
index 9bbf131..6299da5 100644
--- a/bindings/hubbub/parser.c
+++ b/bindings/hubbub/parser.c
@@ -658,8 +658,8 @@ static hubbub_tree_handler tree_handler = {
add_attributes,
set_quirks_mode,
change_encoding,
- NULL,
- complete_script
+ complete_script,
+ NULL
};
/**
-----------------------------------------------------------------------
Summary of changes:
bindings/hubbub/parser.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c
index 9bbf131..6299da5 100644
--- a/bindings/hubbub/parser.c
+++ b/bindings/hubbub/parser.c
@@ -658,8 +658,8 @@ static hubbub_tree_handler tree_handler = {
add_attributes,
set_quirks_mode,
change_encoding,
- NULL,
- complete_script
+ complete_script,
+ NULL
};
/**
--
Document Object Model library
10 years, 6 months