Skip to content

Commit 852c4b3

Browse files
Updates for Win32, WPF, WinForms, UWP and WinUI3 sample apps from 128.0.2730.0
1 parent 02a1ccb commit 852c4b3

20 files changed

+607
-73
lines changed

SampleApps/WebView2APISample/AppWindow.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "ScenarioScreenCapture.h"
4949
#include "ScenarioSharedBuffer.h"
5050
#include "ScenarioSharedWorkerWRR.h"
51+
#include "ScenarioThrottlingControl.h"
5152
#include "ScenarioFileTypePolicy.h"
5253
#include "ScenarioVirtualHostMappingForPopUpWindow.h"
5354
#include "ScenarioVirtualHostMappingForSW.h"
@@ -426,6 +427,7 @@ bool AppWindow::HandleWindowMessage(
426427
break;
427428
//! [RestartManager]
428429
case WM_KEYDOWN:
430+
case WM_SYSKEYDOWN:
429431
{
430432
// If bit 30 is set, it means the WM_KEYDOWN message is autorepeated.
431433
// We want to ignore it in that case.
@@ -667,6 +669,11 @@ bool AppWindow::ExecuteWebViewCommands(WPARAM wParam, LPARAM lParam)
667669
NewComponent<ScenarioAcceleratorKeyPressed>(this);
668670
return true;
669671
}
672+
case IDM_SCENARIO_THROTTLING_CONTROL:
673+
{
674+
NewComponent<ScenarioThrottlingControl>(this);
675+
return true;
676+
}
670677
case IDM_SCENARIO_SCREEN_CAPTURE:
671678
{
672679
NewComponent<ScenarioScreenCapture>(this);
@@ -1249,6 +1256,14 @@ std::function<void()> AppWindow::GetAcceleratorKeyFunction(UINT key)
12491256
return [this] { CloseWebView(); };
12501257
}
12511258
}
1259+
if (GetKeyState(VK_MENU) < 0) // VK_MENU == Alt key
1260+
{
1261+
switch (key)
1262+
{
1263+
case 'D': // Alt+D focuses and selects the address bar, like the browser.
1264+
return [this] { m_toolbar.SelectAddressBar(); };
1265+
}
1266+
}
12521267
return nullptr;
12531268
}
12541269

