mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-03 09:44:24 +03:00
Use mutator to modify content's title field.
svn path=/trunk/netsurf/; revision=10231
This commit is contained in:
parent
6835a312b7
commit
49810d8191
@ -1038,6 +1038,20 @@ void content_add_error(struct content *c, const char *token,
|
||||
{
|
||||
}
|
||||
|
||||
bool content__set_title(struct content *c, const char *title)
|
||||
{
|
||||
char *new_title = talloc_strdup(c, title);
|
||||
if (new_title == NULL)
|
||||
return false;
|
||||
|
||||
if (c->title != NULL)
|
||||
talloc_free(c->title);
|
||||
|
||||
c->title = new_title;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve type of content
|
||||
*
|
||||
|
@ -204,6 +204,7 @@ void content_add_error(struct content *c, const char *token,
|
||||
|
||||
void content__reformat(struct content *c, int width, int height);
|
||||
|
||||
bool content__set_title(struct content *c, const char *title);
|
||||
|
||||
content_type content__get_type(struct content *c);
|
||||
const char *content__get_url(struct content *c);
|
||||
|
11
image/bmp.c
11
image/bmp.c
@ -72,6 +72,7 @@ bool nsbmp_convert(struct content *c)
|
||||
uint32_t swidth;
|
||||
const char *data;
|
||||
unsigned long size;
|
||||
char title[100];
|
||||
|
||||
/* set the bmp data */
|
||||
bmp = c->data.bmp.bmp;
|
||||
@ -98,12 +99,11 @@ bool nsbmp_convert(struct content *c)
|
||||
c->width = bmp->width;
|
||||
c->height = bmp->height;
|
||||
LOG(("BMP width %u height %u", c->width, c->height));
|
||||
c->title = malloc(100);
|
||||
if (c->title)
|
||||
snprintf(c->title, 100, messages_get("BMPTitle"), c->width,
|
||||
c->height, size);
|
||||
snprintf(title, sizeof(title), messages_get("BMPTitle"),
|
||||
c->width, c->height, size);
|
||||
content__set_title(c, title);
|
||||
swidth = bmp->bitmap_callbacks.bitmap_get_bpp(bmp->bitmap) * bmp->width;
|
||||
c->size += (swidth * bmp->height) + 16 + 44 + 100;
|
||||
c->size += (swidth * bmp->height) + 16 + 44;
|
||||
|
||||
/* exit as a success */
|
||||
c->bitmap = bmp->bitmap;
|
||||
@ -159,7 +159,6 @@ void nsbmp_destroy(struct content *c)
|
||||
{
|
||||
bmp_finalise(c->data.bmp.bmp);
|
||||
free(c->data.bmp.bmp);
|
||||
free(c->title);
|
||||
}
|
||||
|
||||
|
||||
|
12
image/gif.c
12
image/gif.c
@ -86,6 +86,7 @@ bool nsgif_convert(struct content *c)
|
||||
union content_msg_data msg_data;
|
||||
const char *data;
|
||||
unsigned long size;
|
||||
char title[100];
|
||||
|
||||
/* Get the animation */
|
||||
gif = c->data.gif.gif;
|
||||
@ -123,12 +124,10 @@ bool nsgif_convert(struct content *c)
|
||||
/* Store our content width and description */
|
||||
c->width = gif->width;
|
||||
c->height = gif->height;
|
||||
c->title = malloc(100);
|
||||
if (c->title) {
|
||||
snprintf(c->title, 100, messages_get("GIFTitle"), c->width,
|
||||
c->height, size);
|
||||
}
|
||||
c->size += (gif->width * gif->height * 4) + 16 + 44 + 100;
|
||||
snprintf(title, sizeof(title), messages_get("GIFTitle"),
|
||||
c->width, c->height, size);
|
||||
content__set_title(c, title);
|
||||
c->size += (gif->width * gif->height * 4) + 16 + 44;
|
||||
|
||||
/* Schedule the animation if we have one */
|
||||
c->data.gif.current_frame = 0;
|
||||
@ -195,7 +194,6 @@ void nsgif_destroy(struct content *c)
|
||||
schedule_remove(nsgif_animate, c);
|
||||
gif_finalise(c->data.gif.gif);
|
||||
free(c->data.gif.gif);
|
||||
free(c->title);
|
||||
}
|
||||
|
||||
|
||||
|
11
image/ico.c
11
image/ico.c
@ -60,6 +60,7 @@ bool nsico_convert(struct content *c)
|
||||
union content_msg_data msg_data;
|
||||
const char *data;
|
||||
unsigned long size;
|
||||
char title[100];
|
||||
|
||||
/* set the ico data */
|
||||
ico = c->data.ico.ico;
|
||||
@ -86,11 +87,10 @@ bool nsico_convert(struct content *c)
|
||||
/* Store our content width and description */
|
||||
c->width = ico->width;
|
||||
c->height = ico->height;
|
||||
c->title = malloc(100);
|
||||
if (c->title)
|
||||
snprintf(c->title, 100, messages_get("ICOTitle"), c->width,
|
||||
c->height, size);
|
||||
c->size += (ico->width * ico->height * 4) + 16 + 44 + 100;
|
||||
snprintf(title, sizeof(title), messages_get("ICOTitle"),
|
||||
c->width, c->height, size);
|
||||
content__set_title(c, title);
|
||||
c->size += (ico->width * ico->height * 4) + 16 + 44;
|
||||
|
||||
/* exit as a success */
|
||||
bmp = ico_find(c->data.ico.ico, 255, 255);
|
||||
@ -167,7 +167,6 @@ void nsico_destroy(struct content *c)
|
||||
{
|
||||
ico_finalise(c->data.ico.ico);
|
||||
free(c->data.ico.ico);
|
||||
free(c->title);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -91,6 +91,7 @@ bool nsjpeg_convert(struct content *c)
|
||||
union content_msg_data msg_data;
|
||||
const char *data;
|
||||
unsigned long size;
|
||||
char title[100];
|
||||
|
||||
data = content__get_source_data(c, &size);
|
||||
|
||||
@ -162,11 +163,10 @@ bool nsjpeg_convert(struct content *c)
|
||||
c->width = width;
|
||||
c->height = height;
|
||||
c->bitmap = bitmap;
|
||||
c->title = malloc(100);
|
||||
if (c->title)
|
||||
snprintf(c->title, 100, messages_get("JPEGTitle"),
|
||||
snprintf(title, sizeof(title), messages_get("JPEGTitle"),
|
||||
width, height, size);
|
||||
c->size += height * rowstride + 100;
|
||||
content__set_title(c, title);
|
||||
c->size += height * rowstride;
|
||||
c->status = CONTENT_STATUS_DONE;
|
||||
/* Done: update status bar */
|
||||
content_set_status(c, "");
|
||||
@ -284,7 +284,6 @@ void nsjpeg_destroy(struct content *c)
|
||||
{
|
||||
if (c->bitmap)
|
||||
bitmap_destroy(c->bitmap);
|
||||
free(c->title);
|
||||
}
|
||||
|
||||
#endif /* WITH_JPEG */
|
||||
|
21
image/mng.c
21
image/mng.c
@ -302,10 +302,9 @@ bool nsmng_process_data(struct content *c, char *data, unsigned int size)
|
||||
bool nsmng_convert(struct content *c)
|
||||
{
|
||||
mng_retcode status;
|
||||
|
||||
union content_msg_data msg_data;
|
||||
const char *data;
|
||||
unsigned long size;
|
||||
char title[100];
|
||||
|
||||
assert(c != NULL);
|
||||
|
||||
@ -319,25 +318,19 @@ bool nsmng_convert(struct content *c)
|
||||
|
||||
/* Set the title
|
||||
*/
|
||||
c->title = malloc(100);
|
||||
if (!c->title) {
|
||||
msg_data.error = messages_get("NoMemory");
|
||||
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (c->type == CONTENT_MNG) {
|
||||
snprintf(c->title, 100, messages_get("MNGTitle"),
|
||||
snprintf(title, sizeof(title), messages_get("MNGTitle"),
|
||||
c->width, c->height, size);
|
||||
} else if (c->type == CONTENT_PNG) {
|
||||
snprintf(c->title, 100, messages_get("PNGTitle"),
|
||||
snprintf(title, sizeof(title), messages_get("PNGTitle"),
|
||||
c->width, c->height, size);
|
||||
} else {
|
||||
snprintf(c->title, 100, messages_get("JNGTitle"),
|
||||
snprintf(title, sizeof(title), messages_get("JNGTitle"),
|
||||
c->width, c->height, size);
|
||||
}
|
||||
content__set_title(c, title);
|
||||
|
||||
c->size += c->width * c->height * 4 + 100;
|
||||
c->size += c->width * c->height * 4;
|
||||
c->status = CONTENT_STATUS_DONE;
|
||||
/* Done: update status bar */
|
||||
content_set_status(c, "");
|
||||
@ -528,8 +521,6 @@ void nsmng_destroy(struct content *c)
|
||||
|
||||
if (c->bitmap)
|
||||
bitmap_destroy(c->bitmap);
|
||||
|
||||
free(c->title);
|
||||
}
|
||||
|
||||
|
||||
|
14
image/png.c
14
image/png.c
@ -51,9 +51,6 @@
|
||||
#define png_set_expand_gray_1_2_4_to_8(png) png_set_gray_1_2_4_to_8(png)
|
||||
#endif
|
||||
|
||||
/* I hate doing this, but without g_strdup_printf or similar, we're a tad stuck. */
|
||||
#define NSPNG_TITLE_LEN (100)
|
||||
|
||||
/* libpng uses names starting png_, so use nspng_ here to avoid clashes */
|
||||
|
||||
static void info_callback(png_structp png, png_infop info);
|
||||
@ -265,6 +262,7 @@ bool nspng_convert(struct content *c)
|
||||
{
|
||||
const char *data;
|
||||
unsigned long size;
|
||||
char title[100];
|
||||
|
||||
assert(c->data.png.png != NULL);
|
||||
assert(c->data.png.info != NULL);
|
||||
@ -273,14 +271,11 @@ bool nspng_convert(struct content *c)
|
||||
|
||||
png_destroy_read_struct(&c->data.png.png, &c->data.png.info, 0);
|
||||
|
||||
c->title = malloc(NSPNG_TITLE_LEN);
|
||||
|
||||
if (c->title != NULL) {
|
||||
snprintf(c->title, NSPNG_TITLE_LEN, messages_get("PNGTitle"),
|
||||
snprintf(title, sizeof(title), messages_get("PNGTitle"),
|
||||
c->width, c->height, size);
|
||||
}
|
||||
content__set_title(c, title);
|
||||
|
||||
c->size += (c->width * c->height * 4) + NSPNG_TITLE_LEN;
|
||||
c->size += (c->width * c->height * 4);
|
||||
|
||||
assert(c->data.png.bitmap != NULL);
|
||||
|
||||
@ -296,7 +291,6 @@ bool nspng_convert(struct content *c)
|
||||
|
||||
void nspng_destroy(struct content *c)
|
||||
{
|
||||
free(c->title);
|
||||
if (c->data.png.bitmap != NULL) {
|
||||
bitmap_destroy(c->data.png.bitmap);
|
||||
}
|
||||
|
@ -510,14 +510,12 @@ bool html_head(struct content *c, xmlNode *head)
|
||||
xmlNode *node;
|
||||
xmlChar *s;
|
||||
|
||||
c->title = 0;
|
||||
|
||||
for (node = head->children; node != 0; node = node->next) {
|
||||
if (node->type != XML_ELEMENT_NODE)
|
||||
continue;
|
||||
|
||||
LOG(("Node: %s", node->name));
|
||||
if (!c->title && strcmp((const char *) node->name,
|
||||
if (c->title == NULL && strcmp((const char *) node->name,
|
||||
"title") == 0) {
|
||||
xmlChar *title = xmlNodeGetContent(node);
|
||||
char *title2;
|
||||
@ -527,10 +525,12 @@ bool html_head(struct content *c, xmlNode *head)
|
||||
xmlFree(title);
|
||||
if (!title2)
|
||||
return false;
|
||||
c->title = talloc_strdup(c, title2);
|
||||
if (content__set_title(c, title2) == false) {
|
||||
free(title2);
|
||||
if (!c->title)
|
||||
return false;
|
||||
}
|
||||
|
||||
free(title2);
|
||||
|
||||
} else if (strcmp((const char *) node->name, "base") == 0) {
|
||||
char *href = (char *) xmlGetProp(node,
|
||||
|
Loading…
Reference in New Issue
Block a user