Skip to content

Commit

Permalink
Update to latest WebView2 library.
Browse files Browse the repository at this point in the history
Fix bugs in XsltControl delayed events.
Publish version 2.9.0.10
  • Loading branch information
lovettchris committed Apr 27, 2024
1 parent 9f10125 commit 3938d96
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 7,703 deletions.
16 changes: 8 additions & 8 deletions src/Application/Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Web.WebView2.Core, Version=1.0.2151.40, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2151.40\lib\net45\Microsoft.Web.WebView2.Core.dll</HintPath>
<Reference Include="Microsoft.Web.WebView2.Core, Version=1.0.2478.35, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2478.35\lib\net45\Microsoft.Web.WebView2.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.WebView2.WinForms, Version=1.0.2151.40, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2151.40\lib\net45\Microsoft.Web.WebView2.WinForms.dll</HintPath>
<Reference Include="Microsoft.Web.WebView2.WinForms, Version=1.0.2478.35, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2478.35\lib\net45\Microsoft.Web.WebView2.WinForms.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.WebView2.Wpf, Version=1.0.2151.40, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2151.40\lib\net45\Microsoft.Web.WebView2.Wpf.dll</HintPath>
<Reference Include="Microsoft.Web.WebView2.Wpf, Version=1.0.2478.35, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2478.35\lib\net45\Microsoft.Web.WebView2.Wpf.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Win32.Registry, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Win32.Registry.5.0.0\lib\net461\Microsoft.Win32.Registry.dll</HintPath>
Expand Down Expand Up @@ -398,11 +398,11 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.2478.35\build\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.2478.35\build\Microsoft.Web.WebView2.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.2151.40\build\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.2151.40\build\Microsoft.Web.WebView2.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.2478.35\build\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.2478.35\build\Microsoft.Web.WebView2.targets'))" />
</Target>
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.2151.40\build\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.2151.40\build\Microsoft.Web.WebView2.targets')" />
</Project>
7,651 changes: 0 additions & 7,651 deletions src/Application/Samples/Hamlet.htm

This file was deleted.

