This allows a frontend to filter the URLs which the browser will
navigate to.
---
 desktop/browser_window.c |  3 +++
 include/netsurf/window.h | 12 ++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/desktop/browser_window.c b/desktop/browser_window.c
index 7b553f4e0..522772bbc 100644
--- a/desktop/browser_window.c
+++ b/desktop/browser_window.c
@@ -3313,6 +3313,9 @@ browser_window_navigate(struct browser_window *bw,
        assert(bw);
        assert(url);
 
+       if (guit->window->url_filter) {
+               url = guit->window->url_filter(bw->window, url);
+       }
        NSLOG(netsurf, INFO, "bw %p, url %s", bw, nsurl_access(url));
 
        /*
diff --git a/include/netsurf/window.h b/include/netsurf/window.h
index 16fd95e30..8ebbfee92 100644
--- a/include/netsurf/window.h
+++ b/include/netsurf/window.h
@@ -376,6 +376,18 @@ struct gui_window_table {
                            const char *msg,
                            size_t msglen,
                            browser_window_console_flags flags);
+
+       /**
+        * Filter URLs for navigation. Return the same nsurl if no filtering is
+        * desired, or leave this table field NULL. The browser will reference
+        * the returned URL.
+        *
+        * \param gw The gui window which is navigating to a URL
+        * \param url The URL being navigated to
+        * \return The same URL, or another URL to load instead.
+        */
+       struct nsurl *(*url_filter)(struct gui_window *gw,
+                                   struct nsurl *url);
 };
 
 #endif
-- 
2.33.0
_______________________________________________
netsurf-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to