netsurf: branch master updated. fb13fcf16648a0e5ba71ac64f9c0441f0516004a

NetSurf Browser Project (Commit Mailer) no-reply at netsurf-browser.org
Mon Nov 26 19:05:07 GMT 2012


Gitweb links:

...log http://git.netsurf-browser.org/netsurf.git/shortlog/fb13fcf16648a0e5ba71ac64f9c0441f0516004a
...commit http://git.netsurf-browser.org/netsurf.git/commit/fb13fcf16648a0e5ba71ac64f9c0441f0516004a
...tree http://git.netsurf-browser.org/netsurf.git/tree/fb13fcf16648a0e5ba71ac64f9c0441f0516004a

The branch, master has been updated
       via  fb13fcf16648a0e5ba71ac64f9c0441f0516004a (commit)
       via  ce309aa5a9c1f813f6bdf152221f9bff88c4d3e1 (commit)
       via  2fef76db1555f49cff7f2baeec7fa084c8a5facb (commit)
      from  840284b24d1a03c14592dd907894b136a37c495c (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/netsurf.git/commitdiff/fb13fcf16648a0e5ba71ac64f9c0441f0516004a
commit fb13fcf16648a0e5ba71ac64f9c0441f0516004a
Author: Vincent Sanders <vince at netsurf-browser.org>
Commit: Vincent Sanders <vince at netsurf-browser.org>

    Improve html renderer error reporting

diff --git a/render/box.h b/render/box.h
index 6b1d28d..a4622e3 100644
--- a/render/box.h
+++ b/render/box.h
@@ -339,7 +339,7 @@ bool box_hscrollbar_present(const struct box *box);
 
 nserror box_construct_init(void);
 void box_construct_fini(void);
-bool xml_to_box(struct dom_node *n, struct html_content *c, 
+nserror dom_to_box(struct dom_node *n, struct html_content *c,
 		box_construct_complete_cb cb);
 
 bool box_normalise_block(struct box *block, struct html_content *c);
diff --git a/render/box_construct.c b/render/box_construct.c
index 26d9b54..6357587 100644
--- a/render/box_construct.c
+++ b/render/box_construct.c
@@ -157,10 +157,10 @@ static const struct element_entry element_table[] = {
  * \param n   xml tree
  * \param c   content of type CONTENT_HTML to construct box tree in
  * \param cb  callback to report conversion completion
- * \return  true on success, false on memory exhaustion
+ * \return    netsurf error code indicating status of call
  */
 
-bool xml_to_box(dom_node *n, html_content *c, box_construct_complete_cb cb)
+nserror dom_to_box(dom_node *n, html_content *c, box_construct_complete_cb cb)
 {
 	struct box_construct_ctx *ctx;
 
@@ -168,13 +168,14 @@ bool xml_to_box(dom_node *n, html_content *c, box_construct_complete_cb cb)
 		/* create a context allocation for this box tree */
 		c->bctx = talloc_zero(0, int);
 		if (c->bctx == NULL) {
-			return false;
+			return NSERROR_NOMEM;
 		}
 	}
 
 	ctx = malloc(sizeof(*ctx));
-	if (ctx == NULL)
-		return false;
+	if (ctx == NULL) {
+		return NSERROR_NOMEM;
+	}
 
 	ctx->content = c;
 	ctx->n = dom_node_ref(n);
@@ -184,7 +185,7 @@ bool xml_to_box(dom_node *n, html_content *c, box_construct_complete_cb cb)
 
 	schedule(0, (schedule_callback_fn) convert_xml_to_box, ctx);
 
-	return true;
+	return NSERROR_OK;
 }
 
 /* mapping from CSS display to box type
diff --git a/render/html.c b/render/html.c
index 6c6dcdf..b5896e1 100644
--- a/render/html.c
+++ b/render/html.c
@@ -78,6 +78,93 @@ static nsurl *html_adblock_stylesheet_url;
 static nsurl *html_quirks_stylesheet_url;
 static nsurl *html_user_stylesheet_url;
 
+static nserror css_error_to_nserror(css_error error)
+{
+	switch (error) {
+	case CSS_OK:
+		return NSERROR_OK;
+
+	case CSS_NOMEM:
+		return NSERROR_NOMEM;
+
+	case CSS_BADPARM:
+		return NSERROR_BAD_PARAMETER;
+
+	case CSS_INVALID:
+		return NSERROR_INVALID;
+
+	case CSS_FILENOTFOUND:
+		return NSERROR_NOT_FOUND;
+
+	case CSS_NEEDDATA:
+		return NSERROR_NEED_DATA;
+
+	case CSS_BADCHARSET:
+		return NSERROR_BAD_ENCODING;
+
+	case CSS_EOF:
+	case CSS_IMPORTS_PENDING:
+	case CSS_PROPERTY_NOT_SET:
+	default:
+		break;
+	}
+	return NSERROR_CSS;
+}
+
+static nserror
+dom_hubbub_error_to_nserror(dom_hubbub_error error)
+{
+	switch (error) {
+
+	/* HUBBUB_REPROCESS is not handled here because it can
+	 * never occur outside the hubbub treebuilder
+	 */
+
+	case DOM_HUBBUB_OK: 
+		/* parsed ok */
+		return NSERROR_OK;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED): 
+		/* hubbub input paused */
+		return NSERROR_OK;
+
+	case DOM_HUBBUB_NOMEM:
+		/* out of memory error from DOM */
+		return NSERROR_NOMEM;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE):
+		/* encoding changed */
+		return NSERROR_ENCODING_CHANGE;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_NOMEM):
+		/* out of memory error from parser */
+		return NSERROR_NOMEM;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_BADPARM):
+		return NSERROR_BAD_PARAMETER;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_INVALID):
+		return NSERROR_INVALID;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_FILENOTFOUND):
+		return NSERROR_NOT_FOUND;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_NEEDDATA):
+		return NSERROR_NEED_DATA;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_BADENCODING):
+		return NSERROR_BAD_ENCODING;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_UNKNOWN):
+		/* currently only generated by the libdom hubbub binding */
+		return NSERROR_DOM;
+	default:
+		/* unknown error */
+		/** @todo better error handling and reporting */
+		return NSERROR_UNKNOWN;
+	}
+	return NSERROR_UNKNOWN;
+}
 
 static void html_destroy_objects(html_content *html)
 {
@@ -106,7 +193,7 @@ static void html_destroy_objects(html_content *html)
  */
 static void html_box_convert_done(html_content *c, bool success)
 {
-	union content_msg_data msg_data;
+	nserror err;
 	dom_exception exc; /* returned by libdom functions */
 	dom_node *html;
 
@@ -114,17 +201,19 @@ static void html_box_convert_done(html_content *c, bool success)
 
 	/* Clean up and report error if unsuccessful or aborted */
 	if ((success == false) || (c->aborted)) {
+		html_destroy_objects(c);
+
 		if (success == false) {
-			msg_data.errorcode = NSERROR_BOX_CONVERT;
+			content_broadcast_errorcode(&c->base, NSERROR_BOX_CONVERT);
 		} else {
-			msg_data.errorcode = NSERROR_STOPPED;
+			content_broadcast_errorcode(&c->base, NSERROR_STOPPED);
 		}
-		html_destroy_objects(c);
-		content_broadcast(&c->base, CONTENT_MSG_ERRORCODE, msg_data);
+
 		content_set_error(&c->base);
 		return;
 	}
 
+
 #if ALWAYS_DUMP_BOX
 	box_dump(stderr, c->layout->children, 0);
 #endif
@@ -139,18 +228,17 @@ static void html_box_convert_done(html_content *c, bool success)
 		 * like the other error paths 
 		 */
 		LOG(("error retrieving html element from dom"));
-		msg_data.errorcode = NSERROR_DOM;
-		content_broadcast(&c->base, CONTENT_MSG_ERRORCODE, msg_data);
+		content_broadcast_errorcode(&c->base, NSERROR_DOM);
 		content_set_error(&c->base);
 		return;
 	}
 
-	/* extract image maps - can't do this sensibly in xml_to_box */
-	msg_data.errorcode = imagemap_extract(c);
-	if (msg_data.errorcode != NSERROR_OK) {
+	/* extract image maps - can't do this sensibly in dom_to_box */
+	err = imagemap_extract(c);
+	if (err != NSERROR_OK) {
 		LOG(("imagemap extraction failed"));
 		html_destroy_objects(c);
-		content_broadcast(&c->base, CONTENT_MSG_ERRORCODE, msg_data);
+		content_broadcast_errorcode(&c->base, err);
 		content_set_error(&c->base);
 		dom_node_unref(html);
 		return;
@@ -171,6 +259,7 @@ static void html_box_convert_done(html_content *c, bool success)
 	dom_node_unref(html);
 }
 
+
 /**
  * Complete conversion of an HTML document
  *
@@ -182,29 +271,28 @@ void html_finish_conversion(html_content *c)
 	dom_exception exc; /* returned by libdom functions */
 	dom_node *html;
 	uint32_t i;
-	css_error error;
+	css_error css_ret;
+	nserror error;
 
 	/* Bail out if we've been aborted */
 	if (c->aborted) {
-		msg_data.error = messages_get("Stopped");
-		content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+		content_broadcast_errorcode(&c->base, NSERROR_STOPPED);
 		content_set_error(&c->base);
 		return;
 	}
 
 	/* check that the base stylesheet loaded; layout fails without it */
 	if (c->stylesheets[STYLESHEET_BASE].data.external == NULL) {
-		msg_data.error = "Base stylesheet failed to load";
-		content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+		content_broadcast_errorcode(&c->base, NSERROR_CSS_BASE);
 		content_set_error(&c->base);
 		return;
 	}
 
 	/* Create selection context */
-	error = css_select_ctx_create(ns_realloc, c, &c->select_ctx);
-	if (error != CSS_OK) {
-		msg_data.error = messages_get("NoMemory");
-		content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+	css_ret = css_select_ctx_create(ns_realloc, c, &c->select_ctx);
+	if (css_ret != CSS_OK) {
+		content_broadcast_errorcode(&c->base,
+					    css_error_to_nserror(css_ret));
 		content_set_error(&c->base);
 		return;
 	}
@@ -230,21 +318,21 @@ void html_finish_conversion(html_content *c)
 		}
 
 		if (sheet != NULL) {
-			error = css_select_ctx_append_sheet(
-					c->select_ctx, sheet,
-					origin, CSS_MEDIA_SCREEN);
-			if (error != CSS_OK) {
-				msg_data.error = messages_get("NoMemory");
-				content_broadcast(&c->base, CONTENT_MSG_ERROR,
-						msg_data);
+			css_ret = css_select_ctx_append_sheet(c->select_ctx,
+							      sheet,
+							      origin,
+							      CSS_MEDIA_SCREEN);
+			if (css_ret != CSS_OK) {
+				content_broadcast_errorcode(&c->base,
+						css_error_to_nserror(css_ret));
 				content_set_error(&c->base);
 				return;
 			}
 		}
 	}
 
-	/* convert xml tree to box tree */
-	LOG(("XML to box (%p)", c));
+	/* convert dom tree to box tree */
+	LOG(("DOM to box (%p)", c));
 	content_set_status(&c->base, messages_get("Processing"));
 	msg_data.explicit_status_text = NULL;
 	content_broadcast(&c->base, CONTENT_MSG_STATUS, msg_data);
@@ -252,17 +340,16 @@ void html_finish_conversion(html_content *c)
 	exc = dom_document_get_document_element(c->document, (void *) &html);
 	if ((exc != DOM_NO_ERR) || (html == NULL)) {
 		LOG(("error retrieving html element from dom"));
-		msg_data.error = messages_get("ParsingFail");
-		content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+		content_broadcast_errorcode(&c->base, NSERROR_DOM);
 		content_set_error(&c->base);
 		return;
 	}
 
-	if (xml_to_box(html, c, html_box_convert_done) == false) {
+	error = dom_to_box(html, c, html_box_convert_done);
+	if (error != NSERROR_OK) {
 		dom_node_unref(html);
 		html_destroy_objects(c);
-		msg_data.error = messages_get("NoMemory");
-		content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+		content_broadcast_errorcode(&c->base, error);
 		content_set_error(&c->base);
 		return;
 	}
@@ -276,7 +363,6 @@ static nserror
 html_create_html_data(html_content *c, const http_parameter *params)
 {
 	lwc_string *charset;
-	union content_msg_data msg_data;
 	nserror nerror;
 
 	c->parser = NULL;
@@ -310,9 +396,6 @@ html_create_html_data(html_content *c, const http_parameter *params)
 	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);
-
 		return NSERROR_NOMEM;
 	}
 
@@ -327,10 +410,6 @@ html_create_html_data(html_content *c, const http_parameter *params)
 		if (c->encoding == NULL) {
 			lwc_string_unref(c->universal);
 			c->universal = NULL;
-
-			msg_data.error = messages_get("NoMemory");
-			content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
-
 			return NSERROR_NOMEM;
 
 		}
@@ -367,9 +446,6 @@ html_create_html_data(html_content *c, const http_parameter *params)
 		lwc_string_unref(c->universal);
 		c->universal = NULL;
 
-		msg_data.error = messages_get("NoMemory");
-		content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
-
 		return NSERROR_NOMEM;
 	}
 
@@ -409,6 +485,7 @@ html_create(const content_handler *handler,
 
 	error = html_create_html_data(html, params);
 	if (error != NSERROR_OK) {
+		content_broadcast_errorcode(&html->base, error);
 		free(html);
 		return error;
 	}
@@ -418,60 +495,6 @@ html_create(const content_handler *handler,
 	return NSERROR_OK;
 }
 
-static nserror
-parse_chunk_to_nserror(dom_hubbub_error error)
-{
-	switch (error) {
-
-	/* HUBBUB_REPROCESS is not handled here because it can
-	 * never occur outside the hubbub treebuilder
-	 */
-
-	case DOM_HUBBUB_OK: 
-		/* parsed ok */
-		return NSERROR_OK;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED): 
-		/* hubbub input paused */
-		return NSERROR_OK;
-
-	case DOM_HUBBUB_NOMEM:
-		/* out of memory error from DOM */
-		return NSERROR_NOMEM;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE):
-		/* encoding changed */
-		return NSERROR_ENCODING_CHANGE;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_NOMEM):
-		/* out of memory error from parser */
-		return NSERROR_NOMEM;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_BADPARM):
-		return NSERROR_BAD_PARAMETER;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_INVALID):
-		return NSERROR_INVALID;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_FILENOTFOUND):
-		return NSERROR_NOT_FOUND;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_NEEDDATA):
-		return NSERROR_NEED_DATA;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_BADENCODING):
-		return NSERROR_BAD_ENCODING;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_UNKNOWN):
-		/* currently only generated by the libdom hubbub binding */
-		return NSERROR_DOM;
-	default:
-		/* unknown error */
-		/** @todo better error handling and reporting */
-		return NSERROR_UNKNOWN;
-	}
-	return NSERROR_UNKNOWN;
-}
 
 
 static nserror
@@ -554,7 +577,7 @@ html_process_encoding_change(struct content *c,
 					      (const uint8_t *)source_data, 
 					      source_size);
 
-	return parse_chunk_to_nserror(error);
+	return dom_hubbub_error_to_nserror(error);
 }
 
 
@@ -566,26 +589,23 @@ 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;
-
-	msg_data.errorcode = NSERROR_OK; /* assume its all going to be ok */
+	dom_hubbub_error dom_ret;
+	nserror err = NSERROR_OK; /* assume its all going to be ok */
 
-	error = dom_hubbub_parser_parse_chunk(html->parser, 
+	dom_ret = dom_hubbub_parser_parse_chunk(html->parser, 
 					      (const uint8_t *) data, 
 					      size);
 
-
-	msg_data.errorcode = parse_chunk_to_nserror(error);
+	err = dom_hubbub_error_to_nserror(dom_ret);
 
 	/* deal with encoding change */
-	if (msg_data.errorcode == NSERROR_ENCODING_CHANGE) {
-		 msg_data.errorcode = html_process_encoding_change(c, data, size);
+	if (err == NSERROR_ENCODING_CHANGE) {
+		 err = html_process_encoding_change(c, data, size);
 	}
 
 	/* broadcast the error if necessary */
-	if (msg_data.errorcode != NSERROR_OK) {
-		content_broadcast(c, CONTENT_MSG_ERRORCODE, msg_data);
+	if (err != NSERROR_OK) {
+		content_broadcast_errorcode(c, err);
 		return false;
 	}
 
@@ -776,7 +796,7 @@ static bool html_process_base(html_content *c, dom_node *node)
  * The title and base href are extracted if present.
  */
 
-static bool html_head(html_content *c, dom_node *head)
+static nserror html_head(html_content *c, dom_node *head)
 {
 	dom_node *node;
 	dom_exception exc; /* returned by libdom functions */
@@ -786,7 +806,7 @@ static bool html_head(html_content *c, dom_node *head)
 
 	exc = dom_node_get_first_child(head, &node);
 	if (exc != DOM_NO_ERR) {
-		return false;
+		return NSERROR_DOM;
 	}
 
 	while (node != NULL) {
@@ -810,8 +830,9 @@ static bool html_head(html_content *c, dom_node *head)
 					html_process_link(c, node);
 				}
 			}
-			if (node_name != NULL)
+			if (node_name != NULL) {
 				dom_string_unref(node_name);
+			}
 		}
 
 		/* move to next node */
@@ -824,10 +845,10 @@ static bool html_head(html_content *c, dom_node *head)
 		}
 	}
 
-	return true;
+	return NSERROR_OK;
 }
 
-static bool html_meta_refresh_process_element(html_content *c, dom_node *n)
+static nserror html_meta_refresh_process_element(html_content *c, dom_node *n)
 {
 	union content_msg_data msg_data;
 	const char *url, *end, *refresh = NULL;
@@ -836,28 +857,32 @@ static bool html_meta_refresh_process_element(html_content *c, dom_node *n)
 	dom_string *equiv, *content;
 	dom_exception exc;
 	nsurl *nsurl;
-	nserror error;
+	nserror error = NSERROR_OK;
 
 	exc = dom_element_get_attribute(n, corestring_dom_http_equiv, &equiv);
-	if (exc != DOM_NO_ERR)
-		return false;
+	if (exc != DOM_NO_ERR) {
+		return NSERROR_DOM;
+	}
 
-	if (equiv == NULL)
-		return true;
+	if (equiv == NULL) {
+		return NSERROR_OK;
+	}
 
 	if (!dom_string_caseless_lwc_isequal(equiv, corestring_lwc_refresh)) {
 		dom_string_unref(equiv);
-		return true;
+		return NSERROR_OK;
 	}
 
 	dom_string_unref(equiv);
 
 	exc = dom_element_get_attribute(n, corestring_dom_content, &content);
-	if (exc != DOM_NO_ERR)
-		return false;
+	if (exc != DOM_NO_ERR) {
+		return NSERROR_DOM;
+	}
 
-	if (content == NULL)
-		return true;
+	if (content == NULL) {
+		return NSERROR_OK;
+	}
 
 	end = dom_string_data(content) + dom_string_byte_length(content);
 
@@ -883,15 +908,16 @@ static bool html_meta_refresh_process_element(html_content *c, dom_node *n)
 	if (url == end || (*url < '0' || '9' < *url)) {
 		/* Empty content, or invalid timeval */
 		dom_string_unref(content);
-		return true;
+		return NSERROR_OK;
 	}
 
 	msg_data.delay = (int) strtol(url, &new_url, 10);
 	/* a very small delay and self-referencing URL can cause a loop
 	 * that grinds machines to a halt. To prevent this we set a
 	 * minimum refresh delay of 1s. */
-	if (msg_data.delay < 1)
+	if (msg_data.delay < 1) {
 		msg_data.delay = 1;
+	}
 
 	url = new_url;
 
@@ -922,9 +948,9 @@ static bool html_meta_refresh_process_element(html_content *c, dom_node *n)
 		c->base.refresh = nsurl_ref(
 				content_get_url(&c->base));
 
-		content_broadcast(&c->base, CONTENT_MSG_REFRESH,
-				msg_data);
-		return true;
+		content_broadcast(&c->base, CONTENT_MSG_REFRESH, msg_data);
+
+		return NSERROR_OK;
 	}
 
 	/* "url" */
@@ -934,12 +960,12 @@ static bool html_meta_refresh_process_element(html_content *c, dom_node *n)
 		} else {
 			/* Unexpected input, ignore this header */
 			dom_string_unref(content);
-			return true;
+			return NSERROR_OK;
 		}
 	} else {
 		/* Insufficient input, ignore this header */
 		dom_string_unref(content);
-		return true;
+		return NSERROR_OK;
 	}
 
 	/* *LWS */
@@ -954,12 +980,12 @@ static bool html_meta_refresh_process_element(html_content *c, dom_node *n)
 		} else {
 			/* Unexpected input, ignore this header */
 			dom_string_unref(content);
-			return true;
+			return NSERROR_OK;
 		}
 	} else {
 		/* Insufficient input, ignore this header */
 		dom_string_unref(content);
-		return true;
+		return NSERROR_OK;
 	}
 
 	/* *LWS */
@@ -992,32 +1018,25 @@ static bool html_meta_refresh_process_element(html_content *c, dom_node *n)
 		new_url = strndup(refresh, url - refresh);
 		if (new_url == NULL) {
 			dom_string_unref(content);
-			return false;
+			return NSERROR_NOMEM;
 		}
 
 		error = nsurl_join(c->base_url, new_url, &nsurl);
-		if (error != NSERROR_OK) {
-			free(new_url);
-
-			dom_string_unref(content);
+		if (error == NSERROR_OK) {
+			/* broadcast valid refresh url */
 
-			msg_data.error = messages_get("NoMemory");
-			content_broadcast(&c->base, CONTENT_MSG_ERROR,
-					msg_data);
+			c->base.refresh = nsurl;
 
-			return false;
+			content_broadcast(&c->base, CONTENT_MSG_REFRESH, msg_data);
 		}
 
 		free(new_url);
 
-		c->base.refresh = nsurl;
-
-		content_broadcast(&c->base, CONTENT_MSG_REFRESH, msg_data);
 	}
 
 	dom_string_unref(content);
 
-	return true;
+	return error;
 }
 
 /**
@@ -1556,7 +1575,6 @@ html_process_style_element(html_content *c,
 	dom_node *child, *next;
 	dom_string *val;
 	dom_exception exc;
-	union content_msg_data msg_data;
 	struct html_stylesheet *stylesheets;
 	struct content_css_data *sheet;
 	nserror error;
@@ -1609,7 +1627,8 @@ html_process_style_element(html_content *c,
 	if (error != NSERROR_OK) {
 		free(sheet);
 		c->stylesheet_count--;
-		goto no_memory;
+		content_broadcast_errorcode(&c->base, error);
+		return false;
 	}
 
 	/* can't just use xmlNodeGetContent(style), because that won't
@@ -1680,8 +1699,7 @@ html_process_style_element(html_content *c,
 	return true;
 
 no_memory:
-	msg_data.error = messages_get("NoMemory");
-	content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+	content_broadcast_errorcode(&c->base, NSERROR_NOMEM);
 	return false;
 }
 
@@ -1701,7 +1719,6 @@ html_process_stylesheet(dom_node *node, dom_string *name, void *vctx)
 	dom_string *rel, *type_attr, *media, *href;
 	struct html_stylesheet *stylesheets;
 	nsurl *joined;
-	union content_msg_data msg_data;
 	dom_exception exc;
 	nserror ns_error;
 	hlcache_child_context child;
@@ -1779,6 +1796,7 @@ html_process_stylesheet(dom_node *node, dom_string *name, void *vctx)
 			      sizeof(struct html_stylesheet) * (ctx->count + 1));
 	if (stylesheets == NULL) {
 		nsurl_unref(joined);
+		ns_error = NSERROR_NOMEM;
 		goto no_memory;
 	}
 
@@ -1812,10 +1830,8 @@ html_process_stylesheet(dom_node *node, dom_string *name, void *vctx)
 	return true;
 
 no_memory:
-	msg_data.error = messages_get("NoMemory");
-	content_broadcast(&ctx->c->base, CONTENT_MSG_ERROR, msg_data);
+	content_broadcast_errorcode(&ctx->c->base, ns_error);
 	return false;
-
 }
 
 
@@ -1831,7 +1847,6 @@ no_memory:
 
 static bool html_find_stylesheets(html_content *c, dom_node *html)
 {
-	union content_msg_data msg_data;
 	nserror ns_error;
 	bool result;
 	struct find_stylesheet_ctx ctx;
@@ -1847,6 +1862,7 @@ static bool html_find_stylesheets(html_content *c, dom_node *html)
 	 * stylesheet 3 is the user stylesheet */
 	c->stylesheets = calloc(STYLESHEET_START, sizeof(struct html_stylesheet));
 	if (c->stylesheets == NULL) {
+		ns_error = NSERROR_NOMEM;
 		goto html_find_stylesheets_no_memory;
 	}
 
@@ -1911,7 +1927,6 @@ static bool html_find_stylesheets(html_content *c, dom_node *html)
 	c->base.active++;
 	LOG(("%d fetches active", c->base.active));
 
-
 	result = libdom_treewalk(html, html_process_stylesheet, &ctx);
 
 	assert(c->stylesheet_count == ctx.count);
@@ -1919,8 +1934,7 @@ static bool html_find_stylesheets(html_content *c, dom_node *html)
 	return result;
 
 html_find_stylesheets_no_memory:
-	msg_data.error = messages_get("NoMemory");
-	content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+	content_broadcast_errorcode(&c->base, ns_error);
 	return false;
 }
 
@@ -1945,7 +1959,6 @@ static bool html_convert(struct content *c)
 	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.
 	 */ 
@@ -1953,14 +1966,13 @@ static bool html_convert(struct content *c)
 		return html_begin_conversion(htmlc);
 	}
 	return true;
-
 }
 
 bool
 html_begin_conversion(html_content *htmlc)
 {
 	dom_node *html, *head;
-	union content_msg_data msg_data;
+	nserror ns_error;
 	struct form *f;
 	dom_exception exc; /* returned by libdom functions */
 	dom_string *node_name = NULL;
@@ -1969,19 +1981,28 @@ html_begin_conversion(html_content *htmlc)
 	/* 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 */
 		LOG(("Parsing failed"));
-		msg_data.error = messages_get("ParsingFail");
-		content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
 
+		content_broadcast_errorcode(&htmlc->base, 
+					    dom_hubbub_error_to_nserror(error));
+
+		return false;
+	}
+
+	/* Give up processing if we've been aborted */
+	if (htmlc->aborted) {
+		content_broadcast_errorcode(&htmlc->base, NSERROR_STOPPED);
 		return false;
 	}
 
+
 	/* complete script execution */
 	html_scripts_exec(htmlc);
 
+	/* fire a simple event that bubbles named DOMContentLoaded at
+	 * the Document.
+	 */
+
 	/* quirks mode */
 	exc = dom_document_get_quirks_mode(htmlc->document, &htmlc->quirks);
 	if (exc != DOM_NO_ERR) {
@@ -1997,32 +2018,24 @@ html_begin_conversion(html_content *htmlc)
 		encoding = dom_hubbub_parser_get_encoding(htmlc->parser,
 					&htmlc->encoding_source);
 		if (encoding == NULL) {
-			msg_data.error = messages_get("NoMemory");
-			content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
+			content_broadcast_errorcode(&htmlc->base, 
+						    NSERROR_NOMEM);
 			return false;
 		}
 
 		htmlc->encoding = strdup(encoding);
 		if (htmlc->encoding == NULL) {
-			msg_data.error = messages_get("NoMemory");
-			content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
+			content_broadcast_errorcode(&htmlc->base, 
+						    NSERROR_NOMEM);
 			return false;
 		}
 	}
 
-	/* Give up processing if we've been aborted */
-	if (htmlc->aborted) {
-		msg_data.error = messages_get("Stopped");
-		content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
-		return false;
-	}
-
 	/* locate root element and ensure it is html */
 	exc = dom_document_get_document_element(htmlc->document, (void *) &html);
 	if ((exc != DOM_NO_ERR) || (html == NULL)) {
 		LOG(("error retrieving html element from dom"));
-		msg_data.error = messages_get("ParsingFail");
-		content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
+		content_broadcast_errorcode(&htmlc->base, NSERROR_DOM);
 		return false;
 	}
 
@@ -2032,8 +2045,7 @@ html_begin_conversion(html_content *htmlc)
 	    (!dom_string_caseless_lwc_isequal(node_name,
 	    		corestring_lwc_html))) {
 		LOG(("root element not html"));
-		msg_data.error = messages_get("ParsingFail");
-		content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
+		content_broadcast_errorcode(&htmlc->base, NSERROR_DOM);
 		dom_node_unref(html);
 		return false;
 	}
@@ -2041,16 +2053,20 @@ html_begin_conversion(html_content *htmlc)
 
 	head = libdom_find_first_element(html, corestring_lwc_head);
 	if (head != NULL) {
-		if (html_head(htmlc, head) == false) {
-			msg_data.error = messages_get("NoMemory");
-			content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
+		ns_error = html_head(htmlc, head);
+		if (ns_error != NSERROR_OK) {
+			content_broadcast_errorcode(&htmlc->base, ns_error);
+
 			dom_node_unref(html);
 			dom_node_unref(head);
 			return false;
 		}
 
 		/* handle meta refresh */
-		if (html_meta_refresh(htmlc, head) == false) {
+		ns_error = html_meta_refresh(htmlc, head);
+		if (ns_error != NSERROR_OK) {
+			content_broadcast_errorcode(&htmlc->base, ns_error);
+
 			dom_node_unref(html);
 			dom_node_unref(head);
 			return false;
@@ -2062,21 +2078,23 @@ html_begin_conversion(html_content *htmlc)
 			(dom_html_document *) htmlc->document);
 	for (f = htmlc->forms; f != NULL; f = f->prev) {
 		nsurl *action;
-		nserror res;
 
 		/* Make all actions absolute */
 		if (f->action == NULL || f->action[0] == '\0') {
 			/* HTML5 4.10.22.3 step 9 */
 			nsurl *doc_addr = content_get_url(&htmlc->base);
-			res = nsurl_join(htmlc->base_url,
-					nsurl_access(doc_addr), &action);
+			ns_error = nsurl_join(htmlc->base_url,
+					      nsurl_access(doc_addr), 
+					      &action);
 		} else {
-			res = nsurl_join(htmlc->base_url, f->action, &action);
+			ns_error = nsurl_join(htmlc->base_url, 
+					      f->action, 
+					      &action);
 		}
 
-		if (res != NSERROR_OK) {
-			msg_data.error = messages_get("NoMemory");
-			content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
+		if (ns_error != NSERROR_OK) {
+			content_broadcast_errorcode(&htmlc->base, ns_error);
+
 			dom_node_unref(html);
 			dom_node_unref(head);
 			return false;
@@ -2086,8 +2104,9 @@ html_begin_conversion(html_content *htmlc)
 		f->action = strdup(nsurl_access(action));
 		nsurl_unref(action);
 		if (f->action == NULL) {
-			msg_data.error = messages_get("NoMemory");
-			content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
+			content_broadcast_errorcode(&htmlc->base, 
+						    NSERROR_NOMEM);
+
 			dom_node_unref(html);
 			dom_node_unref(head);
 			return false;
@@ -2097,10 +2116,8 @@ html_begin_conversion(html_content *htmlc)
 		if (f->document_charset == NULL) {
 			f->document_charset = strdup(htmlc->encoding);
 			if (f->document_charset == NULL) {
-				msg_data.error = messages_get("NoMemory");
-				content_broadcast(&htmlc->base, 
-						  CONTENT_MSG_ERROR,
-						  msg_data);
+				content_broadcast_errorcode(&htmlc->base, 
+							    NSERROR_NOMEM);
 				dom_node_unref(html);
 				dom_node_unref(head);
 				return false;


commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/ce309aa5a9c1f813f6bdf152221f9bff88c4d3e1
commit ce309aa5a9c1f813f6bdf152221f9bff88c4d3e1
Author: Vincent Sanders <vince at netsurf-browser.org>
Commit: Vincent Sanders <vince at netsurf-browser.org>

    add message retrival of error codes ensuring there are messages for all codes

diff --git a/desktop/browser.c b/desktop/browser.c
index 8948460..6262f24 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -1195,99 +1195,7 @@ browser_window_callback_errorcode(hlcache_handle *c,
 {
 	const char* message;
 
-	switch (code) {
-	case NSERROR_OK:
-		/**< No error */
-		message = messages_get("OK");
-		break;
-
-	case NSERROR_NOMEM:
-		/**< Memory exhaustion */
-		message = messages_get("NoMemory");
-		break;
-
-	case NSERROR_NO_FETCH_HANDLER:
-		/**< No fetch handler for URL scheme */
-		message = messages_get("NoHandler");
-		break;
-
-	case NSERROR_NOT_FOUND:
-		/**< Requested item not found */
-		message = messages_get("NotFound");
-		break;
-
-	case NSERROR_SAVE_FAILED:
-		/**< Failed to save data */
-		message = messages_get("SaveFailed");
-		break;
-
-	case NSERROR_CLONE_FAILED:
-		/**< Failed to clone handle */
-		message = messages_get("CloneFailed");
-		break;
-
-	case NSERROR_INIT_FAILED:
-		/**< Initialisation failed */
-		message = messages_get("InitFailed");
-		break;
-
-	case NSERROR_MNG_ERROR:
-		/**< An MNG error occurred */
-		message = messages_get("MNGError");
-		break;
-
-	case NSERROR_BAD_ENCODING:
-		/**< The character set is unknown */
-		message = messages_get("BadEncoding");
-		break;
-
-	case NSERROR_NEED_DATA:
-		/**< More data needed */
-		message = messages_get("NeedData");
-		break;
-
-	case NSERROR_ENCODING_CHANGE:
-		/**< The character set encoding change was unhandled */
-		message = messages_get("EncodingChanged");
-		break;
-
-	case NSERROR_BAD_PARAMETER:
-		/**< Bad Parameter */
-		message = messages_get("BadParameter");
-		break;
-
-	case NSERROR_INVALID:
-		/**< Invalid data */
-		message = messages_get("Invalid");
-		break;
-
-	case NSERROR_BOX_CONVERT:
-		/**< Box conversion failed */
-		message = messages_get("BoxConvert");
-		break;
-
-	case NSERROR_STOPPED:
-		/**< Content conversion stopped */
-		message = messages_get("Stopped");
-		break;
-
-	case NSERROR_DOM:
-		/**< DOM call returned error */
-		message = messages_get("ParsingFail");
-		break;
-
-	case NSERROR_BAD_URL:
-		/**< Bad URL */
-		message = messages_get("BadURL");
-		break;
-
-	default:
-	case NSERROR_UNKNOWN:
-		/**< Unknown error */
-		message = messages_get("Unknown");
-		break;
-
-	}
+	message = messages_get_errorcode(code);
 
 	browser_window_set_status(bw, message);
 
diff --git a/resources/FatMessages b/resources/FatMessages
index d54acad..45b3086 100644
--- a/resources/FatMessages
+++ b/resources/FatMessages
@@ -2787,6 +2787,8 @@ de.all.ParsingFail:Dokumentparsing ist fehlgeschlagen.
 fr.all.ParsingFail:L'analyse syntaxique du document a échoué.
 it.all.ParsingFail:Analisi del documento fallita.
 nl.all.ParsingFail:fout bij ontleden van dit document.
+en.all.CSSGeneric:Error processing CSS
+en.all.CSSBase:Base stylesheet failed to load
 en.all.BadGIF:Reading GIF failed.
 de.all.BadGIF:Lesen einer GIF Datei fehlgeschlagen.
 fr.all.BadGIF:Erreur de lecture de GIF.
diff --git a/utils/errors.h b/utils/errors.h
index 9ad613d..7fcb5bd 100644
--- a/utils/errors.h
+++ b/utils/errors.h
@@ -61,6 +61,10 @@ typedef enum {
 
 	NSERROR_DOM,	                /**< DOM call returned error */
 
+	NSERROR_CSS,	                /**< CSS call returned error */
+
+	NSERROR_CSS_BASE,               /**< CSS base sheet failed */
+
 	NSERROR_BAD_URL			/**< Bad URL */
 } nserror;
 
diff --git a/utils/messages.c b/utils/messages.c
index 5b62912..8ae616b 100644
--- a/utils/messages.c
+++ b/utils/messages.c
@@ -200,3 +200,99 @@ const char *messages_get(const char *key)
 {
 	return messages_get_ctx(key, messages_hash);
 }
+
+
+/**
+ * lookup of a message by errorcode from the standard Messages hash.
+ *
+ * \param code errorcode of message
+ * \return message text
+ */
+
+const char *messages_get_errorcode(nserror code)
+{
+	switch (code) {
+	case NSERROR_OK:
+		/**< No error */
+		return messages_get_ctx("OK", messages_hash);
+
+	case NSERROR_NOMEM:
+		/**< Memory exhaustion */
+		return messages_get_ctx("NoMemory", messages_hash);
+
+	case NSERROR_NO_FETCH_HANDLER:
+		/**< No fetch handler for URL scheme */
+		return messages_get_ctx("NoHandler", messages_hash);
+
+	case NSERROR_NOT_FOUND:
+		/**< Requested item not found */
+		return messages_get_ctx("NotFound", messages_hash);
+
+	case NSERROR_SAVE_FAILED:
+		/**< Failed to save data */
+		return messages_get_ctx("SaveFailed", messages_hash);
+
+	case NSERROR_CLONE_FAILED:
+		/**< Failed to clone handle */
+		return messages_get_ctx("CloneFailed", messages_hash);
+
+	case NSERROR_INIT_FAILED:
+		/**< Initialisation failed */
+		return messages_get_ctx("InitFailed", messages_hash);
+
+	case NSERROR_MNG_ERROR:
+		/**< An MNG error occurred */
+		return messages_get_ctx("MNGError", messages_hash);
+
+	case NSERROR_BAD_ENCODING:
+		/**< The character set is unknown */
+		return messages_get_ctx("BadEncoding", messages_hash);
+
+	case NSERROR_NEED_DATA:
+		/**< More data needed */
+		return messages_get_ctx("NeedData", messages_hash);
+
+	case NSERROR_ENCODING_CHANGE:
+		/**< The character set encoding change was unhandled */
+		return messages_get_ctx("EncodingChanged", messages_hash);
+
+	case NSERROR_BAD_PARAMETER:
+		/**< Bad Parameter */
+		return messages_get_ctx("BadParameter", messages_hash);
+
+	case NSERROR_INVALID:
+		/**< Invalid data */
+		return messages_get_ctx("Invalid", messages_hash);
+
+	case NSERROR_BOX_CONVERT:
+		/**< Box conversion failed */
+		return messages_get_ctx("BoxConvert", messages_hash);
+
+	case NSERROR_STOPPED:
+		/**< Content conversion stopped */
+		return messages_get_ctx("Stopped", messages_hash);
+
+	case NSERROR_DOM:
+		/**< DOM call returned error */
+		return messages_get_ctx("ParsingFail", messages_hash);
+
+	case NSERROR_CSS:
+                /**< CSS call returned error */
+		return messages_get_ctx("CSSGeneric", messages_hash);
+
+	case NSERROR_CSS_BASE:
+		/**< CSS base sheet failed */
+		return messages_get_ctx("CSSBase", messages_hash);
+
+	case NSERROR_BAD_URL:
+		/**< Bad URL */
+		return messages_get_ctx("BadURL", messages_hash);
+
+	default:
+	case NSERROR_UNKNOWN:
+		break;
+	}
+
+	/**< Unknown error */
+	return messages_get_ctx("Unknown", messages_hash);
+}
diff --git a/utils/messages.h b/utils/messages.h
index 2b78d07..81c3805 100644
--- a/utils/messages.h
+++ b/utils/messages.h
@@ -33,6 +33,7 @@
 #ifndef _NETSURF_UTILS_MESSAGES_H_
 #define _NETSURF_UTILS_MESSAGES_H_
 
+#include "utils/errors.h"
 #include "utils/hashtable.h"
 
 void messages_load(const char *path);
@@ -41,6 +42,14 @@ const char *messages_get_ctx(const char *key, struct hash_table *ctx);
 const char *messages_get(const char *key);
 
 /**
+ * lookup of a message by errorcode from the standard Messages hash.
+ *
+ * \param code errorcode of message
+ * \return message text
+ */
+const char *messages_get_errorcode(nserror code);
+
+/**
  * Formatted message from a key in the global message hash.
  *
  * \param  key  key of message


commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/2fef76db1555f49cff7f2baeec7fa084c8a5facb
commit 2fef76db1555f49cff7f2baeec7fa084c8a5facb
Author: Vincent Sanders <vince at netsurf-browser.org>
Commit: Vincent Sanders <vince at netsurf-browser.org>

    add errorcode content broadcast API

diff --git a/content/content.c b/content/content.c
index 353abee..1a92e40 100644
--- a/content/content.c
+++ b/content/content.c
@@ -678,6 +678,23 @@ void content_broadcast(struct content *c, content_msg msg,
 	}
 }
 
+/* exported interface documented in content_protected.h */
+void content_broadcast_errorcode(struct content *c, nserror errorcode)
+{
+	struct content_user *user, *next;
+	union content_msg_data data;
+
+	assert(c);
+
+	data.errorcode = errorcode;
+
+	for (user = c->user_list->next; user != 0; user = next) {
+		next = user->next;  /* user may be destroyed during callback */
+		if (user->callback != 0)
+			user->callback(c, CONTENT_MSG_ERRORCODE, data, user->pw);
+	}
+}
+
 
 /**
  * A window containing the content has been opened.
diff --git a/content/content_protected.h b/content/content_protected.h
index e399797..ecbe17f 100644
--- a/content/content_protected.h
+++ b/content/content_protected.h
@@ -160,6 +160,11 @@ void content_set_error(struct content *c);
 void content_set_status(struct content *c, const char *status_message);
 void content_broadcast(struct content *c, content_msg msg,
 		union content_msg_data data);
+/**
+ * Send an errorcode message to all users.
+ */
+void content_broadcast_errorcode(struct content *c, nserror errorcode);
+
 void content_add_error(struct content *c, const char *token,
 		unsigned int line);
 


-----------------------------------------------------------------------

Summary of changes:
 content/content.c           |   17 ++
 content/content_protected.h |    5 +
 desktop/browser.c           |   94 +----------
 render/box.h                |    2 +-
 render/box_construct.c      |   13 +-
 render/html.c               |  417 ++++++++++++++++++++++---------------------
 resources/FatMessages       |    2 +
 utils/errors.h              |    4 +
 utils/messages.c            |   96 ++++++++++
 utils/messages.h            |    9 +
 10 files changed, 359 insertions(+), 300 deletions(-)

diff --git a/content/content.c b/content/content.c
index 353abee..1a92e40 100644
--- a/content/content.c
+++ b/content/content.c
@@ -678,6 +678,23 @@ void content_broadcast(struct content *c, content_msg msg,
 	}
 }
 
+/* exported interface documented in content_protected.h */
+void content_broadcast_errorcode(struct content *c, nserror errorcode)
+{
+	struct content_user *user, *next;
+	union content_msg_data data;
+
+	assert(c);
+
+	data.errorcode = errorcode;
+
+	for (user = c->user_list->next; user != 0; user = next) {
+		next = user->next;  /* user may be destroyed during callback */
+		if (user->callback != 0)
+			user->callback(c, CONTENT_MSG_ERRORCODE, data, user->pw);
+	}
+}
+
 
 /**
  * A window containing the content has been opened.
diff --git a/content/content_protected.h b/content/content_protected.h
index e399797..ecbe17f 100644
--- a/content/content_protected.h
+++ b/content/content_protected.h
@@ -160,6 +160,11 @@ void content_set_error(struct content *c);
 void content_set_status(struct content *c, const char *status_message);
 void content_broadcast(struct content *c, content_msg msg,
 		union content_msg_data data);
+/**
+ * Send an errorcode message to all users.
+ */
+void content_broadcast_errorcode(struct content *c, nserror errorcode);
+
 void content_add_error(struct content *c, const char *token,
 		unsigned int line);
 
diff --git a/desktop/browser.c b/desktop/browser.c
index 8948460..6262f24 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -1195,99 +1195,7 @@ browser_window_callback_errorcode(hlcache_handle *c,
 {
 	const char* message;
 
-	switch (code) {
-	case NSERROR_OK:
-		/**< No error */
-		message = messages_get("OK");
-		break;
-
-	case NSERROR_NOMEM:
-		/**< Memory exhaustion */
-		message = messages_get("NoMemory");
-		break;
-
-	case NSERROR_NO_FETCH_HANDLER:
-		/**< No fetch handler for URL scheme */
-		message = messages_get("NoHandler");
-		break;
-
-	case NSERROR_NOT_FOUND:
-		/**< Requested item not found */
-		message = messages_get("NotFound");
-		break;
-
-	case NSERROR_SAVE_FAILED:
-		/**< Failed to save data */
-		message = messages_get("SaveFailed");
-		break;
-
-	case NSERROR_CLONE_FAILED:
-		/**< Failed to clone handle */
-		message = messages_get("CloneFailed");
-		break;
-
-	case NSERROR_INIT_FAILED:
-		/**< Initialisation failed */
-		message = messages_get("InitFailed");
-		break;
-
-	case NSERROR_MNG_ERROR:
-		/**< An MNG error occurred */
-		message = messages_get("MNGError");
-		break;
-
-	case NSERROR_BAD_ENCODING:
-		/**< The character set is unknown */
-		message = messages_get("BadEncoding");
-		break;
-
-	case NSERROR_NEED_DATA:
-		/**< More data needed */
-		message = messages_get("NeedData");
-		break;
-
-	case NSERROR_ENCODING_CHANGE:
-		/**< The character set encoding change was unhandled */
-		message = messages_get("EncodingChanged");
-		break;
-
-	case NSERROR_BAD_PARAMETER:
-		/**< Bad Parameter */
-		message = messages_get("BadParameter");
-		break;
-
-	case NSERROR_INVALID:
-		/**< Invalid data */
-		message = messages_get("Invalid");
-		break;
-
-	case NSERROR_BOX_CONVERT:
-		/**< Box conversion failed */
-		message = messages_get("BoxConvert");
-		break;
-
-	case NSERROR_STOPPED:
-		/**< Content conversion stopped */
-		message = messages_get("Stopped");
-		break;
-
-	case NSERROR_DOM:
-		/**< DOM call returned error */
-		message = messages_get("ParsingFail");
-		break;
-
-	case NSERROR_BAD_URL:
-		/**< Bad URL */
-		message = messages_get("BadURL");
-		break;
-
-	default:
-	case NSERROR_UNKNOWN:
-		/**< Unknown error */
-		message = messages_get("Unknown");
-		break;
-
-	}
+	message = messages_get_errorcode(code);
 
 	browser_window_set_status(bw, message);
 
diff --git a/render/box.h b/render/box.h
index 6b1d28d..a4622e3 100644
--- a/render/box.h
+++ b/render/box.h
@@ -339,7 +339,7 @@ bool box_hscrollbar_present(const struct box *box);
 
 nserror box_construct_init(void);
 void box_construct_fini(void);
-bool xml_to_box(struct dom_node *n, struct html_content *c, 
+nserror dom_to_box(struct dom_node *n, struct html_content *c,
 		box_construct_complete_cb cb);
 
 bool box_normalise_block(struct box *block, struct html_content *c);
diff --git a/render/box_construct.c b/render/box_construct.c
index 26d9b54..6357587 100644
--- a/render/box_construct.c
+++ b/render/box_construct.c
@@ -157,10 +157,10 @@ static const struct element_entry element_table[] = {
  * \param n   xml tree
  * \param c   content of type CONTENT_HTML to construct box tree in
  * \param cb  callback to report conversion completion
- * \return  true on success, false on memory exhaustion
+ * \return    netsurf error code indicating status of call
  */
 
-bool xml_to_box(dom_node *n, html_content *c, box_construct_complete_cb cb)
+nserror dom_to_box(dom_node *n, html_content *c, box_construct_complete_cb cb)
 {
 	struct box_construct_ctx *ctx;
 
@@ -168,13 +168,14 @@ bool xml_to_box(dom_node *n, html_content *c, box_construct_complete_cb cb)
 		/* create a context allocation for this box tree */
 		c->bctx = talloc_zero(0, int);
 		if (c->bctx == NULL) {
-			return false;
+			return NSERROR_NOMEM;
 		}
 	}
 
 	ctx = malloc(sizeof(*ctx));
-	if (ctx == NULL)
-		return false;
+	if (ctx == NULL) {
+		return NSERROR_NOMEM;
+	}
 
 	ctx->content = c;
 	ctx->n = dom_node_ref(n);
@@ -184,7 +185,7 @@ bool xml_to_box(dom_node *n, html_content *c, box_construct_complete_cb cb)
 
 	schedule(0, (schedule_callback_fn) convert_xml_to_box, ctx);
 
-	return true;
+	return NSERROR_OK;
 }
 
 /* mapping from CSS display to box type
diff --git a/render/html.c b/render/html.c
index 6c6dcdf..b5896e1 100644
--- a/render/html.c
+++ b/render/html.c
@@ -78,6 +78,93 @@ static nsurl *html_adblock_stylesheet_url;
 static nsurl *html_quirks_stylesheet_url;
 static nsurl *html_user_stylesheet_url;
 
+static nserror css_error_to_nserror(css_error error)
+{
+	switch (error) {
+	case CSS_OK:
+		return NSERROR_OK;
+
+	case CSS_NOMEM:
+		return NSERROR_NOMEM;
+
+	case CSS_BADPARM:
+		return NSERROR_BAD_PARAMETER;
+
+	case CSS_INVALID:
+		return NSERROR_INVALID;
+
+	case CSS_FILENOTFOUND:
+		return NSERROR_NOT_FOUND;
+
+	case CSS_NEEDDATA:
+		return NSERROR_NEED_DATA;
+
+	case CSS_BADCHARSET:
+		return NSERROR_BAD_ENCODING;
+
+	case CSS_EOF:
+	case CSS_IMPORTS_PENDING:
+	case CSS_PROPERTY_NOT_SET:
+	default:
+		break;
+	}
+	return NSERROR_CSS;
+}
+
+static nserror
+dom_hubbub_error_to_nserror(dom_hubbub_error error)
+{
+	switch (error) {
+
+	/* HUBBUB_REPROCESS is not handled here because it can
+	 * never occur outside the hubbub treebuilder
+	 */
+
+	case DOM_HUBBUB_OK: 
+		/* parsed ok */
+		return NSERROR_OK;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED): 
+		/* hubbub input paused */
+		return NSERROR_OK;
+
+	case DOM_HUBBUB_NOMEM:
+		/* out of memory error from DOM */
+		return NSERROR_NOMEM;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE):
+		/* encoding changed */
+		return NSERROR_ENCODING_CHANGE;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_NOMEM):
+		/* out of memory error from parser */
+		return NSERROR_NOMEM;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_BADPARM):
+		return NSERROR_BAD_PARAMETER;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_INVALID):
+		return NSERROR_INVALID;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_FILENOTFOUND):
+		return NSERROR_NOT_FOUND;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_NEEDDATA):
+		return NSERROR_NEED_DATA;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_BADENCODING):
+		return NSERROR_BAD_ENCODING;
+
+	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_UNKNOWN):
+		/* currently only generated by the libdom hubbub binding */
+		return NSERROR_DOM;
+	default:
+		/* unknown error */
+		/** @todo better error handling and reporting */
+		return NSERROR_UNKNOWN;
+	}
+	return NSERROR_UNKNOWN;
+}
 
 static void html_destroy_objects(html_content *html)
 {
@@ -106,7 +193,7 @@ static void html_destroy_objects(html_content *html)
  */
 static void html_box_convert_done(html_content *c, bool success)
 {
-	union content_msg_data msg_data;
+	nserror err;
 	dom_exception exc; /* returned by libdom functions */
 	dom_node *html;
 
@@ -114,17 +201,19 @@ static void html_box_convert_done(html_content *c, bool success)
 
 	/* Clean up and report error if unsuccessful or aborted */
 	if ((success == false) || (c->aborted)) {
+		html_destroy_objects(c);
+
 		if (success == false) {
-			msg_data.errorcode = NSERROR_BOX_CONVERT;
+			content_broadcast_errorcode(&c->base, NSERROR_BOX_CONVERT);
 		} else {
-			msg_data.errorcode = NSERROR_STOPPED;
+			content_broadcast_errorcode(&c->base, NSERROR_STOPPED);
 		}
-		html_destroy_objects(c);
-		content_broadcast(&c->base, CONTENT_MSG_ERRORCODE, msg_data);
+
 		content_set_error(&c->base);
 		return;
 	}
 
+
 #if ALWAYS_DUMP_BOX
 	box_dump(stderr, c->layout->children, 0);
 #endif
@@ -139,18 +228,17 @@ static void html_box_convert_done(html_content *c, bool success)
 		 * like the other error paths 
 		 */
 		LOG(("error retrieving html element from dom"));
-		msg_data.errorcode = NSERROR_DOM;
-		content_broadcast(&c->base, CONTENT_MSG_ERRORCODE, msg_data);
+		content_broadcast_errorcode(&c->base, NSERROR_DOM);
 		content_set_error(&c->base);
 		return;
 	}
 
-	/* extract image maps - can't do this sensibly in xml_to_box */
-	msg_data.errorcode = imagemap_extract(c);
-	if (msg_data.errorcode != NSERROR_OK) {
+	/* extract image maps - can't do this sensibly in dom_to_box */
+	err = imagemap_extract(c);
+	if (err != NSERROR_OK) {
 		LOG(("imagemap extraction failed"));
 		html_destroy_objects(c);
-		content_broadcast(&c->base, CONTENT_MSG_ERRORCODE, msg_data);
+		content_broadcast_errorcode(&c->base, err);
 		content_set_error(&c->base);
 		dom_node_unref(html);
 		return;
@@ -171,6 +259,7 @@ static void html_box_convert_done(html_content *c, bool success)
 	dom_node_unref(html);
 }
 
+
 /**
  * Complete conversion of an HTML document
  *
@@ -182,29 +271,28 @@ void html_finish_conversion(html_content *c)
 	dom_exception exc; /* returned by libdom functions */
 	dom_node *html;
 	uint32_t i;
-	css_error error;
+	css_error css_ret;
+	nserror error;
 
 	/* Bail out if we've been aborted */
 	if (c->aborted) {
-		msg_data.error = messages_get("Stopped");
-		content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+		content_broadcast_errorcode(&c->base, NSERROR_STOPPED);
 		content_set_error(&c->base);
 		return;
 	}
 
 	/* check that the base stylesheet loaded; layout fails without it */
 	if (c->stylesheets[STYLESHEET_BASE].data.external == NULL) {
-		msg_data.error = "Base stylesheet failed to load";
-		content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+		content_broadcast_errorcode(&c->base, NSERROR_CSS_BASE);
 		content_set_error(&c->base);
 		return;
 	}
 
 	/* Create selection context */
-	error = css_select_ctx_create(ns_realloc, c, &c->select_ctx);
-	if (error != CSS_OK) {
-		msg_data.error = messages_get("NoMemory");
-		content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+	css_ret = css_select_ctx_create(ns_realloc, c, &c->select_ctx);
+	if (css_ret != CSS_OK) {
+		content_broadcast_errorcode(&c->base,
+					    css_error_to_nserror(css_ret));
 		content_set_error(&c->base);
 		return;
 	}
@@ -230,21 +318,21 @@ void html_finish_conversion(html_content *c)
 		}
 
 		if (sheet != NULL) {
-			error = css_select_ctx_append_sheet(
-					c->select_ctx, sheet,
-					origin, CSS_MEDIA_SCREEN);
-			if (error != CSS_OK) {
-				msg_data.error = messages_get("NoMemory");
-				content_broadcast(&c->base, CONTENT_MSG_ERROR,
-						msg_data);
+			css_ret = css_select_ctx_append_sheet(c->select_ctx,
+							      sheet,
+							      origin,
+							      CSS_MEDIA_SCREEN);
+			if (css_ret != CSS_OK) {
+				content_broadcast_errorcode(&c->base,
+						css_error_to_nserror(css_ret));
 				content_set_error(&c->base);
 				return;
 			}
 		}
 	}
 
-	/* convert xml tree to box tree */
-	LOG(("XML to box (%p)", c));
+	/* convert dom tree to box tree */
+	LOG(("DOM to box (%p)", c));
 	content_set_status(&c->base, messages_get("Processing"));
 	msg_data.explicit_status_text = NULL;
 	content_broadcast(&c->base, CONTENT_MSG_STATUS, msg_data);
@@ -252,17 +340,16 @@ void html_finish_conversion(html_content *c)
 	exc = dom_document_get_document_element(c->document, (void *) &html);
 	if ((exc != DOM_NO_ERR) || (html == NULL)) {
 		LOG(("error retrieving html element from dom"));
-		msg_data.error = messages_get("ParsingFail");
-		content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+		content_broadcast_errorcode(&c->base, NSERROR_DOM);
 		content_set_error(&c->base);
 		return;
 	}
 
-	if (xml_to_box(html, c, html_box_convert_done) == false) {
+	error = dom_to_box(html, c, html_box_convert_done);
+	if (error != NSERROR_OK) {
 		dom_node_unref(html);
 		html_destroy_objects(c);
-		msg_data.error = messages_get("NoMemory");
-		content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+		content_broadcast_errorcode(&c->base, error);
 		content_set_error(&c->base);
 		return;
 	}
@@ -276,7 +363,6 @@ static nserror
 html_create_html_data(html_content *c, const http_parameter *params)
 {
 	lwc_string *charset;
-	union content_msg_data msg_data;
 	nserror nerror;
 
 	c->parser = NULL;
@@ -310,9 +396,6 @@ html_create_html_data(html_content *c, const http_parameter *params)
 	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);
-
 		return NSERROR_NOMEM;
 	}
 
@@ -327,10 +410,6 @@ html_create_html_data(html_content *c, const http_parameter *params)
 		if (c->encoding == NULL) {
 			lwc_string_unref(c->universal);
 			c->universal = NULL;
-
-			msg_data.error = messages_get("NoMemory");
-			content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
-
 			return NSERROR_NOMEM;
 
 		}
@@ -367,9 +446,6 @@ html_create_html_data(html_content *c, const http_parameter *params)
 		lwc_string_unref(c->universal);
 		c->universal = NULL;
 
-		msg_data.error = messages_get("NoMemory");
-		content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
-
 		return NSERROR_NOMEM;
 	}
 
@@ -409,6 +485,7 @@ html_create(const content_handler *handler,
 
 	error = html_create_html_data(html, params);
 	if (error != NSERROR_OK) {
+		content_broadcast_errorcode(&html->base, error);
 		free(html);
 		return error;
 	}
@@ -418,60 +495,6 @@ html_create(const content_handler *handler,
 	return NSERROR_OK;
 }
 
-static nserror
-parse_chunk_to_nserror(dom_hubbub_error error)
-{
-	switch (error) {
-
-	/* HUBBUB_REPROCESS is not handled here because it can
-	 * never occur outside the hubbub treebuilder
-	 */
-
-	case DOM_HUBBUB_OK: 
-		/* parsed ok */
-		return NSERROR_OK;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED): 
-		/* hubbub input paused */
-		return NSERROR_OK;
-
-	case DOM_HUBBUB_NOMEM:
-		/* out of memory error from DOM */
-		return NSERROR_NOMEM;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE):
-		/* encoding changed */
-		return NSERROR_ENCODING_CHANGE;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_NOMEM):
-		/* out of memory error from parser */
-		return NSERROR_NOMEM;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_BADPARM):
-		return NSERROR_BAD_PARAMETER;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_INVALID):
-		return NSERROR_INVALID;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_FILENOTFOUND):
-		return NSERROR_NOT_FOUND;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_NEEDDATA):
-		return NSERROR_NEED_DATA;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_BADENCODING):
-		return NSERROR_BAD_ENCODING;
-
-	case (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_UNKNOWN):
-		/* currently only generated by the libdom hubbub binding */
-		return NSERROR_DOM;
-	default:
-		/* unknown error */
-		/** @todo better error handling and reporting */
-		return NSERROR_UNKNOWN;
-	}
-	return NSERROR_UNKNOWN;
-}
 
 
 static nserror
@@ -554,7 +577,7 @@ html_process_encoding_change(struct content *c,
 					      (const uint8_t *)source_data, 
 					      source_size);
 
-	return parse_chunk_to_nserror(error);
+	return dom_hubbub_error_to_nserror(error);
 }
 
 
@@ -566,26 +589,23 @@ 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;
-
-	msg_data.errorcode = NSERROR_OK; /* assume its all going to be ok */
+	dom_hubbub_error dom_ret;
+	nserror err = NSERROR_OK; /* assume its all going to be ok */
 
-	error = dom_hubbub_parser_parse_chunk(html->parser, 
+	dom_ret = dom_hubbub_parser_parse_chunk(html->parser, 
 					      (const uint8_t *) data, 
 					      size);
 
-
-	msg_data.errorcode = parse_chunk_to_nserror(error);
+	err = dom_hubbub_error_to_nserror(dom_ret);
 
 	/* deal with encoding change */
-	if (msg_data.errorcode == NSERROR_ENCODING_CHANGE) {
-		 msg_data.errorcode = html_process_encoding_change(c, data, size);
+	if (err == NSERROR_ENCODING_CHANGE) {
+		 err = html_process_encoding_change(c, data, size);
 	}
 
 	/* broadcast the error if necessary */
-	if (msg_data.errorcode != NSERROR_OK) {
-		content_broadcast(c, CONTENT_MSG_ERRORCODE, msg_data);
+	if (err != NSERROR_OK) {
+		content_broadcast_errorcode(c, err);
 		return false;
 	}
 
@@ -776,7 +796,7 @@ static bool html_process_base(html_content *c, dom_node *node)
  * The title and base href are extracted if present.
  */
 
-static bool html_head(html_content *c, dom_node *head)
+static nserror html_head(html_content *c, dom_node *head)
 {
 	dom_node *node;
 	dom_exception exc; /* returned by libdom functions */
@@ -786,7 +806,7 @@ static bool html_head(html_content *c, dom_node *head)
 
 	exc = dom_node_get_first_child(head, &node);
 	if (exc != DOM_NO_ERR) {
-		return false;
+		return NSERROR_DOM;
 	}
 
 	while (node != NULL) {
@@ -810,8 +830,9 @@ static bool html_head(html_content *c, dom_node *head)
 					html_process_link(c, node);
 				}
 			}
-			if (node_name != NULL)
+			if (node_name != NULL) {
 				dom_string_unref(node_name);
+			}
 		}
 
 		/* move to next node */
@@ -824,10 +845,10 @@ static bool html_head(html_content *c, dom_node *head)
 		}
 	}
 
