Skip to content

Commit f65b6ee

Browse files
author
Wangsong Jin
committed
Update FrameProcessInfo.md
1 parent 970d45d commit f65b6ee

1 file changed

Lines changed: 59 additions & 20 deletions

File tree

specs/FrameProcesssInfo.md

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ renderer process.
3838
the `FrameId` property. This property represents the unique identifier of
3939
the frame running in this WebView2 or WebView2Frame.
4040

41-
* We propose extending `CoreWebView2FrameInfo` to include `FrameId` and
42-
`ParentFrameInfo` properties. `FrameId` is the same kind of ID as with
43-
`FrameID` in `CoreWebView2` and `CoreWebView2Frame`. `ParentFrameInfo`
44-
supports to retrive a frame's direct parent, ancestor first level frame
45-
and ancestor main frame. This also can be used to build the architecture
46-
of the frame tree with represent by `FrameInfo`.
41+
* We propose extending `CoreWebView2FrameInfo` to include `FrameId`,
42+
`FrameKind` and `ParentFrameInfo` properties. `FrameId` is the same
43+
kind of ID as with `FrameID` in `CoreWebView2` and `CoreWebView2Frame`.
44+
`ParentFrameInfo` supports to retrive a frame's direct parent, ancestor
45+
first level frame and ancestor main frame. This also can be used to
46+
build the architecture of the frame tree with represent by `FrameInfo`.
4747

4848
# Examples
4949
C++
@@ -56,6 +56,7 @@ wil::com_ptr<ICoreWebView2FrameInfo> GetAncestorFirstLevelFrameInfo(
5656
wil::com_ptr<ICoreWebView2FrameInfo> frameInfo);
5757
wil::com_ptr<ICoreWebView2FrameInfo> GetAncestorMainFrameInfo(
5858
wil::com_ptr<ICoreWebView2FrameInfo> frameInfo);
59+
std::wstring FrameKindToString(COREWEBVIEW2_FRAME_KIND kind);
5960

