From c2fa6af0ff4098501560bd48f78dfbf9173f4021 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 10 Jul 2019 16:42:52 +0100 Subject: make content close check the content status itself make content handler open and close return error status --- content/content.c | 103 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 39 deletions(-) (limited to 'content/content.c') diff --git a/content/content.c b/content/content.c index 3a5628096..f5303400d 100644 --- a/content/content.c +++ b/content/content.c @@ -67,12 +67,12 @@ static void content_convert(struct content *c); nserror content__init(struct content *c, const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, - llcache_handle *llcache, const char *fallback_charset, + llcache_handle *llcache, const char *fallback_charset, bool quirks) { struct content_user *user_sentinel; nserror error; - + NSLOG(netsurf, INFO, "url "URL_FMT_SPC" -> %p", nsurl_access_log(llcache_handle_get_url(llcache)), c); @@ -116,7 +116,7 @@ nserror content__init(struct content *c, const content_handler *handler, content_set_status(c, messages_get("Loading")); /* Finally, claim low-level cache events */ - error = llcache_handle_change_callback(llcache, + error = llcache_handle_change_callback(llcache, content_llcache_callback, c); if (error != NSERROR_OK) { lwc_string_unref(c->mime_type); @@ -147,8 +147,8 @@ nserror content_llcache_callback(llcache_handle *llcache, break; case LLCACHE_EVENT_HAD_DATA: if (c->handler->process_data != NULL) { - if (c->handler->process_data(c, - (const char *) event->data.data.buf, + if (c->handler->process_data(c, + (const char *) event->data.data.buf, event->data.data.len) == false) { llcache_handle_abort(c->llcache); c->status = CONTENT_STATUS_ERROR; @@ -273,7 +273,7 @@ void content_convert(struct content *c) if (c->locked == true) return; - + NSLOG(netsurf, INFO, "content "URL_FMT_SPC" (%p)", nsurl_access_log(llcache_handle_get_url(c->llcache)), c); @@ -295,7 +295,7 @@ void content_convert(struct content *c) void content_set_ready(struct content *c) { - /* The content must be locked at this point, as it can only + /* The content must be locked at this point, as it can only * become READY after conversion. */ assert(c->locked); c->locked = false; @@ -549,21 +549,21 @@ void content__request_redraw(struct content *c, bool content_exec(struct hlcache_handle *h, const char *src, size_t srclen) { struct content *c = hlcache_handle_get_content(h); - + assert(c != NULL); - + if (c->locked) { /* Not safe to do stuff */ NSLOG(netsurf, DEEPDEBUG, "Unable to exec, content locked"); return false; } - + if (c->handler->exec == NULL) { /* Can't exec something on this content */ NSLOG(netsurf, DEEPDEBUG, "Unable to exec, no exec function"); return false; } - + return c->handler->exec(c, src, srclen); } @@ -748,7 +748,7 @@ uint32_t content_count_users(struct content *c) uint32_t counter = 0; assert(c != NULL); - + for (user = c->user_list; user != NULL; user = user->next) counter += 1; @@ -826,22 +826,32 @@ void content_broadcast_errorcode(struct content *c, nserror errorcode) * * \param h handle to content that has been opened * \param bw browser window containing the content - * \param page content of type CONTENT_HTML containing h, or 0 if not an + * \param page content of type CONTENT_HTML containing h, or NULL if not an * object within a page - * \param params object parameters, or 0 if not an object + * \param params object parameters, or NULL if not an object * * Calls the open function for the content. */ -void content_open(hlcache_handle *h, struct browser_window *bw, - struct content *page, struct object_params *params) +nserror +content_open(hlcache_handle *h, + struct browser_window *bw, + struct content *page, + struct object_params *params) { - struct content *c = hlcache_handle_get_content(h); + struct content *c; + nserror res; + + c = hlcache_handle_get_content(h); assert(c != 0); NSLOG(netsurf, INFO, "content %p %s", c, nsurl_access_log(llcache_handle_get_url(c->llcache))); - if (c->handler->open != NULL) - c->handler->open(c, bw, page, params); + if (c->handler->open != NULL) { + res = c->handler->open(c, bw, page, params); + } else { + res = NSERROR_OK; + } + return res; } @@ -851,14 +861,30 @@ void content_open(hlcache_handle *h, struct browser_window *bw, * Calls the close function for the content. */ -void content_close(hlcache_handle *h) +nserror content_close(hlcache_handle *h) { - struct content *c = hlcache_handle_get_content(h); - assert(c != 0); + struct content *c; + nserror res; + + c = hlcache_handle_get_content(h); + if (c == NULL) { + return NSERROR_BAD_PARAMETER; + } + + if ((c->status != CONTENT_STATUS_READY) && + (c->status != CONTENT_STATUS_DONE)) { + /* status is not read or done so nothing to do */ + return NSERROR_INVALID; + } + NSLOG(netsurf, INFO, "content %p %s", c, nsurl_access_log(llcache_handle_get_url(c->llcache))); - if (c->handler->close != NULL) - c->handler->close(c); + if (c->handler->close != NULL) { + res = c->handler->close(c); + } else { + res = NSERROR_OK; + } + return res; } @@ -1012,7 +1038,7 @@ content_find_rfc5988_link(hlcache_handle *h, lwc_string *rel) } struct content_rfc5988_link * -content__free_rfc5988_link(struct content_rfc5988_link *link) +content__free_rfc5988_link(struct content_rfc5988_link *link) { struct content_rfc5988_link *next; @@ -1037,10 +1063,10 @@ content__free_rfc5988_link(struct content_rfc5988_link *link) return next; } -bool content__add_rfc5988_link(struct content *c, +bool content__add_rfc5988_link(struct content *c, const struct content_rfc5988_link *link) { - struct content_rfc5988_link *newlink; + struct content_rfc5988_link *newlink; union content_msg_data msg_data; /* a link relation must be present for it to be a link */ @@ -1055,7 +1081,7 @@ bool content__add_rfc5988_link(struct content *c, newlink = calloc(1, sizeof(struct content_rfc5988_link)); if (newlink == NULL) { - return false; + return false; } /* copy values */ @@ -1300,9 +1326,9 @@ struct bitmap *content__get_bitmap(struct content *c) { struct bitmap *bitmap = NULL; - if ((c != NULL) && - (c->handler != NULL) && - (c->handler->type != NULL) && + if ((c != NULL) && + (c->handler != NULL) && + (c->handler->type != NULL) && (c->handler->type() == CONTENT_IMAGE) && (c->handler->get_internal != NULL) ) { bitmap = c->handler->get_internal(c, NULL); @@ -1324,14 +1350,14 @@ bool content__get_opaque(struct content *c) { bool opaque = false; - if ((c != NULL) && - (c->handler != NULL) && - (c->handler->type != NULL) && + if ((c != NULL) && + (c->handler != NULL) && + (c->handler->type != NULL) && (c->handler->type() == CONTENT_IMAGE) && (c->handler->get_internal != NULL) ) { struct bitmap *bitmap = NULL; bitmap = c->handler->get_internal(c, NULL); - if (bitmap != NULL) { + if (bitmap != NULL) { opaque = guit->bitmap->get_opaque(bitmap); } } @@ -1486,7 +1512,7 @@ nserror content__clone(const struct content *c, struct content *nc) nc->locked = c->locked; nc->total_size = c->total_size; nc->http_code = c->http_code; - + return NSERROR_OK; } @@ -1499,11 +1525,10 @@ nserror content__clone(const struct content *c, struct content *nc) nserror content_abort(struct content *c) { NSLOG(netsurf, INFO, "Aborting %p", c); - + if (c->handler->stop != NULL) c->handler->stop(c); - + /* And for now, abort our llcache object */ return llcache_handle_abort(c->llcache); } - -- cgit v1.2.3