Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Update to WebView2 version 0.9.430 (need help) #81

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions WebWindow.Native.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Global
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B326B50A-F623-40F1-92F7-1EC6A5A48DAC}.Debug|Any CPU.ActiveCfg = Debug|Win32
{B326B50A-F623-40F1-92F7-1EC6A5A48DAC}.Debug|Any CPU.Build.0 = Debug|Win32
{B326B50A-F623-40F1-92F7-1EC6A5A48DAC}.Debug|x64.ActiveCfg = Debug|x64
{B326B50A-F623-40F1-92F7-1EC6A5A48DAC}.Debug|x64.Build.0 = Debug|x64
{B326B50A-F623-40F1-92F7-1EC6A5A48DAC}.Debug|x86.ActiveCfg = Debug|Win32
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
displayName: 'Use .NET Core sdk'
inputs:
packageType: sdk
version: 3.0.100
version: 3.1.200
installationPath: $(Agent.ToolsDirectory)/dotnet
- task: CmdLine@2
displayName: 'Install linux dependencies'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<BuildOutputFiles Include="dist\release\blazor.server.js" />
<BuildOutputFiles Include="dist\release\blazor.webassembly.js" />
</ItemGroup>

<ItemGroup>
<ProjectReference
Include="..\..\SignalR\clients\ts\signalr\signalr.npmproj"
Expand All @@ -26,6 +21,11 @@
Private="false" />
</ItemGroup>

<!-- Workaround strange issues with something calling these targets. -->
<Target Name="GetTargetFramework" />
<Target Name="GetCopyToPublishDirectoryItems" />
<Target Name="GetTargetPath" />

<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Directory.Build.targets))\Directory.Build.targets" />

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Prevent generated files from showing up in git and GitHub diffs. See https://www.git-scm.com/docs/gitattributes#_defining_macro_attributes, https://github.com/github/linguist#generated-code
*.js -diff -merge
*.js linguist-generated=true

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import '@dotnet/jsinterop'; Imported elsewhere
import '@dotnet/jsinterop';
import { resetScrollAfterNextBatch } from '../Rendering/Renderer';
import { EventDelegator } from '../Rendering/EventDelegator';

Expand Down
2 changes: 1 addition & 1 deletion src/WebWindow.Blazor/WebWindow.Blazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Title>WebWindow.Blazor</Title>
<PackageDescription>Host a Blazor application inside a native OS window on Windows, Mac, and Linux</PackageDescription>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand Down
11 changes: 6 additions & 5 deletions src/WebWindow.Native/WebWindow.Native.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
Expand Down Expand Up @@ -82,7 +82,7 @@
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand All @@ -95,6 +95,7 @@
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;shlwapi.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand Down Expand Up @@ -159,14 +160,14 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\packages\Microsoft.Web.WebView2.0.8.355\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\..\packages\Microsoft.Web.WebView2.0.8.355\build\native\Microsoft.Web.WebView2.targets')" />
<Import Project="..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
<Import Project="..\..\packages\Microsoft.Web.WebView2.0.9.430\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\..\packages\Microsoft.Web.WebView2.0.9.430\build\native\Microsoft.Web.WebView2.targets')" />
</ImportGroup>
<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.0.8.355\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Web.WebView2.0.8.355\build\native\Microsoft.Web.WebView2.targets'))" />
<Error Condition="!Exists('..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
<Error Condition="!Exists('..\..\packages\Microsoft.Web.WebView2.0.9.430\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Web.WebView2.0.9.430\build\native\Microsoft.Web.WebView2.targets'))" />
</Target>
</Project>
40 changes: 22 additions & 18 deletions src/WebWindow.Native/WebWindow.Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void WebWindow::RefitContent()
{
RECT bounds;
GetClientRect(_hWnd, &bounds);
_webviewWindow->put_Bounds(bounds);
_webviewHost->put_Bounds(bounds);
}
}

Expand Down Expand Up @@ -206,47 +206,51 @@ void WebWindow::AttachWebView()
std::atomic_flag flag = ATOMIC_FLAG_INIT;
flag.test_and_set();

