Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spec for NestedFrame.md #4950

Merged
merged 7 commits into from
Dec 10, 2024
Merged

Add spec for NestedFrame.md #4950

merged 7 commits into from
Dec 10, 2024

Conversation

JosephJin0815
Copy link
Contributor

This is a review for the new CoreWebView2Frame::FrameCreated API.

@JosephJin0815 JosephJin0815 added the API Proposal Review WebView2 API Proposal for review. label Dec 2, 2024
specs/NestedFrame.md Show resolved Hide resolved
{
//! [AddFrameCreated]
frame7->add_FrameCreated(
Callback<ICoreWebView2FrameNestedFrameCreatedEventHandler>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly by our usual rules of I{interface name}{event name}EventHandler this would be ICoreWebView2FrameFrameCreatedEventHandler. If we think it looks weird then perhaps ICoreWebView2FrameChildFrameCreatedEventHandler

void ScenarioWebViewEventMonitor::InitializeEventView(ICoreWebView2* webviewEventView)
{
auto webviewEventView4 = webviewEventView.try_query<ICoreWebView2_4>();
webviewEventView4->add_FrameCreated(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at InitializeEventView and InitializeFrameEventView the functions look almost identical. Can we add a property like CoreWebView2Frame CoreWebView2.TopLevelFrame {get;}; that is the main ICoreWebView2 object as an ICoreWebView2Frame? That would make lives easier for end devs for cases like these where they want to run the same code on the child frames and the top level CoreWebView2. In the sample code you could remove the first InitislizeEventView method and instead run InitializeFrameEventView on the CoreWebView2.TopLevelFrame

std::wstring message =
L"{ \"kind\": \"event\", \"name\": \"FrameCreated\", \"args\": {";

message += L"\"frame\": " + EncodeQuote(name.get());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a real-world sort of scenario where we would want to use this event? We want samples that demonstrates why an API is useful via a sample that an end dev could want to put in their app.

specs/NestedFrame.md Show resolved Hide resolved
}
}
}
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC we had discussed that this addition would have impact on existing WebView2 APIs where various events can now sort of bubble from one corewebview2frame to their parent to their parent ... to the corewebview2. And how that interacts with event args for cancellation. This should probably be discussed somehow in this API spec. If it doesn't make sense to include in the API ref docs for CoreWebView2Frame.FrameCreated then perhaps you can add it to a new 'Appendix' section at the bottom that lists the other changes you plan to make to the other ref docs of impacted APIs.

@pushkin-
Copy link

pushkin- commented Dec 9, 2024

As far as I can tell, with this approach, we have to subscribe to FrameCreated for each frame and subframe individually, which could be cumbersome. Ideally, it would be nice if the existing FrameCreated event just fired for all nested iframes, though maybe you don't want to introduce a breaking change, and the spec clarifies this is for performance reasons.

The existing solution seems managemeable for us, but it would be nice if the Frame object's FrameCreated fired for all nested subframes rather than only for second-level frames, requiring us to subscribe for all more deeply-nested iframes.

(Alternatively, there was always the option of just passing in more data into the existing navigation events which do fire for nested iframes; assumed that'd be easier to fix but don't know: #4604 )

@JosephJin0815
Copy link
Contributor Author

As far as I can tell, with this approach, we have to subscribe to FrameCreated for each frame and subframe individually, which could be cumbersome. Ideally, it would be nice if the existing FrameCreated event just fired for all nested iframes, though maybe you don't want to introduce a breaking change, and the spec clarifies this is for performance reasons.
The existing solution seems managemeable for us, but it would be nice if the Frame object's FrameCreated fired for all nested subframes rather than only for second-level frames, requiring us to subscribe for all more deeply-nested iframes.
(Alternatively, there was always the option of just passing in more data into the existing navigation events which do fire for nested iframes; assumed that'd be easier to fix but don't know: #4604 )

For your case, you can subscribe the CoreWebView2Frame::FrameCreated event recursively. For example:

void TrackFrames(wil::com_ptr<ICoreWebView2Frame> webviewFrame) {
    auto frame7 = webviewFrame.try_query<ICoreWebView2Frame7>();
    if (frame7)
    {
        //! [AddFrameCreated]
        frame7->add_FrameCreated(
            Callback<ICoreWebView2FrameNestedFrameCreatedEventHandler>(
                [this](
                    ICoreWebView2Frame* sender,
                    ICoreWebView2FrameCreatedEventArgs* args) -> HRESULT
                {
                    wil::com_ptr<ICoreWebView2Frame> webviewFrame;
                    CHECK_FAILURE(args->get_Frame(&webviewFrame));
                    // Make a recursive call to track all nested  webview frame events.
                    TrackFrames(webviewFrame);
                    return S_OK;
                })
                .Get(),
            &m_frameCreatedToken);
        //! [AddFrameCreated]
    }
    //  Manage the current webview frame.
    webviewFrame->add_Destroyed(
    ...
}

We have developers who know the frame structure they are loading and are only interested in specific groups of iframes. For instance, they may only be concerned with second-level iframes. Therefore, tracking all iframes directly, especially for those who prioritize performance, is not an ideal approach. Our design decisions aim to accommodate the needs of a broad range of customers. We believe that enabling this feature will provide more comprehensive functionality and support for various nested iframe use cases.

@JosephJin0815 JosephJin0815 merged commit 2e237f6 into NestedFrame Dec 10, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Proposal Review WebView2 API Proposal for review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants