From 9cf51227979c84a9ed74c339290c3f65f0d58c4f Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 11 Mar 2007 22:08:57 +0000 Subject: Content handlers should not call warn_user - they should broadcast the error using content_broadcast and leave it to the content owner(s) to decide what to do about it. Only use warn_user for top-level contents. svn path=/trunk/netsurf/; revision=3204 --- Docs/01-content | 4 ++-- content/content.c | 4 ---- css/css.c | 2 -- desktop/browser.c | 6 +++++- image/bmp.c | 2 -- image/gif.c | 2 -- image/ico.c | 2 -- image/jpeg.c | 1 - render/html.c | 9 +++++++-- render/textplain.c | 22 +++++++++++++++------- riscos/artworks.c | 3 ++- 11 files changed, 31 insertions(+), 26 deletions(-) diff --git a/Docs/01-content b/Docs/01-content index 3f265fa3e..c6e77424f 100644 --- a/Docs/01-content +++ b/Docs/01-content @@ -85,8 +85,8 @@ type_close():: called when the window containing the content is closed. Optional. If an error occurs in type_create(), type_process_data(), type_convert(), -CONTENT_MSG_ERROR must be broadcast and false returned. Optionally use -warn_user() for serious errors. The _destroy function will be called soon after. +CONTENT_MSG_ERROR must be broadcast and false returned. The _destroy function +will be called soon after. Memory allocation ----------------- diff --git a/content/content.c b/content/content.c index 446f326db..93d37d799 100644 --- a/content/content.c +++ b/content/content.c @@ -535,7 +535,6 @@ bool content_set_type(struct content *c, content_type type, c->status = CONTENT_STATUS_ERROR; msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("NoMemory", 0); return false; } @@ -556,7 +555,6 @@ bool content_set_type(struct content *c, content_type type, msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("NoMemory", 0); return false; } @@ -574,7 +572,6 @@ bool content_set_type(struct content *c, content_type type, msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("NoMemory", 0); return false; } content_remove_user(c, callback, p1, p2); @@ -682,7 +679,6 @@ bool content_process_data(struct content *c, const char *data, c->status = CONTENT_STATUS_ERROR; msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("NoMemory", 0); return false; } c->source_data = source_data; diff --git a/css/css.c b/css/css.c index ac988d321..3ba3da872 100644 --- a/css/css.c +++ b/css/css.c @@ -404,7 +404,6 @@ bool css_convert(struct content *c, int width, int height) msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("NoMemory", 0); return false; } @@ -445,7 +444,6 @@ bool css_convert(struct content *c, int width, int height) if (param.memory_error) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("NoMemory", 0); return false; } diff --git a/desktop/browser.c b/desktop/browser.c index 0273917bc..54a112f27 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -458,7 +458,11 @@ void browser_window_callback(content_msg msg, struct content *c, case CONTENT_MSG_ERROR: browser_window_set_status(bw, data.error); - warn_user(data.error, 0); + + /* Only warn the user about errors in top-level windows */ + if (bw->browser_window_type == BROWSER_WINDOW_NORMAL) + warn_user(data.error, 0); + if (c == bw->loading_content) bw->loading_content = 0; else if (c == bw->current_content) { diff --git a/image/bmp.c b/image/bmp.c index c58bc044f..204dcaf9c 100644 --- a/image/bmp.c +++ b/image/bmp.c @@ -28,7 +28,6 @@ bool nsbmp_create(struct content *c, const char *params[]) { if (!c->data.bmp.bmp) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("NoMemory", 0); return false; } return true; @@ -53,7 +52,6 @@ bool nsbmp_convert(struct content *c, int iwidth, int iheight) { case BMP_INSUFFICIENT_MEMORY: msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("NoMemory", 0); return false; case BMP_INSUFFICIENT_DATA: case BMP_DATA_ERROR: diff --git a/image/gif.c b/image/gif.c index 02148f264..a3e0b00af 100644 --- a/image/gif.c +++ b/image/gif.c @@ -48,7 +48,6 @@ bool nsgif_create(struct content *c, const char *params[]) { if (!c->data.gif.gif) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("NoMemory", 0); return false; } return true; @@ -74,7 +73,6 @@ bool nsgif_convert(struct content *c, int iwidth, int iheight) { case GIF_INSUFFICIENT_MEMORY: msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("NoMemory", 0); return false; case GIF_INSUFFICIENT_DATA: case GIF_DATA_ERROR: diff --git a/image/ico.c b/image/ico.c index 546727595..fbf6405d5 100644 --- a/image/ico.c +++ b/image/ico.c @@ -28,7 +28,6 @@ bool nsico_create(struct content *c, const char *params[]) { if (!c->data.ico.ico) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("NoMemory", 0); return false; } return true; @@ -54,7 +53,6 @@ bool nsico_convert(struct content *c, int iwidth, int iheight) { case BMP_INSUFFICIENT_MEMORY: msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("NoMemory", 0); return false; case BMP_INSUFFICIENT_DATA: case BMP_DATA_ERROR: diff --git a/image/jpeg.c b/image/jpeg.c index 87d251bac..e18d2b0a3 100644 --- a/image/jpeg.c +++ b/image/jpeg.c @@ -104,7 +104,6 @@ bool nsjpeg_convert(struct content *c, int w, int h) msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("NoMemory", 0); return false; } diff --git a/render/html.c b/render/html.c index 46d98b81d..db7c694cc 100644 --- a/render/html.c +++ b/render/html.c @@ -136,7 +136,6 @@ bool html_create(struct content *c, const char *params[]) no_memory: msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("NoMemory", 0); return false; } @@ -1358,7 +1357,13 @@ void html_object_failed(struct box *box, struct content *content, * containers */ ic = box_create(0, 0, 0, 0, 0, content); if (!ic) { - warn_user("NoMemory", 0); + union content_msg_data msg_data; + + msg_data.error = + messages_get("NoMemory"); + content_broadcast(content, + CONTENT_MSG_ERROR, + msg_data); return; } ic->type = BOX_INLINE_CONTAINER; diff --git a/render/textplain.c b/render/textplain.c index 8984ff851..cb9bc644f 100644 --- a/render/textplain.c +++ b/render/textplain.c @@ -76,9 +76,14 @@ bool textplain_create(struct content *c, const char *params[]) iconv_cd = iconv_open("utf-8", "iso-8859-1"); } if (iconv_cd == (iconv_t)(-1)) { - msg_data.error = strerror(errno); + char buf[300]; + + snprintf(buf, sizeof buf, "IconvFailed %s", strerror(errno)); + buf[sizeof buf - 1] = 0; + + msg_data.error = buf; content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("IconvFailed", strerror(errno)); + return false; } @@ -97,7 +102,6 @@ bool textplain_create(struct content *c, const char *params[]) no_memory: msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("NoMemory", 0); return false; } @@ -137,9 +141,15 @@ bool textplain_process_data(struct content *c, char *data, unsigned int size) c->data.textplain.utf8_data = utf8_data; c->data.textplain.utf8_data_allocated = allocated; } else if (count == (size_t)(-1) && errno != EINVAL) { - msg_data.error = strerror(errno); + char buf[300]; + + snprintf(buf, sizeof buf, "IconvFailed %s", + strerror(errno)); + buf[sizeof buf - 1] = 0; + + msg_data.error = buf; content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("IconvFailed", strerror(errno)); + return false; } @@ -152,7 +162,6 @@ bool textplain_process_data(struct content *c, char *data, unsigned int size) no_memory: msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - warn_user("NoMemory", 0); return false; } @@ -266,7 +275,6 @@ void textplain_reformat(struct content *c, int width, int height) no_memory: LOG(("out of memory (line_count %lu)", line_count)); - warn_user("NoMemory", 0); return; } diff --git a/riscos/artworks.c b/riscos/artworks.c index 6a52c5512..9cc219de1 100644 --- a/riscos/artworks.c +++ b/riscos/artworks.c @@ -168,7 +168,8 @@ bool artworks_convert(struct content *c, int width, int height) c->data.artworks.block = malloc(INITIAL_BLOCK_SIZE); if (!c->data.artworks.block) { LOG(("failed to create block for ArtworksRenderer")); - warn_user("NoMemory", 0); + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return false; } -- cgit v1.2.3