From 7ace528729c37d665e269c8a76991739c9437088 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 29 Oct 2014 00:17:11 +0000 Subject: Update url setting API to return nserror code instead of calling warn_user --- desktop/browser.c | 57 ++++++++++++++++++++++++++------------------------- desktop/browser.h | 2 +- desktop/gui_factory.c | 3 ++- desktop/gui_window.h | 2 +- 4 files changed, 33 insertions(+), 31 deletions(-) (limited to 'desktop') diff --git a/desktop/browser.c b/desktop/browser.c index 315859aeb..e6fc2f794 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -769,7 +769,6 @@ nserror browser_window_create(enum browser_window_create_flags flags, if ((ret = calloc(1, sizeof(struct browser_window))) == NULL) { - warn_user("NoMemory", 0); return NSERROR_NOMEM; } @@ -1784,18 +1783,18 @@ static void browser_window_destroy_internal(struct browser_window *bw) * \param bw Browser window to update URL bar for. * \param url URL for content displayed by bw including any fragment. */ -static inline void browser_window_refresh_url_bar_internal( - struct browser_window *bw, nsurl *url) +static inline nserror +browser_window_refresh_url_bar_internal(struct browser_window *bw, nsurl *url) { assert(bw); assert(url); - if (bw->parent != NULL) { - /* Not root window; don't set a URL in GUI URL bar */ - return; + if ((bw->parent != NULL) || (bw->window == NULL)) { + /* Not root window or no gui window so do not set a URL */ + return NSERROR_OK; } - guit->window->set_url(bw->window, nsurl_access(url)); + return guit->window->set_url(bw->window, nsurl_access(url)); } @@ -1811,39 +1810,38 @@ void browser_window_destroy(struct browser_window *bw) } /* exported interface, documented in desktop/browser.h */ -void browser_window_refresh_url_bar(struct browser_window *bw) +nserror browser_window_refresh_url_bar(struct browser_window *bw) { + nserror ret; + nsurl *display_url; + assert(bw); if (bw->parent != NULL) { /* Not root window; don't set a URL in GUI URL bar */ - return; + return NSERROR_OK; } if (bw->current_content == NULL) { - /* TODO: set "about:blank"? */ - return; - } - - if (bw->frag_id == NULL) { - browser_window_refresh_url_bar_internal(bw, + /* no content so return about:blank */ + ret = browser_window_refresh_url_bar_internal(bw, + corestring_nsurl_about_blank); + } else if (bw->frag_id == NULL) { + ret = browser_window_refresh_url_bar_internal(bw, hlcache_handle_get_url(bw->current_content)); } else { - nsurl *display_url; - nserror error; - /* Combine URL and Fragment */ - error = nsurl_refragment( + ret = nsurl_refragment( hlcache_handle_get_url(bw->current_content), bw->frag_id, &display_url); - if (error != NSERROR_OK) { - warn_user("NoMemory", 0); - return; + if (ret == NSERROR_OK) { + ret = browser_window_refresh_url_bar_internal(bw, + display_url); + nsurl_unref(display_url); } - - browser_window_refresh_url_bar_internal(bw, display_url); - nsurl_unref(display_url); } + + return ret; } @@ -1989,11 +1987,13 @@ nserror browser_window_navigate(struct browser_window *bw, case NSERROR_OK: bw->loading_content = c; browser_window_start_throbber(bw); - browser_window_refresh_url_bar_internal(bw, url); + error = browser_window_refresh_url_bar_internal(bw, url); break; case NSERROR_NO_FETCH_HANDLER: /* no handler for this type */ - /** @todo does this always try and download even unverifiable content? */ + /** \todo does this always try and download even + * unverifiable content? + */ error = guit->browser->launch_url(url); break; @@ -2098,7 +2098,8 @@ const char* browser_window_get_title(struct browser_window *bw) return content_get_title(bw->current_content); } - return NULL; + /* no content so return about:blank */ + return nsurl_access(corestring_nsurl_about_blank); } /* Exported interface, documented in browser.h */ diff --git a/desktop/browser.h b/desktop/browser.h index 29a8736d2..5a1d70d7b 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -357,7 +357,7 @@ void browser_window_set_gadget_filename(struct browser_window *bw, * * \param bw Browser window to update URL bar for. */ -void browser_window_refresh_url_bar(struct browser_window *bw); +nserror browser_window_refresh_url_bar(struct browser_window *bw); /** * Handle mouse clicks in a browser window. diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index b69700fca..e26eccb2d 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -42,8 +42,9 @@ static void gui_default_window_set_title(struct gui_window *g, const char *title { } -static void gui_default_window_set_url(struct gui_window *g, const char *url) +static nserror gui_default_window_set_url(struct gui_window *g, const char *url) { + return NSERROR_OK; } static void gui_default_window_start_throbber(struct gui_window *g) diff --git a/desktop/gui_window.h b/desktop/gui_window.h index e503d4b86..38432f567 100644 --- a/desktop/gui_window.h +++ b/desktop/gui_window.h @@ -184,7 +184,7 @@ struct gui_window_table { * \param gw window to update. * \param url The url to use as icon. */ - void (*set_url)(struct gui_window *gw, const char *url); + nserror (*set_url)(struct gui_window *gw, const char *url); /** * Set a favicon for a gui window. -- cgit v1.2.3