Skip to content

Commit

Permalink
Ladybird/AppKit: Add actions to set navigator compatibility mode
Browse files Browse the repository at this point in the history
(cherry picked from commit 98e1ae49f5288c9f25ad018b13b106369af8f75c)
  • Loading branch information
jamierocks authored and nico committed Nov 1, 2024
1 parent 59a95fb commit d145de0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Ladybird/AppKit/Application/ApplicationDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ @interface ApplicationDelegate () <TaskManagerDelegate>
Web::CSS::PreferredColorScheme m_preferred_color_scheme;
Web::CSS::PreferredContrast m_preferred_contrast;
Web::CSS::PreferredMotion m_preferred_motion;
ByteString m_navigator_compatibility_mode;

WebView::SearchEngine m_search_engine;

Expand Down Expand Up @@ -95,6 +96,7 @@ - (instancetype)init:(Vector<URL::URL>)initial_urls
m_preferred_color_scheme = Web::CSS::PreferredColorScheme::Auto;
m_preferred_contrast = Web::CSS::PreferredContrast::Auto;
m_preferred_motion = Web::CSS::PreferredMotion::Auto;
m_navigator_compatibility_mode = "chrome";
m_search_engine = WebView::default_search_engine();

m_allow_popups = allow_popups;
Expand Down Expand Up @@ -668,6 +670,23 @@ - (NSMenuItem*)createDebugMenu
[spoof_user_agent_menu_item setSubmenu:spoof_user_agent_menu];

[submenu addItem:spoof_user_agent_menu_item];

auto* navigator_compatibility_mode_menu = [[NSMenu alloc] init];
auto add_navigator_compatibility_mode = [navigator_compatibility_mode_menu](ByteString name) {
[navigator_compatibility_mode_menu addItem:[[NSMenuItem alloc] initWithTitle:Ladybird::string_to_ns_string(name)
action:@selector(setNavigatorCompatibilityMode:)
keyEquivalent:@""]];
};
add_navigator_compatibility_mode("Chrome");
add_navigator_compatibility_mode("Gecko");
add_navigator_compatibility_mode("WebKit");

auto* navigator_compatibility_mode_menu_item = [[NSMenuItem alloc] initWithTitle:@"Navigator Compatibility Mode"
action:nil
keyEquivalent:@""];
[navigator_compatibility_mode_menu_item setSubmenu:navigator_compatibility_mode_menu];

[submenu addItem:navigator_compatibility_mode_menu_item];
[submenu addItem:[NSMenuItem separatorItem]];

[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Enable Scripting"
Expand Down
1 change: 1 addition & 0 deletions Ladybird/AppKit/UI/TabController.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct TabSettings {
BOOL block_popups { YES };
BOOL same_origin_policy_enabled { NO };
ByteString user_agent_name { "Disabled"sv };
ByteString navigator_compatibility_mode { "chrome"sv };
};

@interface TabController : NSWindowController <NSWindowDelegate>
Expand Down
10 changes: 10 additions & 0 deletions Ladybird/AppKit/UI/TabController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,14 @@ - (void)setUserAgentSpoof:(NSMenuItem*)sender
[self debugRequest:"clear-cache" argument:""]; // clear the cache to ensure requests are re-done with the new user agent
}

- (void)setNavigatorCompatibilityMode:(NSMenuItem*)sender
{
ByteString const compatibility_mode = [[[sender title] lowercaseString] UTF8String];
m_settings.navigator_compatibility_mode = compatibility_mode;

[self debugRequest:"navigator-compatibility-mode" argument:compatibility_mode];
}

#pragma mark - Properties

- (NSButton*)create_button:(NSImageName)image
Expand Down Expand Up @@ -574,6 +582,8 @@ - (BOOL)validateMenuItem:(NSMenuItem*)item
[item setState:m_settings.same_origin_policy_enabled ? NSControlStateValueOn : NSControlStateValueOff];
} else if ([item action] == @selector(setUserAgentSpoof:)) {
[item setState:(m_settings.user_agent_name == [[item title] UTF8String]) ? NSControlStateValueOn : NSControlStateValueOff];
} else if ([item action] == @selector(setNavigatorCompatibilityMode:)) {
[item setState:(m_settings.navigator_compatibility_mode == [[[item title] lowercaseString] UTF8String]) ? NSControlStateValueOn : NSControlStateValueOff];
}

return YES;
Expand Down

0 comments on commit d145de0

Please sign in to comment.