From 946ccfc1083db225ba7771ed33f5c1a9abe820d1 Mon Sep 17 00:00:00 2001 From: Sebastian Zaha Date: Tue, 9 Jul 2024 15:38:21 +0200 Subject: [PATCH] UI/AppKit: Port --allow-popups option from Qt chrome WebDriver requires this option to be present in order to run the WPT tests. --- Ladybird/AppKit/Application/ApplicationDelegate.h | 3 ++- Ladybird/AppKit/Application/ApplicationDelegate.mm | 7 ++++++- Ladybird/AppKit/UI/TabController.h | 2 +- Ladybird/AppKit/UI/TabController.mm | 4 ++-- Ladybird/AppKit/main.mm | 5 ++++- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Ladybird/AppKit/Application/ApplicationDelegate.h b/Ladybird/AppKit/Application/ApplicationDelegate.h index 65dabeacd9d..871bdd5ef61 100644 --- a/Ladybird/AppKit/Application/ApplicationDelegate.h +++ b/Ladybird/AppKit/Application/ApplicationDelegate.h @@ -28,7 +28,8 @@ newTabPageURL:(URL::URL)new_tab_page_url withCookieJar:(NonnullOwnPtr)cookie_jar webContentOptions:(Ladybird::WebContentOptions const&)web_content_options - webdriverContentIPCPath:(StringView)webdriver_content_ipc_path; + webdriverContentIPCPath:(StringView)webdriver_content_ipc_path + allowPopups:(BOOL)allow_popups; - (nonnull TabController*)createNewTab:(Optional const&)url fromTab:(nullable Tab*)tab diff --git a/Ladybird/AppKit/Application/ApplicationDelegate.mm b/Ladybird/AppKit/Application/ApplicationDelegate.mm index 70dd2a0e592..a966bf5c372 100644 --- a/Ladybird/AppKit/Application/ApplicationDelegate.mm +++ b/Ladybird/AppKit/Application/ApplicationDelegate.mm @@ -35,6 +35,8 @@ ByteString m_navigator_compatibility_mode; WebView::SearchEngine m_search_engine; + + BOOL m_allow_popups; } @property (nonatomic, strong) NSMutableArray* managed_tabs; @@ -62,6 +64,7 @@ withCookieJar:(NonnullOwnPtr)cookie_jar webContentOptions:(Ladybird::WebContentOptions const&)web_content_options webdriverContentIPCPath:(StringView)webdriver_content_ipc_path + allowPopups:(BOOL)allow_popups { if (self = [super init]) { [NSApp setMainMenu:[[NSMenu alloc] init]]; @@ -96,6 +99,8 @@ m_navigator_compatibility_mode = "chrome"; m_search_engine = WebView::default_search_engine(); + m_allow_popups = allow_popups; + // Reduce the tooltip delay, as the default delay feels quite long. [[NSUserDefaults standardUserDefaults] setObject:@100 forKey:@"NSInitialToolTipDelay"]; } @@ -199,7 +204,7 @@ - (nonnull TabController*)createNewTab:(Web::HTML::ActivateTab)activate_tab fromTab:(nullable Tab*)tab { - auto* controller = [[TabController alloc] init]; + auto* controller = [[TabController alloc] init:!m_allow_popups]; [controller showWindow:nil]; if (tab) { diff --git a/Ladybird/AppKit/UI/TabController.h b/Ladybird/AppKit/UI/TabController.h index 2ea99895c2c..9e3927e0937 100644 --- a/Ladybird/AppKit/UI/TabController.h +++ b/Ladybird/AppKit/UI/TabController.h @@ -22,7 +22,7 @@ struct TabSettings { @interface TabController : NSWindowController -- (instancetype)init; +- (instancetype)init:(BOOL)block_popups; - (void)loadURL:(URL::URL const&)url; - (void)loadHTML:(StringView)html url:(URL::URL const&)url; diff --git a/Ladybird/AppKit/UI/TabController.mm b/Ladybird/AppKit/UI/TabController.mm index c190d364a3e..19140f8ce9b 100644 --- a/Ladybird/AppKit/UI/TabController.mm +++ b/Ladybird/AppKit/UI/TabController.mm @@ -82,7 +82,7 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde @synthesize new_tab_toolbar_item = _new_tab_toolbar_item; @synthesize tab_overview_toolbar_item = _tab_overview_toolbar_item; -- (instancetype)init +- (instancetype)init:(BOOL)block_popups { if (self = [super init]) { self.toolbar = [[NSToolbar alloc] initWithIdentifier:TOOLBAR_IDENTIFIER]; @@ -91,7 +91,7 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde [self.toolbar setAllowsUserCustomization:NO]; [self.toolbar setSizeMode:NSToolbarSizeModeRegular]; - m_settings = {}; + m_settings = { .block_popups = block_popups }; m_can_navigate_back = false; m_can_navigate_forward = false; } diff --git a/Ladybird/AppKit/main.mm b/Ladybird/AppKit/main.mm index 318aa01a990..567901714af 100644 --- a/Ladybird/AppKit/main.mm +++ b/Ladybird/AppKit/main.mm @@ -88,6 +88,7 @@ ErrorOr serenity_main(Main::Arguments arguments) bool log_all_js_exceptions = false; bool enable_http_cache = false; bool new_window = false; + bool allow_popups = false; Core::ArgsParser args_parser; args_parser.set_general_help("The Ladybird web browser"); @@ -99,6 +100,7 @@ ErrorOr serenity_main(Main::Arguments arguments) args_parser.add_option(log_all_js_exceptions, "Log all JavaScript exceptions", "log-all-js-exceptions"); args_parser.add_option(enable_http_cache, "Enable HTTP cache", "enable-http-cache"); args_parser.add_option(new_window, "Force opening in a new window", "new-window", 'n'); + args_parser.add_option(allow_popups, "Disable popup blocking by default", "allow-popups"); args_parser.parse(arguments); WebView::ChromeProcess chrome_process; @@ -148,7 +150,8 @@ ErrorOr serenity_main(Main::Arguments arguments) newTabPageURL:URL::URL { Browser::default_new_tab_url } withCookieJar:move(cookie_jar) webContentOptions:web_content_options - webdriverContentIPCPath:webdriver_content_ipc_path]; + webdriverContentIPCPath:webdriver_content_ipc_path + allowPopups:allow_popups]; [NSApp setDelegate:delegate];