-	return true;
+	return NSERROR_OK;
 }
 
-static bool html_meta_refresh_process_element(html_content *c, dom_node *n)
+static nserror html_meta_refresh_process_element(html_content *c, dom_node *n)
 {
 	union content_msg_data msg_data;
 	const char *url, *end, *refresh = NULL;
@@ -836,28 +857,32 @@ static bool html_meta_refresh_process_element(html_content *c, dom_node *n)
 	dom_string *equiv, *content;
 	dom_exception exc;
 	nsurl *nsurl;
-	nserror error;
+	nserror error = NSERROR_OK;
 
 	exc = dom_element_get_attribute(n, corestring_dom_http_equiv, &equiv);
-	if (exc != DOM_NO_ERR)
-		return false;
+	if (exc != DOM_NO_ERR) {
+		return NSERROR_DOM;
+	}
 
-	if (equiv == NULL)
-		return true;
+	if (equiv == NULL) {
+		return NSERROR_OK;
+	}
 
 	if (!dom_string_caseless_lwc_isequal(equiv, corestring_lwc_refresh)) {
 		dom_string_unref(equiv);
-		return true;
+		return NSERROR_OK;
 	}
 
 	dom_string_unref(equiv);
 
 	exc = dom_element_get_attribute(n, corestring_dom_content, &content);
-	if (exc != DOM_NO_ERR)
-		return false;
+	if (exc != DOM_NO_ERR) {
+		return NSERROR_DOM;
+	}
 
-	if (content == NULL)
-		return true;
+	if (content == NULL) {
+		return NSERROR_OK;
+	}
 
 	end = dom_string_data(content) + dom_string_byte_length(content);
 
@@ -883,15 +908,16 @@ static bool html_meta_refresh_process_element(html_content *c, dom_node *n)
 	if (url == end || (*url < '0' || '9' < *url)) {
 		/* Empty content, or invalid timeval */
 		dom_string_unref(content);
-		return true;
+		return NSERROR_OK;
 	}
 
 	msg_data.delay = (int) strtol(url, &new_url, 10);
 	/* a very small delay and self-referencing URL can cause a loop
 	 * that grinds machines to a halt. To prevent this we set a
 	 * minimum refresh delay of 1s. */
-	if (msg_data.delay < 1)
+	if (msg_data.delay < 1) {
 		msg_data.delay = 1;
+	}
 
 	url = new_url;
 
@@ -922,9 +948,9 @@ static bool html_meta_refresh_process_element(html_content *c, dom_node *n)
 		c->base.refresh = nsurl_ref(
 				content_get_url(&c->base));
 
-		content_broadcast(&c->base, CONTENT_MSG_REFRESH,
-				msg_data);
-		return true;
+		content_broadcast(&c->base, CONTENT_MSG_REFRESH, msg_data);
+
+		return NSERROR_OK;
 	}
 
 	/* "url" */
