From b1ee46cfb3f9617115e313da500d9b08d01ac345 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 29 Oct 2014 22:47:25 +0000 Subject: make adding a history entry return an error code. This returns the error code to the caller instead of (sometimes) warning the user directly. --- desktop/browser.c | 2 +- desktop/browser_history.c | 33 +++++++++++---------------------- desktop/browser_history.h | 12 +++++++++++- 3 files changed, 23 insertions(+), 24 deletions(-) (limited to 'desktop') diff --git a/desktop/browser.c b/desktop/browser.c index a13c2948e..b1c4044c2 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -1332,7 +1332,7 @@ static nserror browser_window_callback(hlcache_handle *c, /* This is safe as we've just added the URL */ global_history_add(urldb_get_url(url)); } - /* TODO: Urldb / Thumbnails / Local history brokenness + /** \todo Urldb / Thumbnails / Local history brokenness * * We add to local history after calling urldb_add_url * rather than in the block above. If urldb_add_url diff --git a/desktop/browser_history.c b/desktop/browser_history.c index 309bcb2b4..f10f3510f 100644 --- a/desktop/browser_history.c +++ b/desktop/browser_history.c @@ -482,18 +482,8 @@ nserror browser_window_history_clone(const struct browser_window *existing, } -/** - * Insert a url into the history tree. - * - * \param bw browser window with history object - * \param content content to add to history - * \param frag_id fragment identifier, or NULL. - * - * The page is added after the current entry and becomes current. - */ - - -void browser_window_history_add(struct browser_window *bw, +/* exported interface documented in desktop/browser_history.h */ +nserror browser_window_history_add(struct browser_window *bw, struct hlcache_handle *content, lwc_string *frag_id) { struct history *history; @@ -510,14 +500,14 @@ void browser_window_history_add(struct browser_window *bw, /* allocate space */ entry = malloc(sizeof *entry); - if (entry == NULL) - return; + if (entry == NULL) { + return NSERROR_NOMEM; + } title = strdup(content_get_title(content)); if (title == NULL) { - warn_user("NoMemory", 0); free(entry); - return; + return NSERROR_NOMEM; } entry->page.url = nsurl_ref(nsurl); @@ -545,16 +535,13 @@ void browser_window_history_add(struct browser_window *bw, /* if we have a thumbnail, don't update until the page has finished * loading */ bitmap = urldb_get_thumbnail(nsurl); - if (!bitmap) { + if (bitmap == NULL) { LOG(("Creating thumbnail for %s", nsurl_access(nsurl))); bitmap = bitmap_create(WIDTH, HEIGHT, BITMAP_NEW | BITMAP_CLEAR_MEMORY | BITMAP_OPAQUE); - if (!bitmap) { - warn_user("NoMemory", 0); - return; - } - if (thumbnail_create(content, bitmap, nsurl) == false) { + if ((bitmap != NULL) && + (thumbnail_create(content, bitmap, nsurl) == false)) { /* Thumbnailing failed. Ignore it silently */ bitmap_destroy(bitmap); bitmap = NULL; @@ -563,6 +550,8 @@ void browser_window_history_add(struct browser_window *bw, entry->bitmap = bitmap; browser_window_history__layout(history); + + return NSERROR_OK; } diff --git a/desktop/browser_history.h b/desktop/browser_history.h index f3e524baf..d7b2b255e 100644 --- a/desktop/browser_history.h +++ b/desktop/browser_history.h @@ -36,7 +36,17 @@ struct redraw_context; nserror browser_window_history_create(struct browser_window *bw); nserror browser_window_history_clone(const struct browser_window *existing, struct browser_window *clone); -void browser_window_history_add(struct browser_window *bw, +/** + * Insert a url into the history tree. + * + * \param bw browser window with history object + * \param content content to add to history + * \param frag_id fragment identifier, or NULL. + * \return NSERROR_OK or error code on faliure. + * + * The page is added after the current entry and becomes current. + */ +nserror browser_window_history_add(struct browser_window *bw, struct hlcache_handle *content, lwc_string *frag_id); void browser_window_history_update(struct browser_window *bw, struct hlcache_handle *content); -- cgit v1.2.3