make content close check the content status itself

make content handler open and close return error status
This commit is contained in:
Vincent Sanders 2019-07-10 16:42:52 +01:00
parent f46b77160a
commit c2fa6af0ff
8 changed files with 89 additions and 53 deletions

View File

@ -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);
}

View File

@ -278,10 +278,10 @@ void content_mouse_action(struct hlcache_handle *h, struct browser_window *bw,
bool content_keypress(struct hlcache_handle *h, uint32_t key);
void content_open(struct hlcache_handle *h, struct browser_window *bw,
nserror content_open(struct hlcache_handle *h, struct browser_window *bw,
struct content *page, struct object_params *params);
void content_close(struct hlcache_handle *h);
nserror content_close(struct hlcache_handle *h);
void content_clear_selection(struct hlcache_handle *h);

View File

@ -16,8 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
* Content factory (implementation)
/**
* \file
* Content factory implementation
*/
#include <assert.h>

View File

@ -60,9 +60,9 @@ struct content_handler {
bool (*redraw)(struct content *c, struct content_redraw_data *data,
const struct rect *clip,
const struct redraw_context *ctx);
void (*open)(struct content *c, struct browser_window *bw,
nserror (*open)(struct content *c, struct browser_window *bw,
struct content *page, struct object_params *params);
void (*close)(struct content *c);
nserror (*close)(struct content *c);
void (*clear_selection)(struct content *c);
char * (*get_selection)(struct content *c);
nserror (*get_contextual_content)(struct content *c, int x, int y,

View File

@ -1774,7 +1774,7 @@ static nserror html_clone(const struct content *old, struct content **newc)
* Handle a window containing a CONTENT_HTML being opened.
*/
static void
static nserror
html_open(struct content *c,
struct browser_window *bw,
struct content *page,
@ -1794,6 +1794,8 @@ html_open(struct content *c,
html->selection_owner.none = true;
html_object_open_objects(html, bw);
return NSERROR_OK;
}
@ -1801,7 +1803,7 @@ html_open(struct content *c,
* Handle a window containing a CONTENT_HTML being closed.
*/
static void html_close(struct content *c)
static nserror html_close(struct content *c)
{
html_content *htmlc = (html_content *) c;
@ -1822,6 +1824,8 @@ static void html_close(struct content *c)
/* remove all object references from the html content */
html_object_close_objects(htmlc);
return NSERROR_OK;
}

View File

@ -16,8 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
* Content for javascript (implementation)
/**
* \file
* javascript content implementation
*/
#include <assert.h>

View File

@ -1204,7 +1204,7 @@ textplain_redraw(struct content *c,
/**
* Handle a window containing a CONTENT_TEXTPLAIN being opened.
*/
static void
static nserror
textplain_open(struct content *c,
struct browser_window *bw,
struct content *page,
@ -1216,13 +1216,15 @@ textplain_open(struct content *c,
/* text selection */
selection_init(&text->sel, NULL, NULL);
return NSERROR_OK;
}
/**
* Handle a window containing a CONTENT_TEXTPLAIN being closed.
*/
static void textplain_close(struct content *c)
static nserror textplain_close(struct content *c)
{
textplain_content *text = (textplain_content *) c;
@ -1231,6 +1233,8 @@ static void textplain_close(struct content *c)
}
text->bw = NULL;
return NSERROR_OK;
}

View File

@ -16,8 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
* High-level resource cache (interface)
/**
* \file
* High-level resource cache interface
*/
#ifndef NETSURF_CONTENT_HLCACHE_H_