32
32
#include " ScenarioClientCertificateRequested.h"
33
33
#include " ScenarioCookieManagement.h"
34
34
#include " ScenarioCustomDownloadExperience.h"
35
+ #include " ScenarioCustomScheme.h"
35
36
#include " ScenarioDOMContentLoaded.h"
36
37
#include " ScenarioIFrameDevicePermission.h"
37
38
#include " ScenarioNavigateWithWebResourceRequest.h"
@@ -525,7 +526,6 @@ bool AppWindow::ExecuteWebViewCommands(WPARAM wParam, LPARAM lParam)
525
526
case IDM_SCENARIO_AUTHENTICATION:
526
527
{
527
528
NewComponent<ScenarioAuthentication>(this );
528
-
529
529
return true ;
530
530
}
531
531
case IDM_SCENARIO_COOKIE_MANAGEMENT:
@@ -716,13 +716,13 @@ bool AppWindow::ExecuteAppCommands(WPARAM wParam, LPARAM lParam)
716
716
// ! [ClearBrowsingData]
717
717
bool AppWindow::ClearBrowsingData (COREWEBVIEW2_BROWSING_DATA_KINDS dataKinds)
718
718
{
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>();
726
726
CHECK_FEATURE_RETURN (webView2ExperimentalProfile4);
727
727
// Clear the browsing data from the last hour.
728
728
double endTime = (double )std::time (nullptr );
@@ -978,17 +978,16 @@ HRESULT AppWindow::OnCreateEnvironmentCompleted(
978
978
HRESULT AppWindow::CreateControllerWithOptions ()
979
979
{
980
980
// ! [CreateControllerWithOptions]
981
- auto webViewEnvironment8 =
982
- m_webViewEnvironment.try_query <ICoreWebView2ExperimentalEnvironment8>();
983
- if (!webViewEnvironment8)
981
+ auto webViewEnvironment10 = m_webViewEnvironment.try_query <ICoreWebView2Environment10>();
982
+ if (!webViewEnvironment10)
984
983
{
985
984
FeatureNotAvailable ();
986
985
return S_OK;
987
986
}
988
987
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);
992
991
if (hr == E_INVALIDARG)
993
992
{
994
993
ShowFailure (hr, L" Unable to create WebView2 due to an invalid profile name." );
@@ -998,14 +997,19 @@ HRESULT AppWindow::CreateControllerWithOptions()
998
997
CHECK_FAILURE (hr);
999
998
// ! [CreateControllerWithOptions]
1000
999
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
+
1001
1005
#ifdef USE_WEBVIEW2_WIN10
1002
1006
if (m_dcompDevice || m_wincompCompositor)
1003
1007
#else
1004
1008
if (m_dcompDevice)
1005
1009
#endif
1006
1010
{
1007
- CHECK_FAILURE (webViewEnvironment8 ->CreateCoreWebView2CompositionControllerWithOptions (
1008
- m_mainWindow, options.Get (),
1011
+ CHECK_FAILURE (webViewEnvironment10 ->CreateCoreWebView2CompositionControllerWithOptions (
1012
+ m_mainWindow, options.get (),
1009
1013
Callback<ICoreWebView2CreateCoreWebView2CompositionControllerCompletedHandler>(
1010
1014
[this ](
1011
1015
HRESULT result,
@@ -1019,8 +1023,8 @@ HRESULT AppWindow::CreateControllerWithOptions()
1019
1023
}
1020
1024
else
1021
1025
{
1022
- CHECK_FAILURE (webViewEnvironment8 ->CreateCoreWebView2ControllerWithOptions (
1023
- m_mainWindow, options.Get (),
1026
+ CHECK_FAILURE (webViewEnvironment10 ->CreateCoreWebView2ControllerWithOptions (
1027
+ m_mainWindow, options.get (),
1024
1028
Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
1025
1029
this , &AppWindow::OnCreateCoreWebView2ControllerCompleted)
1026
1030
.Get ()));
@@ -1078,27 +1082,23 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICore
1078
1082
// available.
1079
1083
CHECK_FAILURE (m_webView->get_BrowserProcessId (&m_newestBrowserPid));
1080
1084
// ! [CoreWebView2Profile]
1081
- auto webview2Experimental8 = coreWebView2.try_query <ICoreWebView2Experimental8 >();
1082
- if (webview2Experimental8 )
1085
+ auto webView2_12 = coreWebView2.try_query <ICoreWebView2_12 >();
1086
+ if (webView2_12 )
1083
1087
{
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 ();
1090
1093
BOOL inPrivate = FALSE ;
1091
1094
CHECK_FAILURE (profile->get_IsInPrivateModeEnabled (&inPrivate));
1092
1095
if (!m_webviewOption.downloadPath .empty ())
1093
1096
{
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 ()));
1099
1099
}
1100
1100
1101
- // update window title with m_profileDirName
1101
+ // update window title with m_profileName
1102
1102
UpdateAppTitle ();
1103
1103
1104
1104
// update window icon
@@ -1513,7 +1513,7 @@ bool AppWindow::CloseWebView(bool cleanupUserDataFolder)
1513
1513
}
1514
1514
1515
1515
// reset profile name
1516
- m_profileDirName = L" " ;
1516
+ m_profileName = L" " ;
1517
1517
m_documentTitle = L" " ;
1518
1518
return true ;
1519
1519
}
@@ -1631,9 +1631,9 @@ std::wstring AppWindow::GetDocumentTitle()
1631
1631
1632
1632
void AppWindow::UpdateAppTitle () {
1633
1633
std::wstring str (m_appTitle);
1634
- if (!m_profileDirName .empty ())
1634
+ if (!m_profileName .empty ())
1635
1635
{
1636
- str += L" - " + m_profileDirName ;
1636
+ str += L" - " + m_profileName ;
1637
1637
}
1638
1638
if (!m_documentTitle.empty ())
1639
1639
{
0 commit comments