SampleApps/WebView2APISample/AppWindow.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,15 @@ class AppWindow
8787
{
8888
public:
8989
AppWindow(
90-
UINT creationModeId, const WebViewCreateOption& opt,
91-
const std::wstring& initialUri = L"", const std::wstring& userDataFolderParam = L"",
92-
bool isMainWindow = false, std::function<void()> webviewCreatedCallback = nullptr,
93-
bool customWindowRect = false, RECT windowRect = {0}, bool shouldHaveToolbar = true,
90+
UINT creationModeId,
91+
const WebViewCreateOption& opt,
92+
const std::wstring& initialUri = L"",
93+
const std::wstring& userDataFolderParam = L"",
94+
bool isMainWindow = false,
95+
std::function<void()> webviewCreatedCallback = nullptr,
96+
bool customWindowRect = false,
97+
RECT windowRect = {0},
98+
bool shouldHaveToolbar = true,
9499
bool isPopup = false);
95100

96101
~AppWindow();
@@ -210,7 +215,6 @@ class AppWindow
210215
SamplePrintSettings GetSelectedPrinterPrintSettings(std::wstring printerName);
211216
bool PrintToPdfStream();
212217
void ToggleTrackingPrevention();
213-
214218
std::wstring GetLocalPath(std::wstring path, bool keep_exe_path);
215219
void DeleteAllComponents();
216220

@@ -273,7 +277,6 @@ class AppWindow
273277
bool m_isPopupWindow = false;
274278
void EnterFullScreen();
275279
void ExitFullScreen();
276-
277280
// Compositor creation helper methods
278281
HRESULT DCompositionCreateDevice2(IUnknown* renderingDevice, REFIID riid, void** ppv);
279282
HRESULT TryCreateDispatcherQueue();

SampleApps/WebView2APISample/ControlComponent.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ bool ControlComponent::HandleChildWindowMessage(
291291
// If not calling IsDialogMessage to handle tab traversal automatically,
292292
// detect tab traversal and cycle focus through address bar, go button, and
293293
// elements in WebView.
294-
if (message == WM_KEYDOWN)
294+
if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
295295
{
296296
//! [MoveFocus1]
297297
if (wParam == VK_TAB)
@@ -320,6 +320,12 @@ bool ControlComponent::HandleChildWindowMessage(
320320
NavigateToAddressBar();
321321
return true;
322322
}
323+
// Ctrl+A is SelectAll
324+
else if ((GetKeyState(VK_CONTROL) < 0) && ((UINT)wParam == 'A'))
325+
{
326+
m_toolbar->SelectAll();
327+
return true;
328+
}
323329
else
324330
{
325331
// If bit 30 is set, it means the WM_KEYDOWN message is autorepeated.

SampleApps/WebView2APISample/ScenarioNotificationReceived.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@ ScenarioNotificationReceived::ScenarioNotificationReceived(AppWindow* appWindow)
2424
: m_appWindow(appWindow), m_webView(appWindow->GetWebView())
2525
{
2626
m_sampleUri = m_appWindow->GetLocalUri(c_samplePath);
27-
m_webView2Experimental22 = m_webView.try_query<ICoreWebView2Experimental22>();
28-
if (!m_webView2Experimental22)
27+
m_webView2_24 = m_webView.try_query<ICoreWebView2_24>();
28+
if (!m_webView2_24)
2929
return;
3030
//! [NotificationReceived]
3131
// Register a handler for the NotificationReceived event.
32-
CHECK_FAILURE(m_webView2Experimental22->add_NotificationReceived(
33-
Callback<ICoreWebView2ExperimentalNotificationReceivedEventHandler>(
34-
[this](
35-
ICoreWebView2* sender,
36-
ICoreWebView2ExperimentalNotificationReceivedEventArgs* args) -> HRESULT
32+
CHECK_FAILURE(m_webView2_24->add_NotificationReceived(
33+
Callback<ICoreWebView2NotificationReceivedEventHandler>(
34+
[this](ICoreWebView2* sender, ICoreWebView2NotificationReceivedEventArgs* args)
35+
-> HRESULT
3736
{
3837
// Block notifications from specific URIs and set Handled to
3938
// true so the the default notification UI will not be
@@ -45,14 +44,13 @@ ScenarioNotificationReceived::ScenarioNotificationReceived(AppWindow* appWindow)
4544
wil::unique_cotaskmem_string origin;
4645
CHECK_FAILURE(args->get_SenderOrigin(&origin));
4746
std::wstring originString = origin.get();
48-
Microsoft::WRL::ComPtr<ICoreWebView2ExperimentalNotification> notification;
47+
Microsoft::WRL::ComPtr<ICoreWebView2Notification> notification;
4948
CHECK_FAILURE(args->get_Notification(&notification));
5049

5150
notification->add_CloseRequested(
52-
Callback<ICoreWebView2ExperimentalNotificationCloseRequestedEventHandler>(
51+
Callback<ICoreWebView2NotificationCloseRequestedEventHandler>(
5352
[this, &sender](
54-
ICoreWebView2ExperimentalNotification* notification,
55-
IUnknown* args) -> HRESULT
53+
ICoreWebView2Notification* notification, IUnknown* args) -> HRESULT
5654
{
5755
// Remove the notification from the list of active
5856
// notifications.
@@ -64,8 +62,8 @@ ScenarioNotificationReceived::ScenarioNotificationReceived(AppWindow* appWindow)
6462

6563
m_appWindow->RunAsync(
6664
[this,
67-
notificationCom = wil::make_com_ptr<ICoreWebView2ExperimentalNotification>(
68-
notification.Get()),
65+
notificationCom =
66+
wil::make_com_ptr<ICoreWebView2Notification>(notification.Get()),
6967
deferral, originString]()
7068
{
7169
ShowNotification(notificationCom.get(), originString);
@@ -95,7 +93,7 @@ bool ScenarioNotificationReceived::HandleWindowMessage(
9593
}
9694

9795
void ScenarioNotificationReceived::ShowNotification(
98-
ICoreWebView2ExperimentalNotification* notification, std::wstring origin)
96+
ICoreWebView2Notification* notification, std::wstring origin)
9997
{
10098
ICoreWebView2* webView = m_webView.get();
10199
wil::unique_cotaskmem_string title;
@@ -139,8 +137,7 @@ void ScenarioNotificationReceived::ShowNotification(
139137
(response == IDOK) ? notification->ReportClicked() : notification->ReportClosed();
140138
}
141139

142-
void ScenarioNotificationReceived::RemoveNotification(
143-
ICoreWebView2ExperimentalNotification* notification)
140+
void ScenarioNotificationReceived::RemoveNotification(ICoreWebView2Notification* notification)
144141
{
145142
// Close custom notification.
146143

@@ -155,9 +152,8 @@ void ScenarioNotificationReceived::NavigateToNotificationPage()
155152

156153
ScenarioNotificationReceived::~ScenarioNotificationReceived()
157154
{
158-
if (m_webView2Experimental22)
155+
if (m_webView2_24)
159156
{
160-
CHECK_FAILURE(
161-
m_webView2Experimental22->remove_NotificationReceived(m_notificationReceivedToken));
157+
CHECK_FAILURE(m_webView2_24->remove_NotificationReceived(m_notificationReceivedToken));
162158
}
163159
}

SampleApps/WebView2APISample/ScenarioNotificationReceived.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ class ScenarioNotificationReceived : public ComponentBase
2121

2222
private:
2323
void NavigateToNotificationPage();
24-
void ShowNotification(
25-
ICoreWebView2ExperimentalNotification* notification, std::wstring origin);
26-
void RemoveNotification(ICoreWebView2ExperimentalNotification* notification);
24+
void ShowNotification(ICoreWebView2Notification* notification, std::wstring origin);
25+
void RemoveNotification(ICoreWebView2Notification* notification);
2726

2827
AppWindow* m_appWindow = nullptr;
2928
wil::com_ptr<ICoreWebView2> m_webView;
30-
wil::com_ptr<ICoreWebView2Experimental22> m_webView2Experimental22;
29+
wil::com_ptr<ICoreWebView2_24> m_webView2_24;
3130
std::wstring m_sampleUri;
3231
EventRegistrationToken m_notificationReceivedToken = {};
3332
EventRegistrationToken m_notificationCloseRequestedToken = {};

SampleApps/WebView2APISample/ScenarioSaveAs.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ScenarioSaveAs::ScenarioSaveAs(AppWindow* appWindow)
2020
{
2121
if (m_webView)
2222
{
23-
m_webView2Experimental25 = m_webView.try_query<ICoreWebView2Experimental25>();
23+
m_webView2_25 = m_webView.try_query<ICoreWebView2_25>();
2424
}
2525
}
2626

@@ -39,17 +39,16 @@ std::array<std::wstring, 5> saveAsUIResultString{
3939
// This example hides the default save as dialog and shows a customized dialog.
4040
bool ScenarioSaveAs::ToggleSilent()
4141
{
42-
if (!m_webView2Experimental25)
42+
if (!m_webView2_25)
4343
return false;
4444
m_silentSaveAs = !m_silentSaveAs;
4545
if (m_silentSaveAs && m_saveAsUIShowingToken.value == 0)
4646
{
4747
// Register a handler for the `SaveAsUIShowing` event.
48-
m_webView2Experimental25->add_SaveAsUIShowing(
49-
Callback<ICoreWebView2ExperimentalSaveAsUIShowingEventHandler>(
50-
[this](
51-
ICoreWebView2* sender,
52-
ICoreWebView2ExperimentalSaveAsUIShowingEventArgs* args) -> HRESULT
48+
m_webView2_25->add_SaveAsUIShowing(
49+
Callback<ICoreWebView2SaveAsUIShowingEventHandler>(
50+
[this](ICoreWebView2* sender, ICoreWebView2SaveAsUIShowingEventArgs* args)
51+
-> HRESULT
5352
{
5453
// Hide the system default save as dialog.
5554
CHECK_FAILURE(args->put_SuppressDefaultDialog(TRUE));
@@ -111,7 +110,7 @@ bool ScenarioSaveAs::ToggleSilent()
111110
else
112111
{
113112
// Unregister the handler for the `SaveAsUIShowing` event.
114-
m_webView2Experimental25->remove_SaveAsUIShowing(m_saveAsUIShowingToken);
113+
m_webView2_25->remove_SaveAsUIShowing(m_saveAsUIShowingToken);
115114
m_saveAsUIShowingToken.value = 0;
116115
}
117116
MessageBox(
@@ -126,10 +125,10 @@ bool ScenarioSaveAs::ToggleSilent()
126125
// Call ShowSaveAsUI method to trigger the programmatic save as.
127126
bool ScenarioSaveAs::ProgrammaticSaveAs()
128127
{
129-
if (!m_webView2Experimental25)
128+
if (!m_webView2_25)
130129
return false;
131-
m_webView2Experimental25->ShowSaveAsUI(
132-
Callback<ICoreWebView2ExperimentalShowSaveAsUICompletedHandler>(
130+
m_webView2_25->ShowSaveAsUI(
131+
Callback<ICoreWebView2ShowSaveAsUICompletedHandler>(
133132
[this](HRESULT errorCode, COREWEBVIEW2_SAVE_AS_UI_RESULT result) -> HRESULT
134133
{
135134
// Show ShowSaveAsUI returned result, optional.
@@ -165,9 +164,9 @@ bool ScenarioSaveAs::HandleWindowMessage(
165164

166165
ScenarioSaveAs::~ScenarioSaveAs()
167166
{
168-
if (m_webView2Experimental25)
167+
if (m_webView2_25)
169168
{
170-
m_webView2Experimental25->remove_SaveAsUIShowing(m_saveAsUIShowingToken);
169+
m_webView2_25->remove_SaveAsUIShowing(m_saveAsUIShowingToken);
171170
}
172171
}
173172

SampleApps/WebView2APISample/ScenarioSaveAs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ScenarioSaveAs : public ComponentBase
2222
~ScenarioSaveAs() override;
2323
AppWindow* m_appWindow = nullptr;
2424
wil::com_ptr<ICoreWebView2> m_webView;
25-
wil::com_ptr<ICoreWebView2Experimental25> m_webView2Experimental25;
25+
wil::com_ptr<ICoreWebView2_25> m_webView2_25;
2626
EventRegistrationToken m_saveAsUIShowingToken = {};
2727
bool m_silentSaveAs = false;
2828
};

0 commit comments

Comments
 (0)