Explicitization of gfx::NativeWidget/View Constructors and Related Call Refactoring on Mac Platform
Moderate
Commit Hash:
83c8682ba594c789f11751209c6df0ba7e4cd093
Commit Time: 2025-03-20 16:05:58+00:00
Impact Level: Moderate
Generated By: webview2-upstream-sentry
Upstream Review:
View Upstream Review 🔗
📋 Summary
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.
🎯 Impact Analysis
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.
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.
Impacted Classes:
remote_cocoa::NativeWidgetNSWindowBridge
remote_cocoa::NativeWidgetNSWindowHostHelper
remote_cocoa::mojom::NativeWidgetNSWindow
remote_cocoa::mojom::NativeWidgetNSWindowHost