Skip to content

Commit 19de488

Browse files
Smoketest/1.0.1189 testing (#123)
* Updates for Win32, WPF and WinForms sample apps from 100.0.1189.0 * Updated package version for Win32, WPF and WinForms sample apps to 1.0.1189-prerelease Co-authored-by: WebView2 Github Bot <[email protected]>
1 parent 0099f81 commit 19de488

26 files changed

+434
-486
lines changed

SampleApps/WebView2APISample/App.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,21 @@ static int RunMessagePump();
2525
static DWORD WINAPI ThreadProc(void* pvParam);
2626
static void WaitForOtherThreads();
2727

28-
#define NEXT_PARAM_CONTAINS(command) \
28+
#define NEXT_PARAM_CONTAINS(command) \
2929
_wcsnicmp(nextParam.c_str(), command, ARRAYSIZE(command) - 1) == 0
3030

31-
int APIENTRY wWinMain(HINSTANCE hInstance,
32-
HINSTANCE hPrevInstance,
33-
PWSTR lpCmdLine,
34-
int nCmdShow)
31+
int APIENTRY
32+
wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmdShow)
3533
{
3634
g_hInstance = hInstance;
3735
UNREFERENCED_PARAMETER(hPrevInstance);
3836
g_nCmdShow = nCmdShow;
3937

4038
// Default DPI awareness to PerMonitorV2. The commandline parameters can
4139
// override this.
42-
DPI_AWARENESS_CONTEXT dpiAwarenessContext =
43-
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2;
40+
DPI_AWARENESS_CONTEXT dpiAwarenessContext = DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2;
4441
std::wstring appId(L"EBWebView.SampleApp");
45-
std::wstring userDirectoryFolder(L"");
42+
std::wstring userDataFolder(L"");
4643
std::wstring initialUri;
4744
DWORD creationModeId = IDM_CREATION_MODE_WINDOWED;
4845

@@ -92,9 +89,9 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
9289
{
9390
initialUri = nextParam.substr(nextParam.find(L'=') + 1);
9491
}
95-
else if (NEXT_PARAM_CONTAINS(L"userdirectoryfolder="))
92+
else if (NEXT_PARAM_CONTAINS(L"userdatafolder="))
9693
{
97-
userDirectoryFolder = nextParam.substr(nextParam.find(L'=') + 1);
94+
userDataFolder = nextParam.substr(nextParam.find(L'=') + 1);
9895
}
9996
else if (NEXT_PARAM_CONTAINS(L"creationmode="))
10097
{
@@ -125,7 +122,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
125122

126123
DpiUtil::SetProcessDpiAwarenessContext(dpiAwarenessContext);
127124

128-
new AppWindow(creationModeId, WebViewCreateOption(), initialUri, userDirectoryFolder, true);
125+
new AppWindow(creationModeId, WebViewCreateOption(), initialUri, userDataFolder, true);
129126

130127
int retVal = RunMessagePump();
131128

@@ -137,8 +134,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
137134
// Run the message pump for one thread.
138135
static int RunMessagePump()
139136
{
140-
HACCEL hAccelTable =
141-
LoadAccelerators(g_hInstance, MAKEINTRESOURCE(IDC_WEBVIEW2APISAMPLE));
137+
HACCEL hAccelTable = LoadAccelerators(g_hInstance, MAKEINTRESOURCE(IDC_WEBVIEW2APISAMPLE));
142138

143139
MSG msg;
144140

@@ -206,8 +202,8 @@ static void WaitForOtherThreads()
206202

207203
HANDLE* handleArray = threadHandles.data();
208204
DWORD dwIndex = MsgWaitForMultipleObjects(
209-
static_cast<DWORD>(threadHandles.size()), threadHandles.data(), FALSE,
210-
INFINITE, QS_ALLEVENTS);
205+
static_cast<DWORD>(threadHandles.size()), threadHandles.data(), FALSE, INFINITE,
206+
QS_ALLEVENTS);
211207

212208
if (dwIndex == WAIT_OBJECT_0 + threadHandles.size())
213209
{

SampleApps/WebView2APISample/AppWindow.cpp

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ bool AppWindow::ExecuteAppCommands(WPARAM wParam, LPARAM lParam)
613613
CHECK_FEATURE_RETURN(experimentalEnvironment3);
614614
HRESULT hr = experimentalEnvironment3->UpdateRuntime(
615615
Callback<ICoreWebView2ExperimentalUpdateRuntimeCompletedHandler>(
616-
[](HRESULT errorCode,
616+
[this](HRESULT errorCode,
617617
ICoreWebView2ExperimentalUpdateRuntimeResult* result) -> HRESULT {
618618
HRESULT updateError = E_FAIL;
619619
COREWEBVIEW2_UPDATE_RUNTIME_STATUS status =
@@ -627,12 +627,12 @@ bool AppWindow::ExecuteAppCommands(WPARAM wParam, LPARAM lParam)
627627
formattedMessage << "UpdateRuntime result (0x" << std::hex << errorCode
628628
<< "), status(" << status << "), extendedError("
629629
<< updateError << ")";
630-
MessageBox(nullptr, formattedMessage.str().c_str(), nullptr, MB_OK);
630+
AsyncMessageBox(std::move(formattedMessage.str()), L"UpdateRuntimeResult");
631631
return S_OK;
632632
})
633633
.Get());
634634
if (FAILED(hr))
635-
ShowFailure(hr, L"Call to TryUpdateRuntime failed");
635+
ShowFailure(hr, L"Call to UpdateRuntime failed");
636636
//! [UpdateRuntime]
637637
return true;
638638
}
@@ -730,11 +730,8 @@ bool AppWindow::ClearBrowsingData(COREWEBVIEW2_BROWSING_DATA_KINDS dataKinds)
730730
CHECK_FAILURE(webView2ExperimentalProfile4->ClearBrowsingDataInTimeRange(
731731
dataKinds, startTime, endTime,
732732
Callback<ICoreWebView2ExperimentalClearBrowsingDataCompletedHandler>(
733-
[this](HRESULT error)
734-
-> HRESULT {
735-
RunAsync([this]() {
736-
MessageBox(nullptr, L"Completed", L"Clear Browsing Data", MB_OK);
737-
});
733+
[this](HRESULT error) -> HRESULT {
734+
AsyncMessageBox(L"Completed", L"Clear Browsing Data");
738735
return S_OK;
739736
})
740737
.Get()));
@@ -877,7 +874,7 @@ void AppWindow::InitializeWebView()
877874
}
878875
#endif
879876
//! [CreateCoreWebView2EnvironmentWithOptions]
880-
auto options = Microsoft::WRL::Make<CoreWebView2ExperimentalEnvironmentOptions>();
877+
auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
881878
CHECK_FAILURE(
882879
options->put_AllowSingleSignOnUsingOSPrimaryAccount(
883880
m_AADSSOEnabled ? TRUE : FALSE));
@@ -1153,6 +1150,11 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(HRESULT result, ICore
11531150
CHECK_FAILURE(m_webView->Navigate(initialUri.c_str()));
11541151
}
11551152
}
1153+
else if (result == E_ABORT)
1154+
{
1155+
// Webview creation was aborted because the user closed this window.
1156+
// No need to report this as an error.
1157+
}
11561158
else
11571159
{
11581160
ShowFailure(result, L"Failed to create webview");
@@ -1349,29 +1351,33 @@ void AppWindow::RegisterEventHandlers()
13491351
CHECK_FAILURE(m_webViewEnvironment->add_NewBrowserVersionAvailable(
13501352
Callback<ICoreWebView2NewBrowserVersionAvailableEventHandler>(
13511353
[this](ICoreWebView2Environment* sender, IUnknown* args) -> HRESULT {
1352-
std::wstring message = L"We detected there is a new version for the browser.";
1353-
if (m_webView)
1354+
// Don't block the event handler with a message box
1355+
RunAsync([this]
13541356
{
1355-
message += L"Do you want to restart the app? \n\n";
1356-
message += L"Click No if you only want to re-create the webviews. \n";
1357-
message += L"Click Cancel for no action. \n";
1358-
}
1359-
int response = MessageBox(
1360-
m_mainWindow, message.c_str(), L"New available version",
1361-
m_webView ? MB_YESNOCANCEL : MB_OK);
1357+
std::wstring message = L"We detected there is a new version for the browser.";
1358+
if (m_webView)
1359+
{
1360+
message += L"Do you want to restart the app? \n\n";
1361+
message += L"Click No if you only want to re-create the webviews. \n";
1362+
message += L"Click Cancel for no action. \n";
1363+
}
1364+
int response = MessageBox(
1365+
m_mainWindow, message.c_str(), L"New available version",
1366+
m_webView ? MB_YESNOCANCEL : MB_OK);
13621367

1363-
if (response == IDYES)
1364-
{
1365-
RestartApp();
1366-
}
1367-
else if (response == IDNO)
1368-
{
1369-
ReinitializeWebViewWithNewBrowser();
1370-
}
1371-
else
1372-
{
1373-
// do nothing
1374-
}
1368+
if (response == IDYES)
1369+
{
1370+
RestartApp();
1371+
}
1372+
else if (response == IDNO)
1373+
{
1374+
ReinitializeWebViewWithNewBrowser();
1375+
}
1376+
else
1377+
{
1378+
// do nothing
1379+
}
1380+
});
13751381

13761382
return S_OK;
13771383
})
@@ -1466,12 +1472,9 @@ bool AppWindow::CloseWebView(bool cleanupUserDataFolder)
14661472
// The exiting process is not the last in use. Do not attempt cleanup
14671473
// as we might still have a webview open over the user data folder.
14681474
// Do not block from event handler.
1469-
RunAsync([this]() {
1470-
MessageBox(
1471-
m_mainWindow,
1472-
L"A new browser process prevented cleanup of the user data folder.",
1473-
L"Cleanup User Data Folder", MB_OK);
1474-
});
1475+
AsyncMessageBox(
1476+
L"A new browser process prevented cleanup of the user data folder.",
1477+
L"Cleanup User Data Folder");
14751478
}
14761479

14771480
return S_OK;
@@ -1692,6 +1695,14 @@ void AppWindow::RunAsync(std::function<void()> callback)
16921695
PostMessage(m_mainWindow, s_runAsyncWindowMessage, reinterpret_cast<WPARAM>(task), 0);
16931696
}
16941697

1698+
void AppWindow::AsyncMessageBox(std::wstring message, std::wstring title)
1699+
{
1700+
RunAsync([this, message = std::move(message), title = std::move(title)]
1701+
{
1702+
MessageBox(m_mainWindow, message.c_str(), title.c_str(), MB_OK);
1703+
});
1704+
}
1705+
16951706
void AppWindow::EnterFullScreen()
16961707
{
16971708
DWORD style = GetWindowLong(m_mainWindow, GWL_STYLE);

SampleApps/WebView2APISample/AppWindow.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,18 @@ class AppWindow
109109

110110
void DeleteComponent(ComponentBase* scenario);
111111

112+
// Runs a function by posting it to the event loop. Use this to do things
113+
// that shouldn't be done in event handlers, like show message boxes.
114+
// If you use this in a component, capture a pointer to this AppWindow
115+
// instead of the component, because the component could get deleted before
116+
// the AppWindow.
112117
void RunAsync(std::function<void(void)> callback);
113118

119+
// Calls win32 MessageBox inside RunAsync. Always uses MB_OK. If you need
120+
// to get the return value from MessageBox, you'll have to use RunAsync
121+
// yourself.
122+
void AsyncMessageBox(std::wstring message, std::wstring title);
123+
114124
void InstallComplete(int return_code);
115125

116126
void AddRef();

SampleApps/WebView2APISample/ControlComponent.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ ControlComponent::ControlComponent(AppWindow* appWindow, Toolbar* toolbar)
119119
// The web page can cancel its own iframe loads, so we'll ignore that.
120120
if (webErrorStatus != COREWEBVIEW2_WEB_ERROR_STATUS_OPERATION_CANCELED)
121121
{
122-
std::wstring error_msg = WebErrorStatusToString(webErrorStatus);
123-
MessageBox(nullptr,
124-
(std::wstring(L"IFrame navigation failed: ") + error_msg).c_str(),
125-
L"Navigation Failure", MB_OK);
122+
m_appWindow->AsyncMessageBox(
123+
L"Iframe navigation failed: "
124+
+ WebErrorStatusToString(webErrorStatus),
125+
L"Navigation Failure");
126126
}
127127
}
128128
return S_OK;
@@ -187,8 +187,8 @@ ControlComponent::ControlComponent(AppWindow* appWindow, Toolbar* toolbar)
187187
UINT key;
188188
CHECK_FAILURE(args->get_VirtualKey(&key));
189189
// Check if the key is one we want to handle.
190-
if (std::function<void()> action =
191-
m_appWindow->GetAcceleratorKeyFunction(key))
190+
std::function<void()> action = m_appWindow->GetAcceleratorKeyFunction(key);
191+
if (action)
192192
{
193193
// Keep the browser from handling this key, whether it's autorepeated or
194194
// not.

SampleApps/WebView2APISample/FileComponent.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,12 @@ void FileComponent::SaveScreenshot()
8282
defaultName, STGM_READWRITE | STGM_CREATE, FILE_ATTRIBUTE_NORMAL, TRUE, nullptr,
8383
&stream));
8484

85-
HWND mainWindow = m_appWindow->GetMainWindow();
86-
8785
CHECK_FAILURE(m_webView->CapturePreview(
8886
COREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT_PNG, stream.get(),
8987
Callback<ICoreWebView2CapturePreviewCompletedHandler>(
90-
[mainWindow](HRESULT error_code) -> HRESULT {
88+
[appWindow{m_appWindow}](HRESULT error_code) -> HRESULT {
9189
CHECK_FAILURE(error_code);
92-
93-
MessageBox(mainWindow, L"Preview Captured", L"Preview Captured", MB_OK);
90+
appWindow->AsyncMessageBox(L"Preview Captured", L"Preview Captured");
9491
return S_OK;
9592
})
9693
.Get()));
@@ -133,14 +130,10 @@ void FileComponent::PrintToPdf(bool enableLandscape)
133130
[this](HRESULT errorCode, BOOL isSuccessful) -> HRESULT {
134131
CHECK_FAILURE(errorCode);
135132
m_printToPdfInProgress = false;
136-
auto showDialog = [isSuccessful] {
137-
MessageBox(
138-
nullptr,
139-
(isSuccessful) ? L"Print to PDF succeeded"
140-
: L"Print to PDF failed",
141-
L"Print to PDF Completed", MB_OK);
142-
};
143-
m_appWindow->RunAsync([showDialog]() { showDialog(); });
133+
m_appWindow->AsyncMessageBox(
134+
(isSuccessful) ? L"Print to PDF succeeded"
135+
: L"Print to PDF failed",
136+
L"Print to PDF Completed");
144137
return S_OK;
145138
})
146139
.Get()));

SampleApps/WebView2APISample/ProcessComponent.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@ ProcessComponent::ProcessComponent(AppWindow* appWindow)
110110
<< L"Reason: " << ProcessFailedReasonToString(reason) << L"\n"
111111
<< L"Exit code: " << std::to_wstring(exitCode) << L"\n"
112112
<< L"Process description: " << processDescription.get() << std::endl;
113-
m_appWindow->RunAsync([this, message = message.str()]() {
114-
MessageBox(
115-
m_appWindow->GetMainWindow(), message.c_str(),
116-
L"Child process failed", MB_OK);
117-
});
113+
m_appWindow->AsyncMessageBox( std::move(message.str()), L"Child process failed");
118114
}
119115
return S_OK;
120116
})

SampleApps/WebView2APISample/ScenarioAuthentication.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ ScenarioAuthentication::ScenarioAuthentication(AppWindow* appWindow) :
3333
wil::unique_cotaskmem_string authHeaderValue;
3434
if (requestHeaders->GetHeader(L"Authorization", &authHeaderValue) == S_OK)
3535
{
36-
std::wstring message(L"Authorization: ");
37-
message += authHeaderValue.get();
38-
MessageBox(nullptr, message.c_str(), nullptr, MB_OK);
36+
m_appWindow->AsyncMessageBox(
37+
std::wstring(L"Authorization: ") + authHeaderValue.get(),
38+
L"Authentication result");
3939
m_appWindow->DeleteComponent(this);
4040
}
4141
}

SampleApps/WebView2APISample/ScenarioCookieManagement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ void ScenarioCookieManagement::GetCookiesHelper(std::wstring uri)
224224
}
225225
result += L"]";
226226
}
227-
MessageBox(nullptr, result.c_str(), L"GetCookies Result", MB_OK);
227+
m_appWindow->AsyncMessageBox(std::move(result), L"GetCookies Result");
228228
return S_OK;
229229
})
230230
.Get()));

0 commit comments

Comments
 (0)