Skip to content

Commit 4c2f538

Browse files
Smoketest/1.0.1083 prerelease testing (#113)
* Updates for Win32, WPF and WinForms sample apps from 98.0.1083.0 * Updated package version for Win32, WPF and WinForms sample apps to 1.0.1083-prerelease * Disable transparent on Win7 and add AudioComponent https://microsoft.visualstudio.com/Edge/_git/chromium.src/pullrequest/6700976?discussionId=49416487&path=/third_party/edge_webview2/win/WebView2APISample/ViewComponent.cpp https://microsoft.visualstudio.com/Edge/_git/chromium.src/pullrequest/6701751 Co-authored-by: WebView2 Github Bot <[email protected]>
1 parent 0b7797b commit 4c2f538

31 files changed

+657
-129
lines changed

SampleApps/WebView2APISample/AppWindow.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include "SettingsComponent.h"
4343
#include "TextInputDialog.h"
4444
#include "ViewComponent.h"
45-
4645
using namespace Microsoft::WRL;
4746
static constexpr size_t s_maxLoadString = 100;
4847
static constexpr UINT s_runAsyncWindowMessage = WM_APP;
@@ -562,7 +561,6 @@ bool AppWindow::ExecuteWebViewCommands(WPARAM wParam, LPARAM lParam)
562561
}
563562
return false;
564563
}
565-
566564
// Handle commands not related to the WebView, which will work even if the WebView
567565
// is not currently initialized.
568566
bool AppWindow::ExecuteAppCommands(WPARAM wParam, LPARAM lParam)
@@ -904,6 +902,7 @@ HRESULT AppWindow::OnCreateEnvironmentCompleted(
904902

905903
HRESULT AppWindow::CreateControllerWithOptions()
906904
{
905+
//! [CreateControllerWithOptions]
907906
auto webViewEnvironment8 =
908907
m_webViewEnvironment.try_query<ICoreWebView2ExperimentalEnvironment8>();
909908
if (!webViewEnvironment8)
@@ -922,6 +921,7 @@ HRESULT AppWindow::CreateControllerWithOptions()
922921
return S_OK;
923922
}
924923
CHECK_FAILURE(hr);
924+
//! [CreateControllerWithOptions]
925925

926926
#ifdef USE_WEBVIEW2_WIN10
927927
if (m_dcompDevice || m_wincompCompositor)
@@ -1002,6 +1002,7 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICore
10021002
// ProcessFailed event could have been raised yet) so the PID is
10031003
// available.
10041004
CHECK_FAILURE(m_webView->get_BrowserProcessId(&m_newestBrowserPid));
1005+
//! [CoreWebView2Profile]
10051006
auto webview2Experimental8 = coreWebView2.try_query<ICoreWebView2Experimental8>();
10061007
if (webview2Experimental8)
10071008
{
@@ -1019,6 +1020,7 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICore
10191020
// update window icon
10201021
SetAppIcon(inPrivate);
10211022
}
1023+
//! [CoreWebView2Profile]
10221024
// Create components. These will be deleted when the WebView is closed.
10231025
NewComponent<FileComponent>(this);
10241026
NewComponent<ProcessComponent>(this);
@@ -1032,6 +1034,7 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICore
10321034
m_wincompCompositor,
10331035
#endif
10341036
m_creationModeId == IDM_CREATION_MODE_TARGET_DCOMP);
1037+
NewComponent<AudioComponent>(this);
10351038
NewComponent<ControlComponent>(this, &m_toolbar);
10361039
m_webView3 = coreWebView2.try_query<ICoreWebView2_3>();
10371040
if (m_webView3)

SampleApps/WebView2APISample/AudioComponent.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,30 @@
99

1010
using namespace Microsoft::WRL;
1111

12-
//! [IsDocumentPlayingAudioChanged] [IsDocumentPlayingAudio] [ToggleIsMuted]
12+
//! [IsDocumentPlayingAudioChanged] [IsDocumentPlayingAudio] [IsMutedChanged] [ToggleIsMuted]
1313
AudioComponent::AudioComponent(AppWindow* appWindow)
1414
: m_appWindow(appWindow), m_webView(appWindow->GetWebView())
1515
{
16-
auto webviewExperimental9 = m_webView.try_query<ICoreWebView2Experimental9>();
17-
if (webviewExperimental9)
16+
auto webview2_8 = m_webView.try_query<ICoreWebView2_8>();
17+
if (webview2_8)
1818
{
1919
// Register a handler for the IsDocumentPlayingAudioChanged event.
20-
CHECK_FAILURE(webviewExperimental9->add_IsDocumentPlayingAudioChanged(
21-
Callback<ICoreWebView2ExperimentalIsDocumentPlayingAudioChangedEventHandler>(
22-
[this, webviewExperimental9](ICoreWebView2* sender, IUnknown* args) -> HRESULT {
23-
UpdateTitleWithMuteState(webviewExperimental9);
20+
CHECK_FAILURE(webview2_8->add_IsDocumentPlayingAudioChanged(
21+
Callback<ICoreWebView2IsDocumentPlayingAudioChangedEventHandler>(
22+
[this, webview2_8](ICoreWebView2* sender, IUnknown* args) -> HRESULT
23+
{
24+
UpdateTitleWithMuteState(webview2_8);
2425
return S_OK;
2526
})
2627
.Get(),
2728
&m_isDocumentPlayingAudioChangedToken));
2829

2930
// Register a handler for the IsMutedChanged event.
30-
CHECK_FAILURE(webviewExperimental9->add_IsMutedChanged(
31-
Callback<ICoreWebView2ExperimentalIsMutedChangedEventHandler>(
32-
[this, webviewExperimental9](ICoreWebView2* sender, IUnknown* args) -> HRESULT {
33-
UpdateTitleWithMuteState(webviewExperimental9);
31+
CHECK_FAILURE(webview2_8->add_IsMutedChanged(
32+
Callback<ICoreWebView2IsMutedChangedEventHandler>(
33+
[this, webview2_8](ICoreWebView2* sender, IUnknown* args) -> HRESULT
34+
{
35+
UpdateTitleWithMuteState(webview2_8);
3436
return S_OK;
3537
})
3638
.Get(),
@@ -56,23 +58,22 @@ bool AudioComponent::HandleWindowMessage(
5658
// Toggle the mute state of the current window and show a mute or unmute icon on the title bar
5759
void AudioComponent::ToggleMuteState()
5860
{
59-
auto webviewExperimental9 = m_webView.try_query<ICoreWebView2Experimental9>();
60-
if (webviewExperimental9)
61+
auto webview2_8 = m_webView.try_query<ICoreWebView2_8>();
62+
if (webview2_8)
6163
{
6264
BOOL isMuted;
63-
CHECK_FAILURE(webviewExperimental9->get_IsMuted(&isMuted));
64-
CHECK_FAILURE(webviewExperimental9->put_IsMuted(!isMuted));
65+
CHECK_FAILURE(webview2_8->get_IsMuted(&isMuted));
66+
CHECK_FAILURE(webview2_8->put_IsMuted(!isMuted));
6567
}
6668
}
6769

68-
void AudioComponent::UpdateTitleWithMuteState(
69-
wil::com_ptr<ICoreWebView2Experimental9> webviewExperimental9)
70+
void AudioComponent::UpdateTitleWithMuteState(wil::com_ptr<ICoreWebView2_8> webview2_8)
7071
{
7172
BOOL isDocumentPlayingAudio;
72-
CHECK_FAILURE(webviewExperimental9->get_IsDocumentPlayingAudio(&isDocumentPlayingAudio));
73+
CHECK_FAILURE(webview2_8->get_IsDocumentPlayingAudio(&isDocumentPlayingAudio));
7374

7475
BOOL isMuted;
75-
CHECK_FAILURE(webviewExperimental9->get_IsMuted(&isMuted));
76+
CHECK_FAILURE(webview2_8->get_IsMuted(&isMuted));
7677

7778
wil::unique_cotaskmem_string title;
7879
CHECK_FAILURE(m_webView->get_DocumentTitle(&title));
@@ -96,15 +97,15 @@ void AudioComponent::ToggleMuteState()
9697

9798
m_appWindow->SetDocumentTitle(result.c_str());
9899
}
99-
//! [IsDocumentPlayingAudioChanged] [IsDocumentPlayingAudio] [ToggleIsMuted]
100+
//! [IsDocumentPlayingAudioChanged] [IsDocumentPlayingAudio] [IsMutedChanged] [ToggleIsMuted]
100101

101102
AudioComponent::~AudioComponent()
102103
{
103-
auto webviewExperimental9 = m_webView.try_query<ICoreWebView2Experimental9>();
104-
if (webviewExperimental9)
104+
auto webview2_8 = m_webView.try_query<ICoreWebView2_8>();
105+
if (webview2_8)
105106
{
106-
CHECK_FAILURE(webviewExperimental9->remove_IsDocumentPlayingAudioChanged(
107+
CHECK_FAILURE(webview2_8->remove_IsDocumentPlayingAudioChanged(
107108
m_isDocumentPlayingAudioChangedToken));
108-
CHECK_FAILURE(webviewExperimental9->remove_IsMutedChanged(m_isMutedChangedToken));
109+
CHECK_FAILURE(webview2_8->remove_IsMutedChanged(m_isMutedChangedToken));
109110
}
110111
}

SampleApps/WebView2APISample/AudioComponent.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ class AudioComponent : public ComponentBase
2121
LRESULT* result) override;
2222

2323
void ToggleMuteState();
24-
void UpdateTitleWithMuteState(
25-
wil::com_ptr<ICoreWebView2Experimental9> webviewExperimental9);
24+
void UpdateTitleWithMuteState(wil::com_ptr<ICoreWebView2_8> webview2_8);
2625

2726
~AudioComponent() override;
2827

SampleApps/WebView2APISample/CheckFailure.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ void FeatureNotAvailable();
3232

3333
// Wraps the above in a conditional.
3434
#define CHECK_FEATURE_RETURN(feature) { if (!feature) { FeatureNotAvailable(); return true; } }
35+
36+
// Returns nothing, which is different from CHECK_FEATURE_RETURN
37+
#define CHECK_FEATURE_RETURN_EMPTY(feature) { if (!feature) { FeatureNotAvailable(); return; } }

SampleApps/WebView2APISample/ProcessComponent.cpp

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,27 @@ ProcessComponent::ProcessComponent(AppWindow* appWindow)
121121
.Get(),
122122
&m_processFailedToken));
123123
//! [ProcessFailed]
124+
125+
m_webViewEnvironment = appWindow->GetWebViewEnvironment();
126+
auto environment9 = m_webViewEnvironment.try_query<ICoreWebView2ExperimentalEnvironment9>();
127+
if (environment9)
128+
{
129+
CHECK_FAILURE(environment9->GetProcessInfos(&m_processCollection));
130+
// Register a handler for the ProcessInfosChanged event.
131+
//! [ProcessInfosChanged]
132+
CHECK_FAILURE(environment9->add_ProcessInfosChanged(
133+
Callback<ICoreWebView2ExperimentalProcessInfosChangedEventHandler>(
134+
[this](ICoreWebView2Environment* sender, IUnknown* args) -> HRESULT {
135+
wil::com_ptr<ICoreWebView2ExperimentalEnvironment9> webviewEnvironment;
136+
sender->QueryInterface(IID_PPV_ARGS(&webviewEnvironment));
137+
CHECK_FAILURE(
138+
webviewEnvironment->GetProcessInfos(&m_processCollection));
139+
return S_OK;
140+
})
141+
.Get(),
142+
&m_processInfosChangedToken));
143+
//! [ProcessInfosChanged]
144+
}
124145
}
125146

126147
// static
@@ -156,10 +177,14 @@ bool ProcessComponent::HandleWindowMessage(
156177
case IDM_CRASH_RENDER_PROCESS:
157178
CrashRenderProcess();
158179
return true;
180+
case IDM_PERFORMANCE_INFO:
181+
PerformanceInfo();
182+
return true;
159183
}
160184
}
161185
return false;
162186
}
187+
163188
// Show the WebView's PID to the user.
164189
void ProcessComponent::ShowBrowserProcessInfo() {
165190
UINT32 processId;
@@ -220,6 +245,29 @@ std::wstring ProcessComponent::ProcessFailedReasonToString(
220245
return L"REASON: " + std::to_wstring(static_cast<uint32_t>(reason));
221246
}
222247

248+
// Get a string for the process kind enum value.
249+
std::wstring ProcessComponent::ProcessKindToString(const COREWEBVIEW2_PROCESS_KIND kind)
250+
{
251+
switch (kind)
252+
{
253+
#define KIND_ENTRY(kindValue) \
254+
case kindValue: \
255+
return L#kindValue;
256+
257+
KIND_ENTRY(COREWEBVIEW2_PROCESS_KIND_BROWSER);
258+
KIND_ENTRY(COREWEBVIEW2_PROCESS_KIND_RENDERER);
259+
KIND_ENTRY(COREWEBVIEW2_PROCESS_KIND_UTILITY);
260+
KIND_ENTRY(COREWEBVIEW2_PROCESS_KIND_SANDBOX_HELPER);
261+
KIND_ENTRY(COREWEBVIEW2_PROCESS_KIND_GPU);
262+
KIND_ENTRY(COREWEBVIEW2_PROCESS_KIND_PPAPI_PLUGIN);
263+
KIND_ENTRY(COREWEBVIEW2_PROCESS_KIND_PPAPI_BROKER);
264+
265+
#undef KIND_ENTRY
266+
}
267+
268+
return L"PROCESS KIND: " + std::to_wstring(static_cast<uint32_t>(kind));
269+
}
270+
223271
// Crash the browser's process on command, to test crash handlers.
224272
void ProcessComponent::CrashBrowserProcess()
225273
{
@@ -232,11 +280,52 @@ void ProcessComponent::CrashRenderProcess()
232280
m_webView->Navigate(L"edge://kill");
233281
}
234282

235-
//! [ProcessInfoChanged]
283+
//! [ProcessInfosChanged]
236284
void ProcessComponent::PerformanceInfo()
237285
{
286+
std::wstring result;
287+
UINT processListCount;
288+
CHECK_FAILURE(m_processCollection->get_Count(&processListCount));
289+
290+
if (processListCount == 0)
291+
{
292+
result += L"No process found.";
293+
}
294+
else
295+
{
296+
result += std::to_wstring(processListCount) + L" process(s) found";
297+
result += L"\n\n";
298+
for (UINT i = 0; i < processListCount; ++i)
299+
{
300+
wil::com_ptr<ICoreWebView2ExperimentalProcessInfo> processInfo;
301+
CHECK_FAILURE(m_processCollection->GetValueAtIndex(i, &processInfo));
302+
303+
INT32 processId = 0;
304+
COREWEBVIEW2_PROCESS_KIND kind;
305+
CHECK_FAILURE(processInfo->get_ProcessId(&processId));
306+
CHECK_FAILURE(processInfo->get_Kind(&kind));
307+
308+
WCHAR id[4096] = L"";
309+
StringCchPrintf(id, ARRAYSIZE(id), L"Process ID: %u", processId);
310+
311+
HANDLE processHandle =
312+
OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);
313+
PROCESS_MEMORY_COUNTERS_EX pmc;
314+
GetProcessMemoryInfo(
315+
processHandle, reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&pmc), sizeof(pmc));
316+
SIZE_T virtualMemUsed = pmc.PrivateUsage / 1024;
317+
WCHAR memory[4096] = L"";
318+
StringCchPrintf(memory, ARRAYSIZE(memory), L"Memory: %u", virtualMemUsed);
319+
CloseHandle(processHandle);
320+
321+
result = result + id + L" | Process Kind: " + ProcessKindToString(kind) + L" | " +
322+
memory + L" KB\n";
323+
}
324+
}
325+
MessageBox(nullptr, result.c_str(), L"Memory Usage", MB_OK);
238326
}
239-
//! [ProcessInfoChanged]
327+
//! [ProcessInfosChanged]
328+
240329
/*static*/ void ProcessComponent::EnsureProcessIsClosed(UINT processId, int timeoutMs)
241330
{
242331
UINT exitCode = 1;
@@ -285,4 +374,9 @@ void ProcessComponent::ScheduleReloadIfSelectedByUser(
285374
ProcessComponent::~ProcessComponent()
286375
{
287376
m_webView->remove_ProcessFailed(m_processFailedToken);
377+
auto environment9 = m_webViewEnvironment.try_query<ICoreWebView2ExperimentalEnvironment9>();
378+
if (environment9)
379+
{
380+
environment9->remove_ProcessInfosChanged(m_processInfosChangedToken);
381+
}
288382
}

SampleApps/WebView2APISample/ProcessComponent.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ class ProcessComponent : public ComponentBase
2828
void ShowBrowserProcessInfo();
2929
std::wstring ProcessFailedKindToString(const COREWEBVIEW2_PROCESS_FAILED_KIND kind);
3030
std::wstring ProcessFailedReasonToString(const COREWEBVIEW2_PROCESS_FAILED_REASON reason);
31+
std::wstring ProcessKindToString(const COREWEBVIEW2_PROCESS_KIND kind);
3132
void CrashBrowserProcess();
3233
void CrashRenderProcess();
3334
void PerformanceInfo();
35+
3436
~ProcessComponent() override;
3537

3638
// Wait for process to exit for timeoutMs, then force quit it if it hasn't.
@@ -47,6 +49,8 @@ class ProcessComponent : public ComponentBase
4749
wil::com_ptr<ICoreWebView2Environment> m_webViewEnvironment;
4850

4951
UINT m_browserProcessId = 0;
52+
wil::com_ptr<ICoreWebView2ExperimentalProcessInfoCollection> m_processCollection;
53+
5054
EventRegistrationToken m_processFailedToken = {};
51-
EventRegistrationToken m_processInfoChangedToken = {};
55+
EventRegistrationToken m_processInfosChangedToken = {};
5256
};

SampleApps/WebView2APISample/ScenarioAddHostObject.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,8 @@ ScenarioAddHostObject::~ScenarioAddHostObject()
141141
m_webView->RemoveHostObjectFromScript(L"sample");
142142
m_webView->remove_NavigationStarting(m_navigationStartingToken);
143143
wil::com_ptr<ICoreWebView2_4> webview2_4 = m_webView.try_query<ICoreWebView2_4>();
144-
if (webview2_4) webview2_4->remove_FrameCreated(m_frameCreatedToken);
144+
if (webview2_4)
145+
{
146+
webview2_4->remove_FrameCreated(m_frameCreatedToken);
147+
}
145148
}

SampleApps/WebView2APISample/ScenarioAuthentication.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ScenarioAuthentication::ScenarioAuthentication(AppWindow* appWindow) :
4646
&m_webResourceResponseReceivedToken));
4747
//! [WebResourceResponseReceived]
4848

49-
//! [AuthRequested]
49+
//! [BasicAuthenticationRequested]
5050
if (auto webViewExperimental10 = m_webView.try_query<ICoreWebView2Experimental10>())
5151
{
5252
CHECK_FAILURE(webViewExperimental10->add_BasicAuthenticationRequested(
@@ -67,7 +67,7 @@ ScenarioAuthentication::ScenarioAuthentication(AppWindow* appWindow) :
6767
else {
6868
FeatureNotAvailable();
6969
}
70-
//! [AuthRequested]
70+
//! [BasicAuthenticationRequested]
7171
CHECK_FAILURE(m_webView->Navigate(L"https://authenticationtest.com/HTTPAuth/"));
7272
}
7373

SampleApps/WebView2APISample/ScenarioCookieManagement.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ScenarioCookieManagement::ScenarioCookieManagement(AppWindow* appWindow)
2020
{
2121
m_sampleUri = m_appWindow->GetLocalUri(c_samplePath);
2222

23-
ComPtr<ICoreWebView2Settings> settings;
23+
wil::com_ptr<ICoreWebView2Settings> settings;
2424
CHECK_FAILURE(m_webView->get_Settings(&settings));
2525
CHECK_FAILURE(settings->put_IsWebMessageEnabled(TRUE));
2626

@@ -30,6 +30,13 @@ ScenarioCookieManagement::ScenarioCookieManagement(AppWindow* appWindow)
3030
CHECK_FAILURE(m_webview2->get_CookieManager(&m_cookieManager));
3131
//! [CookieManager]
3232

33+
SetupEventsOnWebview();
34+
35+
CHECK_FAILURE(m_webView->Navigate(m_sampleUri.c_str()));
36+
}
37+
38+
void ScenarioCookieManagement::SetupEventsOnWebview()
39+
{
3340
// Setup the web message received event handler before navigating to
3441
// ensure we don't miss any messages.
3542
CHECK_FAILURE(m_webView->add_WebMessageReceived(
@@ -90,8 +97,6 @@ ScenarioCookieManagement::ScenarioCookieManagement(AppWindow* appWindow)
9097
})
9198
.Get(),
9299
&m_contentLoadingToken));
93-
94-
CHECK_FAILURE(m_webView->Navigate(m_sampleUri.c_str()));
95100
}
96101

97102
ScenarioCookieManagement::~ScenarioCookieManagement()

SampleApps/WebView2APISample/ScenarioCookieManagement.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class ScenarioCookieManagement : public ComponentBase
1818

1919
private:
2020
void GetCookiesHelper(std::wstring uri);
21+
void SetupEventsOnWebview();
2122

2223
AppWindow* m_appWindow;
2324
wil::com_ptr<ICoreWebView2Environment> m_webViewEnvironment;

0 commit comments

Comments
 (0)