1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:07:34 +00:00

Ladybird: Add more items to the debug menu of the AppKit chrome

This commit is contained in:
implicitfield 2023-09-10 19:49:53 +04:00 committed by Tim Flynn
parent 63d09f6daf
commit bac4fc1b73
5 changed files with 217 additions and 4 deletions

View file

@ -51,6 +51,8 @@
- (void)setPreferredColorScheme:(Web::CSS::PreferredColorScheme)color_scheme;
- (void)debugRequest:(DeprecatedString const&)request argument:(DeprecatedString const&)argument;
- (void)viewSource;
@end

View file

@ -146,6 +146,11 @@ struct HideCursor {
m_web_view_bridge->set_preferred_color_scheme(color_scheme);
}
- (void)debugRequest:(DeprecatedString const&)request argument:(DeprecatedString const&)argument
{
m_web_view_bridge->debug_request(request, argument);
}
- (void)viewSource
{
m_web_view_bridge->get_source();

View file

@ -11,6 +11,14 @@
#import <System/Cocoa.h>
struct TabSettings {
BOOL should_show_line_box_borders { NO };
BOOL scripting_enabled { YES };
BOOL block_popups { YES };
BOOL same_origin_policy_enabled { NO };
DeprecatedString user_agent_name { "Disabled"sv };
};
@interface TabController : NSWindowController <NSWindowDelegate>
- (instancetype)init;
@ -26,6 +34,8 @@
- (void)reload:(id)sender;
- (void)clearHistory;
- (void)debugRequest:(DeprecatedString const&)request argument:(DeprecatedString const&)argument;
- (void)focusLocationToolbarItem;
@end

View file

@ -7,6 +7,8 @@
#include <LibWebView/History.h>
#import <Application/ApplicationDelegate.h>
#import <LibWebView/UserAgent.h>
#import <LibWeb/Loader/ResourceLoader.h>
#import <UI/LadybirdWebView.h>
#import <UI/Tab.h>
#import <UI/TabController.h>
@ -36,6 +38,8 @@ enum class IsHistoryNavigation {
WebView::History m_history;
IsHistoryNavigation m_is_history_navigation;
TabSettings m_settings;
}
@property (nonatomic, strong) NSToolbar* toolbar;
@ -72,6 +76,7 @@ enum class IsHistoryNavigation {
[self.toolbar setSizeMode:NSToolbarSizeModeRegular];
m_is_history_navigation = IsHistoryNavigation::No;
m_settings = {};
}
return self;
@ -158,6 +163,15 @@ enum class IsHistoryNavigation {
[self updateNavigationButtonStates];
}
- (void)debugRequest:(DeprecatedString const&)request argument:(DeprecatedString const&)argument
{
if (request == "dump-history") {
m_history.dump();
} else {
[[[self tab] web_view] debugRequest:request argument:argument];
}
}
- (void)viewSource:(id)sender
{
[[[self tab] web_view] viewSource];
@ -201,6 +215,100 @@ enum class IsHistoryNavigation {
[self.window toggleTabOverview:sender];
}
- (void)dumpDOMTree:(id)sender
{
[self debugRequest:"dump-dom-tree" argument:""];
}
- (void)dumpLayoutTree:(id)sender
{
[self debugRequest:"dump-layout-tree" argument:""];
}
- (void)dumpPaintTree:(id)sender
{
[self debugRequest:"dump-paint-tree" argument:""];
}
- (void)dumpStackingContextTree:(id)sender
{
[self debugRequest:"dump-stacking-context-tree" argument:""];
}
- (void)dumpStyleSheets:(id)sender
{
[self debugRequest:"dump-style-sheets" argument:""];
}
- (void)dumpAllResolvedStyles:(id)sender
{
[self debugRequest:"dump-all-resolved-styles" argument:""];
}
- (void)dumpHistory:(id)sender
{
[self debugRequest:"dump-history" argument:""];
}
- (void)dumpLocalStorage:(id)sender
{
[self debugRequest:"dump-local-storage" argument:""];
}
- (void)toggleLineBoxBorders:(id)sender
{
m_settings.should_show_line_box_borders = !m_settings.should_show_line_box_borders;
[self debugRequest:"set-line-box-borders" argument:m_settings.should_show_line_box_borders ? "on" : "off"];
}
- (void)collectGarbage:(id)sender
{
[self debugRequest:"collect-garbage" argument:""];
}
- (void)dumpGCGraph:(id)sender
{
[self debugRequest:"dump-gc-graph" argument:""];
}
- (void)clearCache:(id)sender
{
[self debugRequest:"clear-cache" argument:""];
}
- (void)toggleScripting:(id)sender
{
m_settings.scripting_enabled = !m_settings.scripting_enabled;
[self debugRequest:"scripting" argument:m_settings.scripting_enabled ? "on" : "off"];
}
- (void)togglePopupBlocking:(id)sender
{
m_settings.block_popups = !m_settings.block_popups;
[self debugRequest:"block-pop-ups" argument:m_settings.block_popups ? "on" : "off"];
}
- (void)toggleSameOriginPolicy:(id)sender
{
m_settings.same_origin_policy_enabled = !m_settings.same_origin_policy_enabled;
[self debugRequest:"same-origin-policy" argument:m_settings.same_origin_policy_enabled ? "on" : "off"];
}
- (void)setUserAgentSpoof:(NSMenuItem*)sender
{
DeprecatedString const user_agent_name = [[sender title] UTF8String];
DeprecatedString user_agent = "";
if (user_agent_name == "Disabled"sv) {
user_agent = Web::default_user_agent;
} else {
user_agent = WebView::user_agents.get(user_agent_name).value();
}
m_settings.user_agent_name = user_agent_name;
[self debugRequest:"spoof-user-agent" argument:user_agent];
[self debugRequest:"clear-cache" argument:""]; // clear the cache to ensure requests are re-done with the new user agent
}
#pragma mark - Properties
- (NSButton*)create_button:(NSImageName)image
@ -355,6 +463,24 @@ enum class IsHistoryNavigation {
}
}
- (BOOL)validateMenuItem:(NSMenuItem*)item
{
if ([item action] == @selector(toggleLineBoxBorders:)) {
[item setState:m_settings.should_show_line_box_borders ? NSControlStateValueOn : NSControlStateValueOff];
} else if ([item action] == @selector(toggleScripting:)) {
[item setState:m_settings.scripting_enabled ? NSControlStateValueOn : NSControlStateValueOff];
} else if ([item action] == @selector(togglePopupBlocking:)) {
[item setState:m_settings.block_popups ? NSControlStateValueOn : NSControlStateValueOff];
} else if ([item action] == @selector(toggleSameOriginPolicy:)) {
[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];
}
return YES;
}
#pragma mark - NSToolbarDelegate
- (NSToolbarItem*)toolbar:(NSToolbar*)toolbar