2 changes: 1 addition & 1 deletion src/Application/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="LovettSoftware.XmlDiff" version="1.1.0" targetFramework="net472" requireReinstallation="true" />
<package id="Microsoft.Web.WebView2" version="1.0.2151.40" targetFramework="net48" />
<package id="Microsoft.Web.WebView2" version="1.0.2478.35" targetFramework="net48" />
<package id="Microsoft.Win32.Registry" version="5.0.0" targetFramework="net472" />
<package id="Microsoft.Xml.SgmlReader" version="1.8.30" targetFramework="net472" requireReinstallation="true" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net472" />
Expand Down
4 changes: 2 additions & 2 deletions src/Version/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.9.0.9")]
[assembly: AssemblyFileVersion("2.9.0.9")]
[assembly: AssemblyVersion("2.9.0.10")]
[assembly: AssemblyFileVersion("2.9.0.10")]
4 changes: 2 additions & 2 deletions src/Version/Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>2.9.0.9</ApplicationVersion>
<ApplicationVersion>2.9.0.10</ApplicationVersion>
<Version>$(ApplicationVersion)</Version>
<Authors>Chris Lovett</Authors>
<Product>XmlNotepad</Product>
<RepositoryUrl>https://github.com/microsoft/xmlnotepad</RepositoryUrl>
<PackageProjectUrl>https://microsoft.github.io/XmlNotepad/</PackageProjectUrl>
<Company>Microsoft Corporation</Company>
<Copyright>Copyright © 2024 Microsoft Corporation</Copyright>
<WebView2Version>1.0.2151.40</WebView2Version>
<WebView2Version>1.0.2478.35</WebView2Version>
</PropertyGroup>
</Project>
1 change: 0 additions & 1 deletion src/XmlNotepad/AsyncXslt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ async System.Threading.Tasks.Task RunTransform()
watch.Start();
transform.Transform(xmlReader, null, wrapper);
watch.Stop();
this._context.info = new PerformanceInfo();
this._context.info.XsltMilliseconds = watch.ElapsedMilliseconds;
Debug.WriteLine("Transform in {0} milliseconds", watch.ElapsedMilliseconds);
this._xsltUri = resolved;
Expand Down
16 changes: 8 additions & 8 deletions src/XmlNotepad/XmlNotepad.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,14 @@
</ItemGroup>
<ItemGroup>
<Reference Include="Accessibility" />
<Reference Include="Microsoft.Web.WebView2.Core, Version=1.0.2151.40, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2151.40\lib\net45\Microsoft.Web.WebView2.Core.dll</HintPath>
<Reference Include="Microsoft.Web.WebView2.Core, Version=1.0.2478.35, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2478.35\lib\net45\Microsoft.Web.WebView2.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.WebView2.WinForms, Version=1.0.2151.40, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2151.40\lib\net45\Microsoft.Web.WebView2.WinForms.dll</HintPath>
<Reference Include="Microsoft.Web.WebView2.WinForms, Version=1.0.2478.35, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2478.35\lib\net45\Microsoft.Web.WebView2.WinForms.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.WebView2.Wpf, Version=1.0.2151.40, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2151.40\lib\net45\Microsoft.Web.WebView2.Wpf.dll</HintPath>
<Reference Include="Microsoft.Web.WebView2.Wpf, Version=1.0.2478.35, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.2478.35\lib\net45\Microsoft.Web.WebView2.Wpf.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
Expand Down Expand Up @@ -315,11 +315,11 @@
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.2478.35\build\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.2478.35\build\Microsoft.Web.WebView2.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.2151.40\build\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.2151.40\build\Microsoft.Web.WebView2.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.2478.35\build\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.2478.35\build\Microsoft.Web.WebView2.targets'))" />
</Target>
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.2151.40\build\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.2151.40\build\Microsoft.Web.WebView2.targets')" />
</Project>
73 changes: 47 additions & 26 deletions src/XmlNotepad/XsltControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public partial class XsltControl : UserControl
private AsyncXslt _asyncXslt;
private FormTransformProgress _progress;
private ITrustService _trustService;
private CoreWebView2Environment _environment;
private DelayedActions _delayedActions;

public event EventHandler<Exception> WebBrowserException;

Expand All @@ -49,6 +51,7 @@ public XsltControl()
{
InitializeComponent();
_resolver = new XmlUrlResolver();
_delayedActions = new DelayedActions();
}

/// <summary>
Expand All @@ -72,15 +75,24 @@ private async void EnsureCoreWebView2(CoreWebView2Environment environment)
try
{
await this.webBrowser2.EnsureCoreWebView2Async(environment);

this._settings.DelayedActions.StartDelayedAction("CompleteCoreWebView2", CompleteCoreWebView2, TimeSpan.FromMilliseconds(1));
this._delayedActions.StartDelayedAction("CompleteCoreWebView2", CompleteCoreWebView2, TimeSpan.FromMilliseconds(1));
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
HandleWebView2Exception(ex);
}
}

private void HandleWebView2Exception(Exception ex)
{
// fall back on old web browser control
RaiseBrowserException(new WebView2Exception(ex.Message));
this.BrowserVersion = "WebBrowser";
WebBrowserFallback();
this._settings["BrowserVersion"] = "WebBrowser";
this._settings["WebView2Exception"] = ex.Message;
}

private void CompleteCoreWebView2()
{
if (this._webView2Initialized)
Expand All @@ -103,6 +115,7 @@ private void CompleteCoreWebView2()

private async void InitializeBrowser(string version)
{
this._webInitialized = false;
try
{
this.BrowserVersion = version;
Expand All @@ -112,13 +125,21 @@ private async void InitializeBrowser(string version)
{
this.webBrowser2.CoreWebView2InitializationCompleted -= OnCoreWebView2InitializationCompleted;
this.webBrowser2.CoreWebView2InitializationCompleted += OnCoreWebView2InitializationCompleted;
CoreWebView2EnvironmentOptions options = new CoreWebView2EnvironmentOptions()
if (this._environment == null)
{
AllowSingleSignOnUsingOSPrimaryAccount = true
};
CoreWebView2EnvironmentOptions options = new CoreWebView2EnvironmentOptions()
{
AllowSingleSignOnUsingOSPrimaryAccount = true
};

CoreWebView2Environment environment = await CoreWebView2Environment.CreateAsync(userDataFolder: WebViewUserCache, options: options);
this._settings.DelayedActions.StartDelayedAction("EnsureCoreWebView2", () => EnsureCoreWebView2(environment), TimeSpan.FromMilliseconds(1));
this._environment = await CoreWebView2Environment.CreateAsync(userDataFolder: WebViewUserCache, options: options);
this._delayedActions.StartDelayedAction("EnsureCoreWebView2", () => EnsureCoreWebView2(this._environment), TimeSpan.FromMilliseconds(1));
}
}
else
{
// we already know webView2 is supported.
this._webInitialized = true;
}
}
else
Expand All @@ -131,12 +152,7 @@ private async void InitializeBrowser(string version)
}
catch (Exception ex)
{
// fall back on old web browser control
RaiseBrowserException(new WebView2Exception(ex.Message));
this.BrowserVersion = "WebBrowser";
this._settings["BrowserVersion"] = "WebBrowser";
WebBrowserFallback();
this._settings["WebView2Exception"] = ex.Message;
HandleWebView2Exception(ex);
}
}

Expand Down Expand Up @@ -179,13 +195,13 @@ private void OnCoreWebView2InitializationCompleted(object sender, CoreWebView2In
if (e.InitializationException != null)
{
// save this error someplace so we can show it to the user later when they try and enable WebView2.
RaiseBrowserException(new WebView2Exception(e.InitializationException.Message));
RaiseBrowserException(new WebView2Exception(e.InitializationException.Message));
}
}
else
{
this._webView2Initialized = true;
_webInitialized = true;
this._webInitialized = true;
}
}

Expand Down Expand Up @@ -240,10 +256,11 @@ public void DisplayFile(string filename)
_urlWatch.Reset();
_urlWatch.Start();

this.webBrowser2.Visible = UseWebView2();
this.webBrowser1.Visible = !UseWebView2();
bool useWebView2 = UseWebView2();
this.webBrowser2.Visible = useWebView2;
this.webBrowser1.Visible = !useWebView2;

