Remove the DestroyContentView call from NativeWidgetNSWindowBridge::CloseWindow

提交: ed452792 | 2025-08-28 18:41:30+00:00

← 返回列表

Remove the DestroyContentView call from NativeWidgetNSWindowBridge::CloseWindow

Moderate
提交哈希: ed4527922ec426094cd30fb13ea6f872d16373bd
提交时间: 2025-08-28 18:41:30+00:00
影响等级: Moderate
生成工具: webview2-upstream-sentry
上游审核链接: 查看上游审核 🔗

📋 摘要

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.

🎯 影响分析

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.

受影响的类:

NativeWidgetNSWindowBridge HostingNSWindowBridge BridgedContentView Widget APIs (GetNativeView, GetAllChildWidgets)