mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:07:46 +00:00
Ladybird: Protect some application commands against non-Tab key windows
Currently, the only NSWindow type in the AppKit chrome is the Tab. Once we have other window types (e.g. Inspector), commands which assume they are used on a Tab will either crash or behave weirdly. This changes the createNewTab: command to accept the tab from which the new tab is created, rather than assuming that tab is the key window. So if some JS on a page calls window.open() while a non-Tab window is key, the new tab will be opened within the same tab group. This also changes closeCurrentTab: to work on any key window. Regardless of whether the key window is a Tab or some other window, pressing cmd+W should just close that window.
This commit is contained in:
parent
e981c13a4f
commit
70830b711e
4 changed files with 36 additions and 23 deletions
|
@ -178,9 +178,12 @@ struct HideCursor {
|
|||
[self setNeedsDisplay:YES];
|
||||
};
|
||||
|
||||
m_web_view_bridge->on_new_tab = [](auto activate_tab) {
|
||||
m_web_view_bridge->on_new_tab = [self](auto activate_tab) {
|
||||
auto* delegate = (ApplicationDelegate*)[NSApp delegate];
|
||||
auto* controller = [delegate createNewTab:"about:blank"sv activateTab:activate_tab];
|
||||
|
||||
auto* controller = [delegate createNewTab:"about:blank"sv
|
||||
fromTab:[self tab]
|
||||
activateTab:activate_tab];
|
||||
|
||||
auto* tab = (Tab*)[controller window];
|
||||
auto* web_view = [tab web_view];
|
||||
|
@ -353,17 +356,24 @@ struct HideCursor {
|
|||
auto* delegate = (ApplicationDelegate*)[NSApp delegate];
|
||||
|
||||
if (modifiers == Mod_Super) {
|
||||
[delegate createNewTab:url activateTab:Web::HTML::ActivateTab::No];
|
||||
[delegate createNewTab:url
|
||||
fromTab:[self tab]
|
||||
activateTab:Web::HTML::ActivateTab::No];
|
||||
} else if (target == "_blank"sv) {
|
||||
[delegate createNewTab:url activateTab:Web::HTML::ActivateTab::Yes];
|
||||
[delegate createNewTab:url
|
||||
fromTab:[self tab]
|
||||
activateTab:Web::HTML::ActivateTab::Yes];
|
||||
} else {
|
||||
[[self tabController] load:url];
|
||||
}
|
||||
};
|
||||
|
||||
m_web_view_bridge->on_link_middle_click = [](auto url, auto, unsigned) {
|
||||
m_web_view_bridge->on_link_middle_click = [self](auto url, auto, unsigned) {
|
||||
auto* delegate = (ApplicationDelegate*)[NSApp delegate];
|
||||
[delegate createNewTab:url activateTab:Web::HTML::ActivateTab::No];
|
||||
|
||||
[delegate createNewTab:url
|
||||
fromTab:[self tab]
|
||||
activateTab:Web::HTML::ActivateTab::No];
|
||||
};
|
||||
|
||||
m_web_view_bridge->on_context_menu_request = [self](auto position) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue