Skip to content

Latest commit

 

History

History
107 lines (83 loc) · 4.56 KB

icorewebview2experimentalprofile10.md

File metadata and controls

107 lines (83 loc) · 4.56 KB
description title ms.date keywords
This is the ICoreWebView2 experimental profile interface that manages profile deletion.
WebView2 Win32 C++ ICoreWebView2ExperimentalProfile10
04/10/2023
IWebView2, IWebView2WebView, webview2, webview, win32 apps, win32, edge, ICoreWebView2, ICoreWebView2Controller, browser control, edge html, ICoreWebView2ExperimentalProfile10

interface ICoreWebView2ExperimentalProfile10

[!INCLUDE deprecation-note]

[!INCLUDE prerelease-note]

interface ICoreWebView2ExperimentalProfile10
  : public IUnknown

This is the ICoreWebView2 experimental profile interface that manages profile deletion.

Summary

Members Descriptions
add_Deleted Add an event handler for the Deleted event.
Delete After the API is called, the profile will be marked for deletion.
remove_Deleted Remove an event handler previously added with add_Deleted.

Applies to

Product Introduced
WebView2 Win32 N/A
WebView2 Win32 Prerelease 1.0.1724

Members

add_Deleted

Add an event handler for the Deleted event.

public HRESULT add_Deleted(ICoreWebView2ExperimentalProfileDeletedEventHandler * eventHandler, EventRegistrationToken * token)

The Deleted event is raised when the profile is marked for deletion. When this event is raised, the CoreWebView2Profile and its corresponding CoreWebView2s have been closed, and cannot be used anymore.

    auto webView2_13 = m_webView.try_query<ICoreWebView2_13>();
    if (webView2_13)
    {
        wil::com_ptr<ICoreWebView2Profile> webView2ProfileBase;
        webView2_13->get_Profile(&webView2ProfileBase);
        if (webView2ProfileBase)
        {
            auto webView2Profile =
                webView2ProfileBase.try_query<ICoreWebView2ExperimentalProfile10>();
            if (webView2Profile)
            {
                CHECK_FAILURE(webView2Profile->add_Deleted(
                    Microsoft::WRL::Callback<
                        ICoreWebView2ExperimentalProfileDeletedEventHandler>(
                        [this](ICoreWebView2Profile* sender, IUnknown* args)
                        {
                            RunAsync(
                                [this]()
                                {
                                    std::wstring message =
                                        L"The profile has been marked for deletion. Any "
                                        L"associated webview2 objects will be closed.";
                                    MessageBox(
                                        m_mainWindow, message.c_str(), L"webview2 closed",
                                        MB_OK);
                                    CloseAppWindow();
                                });
                            return S_OK;
                        })
                        .Get(),
                    nullptr));
            }
        }
    }

Delete

After the API is called, the profile will be marked for deletion.

public HRESULT Delete()

The local profile's directory will be deleted at browser process exit. If it fails to delete, because something else is holding the files open, WebView2 will try to delete the profile at all future browser process starts until successful. The corresponding CoreWebView2s will be closed and the CoreWebView2Profile.Deleted event will be raised. See CoreWebView2Profile.Deleted for more information. If you try to create a new profile with the same name as an existing profile that has been marked as deleted but hasn't yet been deleted, profile creation will fail with HRESULT_FROM_WIN32(ERROR_DELETE_PENDING).

            CHECK_FEATURE_RETURN(m_webView2_13);
            wil::com_ptr<ICoreWebView2Profile> webView2ProfileBase;
            m_webView2_13->get_Profile(&webView2ProfileBase);
            CHECK_FEATURE_RETURN(webView2ProfileBase);
            auto webView2Profile =
                webView2ProfileBase.try_query<ICoreWebView2ExperimentalProfile10>();
            CHECK_FEATURE_RETURN(webView2Profile);
            webView2Profile->Delete();

remove_Deleted

Remove an event handler previously added with add_Deleted.

public HRESULT remove_Deleted(EventRegistrationToken token)