33
33
#include " ScenarioCookieManagement.h"
34
34
#include " ScenarioCustomDownloadExperience.h"
35
35
#include " ScenarioDOMContentLoaded.h"
36
+ #include " ScenarioIFrameDevicePermission.h"
36
37
#include " ScenarioNavigateWithWebResourceRequest.h"
37
38
#include " ScenarioVirtualHostMappingForPopUpWindow.h"
38
39
#include " ScenarioVirtualHostMappingForSW.h"
42
43
#include " SettingsComponent.h"
43
44
#include " TextInputDialog.h"
44
45
#include " ViewComponent.h"
46
+
45
47
using namespace Microsoft ::WRL;
46
48
static constexpr size_t s_maxLoadString = 100 ;
47
49
static constexpr UINT s_runAsyncWindowMessage = WM_APP;
@@ -109,6 +111,8 @@ static INT_PTR CALLBACK DlgProcStatic(HWND hDlg, UINT message, WPARAM wParam, LP
109
111
SetWindowLongPtr (hDlg, GWLP_USERDATA, (LONG_PTR)app);
110
112
111
113
SetDlgItemText (hDlg, IDC_EDIT_PROFILE, app->GetWebViewOption ().profile .c_str ());
114
+ SetDlgItemText (hDlg, IDC_EDIT_DOWNLOAD_PATH,
115
+ app->GetWebViewOption ().downloadPath .c_str ());
112
116
CheckDlgButton (hDlg, IDC_CHECK_INPRIVATE, app->GetWebViewOption ().isInPrivate );
113
117
return (INT_PTR)TRUE ;
114
118
}
@@ -121,7 +125,15 @@ static INT_PTR CALLBACK DlgProcStatic(HWND hDlg, UINT message, WPARAM wParam, LP
121
125
GetDlgItemText (hDlg, IDC_EDIT_PROFILE, text, length + 1 );
122
126
bool inPrivate = IsDlgButtonChecked (hDlg, IDC_CHECK_INPRIVATE);
123
127
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);
125
137
126
138
// create app window
127
139
new AppWindow (app->GetCreationModeId (), opt);
@@ -558,6 +570,11 @@ bool AppWindow::ExecuteWebViewCommands(WPARAM wParam, LPARAM lParam)
558
570
NewComponent<ScenarioVirtualHostMappingForPopUpWindow>(this );
559
571
return true ;
560
572
}
573
+ case IDM_SCENARIO_IFRAME_DEVICE_PERMISSION:
574
+ {
575
+ NewComponent<ScenarioIFrameDevicePermission>(this );
576
+ return true ;
577
+ }
561
578
}
562
579
return false ;
563
580
}
@@ -659,11 +676,72 @@ bool AppWindow::ExecuteAppCommands(WPARAM wParam, LPARAM lParam)
659
676
case IDM_TOGGLE_EXCLUSIVE_USER_DATA_FOLDER_ACCESS:
660
677
ToggleExclusiveUserDataFolderAccess ();
661
678
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
+ }
662
713
}
663
714
return false ;
664
715
}
665
716
// ! [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
+ }
666
743
// ! [ClearBrowsingData]
744
+
667
745
// Prompt the user for a new language string
668
746
void AppWindow::ChangeLanguage ()
669
747
{
@@ -1014,6 +1092,15 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICore
1014
1092
m_profileDirName = str.substr (str.find_last_of (L' \\ ' ) + 1 );
1015
1093
BOOL inPrivate = FALSE ;
1016
1094
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
+
1017
1104
// update window title with m_profileDirName
1018
1105
UpdateAppTitle ();
1019
1106
@@ -1036,6 +1123,7 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICore
1036
1123
m_creationModeId == IDM_CREATION_MODE_TARGET_DCOMP);
1037
1124
NewComponent<AudioComponent>(this );
1038
1125
NewComponent<ControlComponent>(this , &m_toolbar);
1126
+
1039
1127
m_webView3 = coreWebView2.try_query <ICoreWebView2_3>();
1040
1128
if (m_webView3)
1041
1129
{
@@ -1782,7 +1870,7 @@ void AppWindow::InstallComplete(int return_code)
1782
1870
{
1783
1871
RunAsync ([this ] {
1784
1872
InitializeWebView ();
1785
- });
1873
+ });
1786
1874
}
1787
1875
else if (return_code == 1 )
1788
1876
{
0 commit comments