6061
// Display renderer process info with details which includes the list of
6162
// associated frame infos for the renderer process. Also shows the process
@@ -195,35 +196,40 @@ void ProcessComponent::AppendFrameInfo(
195196
frameInfo2->get_FrameId(&frameId);
196197
result.append(L" | frame Id:" + std::to_wstring(frameId));
197198

198-
// Check if a frame is a main frame.
199199
BOOL isMainFrameOrFirstLevelframeInfo = false;
200200
wil::com_ptr<ICoreWebView2FrameInfo> mainFrameInfo =
201201
GetAncestorMainFrameInfo(frameInfo);
202202
wil::com_ptr<ICoreWebView2FrameInfo> firstLevelFrameInfo =
203203
GetAncestorFirstLevelFrameInfo(frameInfo);
204+
// Check if a frame is a main frame.
204205
if (mainFrameInfo == frameInfo)
205206
{
206-
result.append(L" | frame kind: main frame");
207+
result.append(L" | frame type: main frame");
207208
isMainFrameOrFirstLevelframeInfo = true;
208209
}
209210
// Check if a frame is a first level frame.
210211
if (firstLevelFrameInfo == frameInfo)
211212
{
212-
result.append(L" | frame kind: first level frame");
213+
result.append(L" | frame type: first level frame");
213214
isMainFrameOrFirstLevelframeInfo = true;
214215
}
215216
if (!isMainFrameOrFirstLevelframeInfo)
216217
{
217-
result.append(L" | frame kind: other child frame");
218+
result.append(L" | frame type: other child frame");
218219
}
220+
221+
COREWEBVIEW2_FRAME_KIND frameKind = COREWEBVIEW2_FRAME_KIND_OTHER;
222+
frameInfo2->get_FrameKind(&frameKind);
223+
result.append(L"\n | frame kind:" + FrameKindToString(frameKind));
224+
219225
// Append the frame's direct parent frame's ID if it exists.
220226
wil::com_ptr<ICoreWebView2FrameInfo> parentFrameInfo;
221227
CHECK_FAILURE(frameInfo2->get_ParentFrameInfo(&parentFrameInfo));
222228
if (parentFrameInfo)
223229
{
224230
CHECK_FAILURE(parentFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
225231
CHECK_FAILURE(frameInfo2->get_FrameId(&frameId));
226-
result.append(L" \n | parent frame Id:" + std::to_wstring(frameId));
232+
result.append(L" | parent frame Id:" + std::to_wstring(frameId));
227233
}
228234

229235
wil::unique_cotaskmem_string sourceRaw;
@@ -262,21 +268,38 @@ void ProcessComponent::AppendAncestorFrameInfo(
262268
}
263269
result.append(L"},\n");
264270
}
271+
272+
// Get a string for the frame kind enum value.
273+
std::wstring ProcessComponent::FrameKindToString(const COREWEBVIEW2_FRAME_KIND kind)
274+
{
275+
switch (kind)
276+
{
277+
case kindValue:
278+
return L#kindValue;
279+
280+
KIND_ENTRY(COREWEBVIEW2_FRAME_KIND_MAIN_FRAME);
281+
KIND_ENTRY(COREWEBVIEW2_FRAME_KIND_IFRAME);
282+
KIND_ENTRY(COREWEBVIEW2_FRAME_KIND_OTHER);
283+
}
284+
285+
return std::to_wstring(static_cast<uint32_t>(kind));
286+
}
265287
```
266288
C#
267289
```c#
268-
string AppendFrameInfo(CoreWebView2FrameInfo frameInfo, string kind, string mainFrameId, string firstLevelFrameId) {
290+
string AppendFrameInfo(CoreWebView2FrameInfo frameInfo, string type, string mainFrameId, string firstLevelFrameId) {
269291
string id = frameInfo.FrameId.ToString();
270292
string name = String.IsNullOrEmpty(frameInfo.Name) ? "none" : frameInfo.Name;
271293
string source = String.IsNullOrEmpty(frameInfo.Source) ? "none" : frameInfo.Source;
272294
string parentId = frameInfo.ParentFrameInfo == null ? "none" : frameInfo.ParentFrameInfo.FrameId.ToString();
273295
274296
return $"{{frame Id:{id} " +
275297
$"| frame Name: {name} " +
276-
$"| frame Kind: {kind} " +
298+
$"| frame type: {kind} " +
277299
$"| parent frame Id: {parentId} " +
278300
$"| ancestor main frame Id: {mainFrameId} " +
279301
$"| ancestor first level frame Id: {firstLevelFrameId} " +
302+
$"| frame Kind: {frameInfo.FrameKind} " +
280303
$"| frame Source: \"{source}\"}}\n";
281304
}
282305
@@ -334,7 +357,7 @@ private async void ProcessFrameInfoCmdExecuted(object target, ExecutedRoutedEven
334357
335358
ancestorMainFrameId = mainFrameInfo.FrameId.ToString();
336359
ancestorFirstLevelFrameId = firstLevelFrameInfo.FrameId.ToString();
337-
frameInfosStr += AppendFrameInfo(frameInfo, "other frame", ancestorMainFrameId, ancestorFirstLevelFrameId);
360+
frameInfosStr += AppendFrameInfo(frameInfo, "other child frame", ancestorMainFrameId, ancestorFirstLevelFrameId);
338361
}
339362
// </AssociatedFrameInfos>
340363
string rendererProcessInfoStr = $"{frameInfoCount} frame info(s) found in renderer process ID: {processId}\n {frameInfosStr}";
@@ -368,6 +391,17 @@ interface ICoreWebView2Environment14;
368391
interface ICoreWebView2ProcessInfo2;
369392
interface ICoreWebView2GetProcessInfosWithDetailsCompletedHandler;
370393

394+
// Indicates the frame type used in the `ICoreWebView2FrameInfo2` interface.
395+
[v1_enum]
396+
typedef enum COREWEBVIEW2_FRAME_KIND {
397+
/// Indicates that the frame is a primary main frame(webview).
398+
COREWEBVIEW2_FRAME_KIND_MAIN_FRAME,
399+
/// Indicates that the frame is an iframe.
400+
COREWEBVIEW2_FRAME_KIND_IFRAME,
401+
/// Indicates that the frame is another type of frame.
402+
COREWEBVIEW2_FRAME_KIND_OTHER,
403+
} COREWEBVIEW2_FRAME_KIND;
404+
371405
/// Receives the result of the `GetProcessInfosWithDetails` method.
372406
/// The result is written to the collection of `ProcessInfo`s provided
373407
/// in the `GetProcessInfosWithDetails` method call.
@@ -386,7 +420,7 @@ interface ICoreWebView2ProcessInfo2 : ICoreWebView2ProcessInfo {
386420
/// `CoreWebView2ProcessInfo` corresponds to a renderer process.
387421
/// `CoreWebView2ProcessInfo` objects obtained via `CoreWebView2.GetProcessInfos`
388422
/// or for non-renderer processes will always have an empty `AssociatedFrameInfos`.
389-
/// The `AssociatedFrameInfos` may also be be empty for renderer processes that
423+
/// The `AssociatedFrameInfos` may also be empty for renderer processes that
390424
/// have no active frames.
391425
///
392426
/// \snippet ProcessComponent.cpp AssociatedFrameInfos
@@ -398,7 +432,7 @@ interface ICoreWebView2ProcessInfo2 : ICoreWebView2ProcessInfo {
398432
[uuid(9d4d8624-e2ca-11ed-b5ea-0242ac120002), object, pointer_default(unique)]
399433
interface ICoreWebView2Environment14 : ICoreWebView2Environment13 {
400434
/// Gets a snapshot collection of `ProcessInfo`s corresponding to all currently
401-
/// running processes associated with this `ICoreWebView2Environment` except
435+
/// running processes associated with this `CoreWebView2Environment` except
402436
/// for crashpad process. This provide the same list of `ProcessInfo`s as
403437
/// what's provided in `GetProcessInfos`. Plus, this provide a list of associated
404438
/// `FrameInfo`s which are actively running (showing UI elements) in the renderer
@@ -419,13 +453,15 @@ interface ICoreWebView2FrameInfo2 : ICoreWebView2FrameInfo {
419453
/// Note that this `ParentFrameInfo` could be out of date as it's a snapshot.
420454
[propget] HRESULT ParentFrameInfo([out, retval] ICoreWebView2FrameInfo** frameInfo);
421455
/// The unique identifier of the frame associated with the current `FrameInfo`.
422-
/// It's the same kind of ID as with the `FrameId` in `ICoreWebView2` and via
423-
/// `ICoreWebView2Frame`. `FrameId` will only be populated when obtained
456+
/// It's the same kind of ID as with the `FrameId` in `CoreWebView2` and via
457+
/// `CoreWebView2Frame`. `FrameId` will only be populated when obtained
424458
/// calling `CoreWebView2ProcessInfo.AssociatedFrameInfos`.
425459
/// `CoreWebView2FrameInfo` objects obtained via `CoreWebView2.ProcessFailed` will
426460
/// always have an invalid frame Id 0.
427461
/// Note that this `FrameId` could be out of date as it's a snapshot.
428462
[propget] HRESULT FrameId([out, retval] UINT32* id);
463+
/// The frame kind of the frame.
464+
[propget] HRESULT FrameKind([out, retval] COREWEBVIEW2_FRAME_KIND* kind);
429465
}
430466

431467
/// A continuation of the ICoreWebView2Frame4 interface.
@@ -439,8 +475,9 @@ interface ICoreWebView2Frame5: ICoreWebView2Frame4 {
439475
[uuid(ad712504-a66d-11ed-afa1-0242ac120002), object, pointer_default(unique)]
440476
interface ICoreWebView2_18 : ICoreWebView2_17 {
441477
/// The unique identifier of the current frame.
442-
/// Note that `FrameId` is not valid if `ICoreWebView` has not done
443-
/// any navigation. It returns an invalid frame Id 0.
478+
/// Note that `FrameId` may not valid if `CoreWebView` has not done
479+
/// any navigation. It's safe to get this value during or after the first
480+
/// `DOMContentLoaded` event. Else, it could return an invalid frame Id 0.
444481
[propget] HRESULT FrameId([out, retval] UINT32* id);
445482
}
446483
```
@@ -462,6 +499,8 @@ namespace Microsoft.Web.WebView2.Core
462499
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2FrameInfo2")]
463500
{
464501
CoreWebView2FrameInfo ParentFrameInfo { get; };
502+
UInt32 FrameId { get; };
503+
CoreWebView2FrameKind FrameKind { get; };
465504
}
466505
}
467506

0 commit comments

Comments
 (0)