Skip to content

Commit 6a25eeb

Browse files
WebView2Samples update for 1.0.3230-prerelease (#272)
* Updates for Win32, WPF, WinForms, UWP and WinUI3 sample apps from 136.0.3230.0 * Updated package version for Win32, WPF and WinForms sample apps to 1.0.3230-prerelease --------- Co-authored-by: WebView2 Github Bot <webview2github@microsoft.com>
1 parent 22abe8a commit 6a25eeb

10 files changed

+153
-16
lines changed

Diff for: SampleApps/WebView2APISample/ScenarioFileTypePolicy.cpp

+26-2
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ bool ScenarioFileTypePolicy::SuppressPolicyForExtension()
9191
CHECK_FAILURE(deferral->Complete());
9292
});
9393
}
94-
if (wcscmp(extension_lower.c_str(), L"exe") == 0)
94+
if (wcscmp(extension_lower.c_str(), L".exe") == 0)
9595
{
9696
if (is_exe_blocked.has_value())
9797
{
98-
if (is_exe_blocked)
98+
if (is_exe_blocked.value())
9999
{
100100
args->put_CancelSave(true);
101101
}
@@ -105,6 +105,30 @@ bool ScenarioFileTypePolicy::SuppressPolicyForExtension()
105105
}
106106
}
107107
}
108+
if (wcscmp(extension_lower.c_str(), L".emlx") == 0)
109+
{
110+
wil::com_ptr<ICoreWebView2Deferral> deferral;
111+
CHECK_FAILURE(args->GetDeferral(&deferral));
112+
m_appWindow->RunAsync(
113+
[this, args = wil::make_com_ptr(args), deferral]()
114+
{
115+
// With the deferral, the cancel decision and
116+
// message box can be replaced with a customized UI.
117+
auto selection = MessageBox(
118+
m_appWindow->GetMainWindow(), L"Block the download?",
119+
L"Info", MB_OKCANCEL);
120+
if (selection == IDOK)
121+
{
122+
CHECK_FAILURE(args->put_CancelSave(TRUE));
123+
}
124+
else if (selection == IDCANCEL)
125+
{
126+
CHECK_FAILURE(args->put_SuppressDefaultPolicy(TRUE));
127+
128+
}
129+
CHECK_FAILURE(deferral->Complete());
130+
});
131+
}
108132
return S_OK;
109133
})
110134
.Get(),

