mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
Ladybird: Add more items to the debug menu of the AppKit chrome
This commit is contained in:
parent
63d09f6daf
commit
bac4fc1b73
5 changed files with 217 additions and 4 deletions
|
@ -7,9 +7,11 @@
|
||||||
#include <BrowserSettings/Defaults.h>
|
#include <BrowserSettings/Defaults.h>
|
||||||
|
|
||||||
#import <Application/ApplicationDelegate.h>
|
#import <Application/ApplicationDelegate.h>
|
||||||
|
#import <LibWebView/UserAgent.h>
|
||||||
#import <UI/LadybirdWebView.h>
|
#import <UI/LadybirdWebView.h>
|
||||||
#import <UI/Tab.h>
|
#import <UI/Tab.h>
|
||||||
#import <UI/TabController.h>
|
#import <UI/TabController.h>
|
||||||
|
#import <Utilities/Conversions.h>
|
||||||
#import <Utilities/URL.h>
|
#import <Utilities/URL.h>
|
||||||
|
|
||||||
#if !__has_feature(objc_arc)
|
#if !__has_feature(objc_arc)
|
||||||
|
@ -355,9 +357,79 @@
|
||||||
auto* menu = [[NSMenuItem alloc] init];
|
auto* menu = [[NSMenuItem alloc] init];
|
||||||
auto* submenu = [[NSMenu alloc] initWithTitle:@"Debug"];
|
auto* submenu = [[NSMenu alloc] initWithTitle:@"Debug"];
|
||||||
|
|
||||||
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Dump DOM Tree"
|
||||||
|
action:@selector(dumpDOMTree:)
|
||||||
|
keyEquivalent:@""]];
|
||||||
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Dump Layout Tree"
|
||||||
|
action:@selector(dumpLayoutTree:)
|
||||||
|
keyEquivalent:@""]];
|
||||||
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Dump Paint Tree"
|
||||||
|
action:@selector(dumpPaintTree:)
|
||||||
|
keyEquivalent:@""]];
|
||||||
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Dump Stacking Context Tree"
|
||||||
|
action:@selector(dumpStackingContextTree:)
|
||||||
|
keyEquivalent:@""]];
|
||||||
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Dump Style Sheets"
|
||||||
|
action:@selector(dumpStyleSheets:)
|
||||||
|
keyEquivalent:@""]];
|
||||||
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Dump All Resolved Styles"
|
||||||
|
action:@selector(dumpAllResolvedStyles:)
|
||||||
|
keyEquivalent:@""]];
|
||||||
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Dump History"
|
||||||
|
action:@selector(dumpHistory:)
|
||||||
|
keyEquivalent:@""]];
|
||||||
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Dump Cookies"
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Dump Cookies"
|
||||||
action:@selector(dumpCookies:)
|
action:@selector(dumpCookies:)
|
||||||
keyEquivalent:@""]];
|
keyEquivalent:@""]];
|
||||||
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Dump Local Storage"
|
||||||
|
action:@selector(dumpLocalStorage:)
|
||||||
|
keyEquivalent:@""]];
|
||||||
|
[submenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
|
||||||
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Show Line Box Borders"
|
||||||
|
action:@selector(toggleLineBoxBorders:)
|
||||||
|
keyEquivalent:@""]];
|
||||||
|
[submenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
|
||||||
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Collect Garbage"
|
||||||
|
action:@selector(collectGarbage:)
|
||||||
|
keyEquivalent:@""]];
|
||||||
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Dump GC Graph"
|
||||||
|
action:@selector(dumpGCGraph:)
|
||||||
|
keyEquivalent:@""]];
|
||||||
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Clear Cache"
|
||||||
|
action:@selector(clearCache:)
|
||||||
|
keyEquivalent:@""]];
|
||||||
|
[submenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
|
||||||
|
auto* spoof_user_agent_menu = [[NSMenu alloc] init];
|
||||||
|
auto add_user_agent = [spoof_user_agent_menu](DeprecatedString name) {
|
||||||
|
[spoof_user_agent_menu addItem:[[NSMenuItem alloc] initWithTitle:Ladybird::string_to_ns_string(name)
|
||||||
|
action:@selector(setUserAgentSpoof:)
|
||||||
|
keyEquivalent:@""]];
|
||||||
|
};
|
||||||
|
|
||||||
|
add_user_agent("Disabled");
|
||||||
|
for (auto const& userAgent : WebView::user_agents)
|
||||||
|
add_user_agent(userAgent.key);
|
||||||
|
|
||||||
|
auto* spoof_user_agent_menu_item = [[NSMenuItem alloc] initWithTitle:@"Spoof User Agent"
|
||||||
|
action:nil
|
||||||
|
keyEquivalent:@""];
|
||||||
|
[spoof_user_agent_menu_item setSubmenu:spoof_user_agent_menu];
|
||||||
|
|
||||||
|
[submenu addItem:spoof_user_agent_menu_item];
|
||||||
|
[submenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
|
||||||
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Enable Scripting"
|
||||||
|
action:@selector(toggleScripting:)
|
||||||
|
keyEquivalent:@""]];
|
||||||
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Block Pop-ups"
|
||||||
|
action:@selector(togglePopupBlocking:)
|
||||||
|
keyEquivalent:@""]];
|
||||||
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Enable Same-Origin Policy"
|
||||||
|
action:@selector(toggleSameOriginPolicy:)
|
||||||
|
keyEquivalent:@""]];
|
||||||
|
|
||||||
[menu setSubmenu:submenu];
|
[menu setSubmenu:submenu];
|
||||||
return menu;
|
return menu;
|
||||||
|
@ -409,11 +481,9 @@
|
||||||
|
|
||||||
if ([item action] == @selector(setAutoPreferredColorScheme:)) {
|
if ([item action] == @selector(setAutoPreferredColorScheme:)) {
|
||||||
[item setState:(m_preferred_color_scheme == Auto) ? NSControlStateValueOn : NSControlStateValueOff];
|
[item setState:(m_preferred_color_scheme == Auto) ? NSControlStateValueOn : NSControlStateValueOff];
|
||||||
}
|
} else if ([item action] == @selector(setDarkPreferredColorScheme:)) {
|
||||||
if ([item action] == @selector(setDarkPreferredColorScheme:)) {
|
|
||||||
[item setState:(m_preferred_color_scheme == Dark) ? NSControlStateValueOn : NSControlStateValueOff];
|
[item setState:(m_preferred_color_scheme == Dark) ? NSControlStateValueOn : NSControlStateValueOff];
|
||||||
}
|
} else if ([item action] == @selector(setLightPreferredColorScheme:)) {
|
||||||
if ([item action] == @selector(setLightPreferredColorScheme:)) {
|
|
||||||
[item setState:(m_preferred_color_scheme == Light) ? NSControlStateValueOn : NSControlStateValueOff];
|
[item setState:(m_preferred_color_scheme == Light) ? NSControlStateValueOn : NSControlStateValueOff];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,8 @@
|
||||||
|
|
||||||
- (void)setPreferredColorScheme:(Web::CSS::PreferredColorScheme)color_scheme;
|
- (void)setPreferredColorScheme:(Web::CSS::PreferredColorScheme)color_scheme;
|
||||||
|
|
||||||
|
- (void)debugRequest:(DeprecatedString const&)request argument:(DeprecatedString const&)argument;
|
||||||
|
|
||||||
- (void)viewSource;
|
- (void)viewSource;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -146,6 +146,11 @@ struct HideCursor {
|
||||||
m_web_view_bridge->set_preferred_color_scheme(color_scheme);
|
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
|
- (void)viewSource
|
||||||
{
|
{
|
||||||
m_web_view_bridge->get_source();
|
m_web_view_bridge->get_source();
|
||||||
|
|
|
@ -11,6 +11,14 @@
|
||||||
|
|
||||||
#import <System/Cocoa.h>
|
#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>
|
@interface TabController : NSWindowController <NSWindowDelegate>
|
||||||
|
|
||||||
- (instancetype)init;
|
- (instancetype)init;
|
||||||
|
@ -26,6 +34,8 @@
|
||||||
- (void)reload:(id)sender;
|
- (void)reload:(id)sender;
|
||||||
- (void)clearHistory;
|
- (void)clearHistory;
|
||||||
|
|
||||||
|
- (void)debugRequest:(DeprecatedString const&)request argument:(DeprecatedString const&)argument;
|
||||||
|
|
||||||
- (void)focusLocationToolbarItem;
|
- (void)focusLocationToolbarItem;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include <LibWebView/History.h>
|
#include <LibWebView/History.h>
|
||||||
|
|
||||||
#import <Application/ApplicationDelegate.h>
|
#import <Application/ApplicationDelegate.h>
|
||||||
|
#import <LibWebView/UserAgent.h>
|
||||||
|
#import <LibWeb/Loader/ResourceLoader.h>
|
||||||
#import <UI/LadybirdWebView.h>
|
#import <UI/LadybirdWebView.h>
|
||||||
#import <UI/Tab.h>
|
#import <UI/Tab.h>
|
||||||
#import <UI/TabController.h>
|
#import <UI/TabController.h>
|
||||||
|
@ -36,6 +38,8 @@ enum class IsHistoryNavigation {
|
||||||
|
|
||||||
WebView::History m_history;
|
WebView::History m_history;
|
||||||
IsHistoryNavigation m_is_history_navigation;
|
IsHistoryNavigation m_is_history_navigation;
|
||||||
|
|
||||||
|
TabSettings m_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (nonatomic, strong) NSToolbar* toolbar;
|
@property (nonatomic, strong) NSToolbar* toolbar;
|
||||||
|
@ -72,6 +76,7 @@ enum class IsHistoryNavigation {
|
||||||
[self.toolbar setSizeMode:NSToolbarSizeModeRegular];
|
[self.toolbar setSizeMode:NSToolbarSizeModeRegular];
|
||||||
|
|
||||||
m_is_history_navigation = IsHistoryNavigation::No;
|
m_is_history_navigation = IsHistoryNavigation::No;
|
||||||
|
m_settings = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
@ -158,6 +163,15 @@ enum class IsHistoryNavigation {
|
||||||
[self updateNavigationButtonStates];
|
[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
|
- (void)viewSource:(id)sender
|
||||||
{
|
{
|
||||||
[[[self tab] web_view] viewSource];
|
[[[self tab] web_view] viewSource];
|
||||||
|
@ -201,6 +215,100 @@ enum class IsHistoryNavigation {
|
||||||
[self.window toggleTabOverview:sender];
|
[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
|
#pragma mark - Properties
|
||||||
|
|
||||||
- (NSButton*)create_button:(NSImageName)image
|
- (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
|
#pragma mark - NSToolbarDelegate
|
||||||
|
|
||||||
- (NSToolbarItem*)toolbar:(NSToolbar*)toolbar
|
- (NSToolbarItem*)toolbar:(NSToolbar*)toolbar
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue