Remove duplicate accessibility declarations on macOS; NativeViewAccessible becomes a smart pointer holding id<NSAccessibility>

Commit: b7df7f51 | 2025-04-01 20:04:56+00:00

← Back to List

Remove duplicate accessibility declarations on macOS; NativeViewAccessible becomes a smart pointer holding id<NSAccessibility>

Major
Commit Hash: b7df7f511ec6604ed078633891651bd48bacf16e
Commit Time: 2025-04-01 20:04:56+00:00
Impact Level: Major
Generated By: webview2-upstream-sentry
Upstream Review: View Upstream Review 🔗

📋 Summary

This submission primarily refactors the type definition of NativeViewAccessible on the macOS platform, unifying it from the original raw pointer (id or objc_object*) to the base::apple::OwnedNSAccessibility smart pointer type. Relevant interfaces and call sites have been adapted accordingly; all code that returns, passes, or compares NativeViewAccessible now uses OwnedNSAccessibility, with added access methods such as .Get(). This eliminates redundant type declarations and enhances the safety and consistency of memory management. Related remote_cocoa code (such as native_widget_mac_nswindow.mm) has also been updated to accommodate the new type.

🎯 Impact Analysis

The impact of this change on WebView2Mac is mainly reflected in changes to type compatibility and memory management methods. Since downstream WebView2Mac code extensively inherits and calls remote_cocoa’s NativeViewAccessible-related interfaces, all operations involving accessibility bridging, passing, comparison, assignment, etc., need to be adapted to the OwnedNSAccessibility smart pointer semantics (such as .Get(), construction, null checks, etc.). If downstream code still assumes NativeViewAccessible is a raw pointer, it may result in compilation errors or inconsistent behavior. In addition, the introduction of smart pointers improves memory safety and reduces the risk of dangling pointers and double-free issues. In terms of functionality and performance, there is theoretically no direct negative impact, but it is necessary to ensure all downstream adaptations are in place; otherwise, compilation or runtime issues may occur. It is recommended to focus regression testing on accessibility-related features, especially the lifecycle management of windows, views, and NSAccessibility objects.

Impacted Classes:

NativeWidgetNSWindowBridge NativeWidgetNSWindowHostHelper WebContentsNSViewBridge remote_cocoa::mojom::NativeWidgetNSWindow remote_cocoa::mojom::Application remote_cocoa::mojom::TextInputHost remote_cocoa::mojom::WebContentsNSViewHost 以及所有直接/间接使用 gfx::NativeViewAccessible 的 remote_cocoa 相关类和接口