@@ -30,6 +30,11 @@ HRESULT AppWindow::CreateControllerWithOptions()
3030{
3131 auto webViewEnvironment4 =
3232 m_webViewEnvironment.try_query<ICoreWebView2Environment4>();
33+ if (!webViewEnvironment4)
34+ {
35+ FeatureNotAvailable ();
36+ return S_OK;
37+ }
3338
3439 Microsoft::WRL::ComPtr<ICoreWebView2ControllerOptions> options;
3540 HRESULT hr = webViewEnvironment4->CreateCoreWebView2ControllerOptions(
@@ -43,9 +48,9 @@ HRESULT AppWindow::CreateControllerWithOptions()
4348 CHECK_FAILURE(hr);
4449
4550#ifdef USE_WEBVIEW2_WIN10
46- if (webViewEnvironment4 && ( m_dcompDevice || m_wincompCompositor) )
51+ if (m_dcompDevice || m_wincompCompositor)
4752#else
48- if (webViewEnvironment4 && m_dcompDevice)
53+ if (m_dcompDevice)
4954#endif
5055 {
5156 CHECK_FAILURE (webViewEnvironment4->CreateCoreWebView2CompositionControllerWithOptions(
@@ -88,21 +93,31 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICore
8893 // Gets the webview object from controller.
8994 wil::com_ptr<ICoreWebView2> coreWebView2;
9095 CHECK_FAILURE(m_controller->get_CoreWebView2(&coreWebView2));
91- coreWebView2.query_to(&m_webView);
92- m_webView3 = coreWebView2.try_query<ICoreWebView2_3>();
93-
94- // Gets the profile property of webview.
95- wil::com_ptr<ICoreWebView2Profile> profile;
96- CHECK_FAILURE(m_webView3->get_Profile(&profile));
97-
98- // Accesses the profile object.
99- wil::unique_cotaskmem_string name;
100- CHECK_FAILURE(profile->get_ProfileName(&name));
101- BOOL inPrivateModeEnabled;
102- CHECK_FAILURE(profile->get_InPrivateModeEnablede(&inPrivateModeEnabled));
103- wil::unique_cotaskmem_string path;
104- CHECK_FAILURE(profile->get_ProfilePath(&path));
105-
96+
97+ auto webview7 = coreWebView2.try_query<ICoreWebView2_7>();
98+ if (webview7)
99+ {
100+ // Gets the profile property of webview.
101+ wil::com_ptr<ICoreWebView2Profile> profile;
102+ CHECK_FAILURE(webview7->get_Profile(&profile));
103+
104+ // Accesses the profile object.
105+ wil::unique_cotaskmem_string name;
106+ CHECK_FAILURE(profile->get_ProfileName(&name));
107+ BOOL inPrivateModeEnabled = FALSE;
108+ CHECK_FAILURE(profile->get_InPrivateModeEnablede(&inPrivateModeEnabled));
109+ wil::unique_cotaskmem_string profile_path;
110+ CHECK_FAILURE(profile->get_ProfilePath(&profile_path));
111+ std::wstring str(profile_path.get());
112+ m_profileName = str.substr(str.find_last_of(L'\\') + 1);
113+
114+ // update window title
115+ UpdateAppTitle();
116+
117+ // update window icon
118+ SetAppIcon(inPrivate);
119+ }
120+
106121 // ...
107122}
108123```
0 commit comments