@@ -934,12 +960,12 @@ static bool html_meta_refresh_process_element(html_content *c, dom_node *n)
 		} else {
 			/* Unexpected input, ignore this header */
 			dom_string_unref(content);
-			return true;
+			return NSERROR_OK;
 		}
 	} else {
 		/* Insufficient input, ignore this header */
 		dom_string_unref(content);
-		return true;
+		return NSERROR_OK;
 	}
 
 	/* *LWS */
@@ -954,12 +980,12 @@ static bool html_meta_refresh_process_element(html_content *c, dom_node *n)
 		} else {
 			/* Unexpected input, ignore this header */
 			dom_string_unref(content);
-			return true;
+			return NSERROR_OK;
 		}
 	} else {
 		/* Insufficient input, ignore this header */
 		dom_string_unref(content);
-		return true;
+		return NSERROR_OK;
 	}
 
 	/* *LWS */
@@ -992,32 +1018,25 @@ static bool html_meta_refresh_process_element(html_content *c, dom_node *n)
 		new_url = strndup(refresh, url - refresh);
 		if (new_url == NULL) {
 			dom_string_unref(content);
-			return false;
+			return NSERROR_NOMEM;
 		}
 
 		error = nsurl_join(c->base_url, new_url, &nsurl);
-		if (error != NSERROR_OK) {
-			free(new_url);
-
-			dom_string_unref(content);
+		if (error == NSERROR_OK) {
+			/* broadcast valid refresh url */
 
-			msg_data.error = messages_get("NoMemory");
-			content_broadcast(&c->base, CONTENT_MSG_ERROR,
-					msg_data);
+			c->base.refresh = nsurl;
 
-			return false;
+			content_broadcast(&c->base, CONTENT_MSG_REFRESH, msg_data);
 		}
 
 		free(new_url);
 
-		c->base.refresh = nsurl;
-
-		content_broadcast(&c->base, CONTENT_MSG_REFRESH, msg_data);
 	}
 
 	dom_string_unref(content);
 
-	return true;
+	return error;
 }
 
 /**
@@ -1556,7 +1575,6 @@ html_process_style_element(html_content *c,
 	dom_node *child, *next;
 	dom_string *val;
 	dom_exception exc;
-	union content_msg_data msg_data;
 	struct html_stylesheet *stylesheets;
 	struct content_css_data *sheet;
 	nserror error;
@@ -1609,7 +1627,8 @@ html_process_style_element(html_content *c,
 	if (error != NSERROR_OK) {
 		free(sheet);
 		c->stylesheet_count--;
-		goto no_memory;
+		content_broadcast_errorcode(&c->base, error);
+		return false;
 	}
 
 	/* can't just use xmlNodeGetContent(style), because that won't
@@ -1680,8 +1699,7 @@ html_process_style_element(html_content *c,
 	return true;
 
 no_memory:
-	msg_data.error = messages_get("NoMemory");
-	content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+	content_broadcast_errorcode(&c->base, NSERROR_NOMEM);
 	return false;
 }
 
@@ -1701,7 +1719,6 @@ html_process_stylesheet(dom_node *node, dom_string *name, void *vctx)
 	dom_string *rel, *type_attr, *media, *href;
 	struct html_stylesheet *stylesheets;
 	nsurl *joined;
-	union content_msg_data msg_data;
 	dom_exception exc;
 	nserror ns_error;
 	hlcache_child_context child;
@@ -1779,6 +1796,7 @@ html_process_stylesheet(dom_node *node, dom_string *name, void *vctx)
 			      sizeof(struct html_stylesheet) * (ctx->count + 1));
 	if (stylesheets == NULL) {
 		nsurl_unref(joined);
+		ns_error = NSERROR_NOMEM;
 		goto no_memory;
 	}
 
@@ -1812,10 +1830,8 @@ html_process_stylesheet(dom_node *node, dom_string *name, void *vctx)
 	return true;
 
 no_memory:
-	msg_data.error = messages_get("NoMemory");
-	content_broadcast(&ctx->c->base, CONTENT_MSG_ERROR, msg_data);
+	content_broadcast_errorcode(&ctx->c->base, ns_error);
 	return false;
-
 }
 
 
@@ -1831,7 +1847,6 @@ no_memory:
 
 static bool html_find_stylesheets(html_content *c, dom_node *html)
 {
-	union content_msg_data msg_data;
 	nserror ns_error;
 	bool result;
 	struct find_stylesheet_ctx ctx;
@@ -1847,6 +1862,7 @@ static bool html_find_stylesheets(html_content *c, dom_node *html)
 	 * stylesheet 3 is the user stylesheet */
 	c->stylesheets = calloc(STYLESHEET_START, sizeof(struct html_stylesheet));
 	if (c->stylesheets == NULL) {
+		ns_error = NSERROR_NOMEM;
 		goto html_find_stylesheets_no_memory;
 	}
 
@@ -1911,7 +1927,6 @@ static bool html_find_stylesheets(html_content *c, dom_node *html)
 	c->base.active++;
 	LOG(("%d fetches active", c->base.active));
 
-
 	result = libdom_treewalk(html, html_process_stylesheet, &ctx);
 
 	assert(c->stylesheet_count == ctx.count);
@@ -1919,8 +1934,7 @@ static bool html_find_stylesheets(html_content *c, dom_node *html)
 	return result;
 
 html_find_stylesheets_no_memory:
-	msg_data.error = messages_get("NoMemory");
-	content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+	content_broadcast_errorcode(&c->base, ns_error);
 	return false;
 }
 
@@ -1945,7 +1959,6 @@ static bool html_convert(struct content *c)
 	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.
 	 */ 
@@ -1953,14 +1966,13 @@ static bool html_convert(struct content *c)
 		return html_begin_conversion(htmlc);
 	}
 	return true;
-
 }
 
 bool
 html_begin_conversion(html_content *htmlc)
 {
 	dom_node *html, *head;
-	union content_msg_data msg_data;
+	nserror ns_error;
 	struct form *f;
 	dom_exception exc; /* returned by libdom functions */
 	dom_string *node_name = NULL;
@@ -1969,19 +1981,28 @@ html_begin_conversion(html_content *htmlc)
 	/* 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 */
 		LOG(("Parsing failed"));
-		msg_data.error = messages_get("ParsingFail");
-		content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
 
+		content_broadcast_errorcode(&htmlc->base, 
+					    dom_hubbub_error_to_nserror(error));
+
+		return false;
+	}
+
+	/* Give up processing if we've been aborted */
+	if (htmlc->aborted) {
+		content_broadcast_errorcode(&htmlc->base, NSERROR_STOPPED);
 		return false;
 	}
 
+
 	/* complete script execution */
 	html_scripts_exec(htmlc);
 
