Skip to content

Commit d78d86f

Browse files
1.0.1133 into master (#118)
* Updates for Win32, WPF and WinForms sample apps from 99.0.1133.0 * Updated package version for Win32, WPF and WinForms sample apps to 1.0.1133-prerelease Co-authored-by: WebView2 Github Bot <[email protected]>
1 parent 32332b2 commit d78d86f

30 files changed

+750
-163
lines changed

SampleApps/WebView2APISample/AppWindow.cpp

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
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"
@@ -42,6 +43,7 @@
4243
#include "SettingsComponent.h"
4344
#include "TextInputDialog.h"
4445
#include "ViewComponent.h"
46+
4547
using namespace Microsoft::WRL;
4648
static constexpr size_t s_maxLoadString = 100;
4749
static 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
668746
void 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
{

SampleApps/WebView2APISample/AppWindow.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,26 @@ struct WebViewCreateOption
3535
{
3636
std::wstring profile;
3737
bool isInPrivate = false;
38+
std::wstring downloadPath;
3839

3940
// This value is inherited from the operated AppWindow
4041
WebViewCreateEntry entry = WebViewCreateEntry::OTHER;
4142
WebViewCreateOption()
4243
{
4344
}
4445

45-
WebViewCreateOption(const std::wstring& profile_, bool inPrivate, WebViewCreateEntry entry_)
46-
: profile(profile_), isInPrivate(inPrivate), entry(entry_)
46+
WebViewCreateOption(const std::wstring& profile_, bool inPrivate,
47+
const std::wstring& downloadPath, WebViewCreateEntry entry_)
48+
: profile(profile_), isInPrivate(inPrivate),
49+
downloadPath(downloadPath), entry(entry_)
4750
{
4851
}
4952

5053
WebViewCreateOption(const WebViewCreateOption& opt)
5154
{
5255
profile = opt.profile;
5356
isInPrivate = opt.isInPrivate;
57+
downloadPath = opt.downloadPath;
5458
entry = opt.entry;
5559
}
5660

@@ -163,13 +167,15 @@ class AppWindow
163167
void ChangeLanguage();
164168
void UpdateCreationModeMenu();
165169
void ToggleAADSSO();
170+
bool ClearBrowsingData(COREWEBVIEW2_BROWSING_DATA_KINDS dataKinds);
166171
void UpdateAppTitle();
167172
void ToggleExclusiveUserDataFolderAccess();
168173
#ifdef USE_WEBVIEW2_WIN10
169174
void OnTextScaleChanged(
170175
winrt::Windows::UI::ViewManagement::UISettings const& uiSettings,
171176
winrt::Windows::Foundation::IInspectable const& args);
172177
#endif
178+
173179
std::wstring GetLocalPath(std::wstring path, bool keep_exe_path);
174180
void DeleteAllComponents();
175181

SampleApps/WebView2APISample/ProcessComponent.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,16 @@ ProcessComponent::ProcessComponent(AppWindow* appWindow)
123123
//! [ProcessFailed]
124124

125125
m_webViewEnvironment = appWindow->GetWebViewEnvironment();
126-
auto environment9 = m_webViewEnvironment.try_query<ICoreWebView2ExperimentalEnvironment9>();
127-
if (environment9)
126+
auto environment8 = m_webViewEnvironment.try_query<ICoreWebView2Environment8>();
127+
if (environment8)
128128
{
129-
CHECK_FAILURE(environment9->GetProcessInfos(&m_processCollection));
129+
CHECK_FAILURE(environment8->GetProcessInfos(&m_processCollection));
130130
// Register a handler for the ProcessInfosChanged event.
131131
//! [ProcessInfosChanged]
132-
CHECK_FAILURE(environment9->add_ProcessInfosChanged(
133-
Callback<ICoreWebView2ExperimentalProcessInfosChangedEventHandler>(
132+
CHECK_FAILURE(environment8->add_ProcessInfosChanged(
133+
Callback<ICoreWebView2ProcessInfosChangedEventHandler>(
134134
[this](ICoreWebView2Environment* sender, IUnknown* args) -> HRESULT {
135-
wil::com_ptr<ICoreWebView2ExperimentalEnvironment9> webviewEnvironment;
135+
wil::com_ptr<ICoreWebView2Environment8> webviewEnvironment;
136136
sender->QueryInterface(IID_PPV_ARGS(&webviewEnvironment));
137137
CHECK_FAILURE(
138138
webviewEnvironment->GetProcessInfos(&m_processCollection));
@@ -297,7 +297,7 @@ void ProcessComponent::PerformanceInfo()
297297
result += L"\n\n";
298298
for (UINT i = 0; i < processListCount; ++i)
299299
{
300-
wil::com_ptr<ICoreWebView2ExperimentalProcessInfo> processInfo;
300+
wil::com_ptr<ICoreWebView2ProcessInfo> processInfo;
301301
CHECK_FAILURE(m_processCollection->GetValueAtIndex(i, &processInfo));
302302

303303
INT32 processId = 0;
@@ -374,9 +374,9 @@ void ProcessComponent::ScheduleReloadIfSelectedByUser(
374374
ProcessComponent::~ProcessComponent()
375375
{
376376
m_webView->remove_ProcessFailed(m_processFailedToken);
377-
auto environment9 = m_webViewEnvironment.try_query<ICoreWebView2ExperimentalEnvironment9>();
378-
if (environment9)
377+
auto environment8 = m_webViewEnvironment.try_query<ICoreWebView2Environment8>();
378+
if (environment8)
379379
{
380-
environment9->remove_ProcessInfosChanged(m_processInfosChangedToken);
380+
environment8->remove_ProcessInfosChanged(m_processInfosChangedToken);
381381
}
382382
}

SampleApps/WebView2APISample/ProcessComponent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ProcessComponent : public ComponentBase
4949
wil::com_ptr<ICoreWebView2Environment> m_webViewEnvironment;
5050

5151
UINT m_browserProcessId = 0;
52-
wil::com_ptr<ICoreWebView2ExperimentalProcessInfoCollection> m_processCollection;
52+
wil::com_ptr<ICoreWebView2ProcessInfoCollection> m_processCollection;
5353

5454
EventRegistrationToken m_processFailedToken = {};
5555
EventRegistrationToken m_processInfosChangedToken = {};

SampleApps/WebView2APISample/ScenarioAuthentication.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ ScenarioAuthentication::ScenarioAuthentication(AppWindow* appWindow) :
4747
//! [WebResourceResponseReceived]
4848

4949
//! [BasicAuthenticationRequested]
50-
if (auto webViewExperimental10 = m_webView.try_query<ICoreWebView2Experimental10>())
50+
if (auto webView10 = m_webView.try_query<ICoreWebView2_10>())
5151
{
52-
CHECK_FAILURE(webViewExperimental10->add_BasicAuthenticationRequested(
53-
Callback<ICoreWebView2ExperimentalBasicAuthenticationRequestedEventHandler>(
52+
CHECK_FAILURE(webView10->add_BasicAuthenticationRequested(
53+
Callback<ICoreWebView2BasicAuthenticationRequestedEventHandler>(
5454
[this](
5555
ICoreWebView2* sender,
56-
ICoreWebView2ExperimentalBasicAuthenticationRequestedEventArgs* args) {
57-
wil::com_ptr<ICoreWebView2ExperimentalBasicAuthenticationResponse> basicAuthenticationResponse;
56+
ICoreWebView2BasicAuthenticationRequestedEventArgs* args) {
57+
wil::com_ptr<ICoreWebView2BasicAuthenticationResponse> basicAuthenticationResponse;
5858
CHECK_FAILURE(args->get_Response(&basicAuthenticationResponse));
5959
CHECK_FAILURE(basicAuthenticationResponse->put_UserName(L"user"));
6060
CHECK_FAILURE(basicAuthenticationResponse->put_Password(L"pass"));
@@ -74,9 +74,9 @@ ScenarioAuthentication::ScenarioAuthentication(AppWindow* appWindow) :
7474
ScenarioAuthentication::~ScenarioAuthentication() {
7575
CHECK_FAILURE(
7676
m_webView->remove_WebResourceResponseReceived(m_webResourceResponseReceivedToken));
77-
if (auto webViewExperimental10 = m_webView.try_query<ICoreWebView2Experimental10>())
77+
if (auto webView10 = m_webView.try_query<ICoreWebView2_10>())
7878
{
79-
CHECK_FAILURE(webViewExperimental10->remove_BasicAuthenticationRequested(
79+
CHECK_FAILURE(webView10->remove_BasicAuthenticationRequested(
8080
m_basicAuthenticationRequestedToken));
8181
}
8282
}

SampleApps/WebView2APISample/ScenarioDOMContentLoaded.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,17 @@ ScenarioDOMContentLoaded::ScenarioDOMContentLoaded(AppWindow* appWindow)
6565
[](ICoreWebView2* sender, ICoreWebView2FrameCreatedEventArgs* args) -> HRESULT {
6666
wil::com_ptr<ICoreWebView2Frame> webviewFrame;
6767
CHECK_FAILURE(args->get_Frame(&webviewFrame));
68-
wil::com_ptr<ICoreWebView2ExperimentalFrame> frameExperimental =
69-
webviewFrame.try_query<ICoreWebView2ExperimentalFrame>();
70-
if (frameExperimental)
68+
wil::com_ptr<ICoreWebView2Frame2> frame2 =
69+
webviewFrame.try_query<ICoreWebView2Frame2>();
70+
if (frame2)
7171
{
72-
frameExperimental->add_DOMContentLoaded(
73-
Callback<
74-
ICoreWebView2ExperimentalFrameDOMContentLoadedEventHandler>(
72+
frame2->add_DOMContentLoaded(
73+
Callback<ICoreWebView2FrameDOMContentLoadedEventHandler>(
7574
[](ICoreWebView2Frame* frame,
7675
ICoreWebView2DOMContentLoadedEventArgs* args) -> HRESULT {
77-
wil::com_ptr<ICoreWebView2ExperimentalFrame>
78-
frameExperimental;
79-
frame->QueryInterface(IID_PPV_ARGS(&frameExperimental));
80-
frameExperimental->ExecuteScript(
76+
wil::com_ptr<ICoreWebView2Frame2> frame2;
77+
frame->QueryInterface(IID_PPV_ARGS(&frame2));
78+
frame2->ExecuteScript(
8179
LR"~(
8280
let content = document.createElement("h2");
8381
content.style.color = 'blue';

0 commit comments

Comments
 (0)