Modernize EnumTraits in components/

提交: 51633370 | 2026-03-30 09:13:42

← 返回列表

Modernize EnumTraits in components/

Minor
提交哈希: 51633370fb5ea558e8e721e37e643477c06cddfa
提交时间: 2026-03-30 09:13:42
影响等级: Minor
生成工具: webview2-upstream-sentry
上游审核链接: 查看上游审核 🔗

📋 摘要

This commit is part of a Chromium-wide Mojo EnumTraits modernization refactoring. It changes the FromMojom() method signature from the old output-parameter style (returning bool with result via pointer parameter) to directly returning the target type. For the remote_cocoa part, it modifies two EnumTraits specializations in components/remote_cocoa/common/font_mojom_traits.h:
1. EnumTraits::FromMojom() changed from returning bool + out parameter to directly returning SystemFontType, with invalid input using NOTREACHED().
2. EnumTraits::FromMojom() similarly changed from returning bool + out parameter to directly returning Font::Weight, with invalid input using NOTREACHED().

🎯 影响分析

The impact of this change on WebView2Mac is minor. Key analysis:

1. **Remote Cocoa font Mojo serialization affected**: The modified font_mojom_traits.h is used for Mojo serialization/deserialization of font information in Remote Cocoa cross-process communication. WebView2Mac uses these traits when passing font information between the app shim and browser processes.

2. **API signature change requires sync**: FromMojom()'s signature changed from bool FromMojom(MojomType, NativeType*) to NativeType FromMojom(MojomType), a compile-time API change. If Edge repo has any code directly calling these FromMojom methods (typically called automatically by Mojo infrastructure), it needs to be updated. Since these are traits used internally by the Mojo framework, manual calls are uncommon, and compilation will verify correctness upon integration.

3. **Error handling strategy change**: The old FromMojom returned false on invalid input (allowing callers to handle errors), while the new version uses NOTREACHED() to abort. This means receiving an unknown enum value in cross-process communication will crash rather than silently fail. This is a stricter error handling approach for WebView2Mac stability, but won't trigger during normal operation.

4. **Consistent with Chromium-wide refactoring**: This commit touches numerous files across components/, constituting a global API migration. Edge integration must ensure all affected EnumTraits use the new style to avoid Mojo framework version mismatches.

受影响的类:

mojo::EnumTraits<remote_cocoa::mojom::SystemFont> mojo::EnumTraits<remote_cocoa::mojom::FontWeight>