From 578ad614a42178efb519d40188bc0f5254467f77 Mon Sep 17 00:00:00 2001 From: clavin Date: Tue, 10 Feb 2026 22:52:50 -0800 Subject: [PATCH] fix: restore MAS patch-outs Restores some `#if !IS_MAS_BUILD()` gates dropped in 773054ad59 --- ...dless_mode_handling_in_native_widget.patch | 8 +- ..._avoid_private_macos_api_usage.patch.patch | 122 ++++++++++++++++-- 2 files changed, 118 insertions(+), 12 deletions(-) diff --git a/patches/chromium/fix_adjust_headless_mode_handling_in_native_widget.patch b/patches/chromium/fix_adjust_headless_mode_handling_in_native_widget.patch index ebdb553397..2f5d1bee98 100644 --- a/patches/chromium/fix_adjust_headless_mode_handling_in_native_widget.patch +++ b/patches/chromium/fix_adjust_headless_mode_handling_in_native_widget.patch @@ -23,10 +23,10 @@ additional headless changes from breaking macOS window behavior. https://chromium-review.googlesource.com/c/chromium/src/+/7487666 diff --git a/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm b/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm -index 1b14feb15832bddde0ede2ac066d87a306cb2378..a18a7fa003f5ee5d07a0bc869049cceac2546741 100644 +index 96588e0dfd084822f5c98cfaf2ee3c403fbd5e5f..b7983880254a09722d540c41937095f63cbb8109 100644 --- a/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm +++ b/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm -@@ -211,6 +211,7 @@ @implementation NativeWidgetMacNSWindow { +@@ -218,6 +218,7 @@ @implementation NativeWidgetMacNSWindow { BOOL _isEnforcingNeverMadeVisible; BOOL _activationIndependence; BOOL _isTooltip; @@ -34,7 +34,7 @@ index 1b14feb15832bddde0ede2ac066d87a306cb2378..a18a7fa003f5ee5d07a0bc869049ccea BOOL _isShufflingForOrdering; BOOL _miniaturizationInProgress; std::unique_ptr _headless_info; -@@ -218,6 +219,7 @@ @implementation NativeWidgetMacNSWindow { +@@ -225,6 +226,7 @@ @implementation NativeWidgetMacNSWindow { @synthesize bridgedNativeWidgetId = _bridgedNativeWidgetId; @synthesize bridge = _bridge; @synthesize isTooltip = _isTooltip; @@ -42,7 +42,7 @@ index 1b14feb15832bddde0ede2ac066d87a306cb2378..a18a7fa003f5ee5d07a0bc869049ccea @synthesize isShufflingForOrdering = _isShufflingForOrdering; @synthesize preventKeyWindow = _preventKeyWindow; @synthesize childWindowAddedHandler = _childWindowAddedHandler; -@@ -239,23 +241,6 @@ - (instancetype)initWithContentRect:(NSRect)contentRect +@@ -246,23 +248,6 @@ - (instancetype)initWithContentRect:(NSRect)contentRect return self; } diff --git a/patches/chromium/mas_avoid_private_macos_api_usage.patch.patch b/patches/chromium/mas_avoid_private_macos_api_usage.patch.patch index 42549d056e..41c30f4465 100644 --- a/patches/chromium/mas_avoid_private_macos_api_usage.patch.patch +++ b/patches/chromium/mas_avoid_private_macos_api_usage.patch.patch @@ -519,10 +519,18 @@ index 889c0849910afa8f5be8bd8f55692bb482335383..ff2a4bc790b0fa2dec9702d82a022185 // The NSWindow used by BridgedNativeWidget. Provides hooks into AppKit that // can only be accomplished by overriding methods. diff --git a/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm b/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm -index 20fbdb2d4ac747aa174c5d8e19fd9f1ea48314a9..1b14feb15832bddde0ede2ac066d87a306cb2378 100644 +index 20fbdb2d4ac747aa174c5d8e19fd9f1ea48314a9..96588e0dfd084822f5c98cfaf2ee3c403fbd5e5f 100644 --- a/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm +++ b/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm -@@ -109,11 +109,13 @@ void OrderChildWindow(NSWindow* child_window, +@@ -22,6 +22,7 @@ + #import "components/remote_cocoa/app_shim/views_nswindow_delegate.h" + #import "components/remote_cocoa/app_shim/window_touch_bar_delegate.h" + #include "components/remote_cocoa/common/native_widget_ns_window_host.mojom.h" ++#include "electron/mas.h" + #include "ui/accessibility/platform/ax_platform_node.h" + #import "ui/base/cocoa/user_interface_item_command_handler.h" + #import "ui/base/cocoa/window_size_constants.h" +@@ -109,20 +110,24 @@ void OrderChildWindow(NSWindow* child_window, } // namespace @@ -535,24 +543,63 @@ index 20fbdb2d4ac747aa174c5d8e19fd9f1ea48314a9..1b14feb15832bddde0ede2ac066d87a3 +#endif @interface NSWindow (Private) ++#if !IS_MAS_BUILD() + (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle; -@@ -166,6 +168,7 @@ - (void)cr_mouseDownOnFrameView:(NSEvent*)event { +-- (BOOL)hasKeyAppearance; + - (long long)_resizeDirectionForMouseLocation:(CGPoint)location; + - (BOOL)_isConsideredOpenForPersistentState; + - (void)_zoomToScreenEdge:(NSUInteger)edge; + - (void)_removeFromGroups:(NSWindow*)window; + - (BOOL)_isNonactivatingPanel; ++#endif ++- (BOOL)hasKeyAppearance; + @end + + struct NSEdgeAndCornerThicknesses { +@@ -159,13 +164,17 @@ - (void)cr_mouseDownOnFrameView:(NSEvent*)event; + @implementation NSView (CRFrameViewAdditions) + // If a mouseDown: falls through to the frame view, turn it into a window drag. + - (void)cr_mouseDownOnFrameView:(NSEvent*)event { ++#if !IS_MAS_BUILD() + if ([self.window _resizeDirectionForMouseLocation:event.locationInWindow] != + -1) + return; ++#endif + [self.window performWindowDragWithEvent:event]; } @end +#if !IS_MAS_BUILD() ++ @implementation NativeWidgetMacNSWindowTitledFrame - (void)mouseDown:(NSEvent*)event { if (self.window.isMovable) -@@ -192,6 +195,7 @@ - (BOOL)usesCustomDrawing { - return NO; +@@ -193,6 +202,8 @@ - (BOOL)usesCustomDrawing { } @end -+#endif // !IS_MAS_BUILD() ++#endif // MAS_BUILD ++ @implementation NativeWidgetMacNSWindow { @private -@@ -401,6 +405,8 @@ - (NSAccessibilityRole)accessibilityRole { + CommandDispatcher* __strong _commandDispatcher; +@@ -262,6 +273,7 @@ - (NativeWidgetMacNSWindowHeadlessInfo*)headlessInfo { + // bubbles and the find bar, but these should not be movable. + // Instead, let's push this up to the parent window which should be + // the browser. ++#if !IS_MAS_BUILD() + - (void)_zoomToScreenEdge:(NSUInteger)edge { + if (self.parentWindow) { + [self.parentWindow _zoomToScreenEdge:edge]; +@@ -269,6 +281,7 @@ - (void)_zoomToScreenEdge:(NSUInteger)edge { + [super _zoomToScreenEdge:edge]; + } + } ++#endif + + // This override helps diagnose lifetime issues in crash stacktraces by + // inserting a symbol on NativeWidgetMacNSWindow and should be kept even if it +@@ -401,6 +414,8 @@ - (NSAccessibilityRole)accessibilityRole { // NSWindow overrides. @@ -561,7 +608,7 @@ index 20fbdb2d4ac747aa174c5d8e19fd9f1ea48314a9..1b14feb15832bddde0ede2ac066d87a3 + (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle { if (windowStyle & NSWindowStyleMaskTitled) { if (Class customFrame = [NativeWidgetMacNSWindowTitledFrame class]) -@@ -412,6 +418,8 @@ + (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle { +@@ -412,6 +427,8 @@ + (Class)frameViewClassForStyleMask:(NSWindowStyleMask)windowStyle { return [super frameViewClassForStyleMask:windowStyle]; } @@ -570,6 +617,65 @@ index 20fbdb2d4ac747aa174c5d8e19fd9f1ea48314a9..1b14feb15832bddde0ede2ac066d87a3 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen*)screen { if (self.isHeadless || self.parentWindow) { // AppKit's default implementation moves child windows down to avoid +@@ -449,12 +466,14 @@ - (BOOL)_usesCustomDrawing { + // if it were valid to set that style for windows, setting the window style + // recalculates and re-caches a bunch of stuff, so a surgical override is the + // cleanest approach. ++#if !IS_MAS_BUILD() + - (BOOL)_isNonactivatingPanel { + if (_activationIndependence) { + return YES; + } + return [super _isNonactivatingPanel]; + } ++#endif + + + (void)_getExteriorResizeEdgeThicknesses: + (NSEdgeAndCornerThicknesses*)outThicknesses +@@ -708,9 +727,11 @@ - (id)archiver:(NSKeyedArchiver*)archiver willEncodeObject:(id)object { + } + + - (void)saveRestorableState { ++#if !IS_MAS_BUILD() + if (!_bridge || ![self _isConsideredOpenForPersistentState]) { + return; + } ++#endif + + // Certain conditions, such as in the Speedometer 3 benchmark, can trigger a + // rapid succession of calls to saveRestorableState. If there's no pending +@@ -777,6 +798,7 @@ - (void)reallySaveRestorableState { + // affects its restorable state changes. + - (void)invalidateRestorableState { + [super invalidateRestorableState]; ++#if !IS_MAS_BUILD() + if ([self _isConsideredOpenForPersistentState]) { + if (_willUpdateRestorableState) + return; +@@ -789,6 +811,7 @@ - (void)invalidateRestorableState { + _willUpdateRestorableState = NO; + [NSObject cancelPreviousPerformRequestsWithTarget:self]; + } ++#endif + } + + // On newer SDKs, _canMiniaturize respects NSWindowStyleMaskMiniaturizable in +@@ -965,6 +988,7 @@ - (void)maybeRemoveTreeFromOrderingGroups { + // Since _removeFromGroups: is not documented it could go away in newer + // versions of macOS. If the selector does not exist, DumpWithoutCrashing() so + // we hear about the change. ++#if !IS_MAS_BUILD() + if (![NSWindow instancesRespondToSelector:@selector(_removeFromGroups:)]) { + base::debug::DumpWithoutCrashing(); + return; +@@ -982,6 +1006,7 @@ - (void)maybeRemoveTreeFromOrderingGroups { + [currentWindow _removeFromGroups:child]; + } + } ++#endif + } + + - (NSWindow*)rootWindow { diff --git a/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm b/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm index c6cfdc7b778f2027280d8624a0d48f385365f758..b99b8ec014c81c1d6ad14a6758568dd864102e2a 100644 --- a/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm