3333#include " ScenarioCookieManagement.h"
3434#include " ScenarioCustomDownloadExperience.h"
3535#include " ScenarioDOMContentLoaded.h"
36+ #include " ScenarioIFrameDevicePermission.h"
3637#include " ScenarioNavigateWithWebResourceRequest.h"
3738#include " ScenarioVirtualHostMappingForPopUpWindow.h"
3839#include " ScenarioVirtualHostMappingForSW.h"
4243#include " SettingsComponent.h"
4344#include " TextInputDialog.h"
4445#include " ViewComponent.h"
46+
4547using namespace Microsoft ::WRL;
4648static constexpr size_t s_maxLoadString = 100 ;
4749static constexpr UINT s_runAsyncWindowMessage = WM_APP;
@@ -109,6 +111,8 @@ static INT_PTR CALLBACK DlgProcStatic(HWND hDlg, UINT message, WPARAM wParam, LP
109111 SetWindowLongPtr (hDlg, GWLP_USERDATA, (LONG_PTR)app);
110112
111113 SetDlgItemText (hDlg, IDC_EDIT_PROFILE, app->GetWebViewOption ().profile .c_str ());
114+ SetDlgItemText (hDlg, IDC_EDIT_DOWNLOAD_PATH,
115+ app->GetWebViewOption ().downloadPath .c_str ());
112116 CheckDlgButton (hDlg, IDC_CHECK_INPRIVATE, app->GetWebViewOption ().isInPrivate );
113117 return (INT_PTR)TRUE ;
114118 }
@@ -121,7 +125,15 @@ static INT_PTR CALLBACK DlgProcStatic(HWND hDlg, UINT message, WPARAM wParam, LP
121125 GetDlgItemText (hDlg, IDC_EDIT_PROFILE, text, length + 1 );
122126 bool inPrivate = IsDlgButtonChecked (hDlg, IDC_CHECK_INPRIVATE);
123127
124- WebViewCreateOption opt (std::wstring (std::move (text)), inPrivate, WebViewCreateEntry::EVER_FROM_CREATE_WITH_OPTION_MENU);
128+ int downloadPathLength = GetWindowTextLength (
129+ GetDlgItem (hDlg, IDC_EDIT_DOWNLOAD_PATH));
130+ wchar_t downloadPath[MAX_PATH] = {};
131+ GetDlgItemText (hDlg, IDC_EDIT_DOWNLOAD_PATH, downloadPath,
132+ downloadPathLength + 1 );
133+
134+ WebViewCreateOption opt (std::wstring (std::move (text)), inPrivate,
135+ std::wstring (std::move (downloadPath)),
136+ WebViewCreateEntry::EVER_FROM_CREATE_WITH_OPTION_MENU);
125137
126138 // create app window
127139 new AppWindow (app->GetCreationModeId (), opt);
@@ -558,6 +570,11 @@ bool AppWindow::ExecuteWebViewCommands(WPARAM wParam, LPARAM lParam)
558570 NewComponent<ScenarioVirtualHostMappingForPopUpWindow>(this );
559571 return true ;
560572 }
573+ case IDM_SCENARIO_IFRAME_DEVICE_PERMISSION:
574+ {
575+ NewComponent<ScenarioIFrameDevicePermission>(this );
576+ return true ;
577+ }
561578 }
562579 return false ;
563580}
@@ -659,11 +676,72 @@ bool AppWindow::ExecuteAppCommands(WPARAM wParam, LPARAM lParam)
659676 case IDM_TOGGLE_EXCLUSIVE_USER_DATA_FOLDER_ACCESS:
660677 ToggleExclusiveUserDataFolderAccess ();
661678 return true ;
679+ case IDM_SCENARIO_CLEAR_BROWSING_DATA_COOKIES:
680+ {
681+ return ClearBrowsingData (COREWEBVIEW2_BROWSING_DATA_KINDS_COOKIES);
682+ }
683+ case IDM_SCENARIO_CLEAR_BROWSING_DATA_ALL_DOM_STORAGE:
684+ {
685+ return ClearBrowsingData (COREWEBVIEW2_BROWSING_DATA_KINDS_ALL_DOM_STORAGE);
686+ }
687+ case IDM_SCENARIO_CLEAR_BROWSING_DATA_ALL_SITE:
688+ {
689+ return ClearBrowsingData (COREWEBVIEW2_BROWSING_DATA_KINDS_ALL_SITE);
690+ }
691+ case IDM_SCENARIO_CLEAR_BROWSING_DATA_DISK_CACHE:
692+ {
693+ return ClearBrowsingData (COREWEBVIEW2_BROWSING_DATA_KINDS_DISK_CACHE);
694+ }
695+ case IDM_SCENARIO_CLEAR_BROWSING_DATA_DOWNLOAD_HISTORY:
696+ {
697+ return ClearBrowsingData (COREWEBVIEW2_BROWSING_DATA_KINDS_DOWNLOAD_HISTORY);
698+ }
699+ case IDM_SCENARIO_CLEAR_BROWSING_DATA_AUTOFILL:
700+ {
701+ return ClearBrowsingData (
702+ (COREWEBVIEW2_BROWSING_DATA_KINDS)(COREWEBVIEW2_BROWSING_DATA_KINDS_GENERAL_AUTOFILL |
703+ COREWEBVIEW2_BROWSING_DATA_KINDS_PASSWORD_AUTOSAVE));
704+ }
705+ case IDM_SCENARIO_CLEAR_BROWSING_DATA_BROWSING_HISTORY:
706+ {
707+ return ClearBrowsingData (COREWEBVIEW2_BROWSING_DATA_KINDS_BROWSING_HISTORY);
708+ }
709+ case IDM_SCENARIO_CLEAR_BROWSING_DATA_ALL_PROFILE:
710+ {
711+ return ClearBrowsingData (COREWEBVIEW2_BROWSING_DATA_KINDS_ALL_PROFILE);
712+ }
662713 }
663714 return false ;
664715}
665716// ! [ClearBrowsingData]
717+ bool AppWindow::ClearBrowsingData (COREWEBVIEW2_BROWSING_DATA_KINDS dataKinds)
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>();
726+ CHECK_FEATURE_RETURN (webView2ExperimentalProfile4);
727+ // Clear the browsing data from the last hour.
728+ double endTime = (double )std::time (nullptr );
729+ double startTime = endTime - 3600.0 ;
730+ CHECK_FAILURE (webView2ExperimentalProfile4->ClearBrowsingDataInTimeRange (
731+ dataKinds, startTime, endTime,
732+ Callback<ICoreWebView2ExperimentalClearBrowsingDataCompletedHandler>(
733+ [this ](HRESULT error)
734+ -> HRESULT {
735+ RunAsync ([this ]() {
736+ MessageBox (nullptr , L" Completed" , L" Clear Browsing Data" , MB_OK);
737+ });
738+ return S_OK;
739+ })
740+ .Get ()));
741+ return true ;
742+ }
666743// ! [ClearBrowsingData]
744+
667745// Prompt the user for a new language string
668746void AppWindow::ChangeLanguage ()
669747{
@@ -1014,6 +1092,15 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICore
10141092 m_profileDirName = str.substr (str.find_last_of (L' \\ ' ) + 1 );
10151093 BOOL inPrivate = FALSE ;
10161094 CHECK_FAILURE (profile->get_IsInPrivateModeEnabled (&inPrivate));
1095+ if (!m_webviewOption.downloadPath .empty ())
1096+ {
1097+ auto webView2ExperimentalProfile3 =
1098+ profile.try_query <ICoreWebView2ExperimentalProfile3>();
1099+ CHECK_FAILURE (webView2ExperimentalProfile3->
1100+ put_DefaultDownloadFolderPath (
1101+ m_webviewOption.downloadPath .c_str ()));
1102+ }
1103+
10171104 // update window title with m_profileDirName
10181105 UpdateAppTitle ();
10191106
@@ -1036,6 +1123,7 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICore
10361123 m_creationModeId == IDM_CREATION_MODE_TARGET_DCOMP);
10371124 NewComponent<AudioComponent>(this );
10381125 NewComponent<ControlComponent>(this , &m_toolbar);
1126+
10391127 m_webView3 = coreWebView2.try_query <ICoreWebView2_3>();
10401128 if (m_webView3)
10411129 {
@@ -1782,7 +1870,7 @@ void AppWindow::InstallComplete(int return_code)
17821870 {
17831871 RunAsync ([this ] {
17841872 InitializeWebView ();
1785- });
1873+ });
17861874 }
17871875 else if (return_code == 1 )
17881876 {
0 commit comments