diff options
author | Michael Drake <michael.drake@codethink.co.uk> | 2018-07-23 11:08:15 +0100 |
---|---|---|
committer | Michael Drake <michael.drake@codethink.co.uk> | 2018-07-23 11:33:43 +0100 |
commit | eeb7be1cbf8069cc1304dac4136e7c2090d49e89 (patch) | |
tree | 57d70f99735a5437ca584e34ddba74946dd02837 /desktop/browser.c | |
parent | 09b015bf11be087bdc50e740c2f8ce6a6ff5853e (diff) | |
download | netsurf-eeb7be1cbf8069cc1304dac4136e7c2090d49e89.tar.gz netsurf-eeb7be1cbf8069cc1304dac4136e7c2090d49e89.tar.bz2 |
Browser: Add function to get bw URL with any fragment.
This returns a ref to the URL.
Diffstat (limited to 'desktop/browser.c')
-rw-r--r-- | desktop/browser.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/desktop/browser.c b/desktop/browser.c index 84f6681c8..1c8aa95fa 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -2267,6 +2267,36 @@ nsurl* browser_window_access_url(struct browser_window *bw) return corestring_nsurl_about_blank; } +/* Exported interface, documented in include/netsurf/browser_window.h */ +nserror browser_window_get_url( + struct browser_window *bw, + bool fragment, + nsurl** url_out) +{ + nserror err; + nsurl *url; + + assert(bw != NULL); + + if (!fragment || bw->frag_id == NULL || bw->loading_content != NULL) { + /* If there's a loading content, then the bw->frag_id will have + * been trampled, possibly with a new frag_id, but we will + * still be returning the current URL, so in this edge case + * we just drop any fragment. */ + url = nsurl_ref(browser_window_access_url(bw)); + + } else { + err = nsurl_refragment(browser_window_access_url(bw), + bw->frag_id, &url); + if (err != NSERROR_OK) { + return err; + } + } + + *url_out = url; + return NSERROR_OK; +} + /* Exported interface, documented in browser.h */ const char* browser_window_get_title(struct browser_window *bw) { |