Repository navigation
Conversation
|
|
There was a problem hiding this comment.
Pull request overview
This PR addresses Win32 Skia Gallery WebView failures under .NET 10 NativeAOT by introducing a dedicated WebView2Aot-based implementation and routing the Win32 WebView provider to use it on NET10_0_OR_GREATER, while keeping the existing Microsoft.Web.WebView2 runtime path for earlier TFMs.
Changes:
- Added
Win32NativeWebViewBaseto centralize HWND creation, WndProc handling, sizing/close forwarding, and destruction. - Added
Win32NativeAotWebView(NET10+) usingWebView2AotCOM APIs and wrapper types to preserve existingCoreWebView2behavior. - Added conditional
WebView2Aotpackage reference fornet10.0and pinned its version centrally.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Uno.UI.Runtime.Skia.Win32/Uno.UI.Runtime.Skia.Win32.csproj | Adds conditional WebView2Aot reference for net10 builds. |
| src/Uno.UI.Runtime.Skia.Win32/UI/Xaml/Controls/WebView/Win32NativeWebViewBase.cs | Introduces shared Win32 child window lifecycle + WndProc forwarding for WebView hosting. |
| src/Uno.UI.Runtime.Skia.Win32/UI/Xaml/Controls/WebView/Win32NativeWebView.cs | Routes NET10 to AOT implementation; refactors existing WebView2 runtime implementation to inherit from the shared base. |
| src/Uno.UI.Runtime.Skia.Win32/UI/Xaml/Controls/WebView/Win32NativeAotWebView.cs | Adds the NativeAOT WebView2Aot-backed implementation and WebResourceRequested wrapper types. |
| src/Directory.Build.targets | Pins WebView2Aot package version centrally. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23351/wasm-skia-net9/index.html |
Claude output of: > Update `src/Uno.UI.Runtime.Skia.Win32/UI/Xaml/Controls/WebView/Win32NativeAotWebView.cs` > so that it does not mention `Microsoft.Web.WebView2.Core` or the `mswebview2` extern alias. > All functionality within this file should use only the WebView2Aot NuGet package.
Stop ignoring IDE0055 and address all IDE0055 warnings.
Addresses many Copilot comments.
Context: smourier/DirectNAot#9 `DirectN.PWSTR.From(string)` may interact poorly with the GC; see smourier/DirectNAot#9 for details. Instead of using `PWSTR.From(string)`, use `new PWSTR(char*)`. Update `Uno.UI.Runtime.Skia.Win32.csproj` to use the [Microsoft.CodeAnalysis.BannedApiAnalyzers][0] NuGet package to "ban" use of `PWSTR.From(string)`. [0]: https://www.nuget.org/packages/Microsoft.CodeAnalysis.BannedApiAnalyzers/
7cab432 to
5dfd6fd
Compare
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Web.WebView2" Aliases="mswebview2" PrivateAssets="all" /> | ||
| <PackageReference Include="WebView2Aot" Condition="$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'net10.0'))" /> | ||
|
|
| Presenter.DispatcherQueue.TryEnqueue(() => | ||
| { | ||
| var success = PInvoke.DestroyWindow(Hwnd); | ||
| if (!success && this.Log().IsEnabled(LogLevel.Error)) | ||
| { | ||
| this.Log().Error($"{nameof(PInvoke.DestroyWindow)} failed: {Win32Helper.GetErrorMessage()}"); | ||
| } | ||
|
|
||
| lock (_hwndToWebView) | ||
| { | ||
| _hwndToWebView.Remove(Hwnd); | ||
| } | ||
| }); |
| _coreWebView.RaiseNewWindowRequested( | ||
| e.Uri, | ||
| CoreWebView2.BlankUri, | ||
| out var handled); | ||
| e.Uri, | ||
| CoreWebView2.BlankUri, | ||
| out var handled); | ||
|
|
Remove unnecessary whitespace changes. Add support for `AllowSingleSignOnUsingOSPrimaryAccount` to `Win32NativeAotWebView`, consistent with `Win32NativeWebView`.
| controller.get_CoreWebView2(out var coreWebView).ThrowOnError(); | ||
| tcs.TrySetResult((controller, (WebView2.ICoreWebView2_22)coreWebView)); |
| _nativeWebView.get_Environment(out var environment).ThrowOnError(); | ||
| var env2 = (WebView2.ICoreWebView2Environment2)environment; |
| env2.CreateWebResourceRequest( | ||
| new PWSTR(p_requestUri), | ||
| new PWSTR(p_requestMethod), | ||
| bodyIStream!, | ||
| new PWSTR(p_requestHeaders), | ||
| out var request).ThrowOnError(); |
|
Superseded by #23604. |
PR Type:
🐞 Bugfix
What changed? 🚀
Native AOT on Desktop (
net10.0) could fail when opening Gallery WebView and leave the app UI in a broken state. This PR adds a dedicated Win32 AOT WebView path while preserving the existing runtime path for non-AOT targets.Win32 hosting split
Win32NativeWebViewBaseto centralize HWND lifecycle and WndProc behavior (window creation, WM_SIZE/WM_CLOSE/SC_CLOSE forwarding, destruction).Win32NativeWebViewto inherit from the base and keep non-AOTmswebview2logic local.Native AOT WebView implementation
Win32NativeAotWebView(forNET10_0_OR_GREATER) usingWebView2Aotfor environment/controller creation.CoreWebView2event/navigation flow to keep behavior consistent (navigation, history, title, script execution, resource filters, virtual host mapping).Provider routing
Win32NativeWebViewProvider.CreateNativeWebView()now selects:Win32NativeAotWebViewonNET10_0_OR_GREATERWin32NativeWebViewotherwisePackaging / targeting
WebView2Aotpackage reference inUno.UI.Runtime.Skia.Win32.csprojwith:$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'net10.0'))WebView2Aotinsrc/Directory.Build.targets.PR Checklist ✅
Screenshots Compare Test Runresults.