@@ -215,63 +215,65 @@ std::wstring ProcessComponent::FrameKindToString(const COREWEBVIEW2_FRAME_KIND k
215
215
}
216
216
217
217
void ProcessComponent::AppendFrameInfo (
218
- wil::com_ptr<ICoreWebView2FrameInfo> frameInfo, std::wstring & result)
218
+ wil::com_ptr<ICoreWebView2FrameInfo> frameInfo, std::wstringstream & result)
219
219
{
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 " ;
225
225
wil::unique_cotaskmem_string nameRaw;
226
+ wil::unique_cotaskmem_string sourceRaw;
227
+ COREWEBVIEW2_FRAME_KIND frameKind = COREWEBVIEW2_FRAME_KIND_OTHER;
228
+
226
229
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 ();
229
233
230
234
wil::com_ptr<ICoreWebView2ExperimentalFrameInfo> frameInfoExperimental;
231
235
CHECK_FAILURE (frameInfo->QueryInterface (IID_PPV_ARGS (&frameInfoExperimental)));
232
- UINT32 frameId = 0 ;
233
236
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
+ }
235
246
236
- BOOL isMainFrameOrFirstLevelframeInfo = false ;
237
247
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.
241
248
if (mainFrameInfo == frameInfo)
242
249
{
243
- result.append (L" | frame type: main frame" );
244
- isMainFrameOrFirstLevelframeInfo = true ;
250
+ type = L" main frame" ;
245
251
}
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);
247
257
if (firstLevelFrameInfo == frameInfo)
248
258
{
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" ;
255
260
}
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)
264
262
{
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 ));
268
266
}
269
267
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;
275
277
}
276
278
277
279
// Get the ancestor main frameInfo.
@@ -308,36 +310,6 @@ wil::com_ptr<ICoreWebView2FrameInfo> ProcessComponent::GetAncestorFirstLevelFram
308
310
return firstLevelFrameInfo;
309
311
}
310
312
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
-
341
313
void ProcessComponent::ShowProcessFrameInfo ()
342
314
{
343
315
auto environmentExperimental11 =
@@ -353,8 +325,8 @@ void ProcessComponent::ShowProcessFrameInfo()
353
325
UINT32 processCount = 0 ;
354
326
UINT32 rendererProcessCount = 0 ;
355
327
CHECK_FAILURE (processCollection->get_Count (&processCount));
356
- std::wstring result ;
357
- std::wstring otherProcessResult ;
328
+ std::wstringstream otherProcessInfos ;
329
+ std::wstringstream rendererProcessInfos ;
358
330
for (UINT32 i = 0 ; i < processCount; i++)
359
331
{
360
332
Microsoft::WRL::ComPtr<ICoreWebView2ProcessInfo> processInfo;
@@ -366,7 +338,7 @@ void ProcessComponent::ShowProcessFrameInfo()
366
338
if (kind == COREWEBVIEW2_PROCESS_KIND_RENDERER)
367
339
{
368
340
// ! [AssociatedFrameInfos]
369
- std::wstring rendererProcessResult ;
341
+ std::wstringstream rendererProcess ;
370
342
wil::com_ptr<ICoreWebView2ExperimentalProcessInfo>
371
343
processInfoExperimental;
372
344
CHECK_FAILURE (processInfo->QueryInterface (
@@ -384,39 +356,37 @@ void ProcessComponent::ShowProcessFrameInfo()
384
356
wil::com_ptr<ICoreWebView2FrameInfo> frameInfo;
385
357
CHECK_FAILURE (iterator->GetCurrent (&frameInfo));
386
358
387
- AppendFrameInfo (frameInfo, rendererProcessResult);
388
- AppendAncestorFrameInfo (frameInfo, rendererProcessResult);
359
+ AppendFrameInfo (frameInfo, rendererProcess);
389
360
390
361
BOOL hasNext = FALSE ;
391
362
CHECK_FAILURE (iterator->MoveNext (&hasNext));
392
363
frameInfoCount++;
393
364
}
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 ;
399
370
// ! [AssociatedFrameInfos]
400
371
rendererProcessCount++;
401
372
}
402
373
else
403
374
{
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 ;
407
378
}
408
379
}
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" );
420
390
return S_OK;
421
391
})
422
392
.Get ()));
0 commit comments