Diff for: SampleApps/WebView2APISample/ScenarioWebViewEventMonitor.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1249,12 +1249,12 @@ void ScenarioWebViewEventMonitor::InitializeFrameEventView(
12491249
.Get(),
12501250
NULL);
12511251
}
1252-
auto experimental_frame8 = webviewFrame.try_query<ICoreWebView2ExperimentalFrame8>();
1253-
if (experimental_frame8)
1252+
auto frame7 = webviewFrame.try_query<ICoreWebView2Frame7>();
1253+
if (frame7)
12541254
{
12551255
//! [FrameCreated]
1256-
experimental_frame8->add_FrameCreated(
1257-
Callback<ICoreWebView2ExperimentalFrameChildFrameCreatedEventHandler>(
1256+
frame7->add_FrameCreated(
1257+
Callback<ICoreWebView2FrameChildFrameCreatedEventHandler>(
12581258
[this, depth](
12591259
ICoreWebView2Frame* sender,
12601260
ICoreWebView2FrameCreatedEventArgs* args) noexcept -> HRESULT

Diff for: SampleApps/WebView2APISample/WebView2APISample.vcxproj

+8-2
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@
338338
<CopyFileToFolders Include="assets/AppStartPageBackground.png">
339339
<DestinationFolders>$(OutDir)\assets</DestinationFolders>
340340
</CopyFileToFolders>
341+
<CopyFileToFolders Include="assets/dedicated_worker.js">
342+
<DestinationFolders>$(OutDir)\assets</DestinationFolders>
343+
</CopyFileToFolders>
341344
<CopyFileToFolders Include="assets/DemoWorker.js">
342345
<DestinationFolders>$(OutDir)\assets</DestinationFolders>
343346
</CopyFileToFolders>
@@ -365,6 +368,9 @@
365368
<CopyFileToFolders Include="assets/ScenarioCustomScheme.json">
366369
<DestinationFolders>$(OutDir)\assets</DestinationFolders>
367370
</CopyFileToFolders>
371+
<CopyFileToFolders Include="assets/ScenarioDedicatedWorkerPostMessage.html">
372+
<DestinationFolders>$(OutDir)\assets</DestinationFolders>
373+
</CopyFileToFolders>
368374
<CopyFileToFolders Include="assets/ScenarioDragDrop.html">
369375
<DestinationFolders>$(OutDir)\assets</DestinationFolders>
370376
</CopyFileToFolders>
@@ -496,13 +502,13 @@
496502
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
497503
<ImportGroup Label="ExtensionTargets">
498504
<Import Project="..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
499-
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.3171-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.3171-prerelease\build\native\Microsoft.Web.WebView2.targets')" />
505+
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.3230-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.3230-prerelease\build\native\Microsoft.Web.WebView2.targets')" />
500506
</ImportGroup>
501507
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
502508
<PropertyGroup>
503509
<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>
504510
</PropertyGroup>
505511
<Error Condition="!Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
506-
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.3171-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.3171-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
512+
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.3230-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.3230-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
507513
</Target>
508514
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<title>ScenarioDedicatedWorkerPostMessage</title>
6+
<script>
7+
"use strict";
8+
const worker = new Worker("dedicated_worker.js");
9+
</script>
10+
</head>
11+
12+
<body>
13+
<div>
14+
<h1>DedicatedWorker PostMessage Sample Page</h1>
15+
<p>This page demonstrates basic interaction between the host app and dedicated workers
16+
by means of Web Messages.</p>
17+
</div>
18+
19+
<h2>Posting and receiving messages</h2>
20+
<p>Messages can be posted from the host app to the dedicated worker on this document using
21+
the APIs <code>ICoreWebView2DedicatedWorker::PostWebMessageAsJson</code> and
22+
<code>ICoreWebView2DedicatedWorker::PostWebMessageAsString</code>.
23+
</p>
24+
25+
<p>Messages can be posted from the dedicated worker to the host app using
26+
<code>self.chrome.webview.postMessage</code>. The host app can receive messages by
27+
registering an event handler with
28+
<code>ICoreWebView2DedicatedWorker::add_WebMessageReceived</code>.
29+
</p>
30+
31+
<h2>How to use the sample?</h2>
32+
<p>This document creates a dedicated worker that listens for messages from the host app in
33+
the form of a command (ADD, SUB, MUL, DIV) and two numbers (first and second). It
34+
performs the specified arithmetic operation and responds with the result."
35+
</p>
36+
<p>When the dedicated worker is created, a dialog will be opened to enter a message. Enter a
37+
JSON string with a command and two numbers to receive a response from the worker. Ex:
38+
<code>{"command":"ADD","first":2,"second":3}</code> will send a reply back with 5.
39+
</p>
40+
41+
</body>
42+
43+
</html>

Diff for: SampleApps/WebView2APISample/assets/SecnarioFileTypePolicy.html

+19-4
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,35 @@ <h1>File Type Policy API Demo Page</h1>
3939
<p>Two customized example rules in this demo:</p>
4040
<p>1. Smoothly save *.eml file without file extension warning</p>
4141
<p>2. Intentionally block save *.iso file</p>
42+
<p>3. Block or bypass *.exe file based on configuration</p>
43+
<p>4. Block or bypass *.exe file based on popup response</p>
44+
<p>
45+
<button onclick="allow_exe()">Allow exe</button>
46+
</p>
47+
<p>
48+
<button onclick="block_exe()">Block exe</button>
49+
</p>
50+
<p>
51+
<button onclick="clear_exe_policy()">Clear exe policy</button>
52+
</p>
53+
<h2>File Type Policy API for Save File</h2>
4254
<p>
4355
Please enter a file extension: <input type="text" id="extensionText" placeholder="try eml or iso" />
4456
<button id="showSaveFilePickerButton">save</button>
4557
</p>
4658
<br>
4759
<hr />
4860
<h2>File Type Policy API for download</h2>
49-
<button onclick="allow_exe()">Allow exe</button>
50-
<button onclick="block_exe()">Block exe</button>
51-
<button onclick="clear_exe_policy()">Clear exe policy</button>
61+
5262
<br />
5363
<button onclick="enable_smartscreen()">Enable Smartscreen</button>
64+
<br />
65+
<br />
5466
<button onclick="disable_smartscreen()">Disable Smartscreen</button>
5567
<br />
56-
<a href="https://appassets.example/bad.exe" id="download_elem" download>Download Flagged file</a>
68+
<a href="https://appassets.example/sample.exe" id="download_exe" download>Download exe file</a>
69+
<br />
70+
<a href="https://appassets.example/sample.emlx" id="download_emlx" download>Download emlx file</a>
71+
5772
</body>
5873
</html>
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//! [chromeWebView]
2+
self.chrome.webview.addEventListener('message', (e) => {
3+
const data = e.data;
4+
if (!data.hasOwnProperty('first') || !data.hasOwnProperty('second') ||
5+
!data.hasOwnProperty('command')) {
6+
return;
7+
}
8+
9+
const first = data.first;
10+
const second = data.second;
11+
switch (data.command) {
12+
case 'ADD': {
13+
result = first + second;
14+
break;
15+
}
16+
case 'SUB': {
17+
result = first - second;
18+
break;
19+
}
20+
case 'MUL': {
21+
result = first * second;
22+
break;
23+
}
24+
case 'DIV': {
25+
if (second === 0) {
26+
result = 'Error: Division by zero';
27+
break;
28+
}
29+
30+
result = first / second;
31+
break;
32+
}
33+
default: {
34+
result = 'Failed to process the command';
35+
}
36+
}
37+
38+
// Notify the app about the result.
39+
self.chrome.webview.postMessage('Result = ' + result.toString());
40+
});
41+
//! [chromeWebView]

Diff for: SampleApps/WebView2APISample/packages.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Web.WebView2" version="1.0.3171-prerelease" targetFramework="native" />
3+
<package id="Microsoft.Web.WebView2" version="1.0.3230-prerelease" targetFramework="native" />
44
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.220201.1" targetFramework="native" />
55
</packages>

Diff for: SampleApps/WebView2WindowsFormsBrowser/WebView2WindowsFormsBrowser.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<PlatformTarget>AnyCPU</PlatformTarget>
2626
</PropertyGroup>
2727
<ItemGroup>
28-
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3171-prerelease" />
28+
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3230-prerelease" />
2929
</ItemGroup>
3030
<ItemGroup>
3131
<Folder Include="assets\" />

Diff for: SampleApps/WebView2WpfBrowser/MainWindow.xaml.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ public partial class MainWindow : Window
133133
public static RoutedCommand ServiceWorkerRegisteredCommand = new RoutedCommand();
134134
public static RoutedCommand GetServiceWorkerRegistrationsCommand = new RoutedCommand();
135135
public static RoutedCommand GetServiceWorkerRegisteredForScopeCommand = new RoutedCommand();
136+
public static RoutedCommand ServiceWorkerPostMessageCommand = new RoutedCommand();
136137
public static RoutedCommand DedicatedWorkerCreatedCommand = new RoutedCommand();
138+
public static RoutedCommand DedicatedWorkerPostMessageCommand = new RoutedCommand();
137139
public static RoutedCommand SharedWorkerManagerCommand = new RoutedCommand();
138140
public static RoutedCommand GetSharedWorkersCommand = new RoutedCommand();
139141
public static RoutedCommand ServiceWorkerSyncManagerCommand = new RoutedCommand();
@@ -3833,6 +3835,9 @@ void DedicatedWorkerCreatedExecuted(object target, ExecutedRoutedEventArgs e)
38333835
void RegisterForDedicatedWorkerCreated()
38343836
{
38353837
}
3838+
void DedicatedWorkerPostMessageExecuted(object target, ExecutedRoutedEventArgs e)
3839+
{
3840+
}
38363841
void ServiceWorkerRegisteredExecuted(object target, ExecutedRoutedEventArgs e)
38373842
{
38383843
RegisterForServiceWorkerRegistered();
@@ -3859,11 +3864,14 @@ async void GetServiceWorkerRegisteredForScope()
38593864
{
38603865
await Task.Delay(0);
38613866
}
3867+
3868+
void ServiceWorkerPostMessageExecuted(object target, ExecutedRoutedEventArgs e)
3869+
{
3870+
}
38623871
void SharedWorkerManagerExecuted(object target, ExecutedRoutedEventArgs e)
38633872
{
38643873
RegisterForSharedWorkerCreated();
38653874
}
3866-
38673875
void RegisterForSharedWorkerCreated()
38683876
{
38693877
}

Diff for: SampleApps/WebView2WpfBrowser/WebView2WpfBrowser.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
</Content>
6262
</ItemGroup>
6363
<ItemGroup>
64-
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3171-prerelease" />
64+
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3230-prerelease" />
6565
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
6666
</ItemGroup>
6767
</Project>

0 commit comments

Comments
 (0)