@@ -23,26 +23,26 @@ In this document we describe the updated API. We'd appreciate your feedback.
2323# Description
2424* We propose extending ` CoreWebView2Environment ` to include the
2525` GetProcessInfosWithDetails ` API. This asynchronous call returns the
26- collectionof all ` ProcessInfo ` s running in this ` ICoreWebView2Environment `
26+ collection of all ` ProcessInfo ` s running in this ` ICoreWebView2Environment `
2727except for crashpad process. This provide the same list of ` ProcessInfo ` s as
28- what's providedin ` GetProcessInfos ` . Plus, this also provide the list of
28+ what's provided in ` GetProcessInfos ` . Plus, this also provide the list of
2929associated ` FrameInfo ` s running in the renderer process. Note that instead
3030of providing the real time of ` ProcessInfo ` s like ` GetProcessInfos ` , this
3131provide a snapshot of all ` ProcessInfo ` s.
3232
3333* We propose to add the ` AssociatedFrameInfo ` API to provide a list of
34- ` FrameInfo ` s running on the asscociated renderer process.
34+ ` FrameInfo ` s running in the asscociated renderer process.
3535
3636* We propose extending ` CoreWebView2 ` and ` CoreWebView2Frame ` to include
3737the ` FrameId ` property. This property represents the unique identifier of
38- the frame running on this webview or webview frame.
38+ the frame running in this webview or webview frame.
3939
4040* We propose extending ` CoreWebView2FrameInfo ` to include ` FrameId ` and
4141` ParentFrameInfo ` properties. ` FrameId ` is the same kind of ID as with
4242frame ID in ` CoreWebView2 ` and ` CoreWebView2Frame ` . ` ParentFrameInfo `
43- supports to retrive a frame's direct parent, parent frame in first level
44- and parent main frame. This also can be used to build the architecture of
45- the frame tree with represent by ` FrameInfo ` .
43+ supports to retrive a frame's direct parent, corresponding parent frame
44+ in the first level and corresponding main frame. This also can be used
45+ to build the architecture of the frame tree with represent by ` FrameInfo ` .
4646
4747# Examples
4848C++
@@ -51,11 +51,10 @@ void AppendParentFirstLevelFrameInfoAndParentMainFrameInfo(
5151 wil::com_ptr<ICoreWebView2FrameInfo> frameInfo, std::wstring& result);
5252void AppendFrameInfo(
5353 wil::com_ptr<ICoreWebView2FrameInfo > frameInfo, std::wstring& result);
54- void BuildMainFrameIdAndFirstLevelFrameIdSet(
55- ICoreWebView2ProcessInfoCollection* processCollection);
56-
57- std::set<UINT32 > m_mainFrameIdSet;
58- std::set<UINT32 > m_firstLevelFrameIdSet;
54+ wil::com_ptr<ICoreWebView2FrameInfo > GetParentFirstLevelFrameInfo(
55+ wil::com_ptr<ICoreWebView2FrameInfo > frameInfo);
56+ wil::com_ptr<ICoreWebView2FrameInfo > GetParentMainFrameInfo(
57+ wil::com_ptr<ICoreWebView2FrameInfo > frameInfo);
5958
6059// Display renderer process info with details which includes the list of
6160// associated frame infos for the renderer process. Also shows the process
@@ -72,16 +71,11 @@ void ProcessComponent::ShowRendererProcessFrameInfo()
7271 [ this] (HRESULT error, ICoreWebView2ProcessInfoCollection* processCollection)
7372 -> HRESULT
7473 {
75- BuildMainFrameIdAndFirstLevelFrameIdSet(processCollection);
76-
7774 UINT32 processCount = 0;
7875 UINT32 rendererProcessCount = 0;
7976 CHECK_FAILURE(processCollection->get_Count(&processCount));
8077 std::wstring result;
81- std::wstring otherResult =
82- L"\nRemaining " + std::to_wstring(processCount - rendererProcessCount) +
83- L"Process Infos:\n";
84-
78+ std::wstring otherProcessResult;
8579 for (UINT32 i = 0; i < processCount; i++)
8680 {
8781 Microsoft::WRL::ComPtr<ICoreWebView2ProcessInfo > processInfo;
@@ -92,8 +86,8 @@ void ProcessComponent::ShowRendererProcessFrameInfo()
9286 CHECK_FAILURE(processInfo->get_ProcessId(&processId));
9387 if (kind == COREWEBVIEW2_PROCESS_KIND_RENDERER)
9488 {
95- std::wstring rendererProcessInfoResult;
9689 //! [ AssociatedFrameInfos]
90+ std::wstring rendererProcessInfoResult;
9791 wil::com_ptr<ICoreWebView2ProcessInfo2 > processInfo2;
9892 CHECK_FAILURE(
9993 processInfo->QueryInterface(IID_PPV_ARGS(&processInfo2)));
@@ -118,17 +112,17 @@ void ProcessComponent::ShowRendererProcessFrameInfo()
118112 CHECK_FAILURE(iterator->MoveNext(&hasNext));
119113 frameInfoCount++;
120114 }
121- //! [AssociatedFrameInfos]
122115 rendererProcessInfoResult.insert(
123116 0, std::to_wstring(frameInfoCount) +
124117 L" frameInfo(s) found in Renderer Process ID:" +
125118 std::to_wstring(processId) + L"\n");
126119 result.append(rendererProcessInfoResult + L"\n");
127120 rendererProcessCount++;
121+ //! [AssociatedFrameInfos]
128122 }
129123 else
130124 {
131- otherResult .append(
125+ otherProcessResult .append(
132126 L"Process Id:" + std::to_wstring(processId) +
133127 L" | Process Kind:" + ProcessKindToString(kind) + L"\n");
134128 }
@@ -137,7 +131,10 @@ void ProcessComponent::ShowRendererProcessFrameInfo()
137131 0, std::to_wstring(processCount) + L" process(es) found, from which " +
138132 std::to_wstring(rendererProcessCount) +
139133 L" renderer process(es) found\n\n");
140- result.append(otherResult);
134+ otherProcessResult.insert(
135+ 0, L"\nRemaining " + std::to_wstring(processCount - rendererProcessCount) +
136+ L" Process(es) Infos:\n");
137+ result.append(otherProcessResult);
141138 MessageBox(nullptr, result.c_str(), L"Renderer process frame Info", MB_OK);
142139 return S_OK;
143140 })
@@ -146,70 +143,49 @@ void ProcessComponent::ShowRendererProcessFrameInfo()
146143 }
147144}
148145
149- // Build main frame Id set and first level frame Id set from the list
150- // of all process info.
151- void ProcessComponent::BuildMainFrameIdAndFirstLevelFrameIdSet (
152- ICoreWebView2ProcessInfoCollection * processCollection )
146+ // Get the parent main frameInfo.
147+ // Return itself if it's a main frame.
148+ wil::com_ptr< ICoreWebView2FrameInfo > ProcessComponent::GetParentMainFrameInfo (
149+ wil::com_ptr< ICoreWebView2FrameInfo > frameInfo )
153150{
154- UINT32 processCount = 0 ;
155- CHECK_FAILURE(processCollection->get_Count(&processCount)) ;
156- for (UINT32 i = 0; i < processCount; i++ )
151+ wil::com_ptr< ICoreWebView2FrameInfo > mainFrameInfo ;
152+ wil::com_ptr< ICoreWebView2FrameInfo2 > frameInfo2 ;
153+ while (frameInfo )
157154 {
158- Microsoft::WRL::ComPtr<ICoreWebView2ProcessInfo > processInfo;
159- CHECK_FAILURE(processCollection->GetValueAtIndex(i, &processInfo));
160- COREWEBVIEW2_PROCESS_KIND kind;
161- CHECK_FAILURE(processInfo->get_Kind(&kind));
162- if (kind == COREWEBVIEW2_PROCESS_KIND_RENDERER)
163- {
164- //! [ AssociatedFrameInfos]
165- wil::com_ptr<ICoreWebView2ProcessInfo2 > processInfo2;
166- CHECK_FAILURE(processInfo->QueryInterface(IID_PPV_ARGS(&processInfo2)));
167- wil::com_ptr<ICoreWebView2FrameInfoCollection > frameInfoCollection;
168- CHECK_FAILURE(processInfo2->get_AssociatedFrameInfos(&frameInfoCollection));
169-
170- wil::com_ptr<ICoreWebView2FrameInfoCollectionIterator> iterator;
171- CHECK_FAILURE(frameInfoCollection->GetIterator(&iterator));
172- BOOL hasCurrent = FALSE;
173- while (SUCCEEDED(iterator->get_HasCurrent(&hasCurrent)) && hasCurrent)
174- {
175- wil::com_ptr<ICoreWebView2FrameInfo> frameInfo;
176- CHECK_FAILURE(iterator->GetCurrent(&frameInfo));
177- wil::com_ptr<ICoreWebView2FrameInfo2> frameInfo2;
178- CHECK_FAILURE(frameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
179- UINT32 frameId = 0;
180- frameInfo2->get_FrameId(&frameId);
181- // ![ParentFrameInfo]
182- wil::com_ptr<ICoreWebView2FrameInfo> parentFrameInfo;
183- CHECK_FAILURE(frameInfo2->get_ParentFrameInfo(&parentFrameInfo));
184- // ![ParentFrameInfo]
185- // Add frame to main frame ID set if the frameInfo has no parent.
186- if (!parentFrameInfo)
187- {
188- m_mainFrameIdSet.insert(frameId);
189- BOOL hasNext = FALSE;
190- CHECK_FAILURE(iterator->MoveNext(&hasNext));
191- continue;
192- }
193- CHECK_FAILURE(parentFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
194- CHECK_FAILURE(frameInfo2->get_ParentFrameInfo(&parentFrameInfo));
195- // Add frame to first level frame ID set if the frameInfo's parent has no
196- // parent.
197- if (!parentFrameInfo)
198- {
199- m_firstLevelFrameIdSet.insert(frameId);
200- }
201- BOOL hasNext = FALSE;
202- CHECK_FAILURE(iterator->MoveNext(&hasNext));
203- }
204- //! [AssociatedFrameInfos]
205- }
155+ mainFrameInfo = frameInfo;
156+ CHECK_FAILURE(frameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
157+ CHECK_FAILURE(frameInfo2->get_ParentFrameInfo(&frameInfo));
158+ }
159+ return mainFrameInfo;
160+ }
161+
162+ // Get the parent first level frameInfo.
163+ // Return itself if it's a first level frame.
164+ wil::com_ptr<ICoreWebView2FrameInfo > ProcessComponent::GetParentFirstLevelFrameInfo(
165+ wil::com_ptr<ICoreWebView2FrameInfo > frameInfo)
166+ {
167+ wil::com_ptr<ICoreWebView2FrameInfo > mainFrameInfo;
168+ wil::com_ptr<ICoreWebView2FrameInfo > firstLevelFrameInfo;
169+ wil::com_ptr<ICoreWebView2FrameInfo2 > frameInfo2;
170+ while (frameInfo)
171+ {
172+ firstLevelFrameInfo = mainFrameInfo;
173+ mainFrameInfo = frameInfo;
174+ CHECK_FAILURE(frameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
175+ CHECK_FAILURE(frameInfo2->get_ParentFrameInfo(&frameInfo));
206176 }
177+ return firstLevelFrameInfo;
207178}
208179
209- // Append the current frameInfo's properties.
180+ // Append the frameInfo's properties.
210181void ProcessComponent::AppendFrameInfo(
211182 wil::com_ptr<ICoreWebView2FrameInfo > frameInfo, std::wstring& result)
212183{
184+ if (!frameInfo)
185+ {
186+ return;
187+ }
188+
213189 wil::unique_cotaskmem_string nameRaw;
214190 CHECK_FAILURE(frameInfo->get_Name(&nameRaw));
215191 result.append(L"{frame name:");
@@ -219,39 +195,36 @@ void ProcessComponent::AppendFrameInfo(
219195 CHECK_FAILURE(frameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
220196 UINT32 frameId = 0;
221197 frameInfo2->get_FrameId(&frameId);
222- result.append(L" | frame ID :" + std::to_wstring(frameId));
198+ result.append(L" | frame Id :" + std::to_wstring(frameId));
223199
224200 // Check if a frame is a main frame.
225201 BOOL isMainFrameOrFirstLevelframeInfo = false;
226- if (!m_mainFrameIdSet.empty())
202+ wil::com_ptr<ICoreWebView2FrameInfo> mainFrameInfo = GetParentMainFrameInfo(frameInfo);
203+ wil::com_ptr<ICoreWebView2FrameInfo> firstLevelFrameInfo =
204+ GetParentFirstLevelFrameInfo(frameInfo);
205+ if (mainFrameInfo == frameInfo)
227206 {
228- if (m_mainFrameIdSet.find(frameId) != m_mainFrameIdSet.end())
229- {
230- result.append(L" | frame kind: main frame");
231- isMainFrameOrFirstLevelframeInfo = true;
232- }
207+ result.append(L" | frame kind: main frame");
208+ isMainFrameOrFirstLevelframeInfo = true;
233209 }
234210 // Check if a frame is a first level frame.
235- if (!m_firstLevelFrameIdSet.empty() )
211+ if (firstLevelFrameInfo == frameInfo )
236212 {
237- if (m_firstLevelFrameIdSet.find(frameId) != m_firstLevelFrameIdSet.end())
238- {
239- result.append(L" | frame kind: first level frame");
240- isMainFrameOrFirstLevelframeInfo = true;
241- }
213+ result.append(L" | frame kind: first level frame");
214+ isMainFrameOrFirstLevelframeInfo = true;
242215 }
243216 if (!isMainFrameOrFirstLevelframeInfo)
244217 {
245218 result.append(L" | frame kind: other child frame");
246219 }
247-
220+ // Append the frame's direct parent frame's ID if it exists.
248221 wil::com_ptr<ICoreWebView2FrameInfo> parentFrameInfo;
249222 CHECK_FAILURE(frameInfo2->get_ParentFrameInfo(&parentFrameInfo));
250223 if (parentFrameInfo)
251224 {
252225 CHECK_FAILURE(parentFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
253226 CHECK_FAILURE(frameInfo2->get_FrameId(&frameId));
254- result.append(L" \n | parent frame ID :" + std::to_wstring(frameId));
227+ result.append(L" \n | parent frame Id :" + std::to_wstring(frameId));
255228 }
256229
257230 wil::unique_cotaskmem_string sourceRaw;
@@ -261,43 +234,32 @@ void ProcessComponent::AppendFrameInfo(
261234 result.append(L"\"");
262235}
263236
264- // Append the current frameInfo's parent main frame ID (webview) and
265- // parent first level frame ID if exists.
237+ // Append the frameInfo's parent main frame(webview)'s ID and
238+ // parent first level frame's ID if it exists.
266239void ProcessComponent::AppendParentFirstLevelFrameInfoAndParentMainFrameInfo(
267240 wil::com_ptr<ICoreWebView2FrameInfo > frameInfo, std::wstring& result)
268241{
269- wil::com_ptr<ICoreWebView2FrameInfo > firstLevelFrameInfo;
270- wil::com_ptr<ICoreWebView2FrameInfo > mainFrameInfo;
271- wil::com_ptr<ICoreWebView2FrameInfo2 > frameInfo2;
272- UINT32 frameId = 0;
273- while (frameInfo)
242+ if (frameInfo)
274243 {
275- CHECK_FAILURE(frameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
276- CHECK_FAILURE(frameInfo2->get_FrameId(&frameId));
277- if (m_firstLevelFrameIdSet.find(frameId) != m_firstLevelFrameIdSet.end())
278- {
279- firstLevelFrameInfo = frameInfo;
280- }
281- if (m_mainFrameIdSet.find(frameId) != m_mainFrameIdSet.end())
282- {
283- mainFrameInfo = frameInfo;
284- }
285- CHECK_FAILURE(frameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
286- CHECK_FAILURE(frameInfo2->get_ParentFrameInfo(&frameInfo));
244+ return;
287245 }
288246
247+ wil::com_ptr<ICoreWebView2FrameInfo> mainFrameInfo = GetParentMainFrameInfo(frameInfo);
248+ wil::com_ptr<ICoreWebView2FrameInfo> firstLevelFrameInfo =
249+ GetParentFirstLevelFrameInfo(frameInfo);
250+ wil::com_ptr<ICoreWebView2FrameInfo2> frameInfo2;
251+ UINT32 frameId = 0;
289252 if (firstLevelFrameInfo)
290253 {
291254 CHECK_FAILURE(firstLevelFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
292255 CHECK_FAILURE(frameInfo2->get_FrameId(&frameId));
293- result.append(
294- L"\n | parent first level frame ID:" + std::to_wstring(frameId));
256+ result.append(L"\n | parent first level frame Id:" + std::to_wstring(frameId));
295257 }
296258 if (mainFrameInfo)
297259 {
298260 CHECK_FAILURE(mainFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
299261 CHECK_FAILURE(frameInfo2->get_FrameId(&frameId));
300- result.append(L"\n | parent main frame ID :" + std::to_wstring(frameId));
262+ result.append(L"\n | parent main frame Id :" + std::to_wstring(frameId));
301263 }
302264 result.append(L"},\n");
303265}
@@ -410,10 +372,12 @@ interface ICoreWebView2GetProcessInfosWithDetailsCompletedHandler : IUnknown {
410372[uuid(982ae768-e2ca-11ed-b5ea-0242ac120002), object, pointer_default(unique)]
411373interface ICoreWebView2ProcessInfo2 : ICoreWebView2ProcessInfo {
412374 /// Gets the collection of the assocated ` FrameInfo ` s which are running in that
413- /// renderer process.
414- /// This is only available when process ` Kind ` is ` COREWEBVIEW2_PROCESS_KIND_RENDERER ` .
415- /// ` frames ` is ` null ` for all other process kinds.
416- /// Note that ` frames ` can be ` null ` if there's no frame running in that process.
375+ /// renderer process. Assocated ` FrameInfo ` s can be ` null ` if there's no frame
376+ /// running in that renderer process.
377+ /// Note that this is only available when the process ` Kind ` is
378+ /// ` COREWEBVIEW2_PROCESS_KIND_RENDERER `
379+ /// and it's called from ` ICoreWebView2GetProcessInfosWithDetailsCompletedHandler ` .
380+ /// Else, it returns a HRESULT error code and ` null ` for ` FrameInfo ` list.
417381 ///
418382 /// \snippet ProcessComponent.cpp AssociatedFrameInfos
419383 [ propget] HRESULT AssociatedFrameInfos(
@@ -428,7 +392,7 @@ interface ICoreWebView2Environment14 : ICoreWebView2Environment13 {
428392 /// This provide the same list of ` ProcessInfo ` s as what's provided in
429393 /// ` GetProcessInfos ` . Plus, this provide a list of associated ` FrameInfo ` s running in
430394 /// the renderer process. Check ` AssociatedFrameInfos ` for acquiring
431- /// those details info .
395+ /// this detail infos .
432396 /// Note that instead of providing the real time of ` ProcessInfo ` s as
433397 /// ` GetProcessInfos ` , this provide a snapshot of all ` ProcessInfo ` s.
434398 ///
@@ -441,11 +405,15 @@ interface ICoreWebView2Environment14 : ICoreWebView2Environment13 {
441405interface ICoreWebView2FrameInfo2 : ICoreWebView2FrameInfo {
442406 /// The parent ` FrameInfo ` .
443407 /// This property is ` null ` for the top most document in the WebView2 which has
444- /// no parent frame.
408+ /// no parent frame. Note that this is only available when it's called from
409+ /// ` ICoreWebView2GetProcessInfosWithDetailsCompletedHandler ` .
410+ /// Else, it return a HRESULT error code and ` null ` for parent ` FrameInfo ` .
445411 [ propget] HRESULT ParentFrameInfo([ out, retval] ICoreWebView2FrameInfo** frameInfo);
446412 /// The unique identifier of the frame associated with the current ` FrameInfo ` .
447413 /// It's the same kind of ID as with the frame ID in ` ICoreWebView2 ` and
448- /// ` ICoreWebView2Frame ` .
414+ /// ` ICoreWebView2Frame ` . Note that this is only available when it's called from
415+ /// ` ICoreWebView2GetProcessInfosWithDetailsCompletedHandler ` .
416+ /// Else, it return a HRESULT error codes and 0 for frame ID.
449417 [ propget] HRESULT FrameId([ out, retval] UINT32* id);
450418}
451419
0 commit comments