3232#include " ScenarioClientCertificateRequested.h"
3333#include " ScenarioCookieManagement.h"
3434#include " ScenarioCustomDownloadExperience.h"
35+ #include " ScenarioCustomScheme.h"
3536#include " ScenarioDOMContentLoaded.h"
3637#include " ScenarioIFrameDevicePermission.h"
3738#include " ScenarioNavigateWithWebResourceRequest.h"
@@ -525,7 +526,6 @@ bool AppWindow::ExecuteWebViewCommands(WPARAM wParam, LPARAM lParam)
525526 case IDM_SCENARIO_AUTHENTICATION:
526527 {
527528 NewComponent<ScenarioAuthentication>(this );
528-
529529 return true ;
530530 }
531531 case IDM_SCENARIO_COOKIE_MANAGEMENT:
@@ -716,13 +716,13 @@ bool AppWindow::ExecuteAppCommands(WPARAM wParam, LPARAM lParam)
716716// ! [ClearBrowsingData]
717717bool AppWindow::ClearBrowsingData (COREWEBVIEW2_BROWSING_DATA_KINDS dataKinds)
718718{
719- auto webView2Experimental8 =
720- m_webView. try_query <ICoreWebView2Experimental8>( );
721- CHECK_FEATURE_RETURN (webView2Experimental8) ;
722- wil::com_ptr<ICoreWebView2ExperimentalProfile> webView2ExperimentalProfile ;
723- CHECK_FAILURE (webView2Experimental8-> get_Profile (&webView2ExperimentalProfile) );
724- CHECK_FEATURE_RETURN (webView2ExperimentalProfile);
725- auto webView2ExperimentalProfile4 = webView2ExperimentalProfile .try_query <ICoreWebView2ExperimentalProfile4>();
719+ auto webView2_12 = m_webView. try_query <ICoreWebView2_12>();
720+ CHECK_FEATURE_RETURN (webView2_12 );
721+ wil::com_ptr<ICoreWebView2Profile> webView2Profile ;
722+ CHECK_FAILURE (webView2_12-> get_Profile (&webView2Profile)) ;
723+ CHECK_FEATURE_RETURN (webView2Profile );
724+ auto webView2ExperimentalProfile4 =
725+ webView2Profile .try_query <ICoreWebView2ExperimentalProfile4>();
726726 CHECK_FEATURE_RETURN (webView2ExperimentalProfile4);
727727 // Clear the browsing data from the last hour.
728728 double endTime = (double )std::time (nullptr );
@@ -978,17 +978,16 @@ HRESULT AppWindow::OnCreateEnvironmentCompleted(
978978HRESULT AppWindow::CreateControllerWithOptions ()
979979{
980980 // ! [CreateControllerWithOptions]
981- auto webViewEnvironment8 =
982- m_webViewEnvironment.try_query <ICoreWebView2ExperimentalEnvironment8>();
983- if (!webViewEnvironment8)
981+ auto webViewEnvironment10 = m_webViewEnvironment.try_query <ICoreWebView2Environment10>();
982+ if (!webViewEnvironment10)
984983 {
985984 FeatureNotAvailable ();
986985 return S_OK;
987986 }
988987
989- Microsoft::WRL::ComPtr<ICoreWebView2ExperimentalControllerOptions > options;
990- HRESULT hr = webViewEnvironment8-> CreateCoreWebView2ControllerOptions (
991- m_webviewOption. profile . c_str (), m_webviewOption. isInPrivate , options. GetAddressOf () );
988+ wil::com_ptr<ICoreWebView2ControllerOptions > options;
989+ // The validation of parameters occurs when setting the properties.
990+ HRESULT hr = webViewEnvironment10-> CreateCoreWebView2ControllerOptions (& options);
992991 if (hr == E_INVALIDARG)
993992 {
994993 ShowFailure (hr, L" Unable to create WebView2 due to an invalid profile name." );
@@ -998,14 +997,19 @@ HRESULT AppWindow::CreateControllerWithOptions()
998997 CHECK_FAILURE (hr);
999998 // ! [CreateControllerWithOptions]
1000999
1000+ // If call 'put_ProfileName' with an invalid profile name, the 'E_INVALIDARG' returned
1001+ // immediately. ProfileName could be reused.
1002+ CHECK_FAILURE (options->put_ProfileName (m_webviewOption.profile .c_str ()));
1003+ CHECK_FAILURE (options->put_IsInPrivateModeEnabled (m_webviewOption.isInPrivate ));
1004+
10011005#ifdef USE_WEBVIEW2_WIN10
10021006 if (m_dcompDevice || m_wincompCompositor)
10031007#else
10041008 if (m_dcompDevice)
10051009#endif
10061010 {
1007- CHECK_FAILURE (webViewEnvironment8 ->CreateCoreWebView2CompositionControllerWithOptions (
1008- m_mainWindow, options.Get (),
1011+ CHECK_FAILURE (webViewEnvironment10 ->CreateCoreWebView2CompositionControllerWithOptions (
1012+ m_mainWindow, options.get (),
10091013 Callback<ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandler>(
10101014 [this ](
10111015 HRESULT result,
@@ -1019,8 +1023,8 @@ HRESULT AppWindow::CreateControllerWithOptions()
10191023 }
10201024 else
10211025 {
1022- CHECK_FAILURE (webViewEnvironment8 ->CreateCoreWebView2ControllerWithOptions (
1023- m_mainWindow, options.Get (),
1026+ CHECK_FAILURE (webViewEnvironment10 ->CreateCoreWebView2ControllerWithOptions (
1027+ m_mainWindow, options.get (),
10241028 Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
10251029 this , &AppWindow::OnCreateCoreWebView2ControllerCompleted)
10261030 .Get ()));
@@ -1078,27 +1082,23 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICore
10781082 // available.
10791083 CHECK_FAILURE (m_webView->get_BrowserProcessId (&m_newestBrowserPid));
10801084 // ! [CoreWebView2Profile]
1081- auto webview2Experimental8 = coreWebView2.try_query <ICoreWebView2Experimental8 >();
1082- if (webview2Experimental8 )
1085+ auto webView2_12 = coreWebView2.try_query <ICoreWebView2_12 >();
1086+ if (webView2_12 )
10831087 {
1084- wil::com_ptr<ICoreWebView2ExperimentalProfile> profile;
1085- CHECK_FAILURE (webview2Experimental8->get_Profile (&profile));
1086- wil::unique_cotaskmem_string profile_path;
1087- CHECK_FAILURE (profile->get_ProfilePath (&profile_path));
1088- std::wstring str (profile_path.get ());
1089- m_profileDirName = str.substr (str.find_last_of (L' \\ ' ) + 1 );
1088+ wil::com_ptr<ICoreWebView2Profile> profile;
1089+ CHECK_FAILURE (webView2_12->get_Profile (&profile));
1090+ wil::unique_cotaskmem_string profile_name;
1091+ CHECK_FAILURE (profile->get_ProfileName (&profile_name));
1092+ m_profileName = profile_name.get ();
10901093 BOOL inPrivate = FALSE ;
10911094 CHECK_FAILURE (profile->get_IsInPrivateModeEnabled (&inPrivate));
10921095 if (!m_webviewOption.downloadPath .empty ())
10931096 {
1094- auto webView2ExperimentalProfile3 =
1095- profile.try_query <ICoreWebView2ExperimentalProfile3>();
1096- CHECK_FAILURE (webView2ExperimentalProfile3->
1097- put_DefaultDownloadFolderPath (
1098- m_webviewOption.downloadPath .c_str ()));
1097+ CHECK_FAILURE (profile->put_DefaultDownloadFolderPath (
1098+ m_webviewOption.downloadPath .c_str ()));
10991099 }
11001100
1101- // update window title with m_profileDirName
1101+ // update window title with m_profileName
11021102 UpdateAppTitle ();
11031103
11041104 // update window icon
@@ -1513,7 +1513,7 @@ bool AppWindow::CloseWebView(bool cleanupUserDataFolder)
15131513 }
15141514
15151515 // reset profile name
1516- m_profileDirName = L" " ;
1516+ m_profileName = L" " ;
15171517 m_documentTitle = L" " ;
15181518 return true ;
15191519}
@@ -1631,9 +1631,9 @@ std::wstring AppWindow::GetDocumentTitle()
16311631
16321632void AppWindow::UpdateAppTitle () {
16331633 std::wstring str (m_appTitle);
1634- if (!m_profileDirName .empty ())
1634+ if (!m_profileName .empty ())
16351635 {
1636- str += L" - " + m_profileDirName ;
1636+ str += L" - " + m_profileName ;
16371637 }
16381638 if (!m_documentTitle.empty ())
16391639 {
0 commit comments