Explicitization of gfx::NativeWidget/View Constructors and Related Call Refactoring on Mac Platform

提交: 83c8682b | 2025-03-20 16:05:58+00:00

← 返回列表

Explicitization of gfx::NativeWidget/View Constructors and Related Call Refactoring on Mac Platform

Moderate
提交哈希: 83c8682ba594c789f11751209c6df0ba7e4cd093
提交时间: 2025-03-20 16:05:58+00:00
影响等级: Moderate
生成工具: webview2-upstream-sentry
上游审核链接: 查看上游审核 🔗

📋 摘要

This submission declares the constructors of gfx::NativeView(NSView*) and gfx::NativeWindow(NSWindow*) as explicit on the Mac platform to prevent implicit type conversions. At the same time, it extensively refactors the Chromium source code where conversions between NSView/NSWindow and gfx::NativeView/NativeWindow occur, requiring explicit construction. For the remote_cocoa related parts, the interface in native_widget_ns_window_bridge.h/.mm is changed from GetFromNativeWindow(gfx::NativeWindow) to GetFromNSWindow(NSWindow*), and all call sites are synchronously updated to ensure explicitness and type safety in type conversions.

🎯 影响分析

This change primarily enhances type safety, preventing potential bugs caused by implicit conversions between NSView/NSWindow and gfx::NativeView/NativeWindow. The impact on WebView2Mac is reflected in the following aspects:
1. All downstream code that locates the bridge via remote_cocoa::NativeWidgetNSWindowBridge-related interfaces (such as GetFromNativeWindow) must be switched to GetFromNSWindow, passing NSWindow* instead of gfx::NativeWindow.
2. If downstream code contains implicit conversions between NSWindow and gfx::NativeWindow, all such usages must be changed to explicit construction (e.g., gfx::NativeWindow(window)).
3. This change does not affect remote_cocoa’s Mojo interfaces, core functionality, or lifecycle management; it is solely an enhancement to type interface safety and does not involve changes to business logic.
4. If downstream code already follows the upstream interface specifications, the impact is limited to compile-time adaptation, with no substantive effect on functionality or performance; if not adapted, compilation will fail and batch corrections to type conversion methods will be required.
Overall, this change is a “breaking but controllable” refactor at the interface layer, requiring downstream adaptation of type usage, but it will not affect the core functionality or performance of WebView2Mac.

受影响的类:

remote_cocoa::NativeWidgetNSWindowBridge remote_cocoa::NativeWidgetNSWindowHostHelper remote_cocoa::mojom::NativeWidgetNSWindow remote_cocoa::mojom::NativeWidgetNSWindowHost