HRESULT envResult = CreateWebView2EnvironmentWithDetails(nullptr, nullptr, nullptr,
Callback<IWebView2CreateWebView2EnvironmentCompletedHandler>(
[&, this](HRESULT result, IWebView2Environment* env) -> HRESULT {
HRESULT envResult = CreateCoreWebView2EnvironmentWithDetails(nullptr, nullptr, nullptr,
Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
[&, this](HRESULT result, ICoreWebView2Environment* env) -> HRESULT {
HRESULT envResult = env->QueryInterface(&_webviewEnvironment);
if (envResult != S_OK)
{
return envResult;
}

// Create a WebView, whose parent is the main window hWnd
env->CreateWebView(_hWnd, Callback<IWebView2CreateWebViewCompletedHandler>(
[&, this](HRESULT result, IWebView2WebView* webview) -> HRESULT {
env->CreateCoreWebView2Host(_hWnd, Callback<ICoreWebView2CreateCoreWebView2HostCompletedHandler>(
[&, this](HRESULT result, ICoreWebView2Host* webview) -> HRESULT {
if (result != S_OK) { return result; }
result = webview->QueryInterface(&_webviewWindow);
result = webview->QueryInterface(&_webviewHost);
if (result != S_OK) { return result; }
result = webview->get_CoreWebView2(&_webviewWindow);
if (result != S_OK) { return result; }

// Add a few settings for the webview
// this is a redundant demo step as they are the default settings values
IWebView2Settings* Settings;
ICoreWebView2Settings* Settings;
_webviewWindow->get_Settings(&Settings);
Settings->put_IsScriptEnabled(TRUE);
Settings->put_AreDefaultScriptDialogsEnabled(TRUE);
Settings->put_IsWebMessageEnabled(TRUE);
Settings->put_AreDevToolsEnabled(FALSE);
Settings->put_AreDefaultContextMenusEnabled(FALSE);

// Register interop APIs
EventRegistrationToken webMessageToken;
_webviewWindow->AddScriptToExecuteOnDocumentCreated(L"window.external = { sendMessage: function(message) { window.chrome.webview.postMessage(message); }, receiveMessage: function(callback) { window.chrome.webview.addEventListener(\'message\', function(e) { callback(e.data); }); } };", nullptr);
_webviewWindow->add_WebMessageReceived(Callback<IWebView2WebMessageReceivedEventHandler>(
[this](IWebView2WebView* webview, IWebView2WebMessageReceivedEventArgs* args) -> HRESULT {
_webviewWindow->add_WebMessageReceived(Callback<ICoreWebView2WebMessageReceivedEventHandler>(
[this](ICoreWebView2* webview, ICoreWebView2WebMessageReceivedEventArgs* args) -> HRESULT {
wil::unique_cotaskmem_string message;
args->get_WebMessageAsString(&message);
args->TryGetWebMessageAsString(&message);
_webMessageReceivedCallback(message.get());
return S_OK;
}).Get(), &webMessageToken);

EventRegistrationToken webResourceRequestedToken;
_webviewWindow->AddWebResourceRequestedFilter(L"*", WEBVIEW2_WEB_RESOURCE_CONTEXT_ALL);
_webviewWindow->add_WebResourceRequested(Callback<IWebView2WebResourceRequestedEventHandler>(
[this](IWebView2WebView* sender, IWebView2WebResourceRequestedEventArgs* args)
_webviewWindow->AddWebResourceRequestedFilter(L"*", CORE_WEBVIEW2_WEB_RESOURCE_CONTEXT_ALL);
_webviewWindow->add_WebResourceRequested(Callback<ICoreWebView2WebResourceRequestedEventHandler>(
[this](ICoreWebView2* sender, ICoreWebView2WebResourceRequestedEventArgs* args)
{
IWebView2WebResourceRequest* req;
ICoreWebView2WebResourceRequest* req;
args->get_Request(&req);

wil::unique_cotaskmem_string uri;
Expand All @@ -268,7 +272,7 @@ void WebWindow::AttachWebView()
std::wstring contentTypeWS = contentType;

IStream* dataStream = SHCreateMemStream((BYTE*)dotNetResponse.get(), numBytes);
wil::com_ptr<IWebView2WebResourceResponse> response;
wil::com_ptr<ICoreWebView2WebResourceResponse> response;
_webviewEnvironment->CreateWebResourceResponse(
dataStream, 200, L"OK", (L"Content-Type: " + contentTypeWS).c_str(),
&response);
Expand Down Expand Up @@ -349,7 +353,7 @@ void WebWindow::SetSize(int width, int height)
SetWindowPos(_hWnd, HWND_TOP, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER);
}

BOOL MonitorEnum(HMONITOR monitor, HDC, LPRECT, LPARAM arg)
BOOL __stdcall MonitorEnum(HMONITOR monitor, HDC, LPRECT, LPARAM arg)
{
auto callback = (GetAllMonitorsCallback)arg;
MONITORINFO info = {};
Expand All @@ -370,7 +374,7 @@ BOOL MonitorEnum(HMONITOR monitor, HDC, LPRECT, LPARAM arg)
void WebWindow::GetAllMonitors(GetAllMonitorsCallback callback)
{
if (callback)
{
{
EnumDisplayMonitors(NULL, NULL, MonitorEnum, (LPARAM)callback);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/WebWindow.Native/WebWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <map>
#include <string>
#include <wil/com.h>
#include <WebView2.h>
#include "WebView2.h"
typedef const wchar_t* AutoString;
#else
#ifdef OS_LINUX
Expand Down Expand Up @@ -42,8 +42,9 @@ class WebWindow
static HINSTANCE _hInstance;
HWND _hWnd;
WebWindow* _parent;
wil::com_ptr<IWebView2Environment3> _webviewEnvironment;
wil::com_ptr<IWebView2WebView5> _webviewWindow;
wil::com_ptr<ICoreWebView2Environment> _webviewEnvironment;
wil::com_ptr<ICoreWebView2> _webviewWindow;
wil::com_ptr<ICoreWebView2Host> _webviewHost;
std::map<std::wstring, WebResourceRequestedCallback> _schemeToRequestHandler;
void AttachWebView();
#elif OS_LINUX
Expand Down
2 changes: 1 addition & 1 deletion src/WebWindow.Native/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="Microsoft.Web.WebView2" version="0.8.355" targetFramework="native" />
<package id="Microsoft.Web.WebView2" version="0.9.430" targetFramework="native" />
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.191107.2" targetFramework="native" />
</packages>
2 changes: 1 addition & 1 deletion testassets/HelloWorldApp/HelloWorldApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion testassets/MyBlazorApp/MyBlazorApp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>WinExe</OutputType>
</PropertyGroup>

Expand Down