summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2019-07-10 16:42:52 +0100
committerVincent Sanders <vince@kyllikki.org>2019-07-10 16:42:52 +0100
commitc2fa6af0ff4098501560bd48f78dfbf9173f4021 (patch)
treeffceab0862b8c5e59c74a5ef26b38e051ec0ce50
parentf46b77160a0244b83ccd486df82ce14f7a4df59e (diff)
downloadnetsurf-c2fa6af0ff4098501560bd48f78dfbf9173f4021.tar.gz
netsurf-c2fa6af0ff4098501560bd48f78dfbf9173f4021.tar.bz2
make content close check the content status itself
make content handler open and close return error status
-rw-r--r--content/content.c103
-rw-r--r--content/content.h4
-rw-r--r--content/content_factory.c5
-rw-r--r--content/content_protected.h4
-rw-r--r--content/handlers/html/html.c8
-rw-r--r--content/handlers/javascript/content.c5
-rw-r--r--content/handlers/text/textplain.c8
-rw-r--r--content/hlcache.h5
8 files changed, 89 insertions, 53 deletions
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);
}
-
diff --git a/content/content.h b/content/content.h
index 2cbc9e3dd..2d0646dab 100644
--- a/content/content.h
+++ b/content/content.h
@@ -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);
diff --git a/content/content_factory.c b/content/content_factory.c
index 935354a5d..44fc333c8 100644
--- a/content/content_factory.c
+++ b/content/content_factory.c
@@ -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>
diff --git a/content/content_protected.h b/content/content_protected.h
index 0101790d1..0358269f2 100644
--- a/content/content_protected.h
+++ b/content/content_protected.h
@@ -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,
diff --git a/content/handlers/html/html.c b/content/handlers/html/html.c
index 57f2e42da..a27ebd79a 100644
--- a/content/handlers/html/html.c
+++ b/content/handlers/html/html.c
@@ -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;
}
diff --git a/content/handlers/javascript/content.c b/content/handlers/javascript/content.c
index ef5614094..2cb5ecd6f 100644
--- a/content/handlers/javascript/content.c
+++ b/content/handlers/javascript/content.c
@@ -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>
diff --git a/content/handlers/text/textplain.c b/content/handlers/text/textplain.c
index 9e9e3e9e0..546301ffd 100644
--- a/content/handlers/text/textplain.c
+++ b/content/handlers/text/textplain.c
@@ -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;
}
diff --git a/content/hlcache.h b/content/hlcache.h
index 3d9f41cdb..986bdd3f4 100644
--- a/content/hlcache.h
+++ b/content/hlcache.h
@@ -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_