Skip to content

Commit d99a5e8

Browse files
Update projects to use latest WebView2 SDK 1.0.2106-prerelease (#209)
* Updates for Win32, WPF and WinForms sample apps from 119.0.2106.0 * Updated package version for Win32, WPF and WinForms sample apps to 1.0.2106-prerelease --------- Co-authored-by: WebView2 Github Bot <[email protected]>
1 parent a9d7246 commit d99a5e8

14 files changed

+239
-195
lines changed

SampleApps/WebView2APISample/AppWindow.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,12 +1724,13 @@ void AppWindow::RegisterEventHandlers()
17241724
args->put_Handled(FALSE);
17251725
return S_OK;
17261726
}
1727-
wil::com_ptr<ICoreWebView2ExperimentalNewWindowRequestedEventArgs2>
1728-
experimental_args;
1729-
if (SUCCEEDED(args->QueryInterface(IID_PPV_ARGS(&experimental_args))))
1727+
wil::com_ptr<ICoreWebView2NewWindowRequestedEventArgs> args_as_comptr = args;
1728+
auto args3 =
1729+
args_as_comptr.try_query<ICoreWebView2NewWindowRequestedEventArgs3>();
1730+
if (args3)
17301731
{
17311732
wil::com_ptr<ICoreWebView2FrameInfo> frame_info;
1732-
CHECK_FAILURE(experimental_args->get_OriginalSourceFrameInfo(&frame_info));
1733+
CHECK_FAILURE(args3->get_OriginalSourceFrameInfo(&frame_info));
17331734
wil::unique_cotaskmem_string source;
17341735
CHECK_FAILURE(frame_info->get_Source(&source));
17351736
// The host can decide how to open based on source frame info,

SampleApps/WebView2APISample/ProcessComponent.cpp

Lines changed: 64 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,11 @@ ProcessComponent::ProcessComponent(AppWindow* appWindow)
106106
CHECK_FAILURE(args2->get_ExitCode(&exitCode));
107107

108108
std::wstringstream message;
109-
message << L"Kind: " << ProcessFailedKindToString(kind) << L"\n"
110-
<< L"Reason: " << ProcessFailedReasonToString(reason) << L"\n"
111-
<< L"Exit code: " << std::to_wstring(exitCode) << L"\n"
112-
<< L"Process description: " << processDescription.get() << std::endl;
109+
message << L"Kind: " << ProcessFailedKindToString(kind) << L"\n"
110+
<< L"Reason: " << ProcessFailedReasonToString(reason) << L"\n"
111+
<< L"Exit code: " << exitCode << L"\n"
112+
<< L"Process description: " << processDescription.get()
113+
<< std::endl;
113114
m_appWindow->AsyncMessageBox( std::move(message.str()), L"Child process failed");
114115
}
115116
return S_OK;
@@ -176,8 +177,8 @@ bool ProcessComponent::HandleWindowMessage(
176177
case IDM_PERFORMANCE_INFO:
177178
PerformanceInfo();
178179
return true;
179-
case IDM_PROCESS_FRAME_INFO:
180-
ShowProcessFrameInfo();
180+
case IDM_PROCESS_EXTENDED_INFO:
181+
ShowProcessExtendedInfo();
181182
return true;
182183
}
183184
}
@@ -206,7 +207,9 @@ std::wstring ProcessComponent::FrameKindToString(const COREWEBVIEW2_FRAME_KIND k
206207

207208
KIND_ENTRY(COREWEBVIEW2_FRAME_KIND_MAIN_FRAME);
208209
KIND_ENTRY(COREWEBVIEW2_FRAME_KIND_IFRAME);
209-
KIND_ENTRY(COREWEBVIEW2_FRAME_KIND_OTHER);
210+
KIND_ENTRY(COREWEBVIEW2_FRAME_KIND_EMBED);
211+
KIND_ENTRY(COREWEBVIEW2_FRAME_KIND_OBJECT);
212+
KIND_ENTRY(COREWEBVIEW2_FRAME_KIND_UNKNOWN);
210213

211214
#undef KIND_ENTRY
212215
}
@@ -220,16 +223,16 @@ void ProcessComponent::AppendFrameInfo(
220223
UINT32 frameId = 0;
221224
UINT32 parentFrameId = 0;
222225
UINT32 mainFrameId = 0;
223-
UINT32 firstLevelFrameId = 0;
226+
UINT32 childFrameId = 0;
224227
std::wstring type = L"other child frame";
225228
wil::unique_cotaskmem_string nameRaw;
226229
wil::unique_cotaskmem_string sourceRaw;
227-
COREWEBVIEW2_FRAME_KIND frameKind = COREWEBVIEW2_FRAME_KIND_OTHER;
230+
COREWEBVIEW2_FRAME_KIND frameKind = COREWEBVIEW2_FRAME_KIND_UNKNOWN;
228231

229232
CHECK_FAILURE(frameInfo->get_Name(&nameRaw));
230-
std::wstring name = ((std::wstring)(nameRaw.get())).empty() ? L"none" : nameRaw.get();
233+
std::wstring name = nameRaw.get()[0] ? nameRaw.get() : L"none";
231234
CHECK_FAILURE(frameInfo->get_Source(&sourceRaw));
232-
std::wstring source = ((std::wstring)(sourceRaw.get())).empty() ? L"none" : sourceRaw.get();
235+
std::wstring source = sourceRaw.get()[0] ? sourceRaw.get() : L"none";
233236

234237
wil::com_ptr<ICoreWebView2ExperimentalFrameInfo> frameInfoExperimental;
235238
CHECK_FAILURE(frameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
@@ -252,26 +255,24 @@ void ProcessComponent::AppendFrameInfo(
252255
CHECK_FAILURE(mainFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
253256
CHECK_FAILURE(frameInfoExperimental->get_FrameId(&mainFrameId));
254257

255-
wil::com_ptr<ICoreWebView2FrameInfo> firstLevelFrameInfo =
256-
GetAncestorFirstLevelFrameInfo(frameInfo);
257-
if (firstLevelFrameInfo == frameInfo)
258+
wil::com_ptr<ICoreWebView2FrameInfo> childFrameInfo =
259+
GetAncestorMainFrameDirectChildFrameInfo(frameInfo);
260+
if (childFrameInfo == frameInfo)
258261
{
259262
type = L"first level frame";
260263
}
261-
if (firstLevelFrameInfo)
264+
if (childFrameInfo)
262265
{
263-
CHECK_FAILURE(
264-
firstLevelFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
265-
CHECK_FAILURE(frameInfoExperimental->get_FrameId(&firstLevelFrameId));
266+
CHECK_FAILURE(childFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
267+
CHECK_FAILURE(frameInfoExperimental->get_FrameId(&childFrameId));
266268
}
267269

268-
result << L"{frame name:" << name << L" | frame Id:" << std::to_wstring(frameId)
269-
<< L" | parent frame Id:"
270+
result << L"{frame name:" << name << L" | frame Id:" << frameId << L" | parent frame Id:"
270271
<< ((parentFrameId == 0) ? L"none" : std::to_wstring(parentFrameId))
271272
<< L" | frame type:" << type << L"\n"
272-
<< L" | ancestor main frame Id:" << std::to_wstring(mainFrameId)
273-
<< L" | ancestor first level frame Id:"
274-
<< ((firstLevelFrameId == 0) ? L"none" : std::to_wstring(firstLevelFrameId)) << L"\n"
273+
<< L" | ancestor main frame Id:" << mainFrameId
274+
<< L" | ancestor main frame's direct child frame Id:"
275+
<< ((childFrameId == 0) ? L"none" : std::to_wstring(childFrameId)) << L"\n"
275276
<< L" | frame kind:" << FrameKindToString(frameKind) << L"\n"
276277
<< L" | frame source:" << source << L"}," << std::endl;
277278
}
@@ -292,34 +293,46 @@ wil::com_ptr<ICoreWebView2FrameInfo> ProcessComponent::GetAncestorMainFrameInfo(
292293
return mainFrameInfo;
293294
}
294295

295-
// Get the ancestor first level frameInfo.
296-
// Return itself if it's a first level frameInfo.
297-
wil::com_ptr<ICoreWebView2FrameInfo> ProcessComponent::GetAncestorFirstLevelFrameInfo(
296+
// Get the frame's corresponding main frame's direct child frameInfo.
297+
// Example:
298+
// A (main frame/CoreWebView2)
299+
// | \
300+
// (frame) B C (frame)
301+
// | |
302+
// (frame) D E (frame)
303+
// |
304+
// F (frame)
305+
// C GetAncestorMainFrameDirectChildFrameInfo returns C.
306+
// D GetAncestorMainFrameDirectChildFrameInfo returns B.
307+
// F GetAncestorMainFrameDirectChildFrameInfo returns C.
308+
wil::com_ptr<ICoreWebView2FrameInfo> ProcessComponent::GetAncestorMainFrameDirectChildFrameInfo(
298309
wil::com_ptr<ICoreWebView2FrameInfo> frameInfo)
299310
{
300311
wil::com_ptr<ICoreWebView2FrameInfo> mainFrameInfo;
301-
wil::com_ptr<ICoreWebView2FrameInfo> firstLevelFrameInfo;
312+
wil::com_ptr<ICoreWebView2FrameInfo> childFrameInfo;
302313
wil::com_ptr<ICoreWebView2ExperimentalFrameInfo> frameInfoExperimental;
303314
while (frameInfo)
304315
{
305-
firstLevelFrameInfo = mainFrameInfo;
316+
childFrameInfo = mainFrameInfo;
306317
mainFrameInfo = frameInfo;
307318
CHECK_FAILURE(frameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
308319
CHECK_FAILURE(frameInfoExperimental->get_ParentFrameInfo(&frameInfo));
309320
}
310-
return firstLevelFrameInfo;
321+
return childFrameInfo;
311322
}
312323

313-
void ProcessComponent::ShowProcessFrameInfo()
324+
void ProcessComponent::ShowProcessExtendedInfo()
314325
{
315-
auto environmentExperimental11 =
316-
m_webViewEnvironment.try_query<ICoreWebView2ExperimentalEnvironment11>();
317-
if (environmentExperimental11)
326+
auto environmentExperimental13 =
327+
m_webViewEnvironment.try_query<ICoreWebView2ExperimentalEnvironment13>();
328+
if (environmentExperimental13)
318329
{
319-
//! [GetProcessInfosWithDetails]
320-
CHECK_FAILURE(environmentExperimental11->GetProcessInfosWithDetails(
321-
Callback<ICoreWebView2ExperimentalGetProcessInfosWithDetailsCompletedHandler>(
322-
[this](HRESULT error, ICoreWebView2ProcessInfoCollection* processCollection)
330+
//! [GetProcessExtendedInfos]
331+
CHECK_FAILURE(environmentExperimental13->GetProcessExtendedInfos(
332+
Callback<ICoreWebView2ExperimentalGetProcessExtendedInfosCompletedHandler>(
333+
[this](
334+
HRESULT error,
335+
ICoreWebView2ExperimentalProcessExtendedInfoCollection* processCollection)
323336
-> HRESULT
324337
{
325338
UINT32 processCount = 0;
@@ -329,8 +342,12 @@ void ProcessComponent::ShowProcessFrameInfo()
329342
std::wstringstream rendererProcessInfos;
330343
for (UINT32 i = 0; i < processCount; i++)
331344
{
345+
Microsoft::WRL::ComPtr<ICoreWebView2ExperimentalProcessExtendedInfo>
346+
processExtendedInfo;
347+
CHECK_FAILURE(
348+
processCollection->GetValueAtIndex(i, &processExtendedInfo));
332349
Microsoft::WRL::ComPtr<ICoreWebView2ProcessInfo> processInfo;
333-
CHECK_FAILURE(processCollection->GetValueAtIndex(i, &processInfo));
350+
CHECK_FAILURE(processExtendedInfo->get_ProcessInfo(&processInfo));
334351
COREWEBVIEW2_PROCESS_KIND kind;
335352
CHECK_FAILURE(processInfo->get_Kind(&kind));
336353
INT32 processId = 0;
@@ -339,12 +356,8 @@ void ProcessComponent::ShowProcessFrameInfo()
339356
{
340357
//! [AssociatedFrameInfos]
341358
std::wstringstream rendererProcess;
342-
wil::com_ptr<ICoreWebView2ExperimentalProcessInfo>
343-
processInfoExperimental;
344-
CHECK_FAILURE(processInfo->QueryInterface(
345-
IID_PPV_ARGS(&processInfoExperimental)));
346359
wil::com_ptr<ICoreWebView2FrameInfoCollection> frameInfoCollection;
347-
CHECK_FAILURE(processInfoExperimental->get_AssociatedFrameInfos(
360+
CHECK_FAILURE(processExtendedInfo->get_AssociatedFrameInfos(
348361
&frameInfoCollection));
349362
wil::com_ptr<ICoreWebView2FrameInfoCollectionIterator> iterator;
350363
CHECK_FAILURE(frameInfoCollection->GetIterator(&iterator));
@@ -363,34 +376,32 @@ void ProcessComponent::ShowProcessFrameInfo()
363376
frameInfoCount++;
364377
}
365378
rendererProcessInfos
366-
<< std::to_wstring(frameInfoCount)
367-
<< L" frameInfo(s) found in Renderer Process ID:"
368-
<< std::to_wstring(processId) << L"\n"
379+
<< frameInfoCount
380+
<< L" frameInfo(s) found in Renderer Process ID:" << processId
381+
<< L"\n"
369382
<< rendererProcess.str() << std::endl;
370383
//! [AssociatedFrameInfos]
371384
rendererProcessCount++;
372385
}
373386
else
374387
{
375-
otherProcessInfos << L"Process Id:" << std::to_wstring(processId)
388+
otherProcessInfos << L"Process Id:" << processId
376389
<< L" | Process Kind:"
377390
<< ProcessKindToString(kind) << std::endl;
378391
}
379392
}
380393
std::wstringstream message;
381-
message << std::to_wstring(processCount)
382-
<< L" process(es) found, from which "
383-
<< std::to_wstring(rendererProcessCount)
384-
<< L" renderer process(es) found\n\n"
394+
message << processCount << L" process(es) found, from which "
395+
<< rendererProcessCount << L" renderer process(es) found\n\n"
385396
<< rendererProcessInfos.str() << L"Remaining Process(es) Infos:\n"
386397
<< otherProcessInfos.str();
387398

388399
m_appWindow->AsyncMessageBox(
389-
std::move(message.str()), L"Process Info with Associated Frames");
400+
std::move(message.str()), L"Process Extended Info");
390401
return S_OK;
391402
})
392403
.Get()));
393-
//! [GetProcessInfosWithDetails]
404+
//! [GetProcessExtendedInfos]
394405
}
395406
}
396407

SampleApps/WebView2APISample/ProcessComponent.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ProcessComponent : public ComponentBase
3232
void CrashBrowserProcess();
3333
void CrashRenderProcess();
3434
void PerformanceInfo();
35-
void ShowProcessFrameInfo();
35+
void ShowProcessExtendedInfo();
3636

3737
~ProcessComponent() override;
3838

@@ -55,7 +55,7 @@ class ProcessComponent : public ComponentBase
5555
EventRegistrationToken m_processInfosChangedToken = {};
5656
void AppendFrameInfo(
5757
wil::com_ptr<ICoreWebView2FrameInfo> frameInfo, std::wstringstream& result);
58-
wil::com_ptr<ICoreWebView2FrameInfo> GetAncestorFirstLevelFrameInfo(
58+
wil::com_ptr<ICoreWebView2FrameInfo> GetAncestorMainFrameDirectChildFrameInfo(
5959
wil::com_ptr<ICoreWebView2FrameInfo> frameInfo);
6060
wil::com_ptr<ICoreWebView2FrameInfo> GetAncestorMainFrameInfo(
6161
wil::com_ptr<ICoreWebView2FrameInfo> frameInfo);

SampleApps/WebView2APISample/ScenarioWebViewEventMonitor.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,14 +656,13 @@ void ScenarioWebViewEventMonitor::InitializeEventView(ICoreWebView2* webviewEven
656656
encodedName = EncodeQuote(name.get());
657657
}
658658

659-
wil::com_ptr<ICoreWebView2ExperimentalNewWindowRequestedEventArgs2>
660-
experimental_args;
659+
wil::com_ptr<ICoreWebView2NewWindowRequestedEventArgs3> args3;
661660
std::wstring frameName = EncodeQuote(L"");
662661
std::wstring frameUri = EncodeQuote(L"");
663-
if (SUCCEEDED(args->QueryInterface(IID_PPV_ARGS(&experimental_args))))
662+
if (SUCCEEDED(args->QueryInterface(IID_PPV_ARGS(&args3))))
664663
{
665664
wil::com_ptr<ICoreWebView2FrameInfo> frame_info;
666-
CHECK_FAILURE(experimental_args->get_OriginalSourceFrameInfo(&frame_info));
665+
CHECK_FAILURE(args3->get_OriginalSourceFrameInfo(&frame_info));
667666
wil::unique_cotaskmem_string name;
668667
CHECK_FAILURE(frame_info->get_Name(&name));
669668
frameName = EncodeQuote(name.get());

0 commit comments

Comments
 (0)