From d70beb28db6f978ae9fc674640f3101e20c05bb8 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 26 Aug 2017 15:50:03 +0100 Subject: Content API: Make content_broadcast take pointer to content_msg_data. --- content/content.c | 32 +++++++++++++++++--------------- content/content_protected.h | 2 +- content/handlers/css/css.c | 8 ++++---- content/handlers/image/bmp.c | 6 +++--- content/handlers/image/gif.c | 8 ++++---- content/handlers/image/ico.c | 6 +++--- content/handlers/image/jpeg.c | 2 +- content/handlers/image/nssprite.c | 4 ++-- content/handlers/image/png.c | 8 ++++---- content/handlers/image/rsvg.c | 12 ++++++------ content/handlers/image/svg.c | 2 +- 11 files changed, 46 insertions(+), 44 deletions(-) (limited to 'content') diff --git a/content/content.c b/content/content.c index 7a8bb013f..b53d2cb52 100644 --- a/content/content.c +++ b/content/content.c @@ -163,7 +163,7 @@ nserror content_llcache_callback(llcache_handle *llcache, content_set_status(c, messages_get("Processing")); msg_data.explicit_status_text = NULL; - content_broadcast(c, CONTENT_MSG_STATUS, msg_data); + content_broadcast(c, CONTENT_MSG_STATUS, &msg_data); content_convert(c); } @@ -172,17 +172,17 @@ nserror content_llcache_callback(llcache_handle *llcache, /** \todo Error page? */ c->status = CONTENT_STATUS_ERROR; msg_data.error = event->data.msg; - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); break; case LLCACHE_EVENT_PROGRESS: content_set_status(c, event->data.msg); msg_data.explicit_status_text = NULL; - content_broadcast(c, CONTENT_MSG_STATUS, msg_data); + content_broadcast(c, CONTENT_MSG_STATUS, &msg_data); break; case LLCACHE_EVENT_REDIRECT: msg_data.redirect.from = event->data.redirect.from; msg_data.redirect.to = event->data.redirect.to; - content_broadcast(c, CONTENT_MSG_REDIRECT, msg_data); + content_broadcast(c, CONTENT_MSG_REDIRECT, &msg_data); break; } @@ -292,8 +292,6 @@ void content_convert(struct content *c) void content_set_ready(struct content *c) { - union content_msg_data msg_data; - /* The content must be locked at this point, as it can only * become READY after conversion. */ assert(c->locked); @@ -301,7 +299,7 @@ void content_set_ready(struct content *c) c->status = CONTENT_STATUS_READY; content_update_status(c); - content_broadcast(c, CONTENT_MSG_READY, msg_data); + content_broadcast(c, CONTENT_MSG_READY, NULL); } /** @@ -310,7 +308,6 @@ void content_set_ready(struct content *c) void content_set_done(struct content *c) { - union content_msg_data msg_data; uint64_t now_ms; nsu_getmonotonic_ms(&now_ms); @@ -318,7 +315,7 @@ void content_set_done(struct content *c) c->status = CONTENT_STATUS_DONE; c->time = now_ms - c->time; content_update_status(c); - content_broadcast(c, CONTENT_MSG_DONE, msg_data); + content_broadcast(c, CONTENT_MSG_DONE, NULL); } /** @@ -363,7 +360,7 @@ void content__reformat(struct content *c, bool background, c->locked = false; data.background = background; - content_broadcast(c, CONTENT_MSG_REFORMAT, data); + content_broadcast(c, CONTENT_MSG_REFORMAT, &data); } } @@ -436,7 +433,7 @@ void content_mouse_track(hlcache_handle *h, struct browser_window *bw, } else { union content_msg_data msg_data; msg_data.pointer = BROWSER_POINTER_AUTO; - content_broadcast(c, CONTENT_MSG_POINTER, msg_data); + content_broadcast(c, CONTENT_MSG_POINTER, &msg_data); } @@ -540,7 +537,7 @@ void content__request_redraw(struct content *c, data.redraw.object_width = c->width; data.redraw.object_height = c->height; - content_broadcast(c, CONTENT_MSG_REDRAW, data); + content_broadcast(c, CONTENT_MSG_REDRAW, &data); } @@ -753,15 +750,20 @@ bool content_is_shareable(struct content *c) */ void content_broadcast(struct content *c, content_msg msg, - union content_msg_data data) + const union content_msg_data *data) { struct content_user *user, *next; + union content_msg_data d = { 0 }; assert(c); + + if (data != NULL) { + d = *data; + } // LOG("%p -> msg:%d", c, msg); 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, msg, data, user->pw); + user->callback(c, msg, d, user->pw); } } @@ -1040,7 +1042,7 @@ bool content__add_rfc5988_link(struct content *c, /* broadcast the data */ msg_data.rfc5988_link = newlink; - content_broadcast(c, CONTENT_MSG_LINK, msg_data); + content_broadcast(c, CONTENT_MSG_LINK, &msg_data); return true; } diff --git a/content/content_protected.h b/content/content_protected.h index ef38cb12d..fe4fcdade 100644 --- a/content/content_protected.h +++ b/content/content_protected.h @@ -166,7 +166,7 @@ void content_set_error(struct content *c); void content_set_status(struct content *c, const char *status_message); void content_broadcast(struct content *c, content_msg msg, - union content_msg_data data); + const union content_msg_data *data); /** * Send an errorcode message to all users. */ diff --git a/content/handlers/css/css.c b/content/handlers/css/css.c index 997eb5115..a665fbdc4 100644 --- a/content/handlers/css/css.c +++ b/content/handlers/css/css.c @@ -172,7 +172,7 @@ nscss_create(const content_handler *handler, nscss_content_done, result); if (error != NSERROR_OK) { msg_data.error = messages_get("NoMemory"); - content_broadcast(&result->base, CONTENT_MSG_ERROR, msg_data); + content_broadcast(&result->base, CONTENT_MSG_ERROR, &msg_data); if (charset_value != NULL) lwc_string_unref(charset_value); free(result); @@ -256,7 +256,7 @@ bool nscss_process_data(struct content *c, const char *data, unsigned int size) error = nscss_process_css_data(&css->data, data, size); if (error != CSS_OK && error != CSS_NEEDDATA) { msg_data.error = "?"; - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); } return (error == CSS_OK || error == CSS_NEEDDATA); @@ -292,7 +292,7 @@ bool nscss_convert(struct content *c) error = nscss_convert_css_data(&css->data); if (error != CSS_OK) { msg_data.error = "?"; - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); return false; } @@ -485,7 +485,7 @@ void nscss_content_done(struct content_css_data *css, void *pw) error = css_stylesheet_size(css->sheet, &size); if (error != CSS_OK) { msg_data.error = "?"; - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); content_set_error(c); return; } diff --git a/content/handlers/image/bmp.c b/content/handlers/image/bmp.c index 271787449..47c1d0845 100644 --- a/content/handlers/image/bmp.c +++ b/content/handlers/image/bmp.c @@ -80,7 +80,7 @@ static nserror nsbmp_create_bmp_data(nsbmp_content *bmp) bmp->bmp = calloc(sizeof(struct bmp_image), 1); if (bmp->bmp == NULL) { msg_data.error = messages_get("NoMemory"); - content_broadcast(&bmp->base, CONTENT_MSG_ERROR, msg_data); + content_broadcast(&bmp->base, CONTENT_MSG_ERROR, &msg_data); return NSERROR_NOMEM; } @@ -139,12 +139,12 @@ static bool nsbmp_convert(struct content *c) break; case BMP_INSUFFICIENT_MEMORY: msg_data.error = messages_get("NoMemory"); - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); return false; case BMP_INSUFFICIENT_DATA: case BMP_DATA_ERROR: msg_data.error = messages_get("BadBMP"); - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); return false; } diff --git a/content/handlers/image/gif.c b/content/handlers/image/gif.c index c4f039490..9184f31ce 100644 --- a/content/handlers/image/gif.c +++ b/content/handlers/image/gif.c @@ -86,7 +86,7 @@ static nserror nsgif_create_gif_data(nsgif_content *c) c->gif = calloc(sizeof(gif_animation), 1); if (c->gif == NULL) { msg_data.error = messages_get("NoMemory"); - content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data); + content_broadcast(&c->base, CONTENT_MSG_ERROR, &msg_data); return NSERROR_NOMEM; } gif_create(c->gif, &gif_bitmap_callbacks); @@ -231,7 +231,7 @@ static void nsgif_animate(void *p) data.redraw.object_width = gif->base.width; data.redraw.object_height = gif->base.height; - content_broadcast(&gif->base, CONTENT_MSG_REDRAW, data); + content_broadcast(&gif->base, CONTENT_MSG_REDRAW, &data); } static bool nsgif_convert(struct content *c) @@ -261,7 +261,7 @@ static bool nsgif_convert(struct content *c) msg_data.error = messages_get("NoMemory"); break; } - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); return false; } } while (res != GIF_OK && res != GIF_INSUFFICIENT_FRAME_DATA); @@ -270,7 +270,7 @@ static bool nsgif_convert(struct content *c) if ((gif->gif->frame_count_partial == 0) || (gif->gif->width == 0) || (gif->gif->height == 0)) { msg_data.error = messages_get("BadGIF"); - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); return false; } diff --git a/content/handlers/image/ico.c b/content/handlers/image/ico.c index b14ea7fe1..180b20d7e 100644 --- a/content/handlers/image/ico.c +++ b/content/handlers/image/ico.c @@ -77,7 +77,7 @@ static nserror nsico_create_ico_data(nsico_content *c) c->ico = calloc(sizeof(ico_collection), 1); if (c->ico == NULL) { msg_data.error = messages_get("NoMemory"); - content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data); + content_broadcast(&c->base, CONTENT_MSG_ERROR, &msg_data); return NSERROR_NOMEM; } ico_collection_create(c->ico, &bmp_bitmap_callbacks); @@ -138,12 +138,12 @@ static bool nsico_convert(struct content *c) break; case BMP_INSUFFICIENT_MEMORY: msg_data.error = messages_get("NoMemory"); - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); return false; case BMP_INSUFFICIENT_DATA: case BMP_DATA_ERROR: msg_data.error = messages_get("BadICO"); - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); return false; } diff --git a/content/handlers/image/jpeg.c b/content/handlers/image/jpeg.c index 5ae9e70cd..c5aca1c9b 100644 --- a/content/handlers/image/jpeg.c +++ b/content/handlers/image/jpeg.c @@ -301,7 +301,7 @@ static bool nsjpeg_convert(struct content *c) jpeg_destroy_decompress(&cinfo); msg_data.error = nsjpeg_error_buffer; - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); return false; } diff --git a/content/handlers/image/nssprite.c b/content/handlers/image/nssprite.c index 247574aa4..ab48978e9 100644 --- a/content/handlers/image/nssprite.c +++ b/content/handlers/image/nssprite.c @@ -119,13 +119,13 @@ static bool nssprite_convert(struct content *c) nssprite->bitmap = guit->bitmap->create(sprite->width, sprite->height, BITMAP_NEW); if (!nssprite->bitmap) { msg_data.error = messages_get("NoMemory"); - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); return false; } uint32_t* imagebuf = (uint32_t *)guit->bitmap->get_buffer(nssprite->bitmap); if (!imagebuf) { msg_data.error = messages_get("NoMemory"); - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); return false; } unsigned char *spritebuf = (unsigned char *)sprite->image; diff --git a/content/handlers/image/png.c b/content/handlers/image/png.c index 0baf411bf..136fd8f73 100644 --- a/content/handlers/image/png.c +++ b/content/handlers/image/png.c @@ -247,7 +247,7 @@ static nserror nspng_create_png_data(nspng_content *png_c) png_c->png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); if (png_c->png == NULL) { msg_data.error = messages_get("NoMemory"); - content_broadcast(&png_c->base, CONTENT_MSG_ERROR, msg_data); + content_broadcast(&png_c->base, CONTENT_MSG_ERROR, &msg_data); return NSERROR_NOMEM; } @@ -258,7 +258,7 @@ static nserror nspng_create_png_data(nspng_content *png_c) png_destroy_read_struct(&png_c->png, &png_c->info, 0); msg_data.error = messages_get("NoMemory"); - content_broadcast(&png_c->base, CONTENT_MSG_ERROR, msg_data); + content_broadcast(&png_c->base, CONTENT_MSG_ERROR, &msg_data); return NSERROR_NOMEM; } @@ -269,7 +269,7 @@ static nserror nspng_create_png_data(nspng_content *png_c) png_c->info = NULL; msg_data.error = messages_get("PNGError"); - content_broadcast(&png_c->base, CONTENT_MSG_ERROR, msg_data); + content_broadcast(&png_c->base, CONTENT_MSG_ERROR, &msg_data); return NSERROR_NOMEM; } @@ -363,7 +363,7 @@ static bool nspng_process_data(struct content *c, const char *data, png_c->info = NULL; msg_data.error = messages_get("PNGError"); - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); ret = false; diff --git a/content/handlers/image/rsvg.c b/content/handlers/image/rsvg.c index 0665f217f..24819df57 100644 --- a/content/handlers/image/rsvg.c +++ b/content/handlers/image/rsvg.c @@ -72,7 +72,7 @@ static nserror rsvg_create_svg_data(rsvg_content *c) if ((c->rsvgh = rsvg_handle_new()) == NULL) { LOG("rsvg_handle_new() returned NULL."); msg_data.error = messages_get("NoMemory"); - content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data); + content_broadcast(&c->base, CONTENT_MSG_ERROR, &msg_data); return NSERROR_NOMEM; } @@ -122,7 +122,7 @@ static bool rsvg_process_data(struct content *c, const char *data, &err) == FALSE) { LOG("rsvg_handle_write returned an error: %s", err->message); msg_data.error = err->message; - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); return false; } @@ -168,7 +168,7 @@ static bool rsvg_convert(struct content *c) if (rsvg_handle_close(d->rsvgh, &err) == FALSE) { LOG("rsvg_handle_close returned an error: %s", err->message); msg_data.error = err->message; - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); return false; } @@ -186,7 +186,7 @@ static bool rsvg_convert(struct content *c) BITMAP_NEW)) == NULL) { LOG("Failed to create bitmap for rsvg render."); msg_data.error = messages_get("NoMemory"); - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); return false; } @@ -197,14 +197,14 @@ static bool rsvg_convert(struct content *c) guit->bitmap->get_rowstride(d->bitmap))) == NULL) { LOG("Failed to create Cairo image surface for rsvg render."); msg_data.error = messages_get("NoMemory"); - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); return false; } if ((d->ct = cairo_create(d->cs)) == NULL) { LOG("Failed to create Cairo drawing context for rsvg render."); msg_data.error = messages_get("NoMemory"); - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + content_broadcast(c, CONTENT_MSG_ERROR, &msg_data); return false; } diff --git a/content/handlers/image/svg.c b/content/handlers/image/svg.c index b34c6b7bb..f31ee1f8d 100644 --- a/content/handlers/image/svg.c +++ b/content/handlers/image/svg.c @@ -62,7 +62,7 @@ static nserror svg_create_svg_data(svg_content *c) no_memory: msg_data.error = messages_get("NoMemory"); - content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data); + content_broadcast(&c->base, CONTENT_MSG_ERROR, &msg_data); return NSERROR_NOMEM; } -- cgit v1.2.3