Skip to content

Conversation

Eilon
Copy link
Contributor

@Eilon Eilon commented May 28, 2021

Most of this change is quite un-interesting because it's creating an abstraction, implementing it, and then calling it. The most fundamental change is that the WebView2 package no longer references Edge WebView2. Instead, the WPF and WinForms packages reference it in order to implement the abstractions. This allows .NET MAUI's implementation to reference the WinUI WebView2 package, which has different type identities (and some slightly different APIs, too).

What's actually interesting here?

  1. WebView2 package reference moved from Components WebView2 package into WPF and WinForms packages
  2. EnsureCoreWebView2Async no longer takes in an Environment because that's not allowed in WinUI. So the WPF/WinForms implementation store their created Environment and then pass it in. (Not a big deal.)
  3. The event handler pattern is abstracted and simplified instead of trying to wrap the exact WebView2 API. For BlazorWebView we use a limited set of APIs so they are simplified to the usage. Because event handlers are wrapped, they changed to a pattern Action AddXYZHandler(my_handler) where the returned Action is a removal callback because otherwise the caller couldn't actually un-hook the event. We don't actually use the removal callbacks right now, but when we do proper disposal, we'll want to unhook event handlers.
  4. A new QueueBlazorStart() method was added that isn't used in WPF/WinForms, but is used in .NET MAUI WinUI, because it uses autostart='false' and needs to queue Blazor startup. If we choose to always use autostart='false' then we could remove this method and always do it in the common WebView2WebViewManager class.
  5. I tried this out in .NET MAUI by copying the WebView2 abstractions over and updating the implementations and it works great. I will later update .NET MAUI by commiting those changes so that it's already using this new pattern and when .NET MAUI starts referencing the new types, all we have to do is delete the copied code, and it will continue to work.

The net result is that WebView2WebViewManager changed relatively little, which shows the the abstractions Do The Needful™.

Fixes #32770

@Eilon Eilon requested a review from a team as a code owner May 28, 2021 22:18
@ghost ghost added the area-blazor Includes: Blazor, Razor Components label May 28, 2021
@Eilon
Copy link
Contributor Author

Eilon commented Jun 1, 2021

Pushed a change that should fix the CI failures. It's a bug in the WebView2 packages.

Copy link
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have more high level questions than anything else.

  • Are customers supposed to interact with these "wrappers"?
  • Can we put a comment like this otherwise?

@Eilon
Copy link
Contributor Author

Eilon commented Jun 3, 2021

@javiercn - no & yes. I will add a comment like that on top of the other comments that I have for all the public APIs.

@Eilon
Copy link
Contributor Author

Eilon commented Jun 3, 2021

Comments added.

@Eilon Eilon merged commit ef40046 into main Jun 4, 2021
@Eilon Eilon deleted the eilon/webview2-abs branch June 4, 2021 16:14
@ghost ghost added this to the 6.0-preview6 milestone Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create WebView2 abstraction for sharing code between ASP.NET Core and .NET MAUI
2 participants