diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index 865db4d..a777216 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -34,7 +34,7 @@ jobs:
displayName: 'Use .NET Core sdk'
inputs:
packageType: sdk
- version: 3.0.100
+ version: 3.1.101
installationPath: $(Agent.ToolsDirectory)/dotnet
- task: CmdLine@2
displayName: 'Install linux dependencies'
diff --git a/src/WebWindow.Blazor.JS/WebWindow.Blazor.JS.csproj b/src/WebWindow.Blazor.JS/WebWindow.Blazor.JS.csproj
index 02d5e16..5ddaf02 100644
--- a/src/WebWindow.Blazor.JS/WebWindow.Blazor.JS.csproj
+++ b/src/WebWindow.Blazor.JS/WebWindow.Blazor.JS.csproj
@@ -1,7 +1,7 @@
- netstandard2.0
+ netstandard2.1
true
Latest
${DefaultItemExcludes};node_modules\**
diff --git a/src/WebWindow.Blazor/WebWindow.Blazor.csproj b/src/WebWindow.Blazor/WebWindow.Blazor.csproj
index 504fb9c..5efe95e 100644
--- a/src/WebWindow.Blazor/WebWindow.Blazor.csproj
+++ b/src/WebWindow.Blazor/WebWindow.Blazor.csproj
@@ -1,17 +1,17 @@
- netcoreapp3.0
+ netcoreapp3.1
WebWindow.Blazor
Host a Blazor application inside a native OS window on Windows, Mac, and Linux
Apache-2.0
-
-
-
-
+
+
+
+
diff --git a/src/WebWindow.Native/WebWindow.Native.vcxproj b/src/WebWindow.Native/WebWindow.Native.vcxproj
index 3c5ef82..e8d4df2 100644
--- a/src/WebWindow.Native/WebWindow.Native.vcxproj
+++ b/src/WebWindow.Native/WebWindow.Native.vcxproj
@@ -159,14 +159,14 @@
-
-
+
+
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}.
-
-
+
+
\ No newline at end of file
diff --git a/src/WebWindow.Native/WebWindow.Native.vcxproj.filters b/src/WebWindow.Native/WebWindow.Native.vcxproj.filters
index eaf12b1..9e7bf64 100644
--- a/src/WebWindow.Native/WebWindow.Native.vcxproj.filters
+++ b/src/WebWindow.Native/WebWindow.Native.vcxproj.filters
@@ -31,7 +31,7 @@
-
+
\ No newline at end of file
diff --git a/src/WebWindow.Native/WebWindow.Windows.cpp b/src/WebWindow.Native/WebWindow.Windows.cpp
index f56db8c..61d4fd1 100644
--- a/src/WebWindow.Native/WebWindow.Windows.cpp
+++ b/src/WebWindow.Native/WebWindow.Windows.cpp
@@ -208,81 +208,99 @@ void WebWindow::AttachWebView()
HRESULT envResult = CreateWebView2EnvironmentWithDetails(nullptr, nullptr, nullptr,
Callback(
- [&, this](HRESULT result, IWebView2Environment* env) -> HRESULT {
- _webviewEnvironment = env;
-
- // Create a WebView, whose parent is the main window hWnd
- env->CreateWebView(_hWnd, Callback(
- [&, this](HRESULT result, IWebView2WebView* webview) -> HRESULT {
- if (webview != nullptr) {
- _webviewWindow = webview;
+ [&, this](HRESULT result, IWebView2Environment* env) -> HRESULT
+ {
+ _webviewEnvironment = env;
+
+ // Create a WebView, whose parent is the main window hWnd
+ env->CreateWebView(_hWnd, Callback(
+ [&, this](HRESULT result, IWebView2WebView* webview) -> HRESULT
+ {
+ if (webview != nullptr)
+ {
+ _webviewWindow = static_cast(webview);
+ }
+
+ // Add a few settings for the webview
+ // this is a redundant demo step as they are the default settings values
+ IWebView2Settings* Settings;
+ _webviewWindow->get_Settings(&Settings);
+ Settings->put_IsScriptEnabled(TRUE);
+ Settings->put_AreDefaultScriptDialogsEnabled(TRUE);
+ Settings->put_IsWebMessageEnabled(TRUE);
+
+ // 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(
+ [this](IWebView2WebView* webview, IWebView2WebMessageReceivedEventArgs* args) -> HRESULT
+ {
+ wil::unique_cotaskmem_string message;
+ args->get_WebMessageAsString(&message);
+ _webMessageReceivedCallback(message.get());
+ return S_OK;
+ }).Get(), &webMessageToken);
+
+ EventRegistrationToken webResourceRequestedToken;
+ _webviewWindow->AddWebResourceRequestedFilter(L"*", WEBVIEW2_WEB_RESOURCE_CONTEXT_ALL);
+
+ _webviewWindow->add_WebResourceRequested(
+ Callback(
+ [this](IWebView2WebView* sender, IWebView2WebResourceRequestedEventArgs* args)
+ {
+ IWebView2WebResourceRequest* req;
+ args->get_Request(&req);
+
+ wil::unique_cotaskmem_string uri;
+ req->get_Uri(&uri);
+ std::wstring uriString = uri.get();
+ size_t colonPos = uriString.find(L':', 0);
+
+ if (colonPos > 0)
+ {
+ std::wstring scheme = uriString.substr(0, colonPos);
+ WebResourceRequestedCallback handler = _schemeToRequestHandler[scheme];
+
+ if (handler != NULL)
+ {
+ int numBytes;
+
+ AutoString contentType;
+
+ wil::unique_cotaskmem dotNetResponse(handler(uriString.c_str(), &numBytes, &contentType));
+
+ if (dotNetResponse != nullptr && contentType != nullptr)
+ {
+ std::wstring contentTypeWS = contentType;
+
+ IStream* dataStream = SHCreateMemStream((BYTE*)dotNetResponse.get(), numBytes);
+
+ wil::com_ptr response;
+
+ _webviewEnvironment->CreateWebResourceResponse(
+ dataStream, 200, L"OK", (L"Content-Type: " + contentTypeWS).c_str(), &response);
+
+ args->put_Response(response.get());
}
+ }
+ }
- // Add a few settings for the webview
- // this is a redundant demo step as they are the default settings values
- IWebView2Settings* Settings;
- _webviewWindow->get_Settings(&Settings);
- Settings->put_IsScriptEnabled(TRUE);
- Settings->put_AreDefaultScriptDialogsEnabled(TRUE);
- Settings->put_IsWebMessageEnabled(TRUE);
-
- // 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(
- [this](IWebView2WebView* webview, IWebView2WebMessageReceivedEventArgs* args) -> HRESULT {
- wil::unique_cotaskmem_string message;
- args->get_WebMessageAsString(&message);
- _webMessageReceivedCallback(message.get());
- return S_OK;
- }).Get(), &webMessageToken);
-
- EventRegistrationToken webResourceRequestedToken;
- _webviewWindow->add_WebResourceRequested(nullptr, nullptr, 0, Callback(
- [this](IWebView2WebView* sender, IWebView2WebResourceRequestedEventArgs* args)
- {
- IWebView2WebResourceRequest* req;
- args->get_Request(&req);
-
- wil::unique_cotaskmem_string uri;
- req->get_Uri(&uri);
- std::wstring uriString = uri.get();
- size_t colonPos = uriString.find(L':', 0);
- if (colonPos > 0)
- {
- std::wstring scheme = uriString.substr(0, colonPos);
- WebResourceRequestedCallback handler = _schemeToRequestHandler[scheme];
- if (handler != NULL)
- {
- int numBytes;
- AutoString contentType;
- wil::unique_cotaskmem dotNetResponse(handler(uriString.c_str(), &numBytes, &contentType));
-
- if (dotNetResponse != nullptr && contentType != nullptr)
- {
- std::wstring contentTypeWS = contentType;
-
- IStream* dataStream = SHCreateMemStream((BYTE*)dotNetResponse.get(), numBytes);
- wil::com_ptr response;
- _webviewEnvironment->CreateWebResourceResponse(
- dataStream, 200, L"OK", (L"Content-Type: " + contentTypeWS).c_str(),
- &response);
- args->put_Response(response.get());
- }
- }
- }
-
- return S_OK;
- }
- ).Get(), &webResourceRequestedToken);
-
- RefitContent();
-
- flag.clear();
- return S_OK;
- }).Get());
return S_OK;
- }).Get());
+
+ }).Get(), &webResourceRequestedToken);
+
+ RefitContent();
+
+ flag.clear();
+
+ return S_OK;
+
+ }).Get());
+
+ return S_OK;
+
+ }).Get());
if (envResult != S_OK)
{
@@ -295,6 +313,7 @@ void WebWindow::AttachWebView()
// Block until it's ready. This simplifies things for the caller, so they
// don't need to regard this process as async.
MSG msg = { };
+
while (flag.test_and_set() && GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
diff --git a/src/WebWindow.Native/WebWindow.h b/src/WebWindow.Native/WebWindow.h
index f5cf4f7..68913e6 100644
--- a/src/WebWindow.Native/WebWindow.h
+++ b/src/WebWindow.Native/WebWindow.h
@@ -43,7 +43,7 @@ class WebWindow
HWND _hWnd;
WebWindow* _parent;
wil::com_ptr _webviewEnvironment;
- wil::com_ptr _webviewWindow;
+ wil::com_ptr _webviewWindow;
std::map _schemeToRequestHandler;
void AttachWebView();
#elif OS_LINUX
diff --git a/src/WebWindow.Native/packages.config b/src/WebWindow.Native/packages.config
index 8137acf..f10b389 100644
--- a/src/WebWindow.Native/packages.config
+++ b/src/WebWindow.Native/packages.config
@@ -1,5 +1,5 @@
-
-
+
+
\ No newline at end of file
diff --git a/testassets/HelloWorldApp/HelloWorldApp.csproj b/testassets/HelloWorldApp/HelloWorldApp.csproj
index 6cb80cf..f6b6a0f 100644
--- a/testassets/HelloWorldApp/HelloWorldApp.csproj
+++ b/testassets/HelloWorldApp/HelloWorldApp.csproj
@@ -2,7 +2,7 @@
Exe
- netcoreapp3.0
+ netcoreapp3.1
diff --git a/testassets/MyBlazorApp/MyBlazorApp.csproj b/testassets/MyBlazorApp/MyBlazorApp.csproj
index b855521..5a54d27 100644
--- a/testassets/MyBlazorApp/MyBlazorApp.csproj
+++ b/testassets/MyBlazorApp/MyBlazorApp.csproj
@@ -1,7 +1,7 @@
- netcoreapp3.0
+ netcoreapp3.1
WinExe