diff --git a/Ladybird/AppKit/UI/LadybirdWebView.h b/Ladybird/AppKit/UI/LadybirdWebView.h index f23fb83095d..f0e351c61e9 100644 --- a/Ladybird/AppKit/UI/LadybirdWebView.h +++ b/Ladybird/AppKit/UI/LadybirdWebView.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #import @@ -28,6 +29,8 @@ - (void)loadURL:(URL::URL const&)url; - (void)onLoadStart:(URL::URL const&)url isRedirect:(BOOL)is_redirect; - (void)onLoadFinish:(URL::URL const&)url; +- (void)onURLUpdated:(URL::URL const&)url + historyBehavior:(Web::HTML::HistoryHandlingBehavior)history_behavior; - (void)onTitleChange:(ByteString const&)title; - (void)onFaviconChange:(Gfx::Bitmap const&)bitmap; diff --git a/Ladybird/AppKit/UI/LadybirdWebView.mm b/Ladybird/AppKit/UI/LadybirdWebView.mm index 150d8de40e5..33325725b83 100644 --- a/Ladybird/AppKit/UI/LadybirdWebView.mm +++ b/Ladybird/AppKit/UI/LadybirdWebView.mm @@ -282,6 +282,10 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_ [self.observer onLoadFinish:url]; }; + m_web_view_bridge->on_url_updated = [self](auto const& url, auto history_behavior) { + [self.observer onURLUpdated:url historyBehavior:history_behavior]; + }; + m_web_view_bridge->on_title_change = [self](auto const& title) { [self.observer onTitleChange:title]; }; diff --git a/Ladybird/AppKit/UI/Tab.mm b/Ladybird/AppKit/UI/Tab.mm index ec51d18c7a7..61e5a3bc0cb 100644 --- a/Ladybird/AppKit/UI/Tab.mm +++ b/Ladybird/AppKit/UI/Tab.mm @@ -221,12 +221,12 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800; - (void)onLoadStart:(URL::URL const&)url isRedirect:(BOOL)is_redirect { - [[self tabController] onLoadStart:url isRedirect:is_redirect]; - self.title = Ladybird::string_to_ns_string(url.serialize()); self.favicon = [Tab defaultFavicon]; [self updateTabTitleAndFavicon]; + [[self tabController] onLoadStart:url isRedirect:is_redirect]; + if (self.inspector_controller != nil) { auto* inspector = (Inspector*)[self.inspector_controller window]; [inspector reset]; @@ -241,6 +241,12 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800; } } +- (void)onURLUpdated:(URL::URL const&)url + historyBehavior:(Web::HTML::HistoryHandlingBehavior)history_behavior +{ + [[self tabController] onURLUpdated:url historyBehavior:history_behavior]; +} + - (void)onTitleChange:(ByteString const&)title { [[self tabController] onTitleChange:title]; diff --git a/Ladybird/AppKit/UI/TabController.h b/Ladybird/AppKit/UI/TabController.h index 8194da3be20..1f6cb17d431 100644 --- a/Ladybird/AppKit/UI/TabController.h +++ b/Ladybird/AppKit/UI/TabController.h @@ -8,6 +8,7 @@ #include #include +#include #import @@ -27,6 +28,8 @@ struct TabSettings { - (void)loadHTML:(StringView)html url:(URL::URL const&)url; - (void)onLoadStart:(URL::URL const&)url isRedirect:(BOOL)isRedirect; +- (void)onURLUpdated:(URL::URL const&)url + historyBehavior:(Web::HTML::HistoryHandlingBehavior)history_behavior; - (void)onTitleChange:(ByteString const&)title; - (void)navigateBack:(id)sender; diff --git a/Ladybird/AppKit/UI/TabController.mm b/Ladybird/AppKit/UI/TabController.mm index 7886e316b23..027b45930f9 100644 --- a/Ladybird/AppKit/UI/TabController.mm +++ b/Ladybird/AppKit/UI/TabController.mm @@ -133,6 +133,22 @@ enum class IsHistoryNavigation { [self updateNavigationButtonStates]; } +- (void)onURLUpdated:(URL::URL const&)url + historyBehavior:(Web::HTML::HistoryHandlingBehavior)history_behavior +{ + switch (history_behavior) { + case Web::HTML::HistoryHandlingBehavior::Push: + m_history.push(url, m_title); + break; + case Web::HTML::HistoryHandlingBehavior::Replace: + m_history.replace_current(url, m_title); + break; + } + + [self setLocationFieldText:url.serialize()]; + [self updateNavigationButtonStates]; +} + - (void)onTitleChange:(ByteString const&)title { m_title = title;