string profileName = controller.CoreWebView2.Profile.ProfileName;
bool inPrivate = controller.CoreWebView2.Profile.IsInPrivateModeEnabled;
// update window title with profileName
UpdateAppTitle(profileName);
// update window icon
SetAppIcon(inPrivate);
string profileName = controller.CoreWebView2.Profile.ProfileName;
bool inPrivate = controller.CoreWebView2.Profile.IsInPrivateModeEnabled;
// update window title with profileName
UpdateAppTitle(profileName);
// update window icon
SetAppIcon(inPrivate);
// This is the callback passed to CreateCoreWebView2Controller.
// Here we can get the profile property of the WebView2 control, then manipulate it.
HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICoreWebView2Controller* controller)
{
// ...
m_controller = controller;
wil::com_ptr<ICoreWebView2> coreWebView2;
CHECK_FAILURE(m_controller->get_CoreWebView2(&coreWebView2));
// We should check for failure here because if this app is using a newer
// SDK version compared to the install of the Edge browser, the Edge
// browser might not have support for the latest version of the
// ICoreWebView2_N interface.
coreWebView2.query_to(&m_webView);
// Save PID of the browser process serving last WebView created from our
// CoreWebView2Environment. We know the controller was created with
// S_OK, and it hasn't been closed (we haven't called Close and no
// ProcessFailed event could have been raised yet) so the PID is
// available.
CHECK_FAILURE(m_webView->get_BrowserProcessId(&m_newestBrowserPid));
auto webView2_13 = coreWebView2.try_query<ICoreWebView2_13>();
if (webView2_13)
{
wil::com_ptr<ICoreWebView2Profile> profile;
CHECK_FAILURE(webView2_13->get_Profile(&profile));
wil::unique_cotaskmem_string profile_name;
CHECK_FAILURE(profile->get_ProfileName(&profile_name));
m_profileName = profile_name.get();
BOOL inPrivate = FALSE;
CHECK_FAILURE(profile->get_IsInPrivateModeEnabled(&inPrivate));
if (!m_webviewOption.downloadPath.empty())
{
CHECK_FAILURE(profile->put_DefaultDownloadFolderPath(
m_webviewOption.downloadPath.c_str()));
}
// update window title with m_profileName
UpdateAppTitle();
// update window icon
SetAppIcon(inPrivate);
}
// ...
}