+	/* fire a simple event that bubbles named DOMContentLoaded at
+	 * the Document.
+	 */
+
 	/* quirks mode */
 	exc = dom_document_get_quirks_mode(htmlc->document, &htmlc->quirks);
 	if (exc != DOM_NO_ERR) {
@@ -1997,32 +2018,24 @@ html_begin_conversion(html_content *htmlc)
 		encoding = dom_hubbub_parser_get_encoding(htmlc->parser,
 					&htmlc->encoding_source);
 		if (encoding == NULL) {
-			msg_data.error = messages_get("NoMemory");
-			content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
+			content_broadcast_errorcode(&htmlc->base, 
+						    NSERROR_NOMEM);
 			return false;
 		}
 
 		htmlc->encoding = strdup(encoding);
 		if (htmlc->encoding == NULL) {
-			msg_data.error = messages_get("NoMemory");
-			content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
+			content_broadcast_errorcode(&htmlc->base, 
+						    NSERROR_NOMEM);
 			return false;
 		}
 	}
 
-	/* Give up processing if we've been aborted */
-	if (htmlc->aborted) {
-		msg_data.error = messages_get("Stopped");
-		content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
-		return false;
-	}
-
 	/* locate root element and ensure it is html */
 	exc = dom_document_get_document_element(htmlc->document, (void *) &html);
 	if ((exc != DOM_NO_ERR) || (html == NULL)) {
 		LOG(("error retrieving html element from dom"));
-		msg_data.error = messages_get("ParsingFail");
-		content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
+		content_broadcast_errorcode(&htmlc->base, NSERROR_DOM);
 		return false;
 	}
 
@@ -2032,8 +2045,7 @@ html_begin_conversion(html_content *htmlc)
 	    (!dom_string_caseless_lwc_isequal(node_name,
 	    		corestring_lwc_html))) {
 		LOG(("root element not html"));
-		msg_data.error = messages_get("ParsingFail");
-		content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
+		content_broadcast_errorcode(&htmlc->base, NSERROR_DOM);
 		dom_node_unref(html);
 		return false;
 	}
@@ -2041,16 +2053,20 @@ html_begin_conversion(html_content *htmlc)
 
 	head = libdom_find_first_element(html, corestring_lwc_head);
 	if (head != NULL) {
-		if (html_head(htmlc, head) == false) {
-			msg_data.error = messages_get("NoMemory");
-			content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
+		ns_error = html_head(htmlc, head);
+		if (ns_error != NSERROR_OK) {
+			content_broadcast_errorcode(&htmlc->base, ns_error);
+
 			dom_node_unref(html);
 			dom_node_unref(head);
 			return false;
 		}
 
 		/* handle meta refresh */
-		if (html_meta_refresh(htmlc, head) == false) {
+		ns_error = html_meta_refresh(htmlc, head);
+		if (ns_error != NSERROR_OK) {
+			content_broadcast_errorcode(&htmlc->base, ns_error);
+
 			dom_node_unref(html);
 			dom_node_unref(head);
 			return false;
@@ -2062,21 +2078,23 @@ html_begin_conversion(html_content *htmlc)
 			(dom_html_document *) htmlc->document);
 	for (f = htmlc->forms; f != NULL; f = f->prev) {
 		nsurl *action;
-		nserror res;
 
 		/* Make all actions absolute */
 		if (f->action == NULL || f->action[0] == '\0') {
 			/* HTML5 4.10.22.3 step 9 */
 			nsurl *doc_addr = content_get_url(&htmlc->base);
-			res = nsurl_join(htmlc->base_url,
-					nsurl_access(doc_addr), &action);
+			ns_error = nsurl_join(htmlc->base_url,
+					      nsurl_access(doc_addr), 
+					      &action);
 		} else {
-			res = nsurl_join(htmlc->base_url, f->action, &action);
+			ns_error = nsurl_join(htmlc->base_url, 
+					      f->action, 
+					      &action);
 		}
 
-		if (res != NSERROR_OK) {
-			msg_data.error = messages_get("NoMemory");
-			content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
+		if (ns_error != NSERROR_OK) {
+			content_broadcast_errorcode(&htmlc->base, ns_error);
+
 			dom_node_unref(html);
 			dom_node_unref(head);
 			return false;
@@ -2086,8 +2104,9 @@ html_begin_conversion(html_content *htmlc)
 		f->action = strdup(nsurl_access(action));
 		nsurl_unref(action);
 		if (f->action == NULL) {
-			msg_data.error = messages_get("NoMemory");
-			content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
+			content_broadcast_errorcode(&htmlc->base, 
+						    NSERROR_NOMEM);
+
 			dom_node_unref(html);
 			dom_node_unref(head);
 			return false;
@@ -2097,10 +2116,8 @@ html_begin_conversion(html_content *htmlc)
 		if (f->document_charset == NULL) {
 			f->document_charset = strdup(htmlc->encoding);
 			if (f->document_charset == NULL) {
-				msg_data.error = messages_get("NoMemory");
-				content_broadcast(&htmlc->base, 
-						  CONTENT_MSG_ERROR,
-						  msg_data);
+				content_broadcast_errorcode(&htmlc->base, 
+							    NSERROR_NOMEM);
 				dom_node_unref(html);
 				dom_node_unref(head);
 				return false;
diff --git a/resources/FatMessages b/resources/FatMessages
index d54acad..45b3086 100644
--- a/resources/FatMessages
+++ b/resources/FatMessages
@@ -2787,6 +2787,8 @@ de.all.ParsingFail:Dokumentparsing ist fehlgeschlagen.
 fr.all.ParsingFail:L'analyse syntaxique du document a échoué.
 it.all.ParsingFail:Analisi del documento fallita.
 nl.all.ParsingFail:fout bij ontleden van dit document.
+en.all.CSSGeneric:Error processing CSS
+en.all.CSSBase:Base stylesheet failed to load
 en.all.BadGIF:Reading GIF failed.
 de.all.BadGIF:Lesen einer GIF Datei fehlgeschlagen.
 fr.all.BadGIF:Erreur de lecture de GIF.
diff --git a/utils/errors.h b/utils/errors.h
index 9ad613d..7fcb5bd 100644
--- a/utils/errors.h
+++ b/utils/errors.h
@@ -61,6 +61,10 @@ typedef enum {
 
 	NSERROR_DOM,	                /**< DOM call returned error */
 
+	NSERROR_CSS,	                /**< CSS call returned error */
+
+	NSERROR_CSS_BASE,               /**< CSS base sheet failed */
+
 	NSERROR_BAD_URL			/**< Bad URL */
 } nserror;
 
diff --git a/utils/messages.c b/utils/messages.c
index 5b62912..8ae616b 100644
--- a/utils/messages.c
+++ b/utils/messages.c
@@ -200,3 +200,99 @@ const char *messages_get(const char *key)
 {
 	return messages_get_ctx(key, messages_hash);
 }
+
+
+/**
+ * lookup of a message by errorcode from the standard Messages hash.
+ *
+ * \param code errorcode of message
+ * \return message text
+ */
+
+const char *messages_get_errorcode(nserror code)
+{
+	switch (code) {
+	case NSERROR_OK:
+		/**< No error */
+		return messages_get_ctx("OK", messages_hash);
+
+	case NSERROR_NOMEM:
+		/**< Memory exhaustion */
+		return messages_get_ctx("NoMemory", messages_hash);
+
+	case NSERROR_NO_FETCH_HANDLER:
+		/**< No fetch handler for URL scheme */
+		return messages_get_ctx("NoHandler", messages_hash);
+
+	case NSERROR_NOT_FOUND:
+		/**< Requested item not found */
+		return messages_get_ctx("NotFound", messages_hash);
+
+	case NSERROR_SAVE_FAILED:
+		/**< Failed to save data */
+		return messages_get_ctx("SaveFailed", messages_hash);
+
+	case NSERROR_CLONE_FAILED:
+		/**< Failed to clone handle */
+		return messages_get_ctx("CloneFailed", messages_hash);
+
+	case NSERROR_INIT_FAILED:
+		/**< Initialisation failed */
+		return messages_get_ctx("InitFailed", messages_hash);
+
+	case NSERROR_MNG_ERROR:
+		/**< An MNG error occurred */
+		return messages_get_ctx("MNGError", messages_hash);
+
+	case NSERROR_BAD_ENCODING:
+		/**< The character set is unknown */
+		return messages_get_ctx("BadEncoding", messages_hash);
+
+	case NSERROR_NEED_DATA:
+		/**< More data needed */
+		return messages_get_ctx("NeedData", messages_hash);
+
+	case NSERROR_ENCODING_CHANGE:
+		/**< The character set encoding change was unhandled */
+		return messages_get_ctx("EncodingChanged", messages_hash);
+
+	case NSERROR_BAD_PARAMETER:
+		/**< Bad Parameter */
+		return messages_get_ctx("BadParameter", messages_hash);
+
+	case NSERROR_INVALID:
+		/**< Invalid data */
+		return messages_get_ctx("Invalid", messages_hash);
+
+	case NSERROR_BOX_CONVERT:
+		/**< Box conversion failed */
+		return messages_get_ctx("BoxConvert", messages_hash);
+
+	case NSERROR_STOPPED:
+		/**< Content conversion stopped */
+		return messages_get_ctx("Stopped", messages_hash);
+
+	case NSERROR_DOM:
+		/**< DOM call returned error */
+		return messages_get_ctx("ParsingFail", messages_hash);
+
+	case NSERROR_CSS:
+                /**< CSS call returned error */
+		return messages_get_ctx("CSSGeneric", messages_hash);
+
+	case NSERROR_CSS_BASE:
+		/**< CSS base sheet failed */
+		return messages_get_ctx("CSSBase", messages_hash);
+
+	case NSERROR_BAD_URL:
+		/**< Bad URL */
+		return messages_get_ctx("BadURL", messages_hash);
+
+	default:
+	case NSERROR_UNKNOWN:
+		break;
+	}
+
+	/**< Unknown error */
+	return messages_get_ctx("Unknown", messages_hash);
+}
diff --git a/utils/messages.h b/utils/messages.h
index 2b78d07..81c3805 100644
--- a/utils/messages.h
+++ b/utils/messages.h
@@ -33,6 +33,7 @@
 #ifndef _NETSURF_UTILS_MESSAGES_H_
 #define _NETSURF_UTILS_MESSAGES_H_
 
+#include "utils/errors.h"
 #include "utils/hashtable.h"
 
 void messages_load(const char *path);
@@ -41,6 +42,14 @@ const char *messages_get_ctx(const char *key, struct hash_table *ctx);
 const char *messages_get(const char *key);
 
 /**
+ * lookup of a message by errorcode from the standard Messages hash.
+ *
+ * \param code errorcode of message
+ * \return message text
+ */
+const char *messages_get_errorcode(nserror code);
+
+/**
  * Formatted message from a key in the global message hash.
  *
  * \param  key  key of message


-- 
NetSurf Browser



More information about the netsurf-commits mailing list