@@ -48,13 +48,13 @@ to build the architecture of the frame tree with represent by `FrameInfo`.
4848# Examples
4949C++
5050``` c++
51- void AppendParentFirstLevelFrameInfoAndParentMainFrameInfo (
51+ void AppendAncestorFrameInfo (
5252 wil::com_ptr<ICoreWebView2FrameInfo> frameInfo, std::wstring& result);
5353void AppendFrameInfo(
5454 wil::com_ptr<ICoreWebView2FrameInfo > frameInfo, std::wstring& result);
55- wil::com_ptr<ICoreWebView2FrameInfo > GetParentFirstLevelFrameInfo (
55+ wil::com_ptr<ICoreWebView2FrameInfo > GetAncestorFirstLevelFrameInfo (
5656 wil::com_ptr<ICoreWebView2FrameInfo > frameInfo);
57- wil::com_ptr<ICoreWebView2FrameInfo > GetParentMainFrameInfo (
57+ wil::com_ptr<ICoreWebView2FrameInfo > GetAncestorMainFrameInfo (
5858 wil::com_ptr<ICoreWebView2FrameInfo > frameInfo);
5959
6060// Display renderer process info with details which includes the list of
@@ -88,7 +88,7 @@ void ProcessComponent::ShowRendererProcessFrameInfo()
8888 if (kind == COREWEBVIEW2_PROCESS_KIND_RENDERER)
8989 {
9090 //! [ AssociatedFrameInfos]
91- std::wstring rendererProcessInfoResult ;
91+ std::wstring rendererProcessResult ;
9292 wil::com_ptr<ICoreWebView2ProcessInfo2 > processInfo2;
9393 CHECK_FAILURE(
9494 processInfo->QueryInterface(IID_PPV_ARGS(&processInfo2)));
@@ -105,38 +105,35 @@ void ProcessComponent::ShowRendererProcessFrameInfo()
105105 wil::com_ptr<ICoreWebView2FrameInfo > frameInfo;
106106 CHECK_FAILURE(iterator->GetCurrent(&frameInfo));
107107
108- AppendFrameInfo(frameInfo, rendererProcessInfoResult);
109- AppendParentFirstLevelFrameInfoAndParentMainFrameInfo(
110- frameInfo, rendererProcessInfoResult);
108+ AppendFrameInfo(frameInfo, rendererProcessResult);
109+ AppendAncestorFrameInfo(frameInfo, rendererProcessResult);
111110
112111 BOOL hasNext = FALSE;
113112 CHECK_FAILURE(iterator->MoveNext(&hasNext));
114113 frameInfoCount++;
115114 }
116- rendererProcessInfoResult.insert(
117- 0, std::to_wstring(frameInfoCount) +
118- L" frameInfo(s) found in Renderer Process ID:" +
119- std::to_wstring(processId) + L"\n");
120- result.append(rendererProcessInfoResult + L"\n");
115+ rendererProcessResult.insert(0, std::to_wstring(frameInfoCount) +
116+ L" frameInfo(s) found in Renderer Process ID:" +
117+ std::to_wstring(processId) + L"\n");
118+ result.append(rendererProcessResult + L"\n");
121119 rendererProcessCount++;
122120 //! [AssociatedFrameInfos]
123121 }
124122 else
125123 {
126- otherProcessResult.append(
127- L"Process Id:" + std::to_wstring(processId) +
128- L" | Process Kind:" + ProcessKindToString(kind) + L"\n");
124+ otherProcessResult.append(L"Process Id:" + std::to_wstring(processId) +
125+ L" | Process Kind:" + ProcessKindToString(kind) + L"\n");
129126 }
130127 }
131- result.insert(
132- 0, std::to_wstring(processCount) + L" process(es) found, from which " +
133- std::to_wstring(rendererProcessCount) +
128+ result.insert(0, std::to_wstring(processCount) +
129+ L" process(es) found, from which " +
130+ std::to_wstring(rendererProcessCount) +
134131 L" renderer process(es) found\n\n");
135- otherProcessResult.insert(
136- 0, L"\nRemaining " + std::to_wstring(processCount - rendererProcessCount) +
137- L" Process(es) Infos:\n");
132+ otherProcessResult.insert(0, L"\nRemaining " +
133+ std::to_wstring(processCount - rendererProcessCount) +
134+ L" Process(es) Infos:\n");
138135 result.append(otherProcessResult);
139- MessageBox(nullptr, result.c_str(), L"Renderer process frame Info ", MB_OK);
136+ MessageBox(nullptr, result.c_str(), L"Process Info with Associated Frames ", MB_OK);
140137 return S_OK;
141138 })
142139 .Get()));
@@ -146,7 +143,7 @@ void ProcessComponent::ShowRendererProcessFrameInfo()
146143
147144// Get the parent main frameInfo.
148145// Return itself if it's a main frame.
149- wil::com_ptr<ICoreWebView2FrameInfo > ProcessComponent::GetParentMainFrameInfo (
146+ wil::com_ptr<ICoreWebView2FrameInfo > ProcessComponent::GetAncestorMainFrameInfo (
150147 wil::com_ptr<ICoreWebView2FrameInfo > frameInfo)
151148{
152149 wil::com_ptr<ICoreWebView2FrameInfo > mainFrameInfo;
@@ -162,7 +159,7 @@ wil::com_ptr<ICoreWebView2FrameInfo> ProcessComponent::GetParentMainFrameInfo(
162159
163160// Get the parent first level frameInfo.
164161// Return itself if it's a first level frame.
165- wil::com_ptr<ICoreWebView2FrameInfo > ProcessComponent::GetParentFirstLevelFrameInfo (
162+ wil::com_ptr<ICoreWebView2FrameInfo > ProcessComponent::GetAncestorFirstLevelFrameInfo (
166163 wil::com_ptr<ICoreWebView2FrameInfo > frameInfo)
167164{
168165 wil::com_ptr<ICoreWebView2FrameInfo > mainFrameInfo;
@@ -200,9 +197,10 @@ void ProcessComponent::AppendFrameInfo(
200197
201198 // Check if a frame is a main frame.
202199 BOOL isMainFrameOrFirstLevelframeInfo = false;
203- wil::com_ptr<ICoreWebView2FrameInfo> mainFrameInfo = GetParentMainFrameInfo(frameInfo);
200+ wil::com_ptr<ICoreWebView2FrameInfo> mainFrameInfo =
201+ GetAncestorMainFrameInfo(frameInfo);
204202 wil::com_ptr<ICoreWebView2FrameInfo> firstLevelFrameInfo =
205- GetParentFirstLevelFrameInfo (frameInfo);
203+ GetAncestorFirstLevelFrameInfo (frameInfo);
206204 if (mainFrameInfo == frameInfo)
207205 {
208206 result.append(L" | frame kind: main frame");
@@ -237,116 +235,130 @@ void ProcessComponent::AppendFrameInfo(
237235
238236// Append the frameInfo's parent main frame(webview)'s ID and
239237// parent first level frame's ID if it exists.
240- void ProcessComponent::AppendParentFirstLevelFrameInfoAndParentMainFrameInfo (
238+ void ProcessComponent::AppendAncestorFrameInfo (
241239 wil::com_ptr<ICoreWebView2FrameInfo > frameInfo, std::wstring& result)
242240{
243241 if (frameInfo)
244242 {
245243 return;
246244 }
247245
248- wil::com_ptr<ICoreWebView2FrameInfo> mainFrameInfo = GetParentMainFrameInfo (frameInfo);
246+ wil::com_ptr<ICoreWebView2FrameInfo> mainFrameInfo = GetAncestorMainFrameInfo (frameInfo);
249247 wil::com_ptr<ICoreWebView2FrameInfo> firstLevelFrameInfo =
250- GetParentFirstLevelFrameInfo (frameInfo);
248+ GetAncestorFirstLevelFrameInfo (frameInfo);
251249 wil::com_ptr<ICoreWebView2FrameInfo2> frameInfo2;
252250 UINT32 frameId = 0;
253251 if (firstLevelFrameInfo)
254252 {
255253 CHECK_FAILURE(firstLevelFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
256254 CHECK_FAILURE(frameInfo2->get_FrameId(&frameId));
257- result.append(L"\n | parent first level frame Id:" + std::to_wstring(frameId));
255+ result.append(L"\n | ancestor first level frame Id:" + std::to_wstring(frameId));
258256 }
259257 if (mainFrameInfo)
260258 {
261259 CHECK_FAILURE(mainFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
262260 CHECK_FAILURE(frameInfo2->get_FrameId(&frameId));
263- result.append(L"\n | parent main frame Id:" + std::to_wstring(frameId));
261+ result.append(L"\n | ancestor main frame Id:" + std::to_wstring(frameId));
264262 }
265263 result.append(L"},\n");
266264}
267265```
268266C#
269267```c#
268+ string AppendFrameInfo(string id, string name, string kind, string parentId, string source,
269+ string ancestorMainFrameId, string ancestorFirstLevelFrameId) {
270+ return $"{{frame Id:{id} " +
271+ $"| frame Name: {name} " +
272+ $"| frame Kind: {kind} " +
273+ $"| parent frame Id: {parentId} " +
274+ $"| ancestor main frame Id: {ancestorMainFrameId} " +
275+ $"| ancestor first level frame Id: {ancestorFirstLevelFrameId} " +
276+ $"| frame Source: \"{source}\"}}\n";
277+ }
278+
270279// Display renderer process info with details which includes the list of
271280// associated frame infos for the renderer process. Also shows the process
272281// info of other type of process.
273- private async void RendererProcessFrameInfoCmdExecuted (object target, ExecutedRoutedEventArgs e)
282+ private async void ProcessFrameInfoCmdExecuted (object target, ExecutedRoutedEventArgs e)
274283{
275284 try
276285 {
277286 // <GetProcessInfosWithDetailsAsync>
278287 IReadOnlyList<CoreWebView2ProcessInfo> processList = await webView.CoreWebView2.Environment.GetProcessInfosWithDetailsAsync();
279288 int processListCount = processList.Count;
280- string result = $"{processListCount} process(es) found, from which ";
281- string otherProcessInfoStr = $"\nRemaining Process Infos:\n";
282- int processWithFrameCount = 0;
289+ string rendererProcessInfosStr = $"{processListCount} process(es) found in total\n\n ";
290+ string otherProcessInfosStr = $"\nRemaining Process Infos:\n";
291+ int rendererProcessCount = 0;
283292 for (int i = 0; i < processListCount; ++i)
284293 {
285294 CoreWebView2ProcessKind kind = processList[i].Kind;
286295 int processId = processList[i].ProcessId;
287296 if (kind == CoreWebView2ProcessKind.Renderer)
288297 {
289298 int frameInfoCount = 0;
290- string renderProcessInfoStr = "";
299+ string frameInfosStr = "";
291300 // <AssociatedFrameInfos>
292301 IReadOnlyList<CoreWebView2FrameInfo> frameInfoList = processList[i].AssociatedFrameInfos;
293302 foreach (CoreWebView2FrameInfo frameInfo in frameInfoList)
294303 {
295- renderProcessInfoStr += $"{{frame ID:{frameInfo.FrameId} | frame Name:{frameInfo.Name}";
304+ string parentFrameId = "Not Existed";
305+ string ancestorMainFrameId = "Not Existed";
306+ string ancestorFirstLevelFrameId = "Not Existed";
307+ string frameSource = frameInfo.Source;
308+ string frameId = frameInfo.FrameId.ToString();
309+ string frameName = frameInfo.Name;
296310 CoreWebView2FrameInfo parentFrameInfo = frameInfo.ParentFrameInfo;
297311 if (parentFrameInfo != null)
298312 {
299- renderProcessInfoStr += $" | parent frame ID: { parentFrameInfo.FrameId}\n" ;
313+ parentFrameId = parentFrameInfo.FrameId.ToString() ;
300314 }
301- renderProcessInfoStr += $" | frame Source: \"{frameInfo.Source}\" \n";
315+
302316 frameInfoCount++;
303- // If the frame has not parent, then it's a main frame.
317+ // If the frame has no parent, then it's a main frame.
304318 if (parentFrameInfo == null)
305319 {
306- renderProcessInfoStr += $" | frame Kind: main fame\n" ;
307- renderProcessInfoStr += $" | parent main frame ID:{frameInfo.FrameId}}}\n" ;
320+ ancestorMainFrameId = frameInfo.FrameId.ToString() ;
321+ frameInfosStr += AppendFrameInfo(frameId, frameName, " main frame", parentFrameId, frameSource, ancestorMainFrameId, ancestorFirstLevelFrameId) ;
308322 continue;
309323 }
310324 CoreWebView2FrameInfo firstLevelFrameInfo = parentFrameInfo;
311325 parentFrameInfo = parentFrameInfo.ParentFrameInfo;
312326 // If the frame's parent has no parent frame, then it's a first level frame.
313327 if (parentFrameInfo == null)
314328 {
315- renderProcessInfoStr += $" | frame Kind: first level frame\n" ;
316- renderProcessInfoStr += $" | parent main frame ID:{ frameInfo.ParentFrameInfo.FrameId}\n" ;
317- renderProcessInfoStr += $" | parent first level frame ID:{frameInfo.FrameId}}}\n" ;
329+ ancestorMainFrameId = frameInfo.FrameId.ToString() ;
330+ ancestorFirstLevelFrameId = frameInfo.ParentFrameInfo.FrameId.ToString() ;
331+ frameInfosStr += AppendFrameInfo(frameId, frameName, " first level frame frame", parentFrameId, frameSource, ancestorMainFrameId, ancestorFirstLevelFrameId) ;
318332 continue;
319333 }
320- // Traverse parent frame until find the parent main frame.
334+ // For other child frames, we traverse the parent frame until find the ancestor main frame.
321335 while (parentFrameInfo.ParentFrameInfo != null)
322336 {
323337 firstLevelFrameInfo = parentFrameInfo;
324338 parentFrameInfo = parentFrameInfo.ParentFrameInfo;
325339 }
326- renderProcessInfoStr += $" | frame Kind: other frame\n" ;
327- renderProcessInfoStr += $" | parent main frame ID:{parentFrameInfo .FrameId}\n" ;
328- renderProcessInfoStr += $" | parent first level frame ID:{firstLevelFrameInfo.FrameId}}}\n" ;
340+ ancestorMainFrameId = parentFrameInfo.FrameId.ToString() ;
341+ ancestorFirstLevelFrameId = firstLevelFrameInfo .FrameId.ToString() ;
342+ frameInfosStr += AppendFrameInfo(frameId, frameName, "other frame", parentFrameId, frameSource, ancestorMainFrameId, ancestorFirstLevelFrameId) ;
329343 }
330344 // </AssociatedFrameInfos>
331- string frameInfoRes = $"{frameInfoCount} frame info(s) found in renderer process ID: {processId}\n";
332- frameInfoRes += renderProcessInfoStr;
333- result += $"{frameInfoRes} \n";
334- processWithFrameCount++;
345+ string rendererProcessInfoStr = $"{frameInfoCount} frame info(s) found in renderer process ID: {processId}\n {frameInfosStr}";
346+ rendererProcessInfosStr += $"{rendererProcessInfoStr} \n";
347+ rendererProcessCount++;
335348 }
336- else
349+ else
337350 {
338- otherProcessInfoStr += $"Process ID: {processId} | Process Kind: {kind}\n";
351+ otherProcessInfosStr += $"Process ID: {processId} | Process Kind: {kind}\n";
339352 }
340-
341353 }
342354 // </GetProcessInfosWithDetailsAsync>
343- string processCountStr = $"{processWithFrameCount } renderer process(es)\n\n ";
344- MessageBox.Show(this, processCountStr + result + otherProcessInfoStr , "Process Frame Info List ");
355+ string message = $"{rendererProcessCount } renderer process(es) found, {rendererProcessInfosStr + otherProcessInfosStr} ";
356+ MessageBox.Show(this, message , "Process Info with Associated Frames ");
345357 }
346- catch (NotImplementedException)
358+ catch (NotImplementedException exception )
347359 {
348- // If the runtime support is not there we probably want this
349- // to be a no-op.
360+ MessageBox.Show(this, "GetProcessInfosWithDetailsAsync Failed: " + exception.Message,
361+ "Process Info with Associated Frames");
350362 }
351363}
352364```
@@ -372,13 +384,16 @@ interface ICoreWebView2GetProcessInfosWithDetailsCompletedHandler : IUnknown {
372384// / A continuation of the ICoreWebView2ProcessInfo interface.
373385[uuid(982ae768-e2ca-11ed-b5ea-0242ac120002), object, pointer_default(unique)]
374386interface ICoreWebView2ProcessInfo2 : ICoreWebView2ProcessInfo {
375- /// Gets the collection of the assocated ` FrameInfo ` s which are actively running
376- /// (showing UI elements) in that renderer process. Assocated ` FrameInfo ` s is
377- /// empty if there's no frame actively running in that renderer process or it's
378- /// not called from
379- /// ` ICoreWebView2GetProcessInfosWithDetailsCompletedHandler ` .
380- /// Note that if this is call from other process Kind, it also returns an empty
381- /// ` FrameInfo ` s as frames run on renderer process.
387+ /// The collection of associated ` FrameInfo ` s which are actively running
388+ /// (showing UI elements) in this renderer process. ` AssociatedFrameInfos `
389+ /// will only be populated when obtained via calling
390+ /// ` CoreWebView2.GetProcessInfosWithDetails ` and when this
391+ /// ` CoreWebView2ProcessInfo ` corresponds to a renderer process.
392+ /// ` CoreWebView2ProcessInfo ` objects obtained via ` CoreWebView2.GetProcessInfos `
393+ /// or for non-renderer processes will always have an empty ` AssociatedFrameInfos ` .
394+ /// The ` AssociatedFrameInfos ` may also be be empty for renderer processes that
395+ /// have no active frames.
396+ ///
382397 /// \snippet ProcessComponent.cpp AssociatedFrameInfos
383398 [ propget] HRESULT AssociatedFrameInfos(
384399 [ out, retval] ICoreWebView2FrameInfoCollection** frames);
0 commit comments