browser_window: Ensure that back works like 'back to safety'

Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
This commit is contained in:
Daniel Silverstone 2019-08-21 20:33:52 +01:00
parent 6bce06b91f
commit b67bbe3280
3 changed files with 59 additions and 18 deletions

View File

@ -37,6 +37,7 @@
#include "content/hlcache.h"
#include "content/urldb.h"
#include "netsurf/bitmap.h"
#include "utils/corestrings.h"
#include "desktop/gui_internal.h"
#include "desktop/browser_private.h"
@ -519,6 +520,24 @@ void browser_window_history_destroy(struct browser_window *bw)
/* exported interface documented in desktop/browser_history.h */
nserror browser_window_history_back(struct browser_window *bw, bool new_window)
{
if (bw != NULL && bw->internal_nav) {
/* All internal nav back operations ignore new_window */
if (bw->current_parameters.url != NULL) {
/* There are some internal parameters, restart from there */
return browser_window__reload_current_parameters(bw);
} else {
/* No internal parameters, just navigate to about:blank */
return browser_window_navigate(
bw,
corestring_nsurl_about_blank,
NULL, /* Referer */
BW_NAVIGATE_HISTORY,
NULL, /* Post */
NULL, /* Post */
NULL /* parent fetch */);
}
}
if (!bw || !bw->history || !bw->history->current ||
!bw->history->current->back) {
return NSERROR_BAD_PARAMETER;

View File

@ -408,4 +408,11 @@ void browser_window_history_destroy(struct browser_window *bw);
*/
typedef nserror (*browser_window_query_callback)(bool proceed, void *pw);
/**
* Navigate a browser window to the current parameters
*
* \param bw The browser window to cause to navigate
*/
nserror browser_window__reload_current_parameters(struct browser_window *bw);
#endif

View File

@ -864,23 +864,7 @@ browser_window__handle_ssl_query_response(bool proceed, void *pw)
* nav to the old 'current' parameters, with any post data
* stripped away
*/
if (bw->current_parameters.post_urlenc != NULL) {
free(bw->current_parameters.post_urlenc);
bw->current_parameters.post_urlenc = NULL;
}
if (bw->current_parameters.post_multipart != NULL) {
fetch_multipart_data_destroy(bw->current_parameters.post_multipart);
bw->current_parameters.post_multipart = NULL;
}
bw->current_parameters.flags &= ~BW_NAVIGATE_HISTORY;
bw->internal_nav = false;
browser_window__free_fetch_parameters(&bw->loading_parameters);
memcpy(&bw->loading_parameters, &bw->current_parameters, sizeof(bw->loading_parameters));
memset(&bw->current_parameters, 0, sizeof(bw->current_parameters));
return browser_window__navigate_internal(bw, &bw->loading_parameters);
return browser_window__reload_current_parameters(bw);
}
/* We're processing a "proceed" attempt from the form */
@ -1694,7 +1678,9 @@ browser_window_refresh_url_bar_internal(struct browser_window *bw, nsurl *url)
/* Not root window or no gui window so do not set a URL */
return NSERROR_OK;
}
NSLOG(netsurf, CRITICAL, "Updating the URL to %s", nsurl_access(url));
return guit->window->set_url(bw->window, url);
}
@ -4275,6 +4261,10 @@ void browser_window_page_drag_start(struct browser_window *bw, int x, int y)
/* exported interface documented in netsurf/browser_window.h */
bool browser_window_back_available(struct browser_window *bw)
{
if (bw != NULL && bw->internal_nav) {
/* Internal nav, back is possible */
return true;
}
return (bw && bw->history && browser_window_history_back_available(bw));
}
@ -4375,3 +4365,28 @@ browser_window_console_log(struct browser_window *bw,
return NSERROR_OK;
}
/* Exported interface, documented in browser_private.h */
nserror
browser_window__reload_current_parameters(struct browser_window *bw)
{
assert(bw != NULL);
if (bw->current_parameters.post_urlenc != NULL) {
free(bw->current_parameters.post_urlenc);
bw->current_parameters.post_urlenc = NULL;
}
if (bw->current_parameters.post_multipart != NULL) {
fetch_multipart_data_destroy(bw->current_parameters.post_multipart);
bw->current_parameters.post_multipart = NULL;
}
bw->current_parameters.flags &= ~BW_NAVIGATE_HISTORY;
bw->internal_nav = false;
browser_window__free_fetch_parameters(&bw->loading_parameters);
memcpy(&bw->loading_parameters, &bw->current_parameters, sizeof(bw->loading_parameters));
memset(&bw->current_parameters, 0, sizeof(bw->current_parameters));
return browser_window__navigate_internal(bw, &bw->loading_parameters);
}