diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2019-08-05 14:29:53 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2019-08-05 14:30:30 +0100 |
commit | 6ba199c7d7bee1909107ee0b8cbaf749c575b310 (patch) | |
tree | 9932d32f3fd90c341022257d6c22061fe990725c | |
parent | 2171f13ab334716250ca2bc53946806f7a88c8a3 (diff) | |
download | netsurf-6ba199c7d7bee1909107ee0b8cbaf749c575b310.tar.gz netsurf-6ba199c7d7bee1909107ee0b8cbaf749c575b310.tar.bz2 |
Content messages: Remove ERRORCODE, rework ERROR
This reworks CONTENT_MSG_ERROR to be structured data and
removes the CONTENT_MSG_ERRORCODE message kind.
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rw-r--r-- | content/content.c | 8 | ||||
-rw-r--r-- | content/content.h | 16 | ||||
-rw-r--r-- | content/handlers/css/css.c | 1 | ||||
-rw-r--r-- | content/handlers/html/html_css.c | 4 | ||||
-rw-r--r-- | content/handlers/html/html_object.c | 8 | ||||
-rw-r--r-- | content/handlers/html/html_script.c | 12 | ||||
-rw-r--r-- | content/handlers/image/jpeg.c | 3 | ||||
-rw-r--r-- | content/hlcache.c | 14 | ||||
-rw-r--r-- | desktop/browser_window.c | 49 | ||||
-rw-r--r-- | desktop/searchweb.c | 8 |
10 files changed, 43 insertions, 80 deletions
diff --git a/content/content.c b/content/content.c index af4cdaac3..367a0e5d1 100644 --- a/content/content.c +++ b/content/content.c @@ -173,7 +173,8 @@ nserror content_llcache_callback(llcache_handle *llcache, case LLCACHE_EVENT_ERROR: /** \todo Error page? */ c->status = CONTENT_STATUS_ERROR; - msg_data.error = event->data.msg; + msg_data.errordata.errorcode = NSERROR_UNKNOWN; + msg_data.errordata.errormsg = event->data.msg; content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); break; case LLCACHE_EVENT_PROGRESS: @@ -816,12 +817,13 @@ void content_broadcast_errorcode(struct content *c, nserror errorcode) assert(c); - data.errorcode = errorcode; + data.errordata.errorcode = errorcode; + data.errordata.errormsg = NULL; 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, + user->callback(c, CONTENT_MSG_ERROR, &data, user->pw); } } diff --git a/content/content.h b/content/content.h index 304384b8f..4fdcaf2c0 100644 --- a/content/content.h +++ b/content/content.h @@ -65,7 +65,6 @@ typedef enum { CONTENT_MSG_READY, /**< may be displayed */ CONTENT_MSG_DONE, /**< finished */ CONTENT_MSG_ERROR, /**< error occurred */ - CONTENT_MSG_ERRORCODE, /**< error occurred return nserror */ CONTENT_MSG_REDIRECT, /**< fetch url redirect occured */ CONTENT_MSG_STATUS, /**< new status string */ CONTENT_MSG_REFORMAT, /**< content_reformat done */ @@ -112,10 +111,17 @@ union content_msg_data { const struct llcache_query_msg *query_msg; /** CONTENT_MSG_QUERY_FINISHED - Query from underlying object finished */ void *query_finished_pw; - /** CONTENT_MSG_ERROR - Error message */ - const char *error; - /** CONTENT_MSG_ERRORCODE - Error code */ - nserror errorcode; + /** CONTENT_MSG_ERROR - Error from content or underlying fetch */ + struct { + nserror errorcode; /**< The error code to convey meaning */ + const char *errormsg; /**< The message. + * if NSERROR_UNKNOWN then this is the + * direct message, otherwise is some + * kind of metadata (e.g. a message name + * or somesuch) but always a nul + * terminated string. + */ + } errordata; /** CONTENT_MSG_REDIRECT - Redirect info */ struct { struct nsurl *from; /**< Redirect origin */ diff --git a/content/handlers/css/css.c b/content/handlers/css/css.c index 3e00879f3..af7aafc60 100644 --- a/content/handlers/css/css.c +++ b/content/handlers/css/css.c @@ -634,7 +634,6 @@ nserror nscss_import(hlcache_handle *handle, error = nscss_import_complete(ctx); break; - case CONTENT_MSG_ERRORCODE: case CONTENT_MSG_ERROR: hlcache_handle_release(handle); ctx->css->imports[ctx->index].c = NULL; diff --git a/content/handlers/html/html_css.c b/content/handlers/html/html_css.c index 70ed83f3d..9d7cc7132 100644 --- a/content/handlers/html/html_css.c +++ b/content/handlers/html/html_css.c @@ -116,10 +116,8 @@ html_convert_css_callback(hlcache_handle *css, case CONTENT_MSG_ERROR: NSLOG(netsurf, INFO, "stylesheet %s failed: %s", nsurl_access(hlcache_handle_get_url(css)), - event->data.error); - /* fall through */ + event->data.errordata.errormsg); - case CONTENT_MSG_ERRORCODE: hlcache_handle_release(css); s->sheet = NULL; parent->base.active--; diff --git a/content/handlers/html/html_object.c b/content/handlers/html/html_object.c index f49af6505..dc8524499 100644 --- a/content/handlers/html/html_object.c +++ b/content/handlers/html/html_object.c @@ -137,9 +137,7 @@ html_object_callback(hlcache_handle *object, struct box *box; box = o->box; - if (box == NULL && - event->type != CONTENT_MSG_ERROR && - event->type != CONTENT_MSG_ERRORCODE) { + if (box == NULL && event->type != CONTENT_MSG_ERROR) { return NSERROR_OK; } @@ -195,7 +193,6 @@ html_object_callback(hlcache_handle *object, } break; - case CONTENT_MSG_ERRORCODE: case CONTENT_MSG_ERROR: hlcache_handle_release(object); @@ -472,8 +469,7 @@ html_object_callback(hlcache_handle *object, c->base.active == 0 && (event->type == CONTENT_MSG_LOADING || event->type == CONTENT_MSG_DONE || - event->type == CONTENT_MSG_ERROR || - event->type == CONTENT_MSG_ERRORCODE)) { + event->type == CONTENT_MSG_ERROR)) { /* all objects have arrived */ content__reformat(&c->base, false, c->base.available_width, c->base.available_height); diff --git a/content/handlers/html/html_script.c b/content/handlers/html/html_script.c index 5af4750ff..14e291ae1 100644 --- a/content/handlers/html/html_script.c +++ b/content/handlers/html/html_script.c @@ -183,10 +183,8 @@ convert_script_async_cb(hlcache_handle *script, case CONTENT_MSG_ERROR: NSLOG(netsurf, INFO, "script %s failed: %s", nsurl_access(hlcache_handle_get_url(script)), - event->data.error); - /* fall through */ + event->data.errordata.errormsg); - case CONTENT_MSG_ERRORCODE: hlcache_handle_release(script); s->data.handle = NULL; parent->base.active--; @@ -259,10 +257,8 @@ convert_script_defer_cb(hlcache_handle *script, case CONTENT_MSG_ERROR: NSLOG(netsurf, INFO, "script %s failed: %s", nsurl_access(hlcache_handle_get_url(script)), - event->data.error); - /* fall through */ + event->data.errordata.errormsg); - case CONTENT_MSG_ERRORCODE: hlcache_handle_release(script); s->data.handle = NULL; parent->base.active--; @@ -350,10 +346,8 @@ convert_script_sync_cb(hlcache_handle *script, case CONTENT_MSG_ERROR: NSLOG(netsurf, INFO, "script %s failed: %s", nsurl_access(hlcache_handle_get_url(script)), - event->data.error); - /* fall through */ + event->data.errordata.errormsg); - case CONTENT_MSG_ERRORCODE: hlcache_handle_release(script); s->data.handle = NULL; parent->base.active--; diff --git a/content/handlers/image/jpeg.c b/content/handlers/image/jpeg.c index 52cdb2201..9df084b74 100644 --- a/content/handlers/image/jpeg.c +++ b/content/handlers/image/jpeg.c @@ -329,7 +329,8 @@ static bool nsjpeg_convert(struct content *c) if (setjmp(setjmp_buffer)) { jpeg_destroy_decompress(&cinfo); - msg_data.error = nsjpeg_error_buffer; + msg_data.errordata.errorcode = NSERROR_UNKNOWN; + msg_data.errordata.errormsg = nsjpeg_error_buffer; content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); return false; } diff --git a/content/hlcache.c b/content/hlcache.c index 92bf690ed..ca0e47907 100644 --- a/content/hlcache.c +++ b/content/hlcache.c @@ -361,7 +361,8 @@ static nserror hlcache_migrate_ctx(hlcache_retrieval_ctx *ctx, hlcache_event hlevent; hlevent.type = CONTENT_MSG_ERROR; - hlevent.data.error = messages_get("MiscError"); + hlevent.data.errordata.errorcode = NSERROR_UNKNOWN; + hlevent.data.errordata.errormsg = messages_get("MiscError"); ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); @@ -393,7 +394,8 @@ static nserror hlcache_migrate_ctx(hlcache_retrieval_ctx *ctx, hlcache_event hlevent; hlevent.type = CONTENT_MSG_ERROR; - hlevent.data.error = messages_get("UnacceptableType"); + hlevent.data.errordata.errorcode = NSERROR_UNKNOWN; + hlevent.data.errordata.errormsg = messages_get("UnacceptableType"); ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); @@ -489,8 +491,9 @@ static nserror hlcache_llcache_callback(llcache_handle *handle, if (ctx->handle->cb != NULL) { hlcache_event hlevent; - hlevent.type = CONTENT_MSG_ERRORCODE; - hlevent.data.errorcode = error; + hlevent.type = CONTENT_MSG_ERROR; + hlevent.data.errordata.errorcode = error; + hlevent.data.errordata.errormsg = NULL; ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); } @@ -500,7 +503,8 @@ static nserror hlcache_llcache_callback(llcache_handle *handle, hlcache_event hlevent; hlevent.type = CONTENT_MSG_ERROR; - hlevent.data.error = event->data.msg; + hlevent.data.errordata.errorcode = NSERROR_UNKNOWN; + hlevent.data.errordata.errormsg = event->data.msg; ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); } diff --git a/desktop/browser_window.c b/desktop/browser_window.c index 176fced3d..8d5b1ee5e 100644 --- a/desktop/browser_window.c +++ b/desktop/browser_window.c @@ -410,7 +410,6 @@ browser_window_favicon_callback(hlcache_handle *c, break; case CONTENT_MSG_ERROR: - case CONTENT_MSG_ERRORCODE: /* clean up after ourselves */ if (c == bw->favicon.loading) { @@ -557,38 +556,6 @@ browser_window_update_favicon(hlcache_handle *c, /** - * window callback errorcode handling. - */ -static void -browser_window_callback_errorcode(hlcache_handle *c, - struct browser_window *bw, - nserror code) -{ - const char* message; - - message = messages_get_errorcode(code); - - browser_window_set_status(bw, message); - - /* Only warn the user about errors in top-level windows */ - if (bw->browser_window_type == BROWSER_WINDOW_NORMAL) { - guit->misc->warning(message, NULL); - } - - if (c == bw->loading_content) { - bw->loading_content = NULL; - } else if (c == bw->current_content) { - bw->current_content = NULL; - browser_window_remove_caret(bw, false); - } - - hlcache_handle_release(c); - - browser_window_stop_throbber(bw); -} - - -/** * Handle meta http-equiv refresh time elapsing by loading a new page. * * \param p browser window to refresh with new page @@ -867,16 +834,16 @@ browser_window_callback(hlcache_handle *c, const hlcache_event *event, void *pw) res = browser_window_content_done(bw); break; - case CONTENT_MSG_ERRORCODE: - browser_window_callback_errorcode(c, bw, event->data.errorcode); - break; - - case CONTENT_MSG_ERROR: - browser_window_set_status(bw, event->data.error); + case CONTENT_MSG_ERROR: { + const char *message = event->data.errordata.errormsg; + if (event->data.errordata.errorcode != NSERROR_UNKNOWN) { + message = messages_get_errorcode(event->data.errordata.errorcode); + } + browser_window_set_status(bw, message); /* Only warn the user about errors in top-level windows */ if (bw->browser_window_type == BROWSER_WINDOW_NORMAL) { - guit->misc->warning(event->data.error, NULL); + guit->misc->warning(message, NULL); } if (c == bw->loading_content) { @@ -890,7 +857,7 @@ browser_window_callback(hlcache_handle *c, const hlcache_event *event, void *pw) browser_window_stop_throbber(bw); break; - + } case CONTENT_MSG_REDIRECT: if (urldb_add_url(event->data.redirect.from)) urldb_update_url_visit_data(event->data.redirect.from); diff --git a/desktop/searchweb.c b/desktop/searchweb.c index c934ff4fa..de38ef191 100644 --- a/desktop/searchweb.c +++ b/desktop/searchweb.c @@ -298,10 +298,8 @@ search_web_ico_callback(hlcache_handle *ico, case CONTENT_MSG_ERROR: NSLOG(netsurf, INFO, "icon %s error: %s", nsurl_access(hlcache_handle_get_url(ico)), - event->data.error); - /* fall through */ + event->data.errordata.errormsg); - case CONTENT_MSG_ERRORCODE: hlcache_handle_release(ico); /* clear reference to released handle */ provider->ico_handle = NULL; @@ -468,10 +466,8 @@ default_ico_callback(hlcache_handle *ico, case CONTENT_MSG_ERROR: NSLOG(netsurf, INFO, "icon %s error: %s", nsurl_access(hlcache_handle_get_url(ico)), - event->data.error); - /* fall through */ + event->data.errordata.errormsg); - case CONTENT_MSG_ERRORCODE: hlcache_handle_release(ico); /* clear reference to released handle */ ctx->default_ico_handle = NULL; |