if (UseWebView2())
if (useWebView2)
{
var uri = new Uri(filename);
try
Expand Down Expand Up @@ -304,15 +321,17 @@ private void Display(string content)
_urlWatch.Reset();
_urlWatch.Start();

this.webBrowser2.Visible = UseWebView2();
this.webBrowser1.Visible = !UseWebView2();
bool useWebView2 = UseWebView2();
this.webBrowser2.Visible = useWebView2;
this.webBrowser1.Visible = !useWebView2;

if (UseWebView2())
if (useWebView2)
{
try
{
if (content.Length > 1000000)
{
// NavigateToString is unfortunately limited to 1 mb.
content = content.Substring(0, 1000000) + "<h1>content truncated...";
}
// this has a 1mb limit for some unknown reason.
Expand Down Expand Up @@ -466,6 +485,7 @@ public async Task<string> DisplayXsltResults(XmlDocument doc, string xsltfilenam
hasDefaultXsltOutput = HasXsltOutput.Value;
}

this._info = new PerformanceInfo();

var context = new AsyncXsltContext()
{
Expand All @@ -480,6 +500,7 @@ public async Task<string> DisplayXsltResults(XmlDocument doc, string xsltfilenam
enableScripts = this.EnableScripts,
disableOutputFile = this.DisableOutputFile,
resolver = this._resolver,
info = this._info,
};

if (_previousTransform != null && _previousTransform.xsltfilename == xsltfilename)
Expand All @@ -488,7 +509,7 @@ public async Task<string> DisplayXsltResults(XmlDocument doc, string xsltfilenam
}
_previousTransform = context;

this._settings.DelayedActions.StartDelayedAction("SlowTransformProgress",
this._delayedActions.StartDelayedAction("SlowTransformProgress",
OnSlowTransform, TimeSpan.FromSeconds(1));

bool tryAgain = false;
Expand Down Expand Up @@ -558,7 +579,7 @@ public async Task<string> DisplayXsltResults(XmlDocument doc, string xsltfilenam

private void StopAsyncTransform()
{
this._settings.DelayedActions.CancelDelayedAction("SlowTransformProgress");
this._delayedActions.CancelDelayedAction("SlowTransformProgress");
if (this._progress != null)
{
this._progress.Close();
Expand All @@ -573,7 +594,7 @@ private void OnSlowTransform()
{
this._progress = new FormTransformProgress();
this._progress.SetProgress(0, (int)this._previousTransform.Size, (int)this._previousTransform.Position);
this._settings.DelayedActions.StartDelayedAction("UpdateTransformProgress", UpdateTransformProgress, TimeSpan.FromMilliseconds(30));
this._delayedActions.StartDelayedAction("UpdateTransformProgress", UpdateTransformProgress, TimeSpan.FromMilliseconds(30));
if (this._progress.ShowDialog() == DialogResult.Cancel)
{
this._previousTransform.Cancel();
Expand All @@ -586,7 +607,7 @@ private void UpdateTransformProgress()
if (this._progress != null)
{
this._progress.SetProgress(0, (int)this._previousTransform.Size, (int)this._previousTransform.Position);
this._settings.DelayedActions.StartDelayedAction("UpdateTransformProgress", UpdateTransformProgress, TimeSpan.FromMilliseconds(30));
this._delayedActions.StartDelayedAction("UpdateTransformProgress", UpdateTransformProgress, TimeSpan.FromMilliseconds(30));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/XmlNotepad/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="LovettSoftware.XmlDiff" version="1.1.0" targetFramework="net472" requireReinstallation="true" />
<package id="Microsoft.Web.WebView2" version="1.0.2151.40" targetFramework="net48" />
<package id="Microsoft.Web.WebView2" version="1.0.2478.35" targetFramework="net48" />
</packages>
2 changes: 1 addition & 1 deletion src/XmlNotepadBundle/Bundle.wxs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
<Bundle Name="XML Notepad" Version="2.9.0.9" Manufacturer="Lovett Software" UpgradeCode="b39cd92c-6bf2-4f4c-9e2c-fb402781a316">
<Bundle Name="XML Notepad" Version="2.9.0.10" Manufacturer="Lovett Software" UpgradeCode="b39cd92c-6bf2-4f4c-9e2c-fb402781a316">
<BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense">
<bal:WixStandardBootstrapperApplication LicenseFile="..\Application\license.rtf" ShowVersion="yes" />
</BootstrapperApplicationRef>
Expand Down
2 changes: 1 addition & 1 deletion src/XmlNotepadPackage/Package.appxmanifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap rescap">
<Identity Name="43906ChrisLovett.XmlNotepad" Publisher="CN=BC801FCC-0BF8-49D7-9F51-1B625C3BE476" Version="2.9.0.9" />
<Identity Name="43906ChrisLovett.XmlNotepad" Publisher="CN=BC801FCC-0BF8-49D7-9F51-1B625C3BE476" Version="2.9.0.10" />
<Properties>
<DisplayName>XmlNotepad</DisplayName>
<PublisherDisplayName>Chris Lovett</PublisherDisplayName>
Expand Down
Loading

0 comments on commit 3938d96

Please sign in to comment.