Remove the DestroyContentView call from NativeWidgetNSWindowBridge::CloseWindow
Moderate
Commit Hash:
ed4527922ec426094cd30fb13ea6f872d16373bd
Commit Time: 2025-08-28 18:41:30+00:00
Impact Level: Moderate
Generated By: webview2-upstream-sentry
Upstream Review:
View Upstream Review 🔗
📋 Summary
This commit removes the call to DestroyContentView() in the NativeWidgetNSWindowBridge::CloseWindow() method. The previous purpose of this call was to destroy the NSView of the NSWindow when the window is closed, thereby ensuring that Widget::GetNativeView() returns nil after the window is closed, in order to prevent NSView-related events from being delivered to host_ after the window is closed. However, this approach is inconsistent with other desktop platforms (on other platforms, gfx::NativeView remains valid until the Widget is destroyed), and it breaks many Widget APIs that handle gfx::NativeView (such as Widget::GetAllChildWidgets). The Chromium Widget-related code is already able to correctly handle such events received between Widget::Close() and ~Widget, so destroying the content view in advance is unnecessary.
🎯 Impact Analysis
This change has a moderate impact on WebView2Mac. WebView2Mac’s HostingNSWindowBridge inherits from remote_cocoa::NativeWidgetNSWindowBridge, so it is directly affected by this change. The main impacts include: 1) Change in window closing behavior: Previously, the content view would be destroyed immediately upon calling CloseWindow(); now, the content view remains valid until the window is actually destroyed. This may alter the lifecycle management of NSView in WebView2Mac. 2) Change in event handling: Between window closure and actual destruction, the NSView can still receive events, which may affect WebView2Mac’s event handling logic. 3) Improved API compatibility: APIs such as GetNativeView() remain valid after the window is closed, helping to improve consistency between WebView2Mac and other platforms. 4) Verification required: WebView2Mac needs to ensure its code can correctly handle NSView events received after the window is closed, especially within hosting_ns_window_bridge and related components.
Impacted Classes:
NativeWidgetNSWindowBridge
HostingNSWindowBridge
BridgedContentView
Widget APIs (GetNativeView, GetAllChildWidgets)