@@ -215,63 +215,65 @@ std::wstring ProcessComponent::FrameKindToString(const COREWEBVIEW2_FRAME_KIND k
215215}
216216
217217void ProcessComponent::AppendFrameInfo (
218- wil::com_ptr<ICoreWebView2FrameInfo> frameInfo, std::wstring & result)
218+ wil::com_ptr<ICoreWebView2FrameInfo> frameInfo, std::wstringstream & result)
219219{
220- if (!frameInfo)
221- {
222- return ;
223- }
224-
220+ UINT32 frameId = 0 ;
221+ UINT32 parentFrameId = 0 ;
222+ UINT32 mainFrameId = 0 ;
223+ UINT32 firstLevelFrameId = 0 ;
224+ std::wstring type = L" other child frame " ;
225225 wil::unique_cotaskmem_string nameRaw;
226+ wil::unique_cotaskmem_string sourceRaw;
227+ COREWEBVIEW2_FRAME_KIND frameKind = COREWEBVIEW2_FRAME_KIND_OTHER;
228+
226229 CHECK_FAILURE (frameInfo->get_Name (&nameRaw));
227- result.append (L" {frame name:" );
228- result.append (nameRaw.get ());
230+ std::wstring name = ((std::wstring)(nameRaw.get ())).empty () ? L" none" : nameRaw.get ();
231+ CHECK_FAILURE (frameInfo->get_Source (&sourceRaw));
232+ std::wstring source = ((std::wstring)(sourceRaw.get ())).empty () ? L" none" : sourceRaw.get ();
229233
230234 wil::com_ptr<ICoreWebView2ExperimentalFrameInfo> frameInfoExperimental;
231235 CHECK_FAILURE (frameInfo->QueryInterface (IID_PPV_ARGS (&frameInfoExperimental)));
232- UINT32 frameId = 0 ;
233236 frameInfoExperimental->get_FrameId (&frameId);
234- result.append (L" | frame Id:" + std::to_wstring (frameId));
237+ frameInfoExperimental->get_FrameKind (&frameKind);
238+
239+ wil::com_ptr<ICoreWebView2FrameInfo> parentFrameInfo;
240+ CHECK_FAILURE (frameInfoExperimental->get_ParentFrameInfo (&parentFrameInfo));
241+ if (parentFrameInfo)
242+ {
243+ CHECK_FAILURE (parentFrameInfo->QueryInterface (IID_PPV_ARGS (&frameInfoExperimental)));
244+ CHECK_FAILURE (frameInfoExperimental->get_FrameId (&parentFrameId));
245+ }
235246
236- BOOL isMainFrameOrFirstLevelframeInfo = false ;
237247 wil::com_ptr<ICoreWebView2FrameInfo> mainFrameInfo = GetAncestorMainFrameInfo (frameInfo);
238- wil::com_ptr<ICoreWebView2FrameInfo> firstLevelFrameInfo =
239- GetAncestorFirstLevelFrameInfo (frameInfo);
240- // check if a frame is a main frame.
241248 if (mainFrameInfo == frameInfo)
242249 {
243- result.append (L" | frame type: main frame" );
244- isMainFrameOrFirstLevelframeInfo = true ;
250+ type = L" main frame" ;
245251 }
246- // check if a frame is a first level frame.
252+ CHECK_FAILURE (mainFrameInfo->QueryInterface (IID_PPV_ARGS (&frameInfoExperimental)));
253+ CHECK_FAILURE (frameInfoExperimental->get_FrameId (&mainFrameId));
254+
255+ wil::com_ptr<ICoreWebView2FrameInfo> firstLevelFrameInfo =
256+ GetAncestorFirstLevelFrameInfo (frameInfo);
247257 if (firstLevelFrameInfo == frameInfo)
248258 {
249- result.append (L" | frame type: first level frame" );
250- isMainFrameOrFirstLevelframeInfo = true ;
251- }
252- if (!isMainFrameOrFirstLevelframeInfo)
253- {
254- result.append (L" | frame type: other child frame" );
259+ type = L" first level frame" ;
255260 }
256-
257- COREWEBVIEW2_FRAME_KIND frameKind = COREWEBVIEW2_FRAME_KIND_OTHER;
258- frameInfoExperimental->get_FrameKind (&frameKind);
259- result.append (L" \n | frame kind:" + FrameKindToString (frameKind));
260-
261- wil::com_ptr<ICoreWebView2FrameInfo> parentFrameInfo;
262- CHECK_FAILURE (frameInfoExperimental->get_ParentFrameInfo (&parentFrameInfo));
263- if (parentFrameInfo)
261+ if (firstLevelFrameInfo)
264262 {
265- CHECK_FAILURE (parentFrameInfo-> QueryInterface ( IID_PPV_ARGS (&frameInfoExperimental)));
266- CHECK_FAILURE (frameInfoExperimental-> get_FrameId (&frameId ));
267- result. append ( L" | parent frame Id: " + std::to_wstring (frameId ));
263+ CHECK_FAILURE (
264+ firstLevelFrameInfo-> QueryInterface ( IID_PPV_ARGS (&frameInfoExperimental) ));
265+ CHECK_FAILURE (frameInfoExperimental-> get_FrameId (&firstLevelFrameId ));
268266 }
269267
270- wil::unique_cotaskmem_string sourceRaw;
271- CHECK_FAILURE (frameInfo->get_Source (&sourceRaw));
272- result.append (L" \n | frame source:\n\" " );
273- result.append (sourceRaw.get ());
274- result.append (L" \" " );
268+ result << L" {frame name:" << name << L" | frame Id:" << std::to_wstring (frameId)
269+ << L" | parent frame Id:"
270+ << ((parentFrameId == 0 ) ? L" none" : std::to_wstring (parentFrameId))
271+ << 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 "
275+ << L" | frame kind:" << FrameKindToString (frameKind) << L" \n "
276+ << L" | frame source:" << source << L" }," << std::endl;
275277}
276278
277279// Get the ancestor main frameInfo.
@@ -308,36 +310,6 @@ wil::com_ptr<ICoreWebView2FrameInfo> ProcessComponent::GetAncestorFirstLevelFram
308310 return firstLevelFrameInfo;
309311}
310312
311- // Append the frame Id of the ancestor first level frame and ancestor main frame.
312- void ProcessComponent::AppendAncestorFrameInfo (
313- wil::com_ptr<ICoreWebView2FrameInfo> frameInfo, std::wstring& result)
314- {
315- if (!frameInfo)
316- {
317- return ;
318- }
319-
320- wil::com_ptr<ICoreWebView2FrameInfo> mainFrameInfo = GetAncestorMainFrameInfo (frameInfo);
321- wil::com_ptr<ICoreWebView2FrameInfo> firstLevelFrameInfo =
322- GetAncestorFirstLevelFrameInfo (frameInfo);
323- wil::com_ptr<ICoreWebView2ExperimentalFrameInfo> frameInfoExperimental;
324- UINT32 frameId = 0 ;
325- if (firstLevelFrameInfo)
326- {
327- CHECK_FAILURE (
328- firstLevelFrameInfo->QueryInterface (IID_PPV_ARGS (&frameInfoExperimental)));
329- CHECK_FAILURE (frameInfoExperimental->get_FrameId (&frameId));
330- result.append (L" \n | ancestor first level frame Id:" + std::to_wstring (frameId));
331- }
332- if (mainFrameInfo)
333- {
334- CHECK_FAILURE (mainFrameInfo->QueryInterface (IID_PPV_ARGS (&frameInfoExperimental)));
335- CHECK_FAILURE (frameInfoExperimental->get_FrameId (&frameId));
336- result.append (L" \n | ancestor main frame Id:" + std::to_wstring (frameId));
337- }
338- result.append (L" },\n " );
339- }
340-
341313void ProcessComponent::ShowProcessFrameInfo ()
342314{
343315 auto environmentExperimental11 =
@@ -353,8 +325,8 @@ void ProcessComponent::ShowProcessFrameInfo()
353325 UINT32 processCount = 0 ;
354326 UINT32 rendererProcessCount = 0 ;
355327 CHECK_FAILURE (processCollection->get_Count (&processCount));
356- std::wstring result ;
357- std::wstring otherProcessResult ;
328+ std::wstringstream otherProcessInfos ;
329+ std::wstringstream rendererProcessInfos ;
358330 for (UINT32 i = 0 ; i < processCount; i++)
359331 {
360332 Microsoft::WRL::ComPtr<ICoreWebView2ProcessInfo> processInfo;
@@ -366,7 +338,7 @@ void ProcessComponent::ShowProcessFrameInfo()
366338 if (kind == COREWEBVIEW2_PROCESS_KIND_RENDERER)
367339 {
368340 // ! [AssociatedFrameInfos]
369- std::wstring rendererProcessResult ;
341+ std::wstringstream rendererProcess ;
370342 wil::com_ptr<ICoreWebView2ExperimentalProcessInfo>
371343 processInfoExperimental;
372344 CHECK_FAILURE (processInfo->QueryInterface (
@@ -384,39 +356,37 @@ void ProcessComponent::ShowProcessFrameInfo()
384356 wil::com_ptr<ICoreWebView2FrameInfo> frameInfo;
385357 CHECK_FAILURE (iterator->GetCurrent (&frameInfo));
386358
387- AppendFrameInfo (frameInfo, rendererProcessResult);
388- AppendAncestorFrameInfo (frameInfo, rendererProcessResult);
359+ AppendFrameInfo (frameInfo, rendererProcess);
389360
390361 BOOL hasNext = FALSE ;
391362 CHECK_FAILURE (iterator->MoveNext (&hasNext));
392363 frameInfoCount++;
393364 }
394- rendererProcessResult. insert (
395- 0 , std::to_wstring (frameInfoCount) +
396- L" frameInfo(s) found in Renderer Process ID:" +
397- std::to_wstring (processId) + L" \n " );
398- result. append (rendererProcessResult + L" \n " ) ;
365+ rendererProcessInfos
366+ << std::to_wstring (frameInfoCount)
367+ << L" frameInfo(s) found in Renderer Process ID:"
368+ << std::to_wstring (processId) << L" \n "
369+ << rendererProcess. str () << std::endl ;
399370 // ! [AssociatedFrameInfos]
400371 rendererProcessCount++;
401372 }
402373 else
403374 {
404- otherProcessResult. append (
405- L" Process Id: " + std::to_wstring (processId) +
406- L" | Process Kind: " + ProcessKindToString (kind) + L" \n " ) ;
375+ otherProcessInfos << L" Process Id: " << std::to_wstring (processId)
376+ << L" | Process Kind: "
377+ << ProcessKindToString (kind) << std::endl ;
407378 }
408379 }
409- result.insert (
410- 0 , std::to_wstring (processCount) + L" process(es) found, from which " +
411- std::to_wstring (rendererProcessCount) +
412- L" renderer process(es) found\n\n " );
413- otherProcessResult.insert (
414- 0 , L" \n Remaining " +
415- std::to_wstring (processCount - rendererProcessCount) +
416- L" Process(es) Infos:\n " );
417- result.append (otherProcessResult);
418- MessageBox (
419- nullptr , result.c_str (), L" Process Info with Associated Frames" , MB_OK);
380+ 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 "
385+ << rendererProcessInfos.str () << L" Remaining Process(es) Infos:\n "
386+ << otherProcessInfos.str ();
387+
388+ m_appWindow->AsyncMessageBox (
389+ std::move (message.str ()), L" Process Info with Associated Frames" );
420390 return S_OK;
421391 })
422392 .Get ()));
0 commit comments