UI/AppKit: Do not open child web views with an about:blank URL

This is overriding the URL passed to e.g. window.open and link clicks on
an <a target=_blank> element.

Note: This alone is not enough to support such use cases. We will also
need to actually implement opening child web views. But getting this fix
out of the way first makes that patch a bit simpler.
This commit is contained in:
Timothy Flynn 2024-09-17 15:54:34 -04:00 committed by Andreas Kling
parent 89b6cd3fb1
commit e6965b11e4
Notes: github-actions[bot] 2024-09-18 08:11:10 +00:00
5 changed files with 8 additions and 5 deletions

View file

@ -97,7 +97,10 @@
activateTab:(Web::HTML::ActivateTab)activate_tab
{
auto* controller = [self createNewTab:activate_tab fromTab:tab];
[controller loadURL:url.value_or(WebView::Application::chrome_options().new_tab_page_url)];
if (url.has_value()) {
[controller loadURL:*url];
}
return controller;
}

View file

@ -20,7 +20,7 @@
@protocol LadybirdWebViewObserver <NSObject>
- (String const&)onCreateNewTab:(URL::URL const&)url
- (String const&)onCreateNewTab:(Optional<URL::URL> const&)url
activateTab:(Web::HTML::ActivateTab)activate_tab;
- (String const&)onCreateNewTab:(StringView)html

View file

@ -323,7 +323,7 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_
return String {};
}
// FIXME: Create a child tab that re-uses the ConnectionFromClient of the parent tab
return [self.observer onCreateNewTab:"about:blank"sv activateTab:activate_tab];
return [self.observer onCreateNewTab:{} activateTab:activate_tab];
};
m_web_view_bridge->on_request_web_content = [weak_self]() {

View file

@ -268,7 +268,7 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
#pragma mark - LadybirdWebViewObserver
- (String const&)onCreateNewTab:(URL::URL const&)url
- (String const&)onCreateNewTab:(Optional<URL::URL> const&)url
activateTab:(Web::HTML::ActivateTab)activate_tab
{
auto* delegate = (ApplicationDelegate*)[NSApp delegate];

View file

@ -214,7 +214,7 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde
self.tab.titlebarAppearsTransparent = NO;
[delegate createNewTab:OptionalNone {}
[delegate createNewTab:WebView::Application::chrome_options().new_tab_page_url
fromTab:[self tab]
activateTab:Web::HTML::ActivateTab::Yes];