Skip to content

Commit c7d7c75

Browse files
authored
Merge pull request #99 from MicrosoftEdge/smoketesting
Move projects to use latest WebView2 SDK 1.0.955-prerelease
2 parents 9a076c4 + 847ce02 commit c7d7c75

29 files changed

Lines changed: 644 additions & 390 deletions

SampleApps/WebView2APISample/AppWindow.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828
#include "Resource.h"
2929
#include "ScenarioAddHostObject.h"
3030
#include "ScenarioAuthentication.h"
31-
#include "ScenarioCookieManagement.h"
3231
#include "ScenarioClientCertificateRequested.h"
32+
#include "ScenarioCookieManagement.h"
3333
#include "ScenarioCustomDownloadExperience.h"
3434
#include "ScenarioDOMContentLoaded.h"
3535
#include "ScenarioNavigateWithWebResourceRequest.h"
36+
#include "ScenarioVirtualHostMappingForSW.h"
3637
#include "ScenarioWebMessage.h"
3738
#include "ScenarioWebViewEventMonitor.h"
3839
#include "ScriptComponent.h"
@@ -299,6 +300,12 @@ bool AppWindow::HandleWindowMessage(
299300
return true;
300301
}
301302
break;
303+
case WM_CLOSE:
304+
{
305+
CloseAppWindow();
306+
return true;
307+
}
308+
break;
302309
case WM_NCDESTROY:
303310
{
304311
int retValue = 0;
@@ -466,6 +473,11 @@ bool AppWindow::ExecuteWebViewCommands(WPARAM wParam, LPARAM lParam)
466473
NewComponent<ScenarioClientCertificateRequested>(this);
467474
return true;
468475
}
476+
case IDM_SCENARIO_VIRTUAL_HOST_MAPPING:
477+
{
478+
NewComponent<ScenarioVirtualHostMappingForSW>(this);
479+
return true;
480+
}
469481
}
470482
return false;
471483
}
@@ -1244,6 +1256,11 @@ HRESULT AppWindow::DeleteFileRecursive(std::wstring path)
12441256

12451257
void AppWindow::CloseAppWindow()
12461258
{
1259+
if (m_onAppWindowClosing)
1260+
{
1261+
m_onAppWindowClosing();
1262+
m_onAppWindowClosing = nullptr;
1263+
}
12471264
CloseWebView();
12481265
DestroyWindow(m_mainWindow);
12491266
}

SampleApps/WebView2APISample/AppWindow.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ class AppWindow
7777
void Release();
7878
void NotifyClosed();
7979

80+
void SetOnAppWindowClosing(std::function<void()>&& f) {
81+
m_onAppWindowClosing = std::move(f);
82+
}
83+
8084
std::wstring GetUserDataFolder()
8185
{
8286
return m_userDataFolder;
@@ -128,6 +132,7 @@ class AppWindow
128132
HWND m_mainWindow = nullptr;
129133
Toolbar m_toolbar;
130134
std::function<void()> m_onWebViewFirstInitialized;
135+
std::function<void()> m_onAppWindowClosing;
131136
DWORD m_creationModeId = 0;
132137
int m_refCount = 1;
133138
bool m_isClosed = false;

SampleApps/WebView2APISample/ControlComponent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ void ControlComponent::TabForwards(size_t currentIndex)
400400
void ControlComponent::TabBackwards(size_t currentIndex)
401401
{
402402
// Find first enabled window before the active one
403-
for (size_t i = currentIndex - 1; i >= 0; i--)
403+
for (size_t i = currentIndex - 1; i >= 0 && i < m_tabbableWindows.size(); i--)
404404
{
405405
HWND hwnd = m_tabbableWindows.at(i).first;
406406
if (IsWindowEnabled(hwnd))

SampleApps/WebView2APISample/ScenarioAddHostObject.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ ScenarioAddHostObject::ScenarioAddHostObject(AppWindow* appWindow)
7575
return S_OK;
7676
}).Get(), &m_navigationStartingToken));
7777

78-
7978
wil::com_ptr<ICoreWebView2_4> webview2_4 = m_webView.try_query<ICoreWebView2_4>();
8079
if (webview2_4)
8180
{

SampleApps/WebView2APISample/ScenarioAuthentication.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010

1111
using namespace Microsoft::WRL;
1212

13-
ScenarioAuthentication::ScenarioAuthentication(AppWindow* appWindow) : m_appWindow(appWindow)
13+
ScenarioAuthentication::ScenarioAuthentication(AppWindow* appWindow) :
14+
m_appWindow(appWindow)
1415
{
16+
m_webView = wil::com_ptr<ICoreWebView2>(m_appWindow->GetWebView()).query<ICoreWebView2_2>();
1517
MessageBox(
1618
nullptr,
1719
L"Authentication scenario:\n Click HTML/NTLM Auth to get Authentication headers",
1820
nullptr, MB_OK);
1921
//! [WebResourceResponseReceived]
20-
wil::com_ptr<ICoreWebView2_2> webview2;
21-
CHECK_FAILURE(m_appWindow->GetWebView()->QueryInterface(IID_PPV_ARGS(&webview2)));
22-
CHECK_FAILURE(webview2->add_WebResourceResponseReceived(
22+
CHECK_FAILURE(m_webView->add_WebResourceResponseReceived(
2323
Callback<ICoreWebView2WebResourceResponseReceivedEventHandler>(
2424
[this](
2525
ICoreWebView2* sender,
@@ -48,12 +48,10 @@ ScenarioAuthentication::ScenarioAuthentication(AppWindow* appWindow) : m_appWind
4848
.Get(),
4949
&m_webResourceResponseReceivedToken));
5050
//! [WebResourceResponseReceived]
51-
CHECK_FAILURE(m_appWindow->GetWebView()->Navigate(L"https://authenticationtest.com"));
51+
CHECK_FAILURE(m_webView->Navigate(L"https://authenticationtest.com"));
5252
}
5353

5454
ScenarioAuthentication::~ScenarioAuthentication() {
55-
wil::com_ptr<ICoreWebView2_2> webview2;
56-
CHECK_FAILURE(m_appWindow->GetWebView()->QueryInterface(IID_PPV_ARGS(&webview2)));
5755
CHECK_FAILURE(
58-
webview2->remove_WebResourceResponseReceived(m_webResourceResponseReceivedToken));
56+
m_webView->remove_WebResourceResponseReceived(m_webResourceResponseReceivedToken));
5957
}

SampleApps/WebView2APISample/ScenarioAuthentication.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ class ScenarioAuthentication : public ComponentBase
1919
private:
2020
EventRegistrationToken m_webResourceResponseReceivedToken = {};
2121
AppWindow* m_appWindow = nullptr;
22+
wil::com_ptr<ICoreWebView2_2> m_webView = nullptr;
2223
};

SampleApps/WebView2APISample/ScenarioClientCertificateRequested.cpp

Lines changed: 123 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -11,128 +11,135 @@ using namespace Microsoft::WRL;
1111
static PCWSTR NameOfCertificateKind(COREWEBVIEW2_CLIENT_CERTIFICATE_KIND kind);
1212

1313
ScenarioClientCertificateRequested::ScenarioClientCertificateRequested(AppWindow* appWindow)
14-
: m_appWindow(appWindow), m_webView(appWindow->GetWebView())
14+
: m_appWindow(appWindow), m_webView(appWindow->GetWebView())
1515
{
16-
// Register a handler for the `ClientCertificateRequested` event.
17-
// This example hides the default client certificate dialog and shows a custom dialog instead.
18-
// The dialog box displays mutually trusted certificates list and allows the user to select a certificate.
19-
// Selecting `OK` will continue the request with a certificate.
20-
// Selecting `CANCEL` will continue the request without a certificate.
21-
//! [ClientCertificateRequested2]
22-
m_webViewExperimental = m_webView.try_query<ICoreWebView2Experimental3>();
23-
if (m_webViewExperimental)
24-
{
25-
CHECK_FAILURE(m_webViewExperimental->add_ClientCertificateRequested(
26-
Callback<ICoreWebView2ExperimentalClientCertificateRequestedEventHandler>(
27-
[this](
28-
ICoreWebView2* sender,
29-
ICoreWebView2ExperimentalClientCertificateRequestedEventArgs* args) {
30-
auto showDialog = [this, args] {
31-
wil::com_ptr<ICoreWebView2ExperimentalClientCertificateCollection> certificateCollection;
32-
CHECK_FAILURE(args->get_MutuallyTrustedCertificates(&certificateCollection));
33-
34-
wil::unique_cotaskmem_string host;
35-
CHECK_FAILURE(args->get_Host(&host));
36-
37-
INT port = FALSE;
38-
CHECK_FAILURE(args->get_Port(&port));
39-
40-
UINT certificateCollectionCount;
41-
CHECK_FAILURE(certificateCollection->get_Count(&certificateCollectionCount));
42-
43-
wil::com_ptr<ICoreWebView2ExperimentalClientCertificate> certificate = nullptr;
44-
45-
if (certificateCollectionCount > 0)
46-
{
47-
ClientCertificate clientCertificate;
48-
for (UINT i = 0; i < certificateCollectionCount; i++)
49-
{
50-
CHECK_FAILURE(
51-
certificateCollection->GetValueAtIndex(i, &certificate));
52-
53-
CHECK_FAILURE(certificate->get_Subject(&clientCertificate.Subject));
54-
55-
CHECK_FAILURE(certificate->get_DisplayName(&clientCertificate.DisplayName));
56-
57-
CHECK_FAILURE(certificate->get_Issuer(&clientCertificate.Issuer));
58-
59-
COREWEBVIEW2_CLIENT_CERTIFICATE_KIND Kind;
60-
CHECK_FAILURE(
61-
certificate->get_Kind(&Kind));
62-
clientCertificate.CertificateKind = NameOfCertificateKind(Kind);
63-
64-
CHECK_FAILURE(certificate->get_ValidFrom(&clientCertificate.ValidFrom));
65-
66-
CHECK_FAILURE(certificate->get_ValidTo(&clientCertificate.ValidTo));
67-
68-
clientCertificates_.push_back(clientCertificate);
69-
}
70-
71-
// Display custom dialog box for the client certificate selection.
72-
ClientCertificateSelectionDialog dialog(
73-
m_appWindow->GetMainWindow(), L"Select a Certificate for authentication", host.get(), port, clientCertificates_);
74-
75-
if (dialog.confirmed)
76-
{
77-
int selectedIndex = dialog.selectedItem;
78-
if (selectedIndex >= 0)
79-
{
80-
CHECK_FAILURE(
81-
certificateCollection->GetValueAtIndex(selectedIndex, &certificate));
82-
// Continue with the selected certificate to respond to the server if `OK` is selected.
83-
CHECK_FAILURE(args->put_SelectedCertificate(certificate.get()));
84-
}
85-
}
86-
// Continue without a certificate to respond to the server if `CANCEL` is selected.
87-
CHECK_FAILURE(args->put_Handled(TRUE));
88-
}
89-
else
90-
{
91-
// Continue without a certificate to respond to the server if certificate collection is empty.
92-
CHECK_FAILURE(args->put_Handled(TRUE));
93-
}
94-
};
95-
96-
// Obtain a deferral for the event so that the CoreWebView2
97-
// doesn't examine the properties we set on the event args and
98-
// after we call the Complete method asynchronously later.
99-
wil::com_ptr<ICoreWebView2Deferral> deferral;
100-
CHECK_FAILURE(args->GetDeferral(&deferral));
101-
102-
// complete the deferral asynchronously.
103-
m_appWindow->RunAsync([deferral, showDialog]() {
104-
showDialog();
105-
CHECK_FAILURE(deferral->Complete());
106-
});
107-
108-
return S_OK;
109-
})
110-
.Get(),
111-
&m_ClientCertificateRequestedToken));
112-
113-
MessageBox(
114-
nullptr, L"Custom Client Certificate selection dialog will be used next when WebView2 "
115-
L"is making a request to an HTTP server that needs a client certificate.",
116-
L"Client certificate selection", MB_OK);
117-
}
118-
//! [ClientCertificateRequested2]
16+
// Register a handler for the `ClientCertificateRequested` event.
17+
// This example hides the default client certificate dialog and shows a custom dialog instead.
18+
// The dialog box displays mutually trusted certificates list and allows the user to select a certificate.
19+
// Selecting `OK` will continue the request with a certificate.
20+
// Selecting `CANCEL` will continue the request without a certificate.
21+
//! [ClientCertificateRequested2]
22+
m_webView2_5 = m_webView.try_query<ICoreWebView2_5>();
23+
if (m_webView2_5)
24+
{
25+
CHECK_FAILURE(m_webView2_5->add_ClientCertificateRequested(
26+
Callback<ICoreWebView2ClientCertificateRequestedEventHandler>(
27+
[this](
28+
ICoreWebView2* sender,
29+
ICoreWebView2ClientCertificateRequestedEventArgs* args) {
30+
auto showDialog = [this, args] {
31+
wil::com_ptr<ICoreWebView2ClientCertificateCollection> certificateCollection;
32+
CHECK_FAILURE(args->get_MutuallyTrustedCertificates(&certificateCollection));
33+
34+
wil::unique_cotaskmem_string host;
35+
CHECK_FAILURE(args->get_Host(&host));
36+
37+
INT port = FALSE;
38+
CHECK_FAILURE(args->get_Port(&port));
39+
40+
UINT certificateCollectionCount;
41+
CHECK_FAILURE(certificateCollection->get_Count(&certificateCollectionCount));
42+
43+
wil::com_ptr<ICoreWebView2ClientCertificate> certificate = nullptr;
44+
45+
if (certificateCollectionCount > 0)
46+
{
47+
ClientCertificate clientCertificate;
48+
for (UINT i = 0; i < certificateCollectionCount; i++)
49+
{
50+
CHECK_FAILURE(
51+
certificateCollection->GetValueAtIndex(i, &certificate));
52+
53+
CHECK_FAILURE(certificate->get_Subject(&clientCertificate.Subject));
54+
55+
CHECK_FAILURE(certificate->get_DisplayName(&clientCertificate.DisplayName));
56+
57+
CHECK_FAILURE(certificate->get_Issuer(&clientCertificate.Issuer));
58+
59+
COREWEBVIEW2_CLIENT_CERTIFICATE_KIND Kind;
60+
CHECK_FAILURE(
61+
certificate->get_Kind(&Kind));
62+
clientCertificate.CertificateKind = NameOfCertificateKind(Kind);
63+
64+
CHECK_FAILURE(certificate->get_ValidFrom(&clientCertificate.ValidFrom));
65+
66+
CHECK_FAILURE(certificate->get_ValidTo(&clientCertificate.ValidTo));
67+
68+
clientCertificates_.push_back(clientCertificate);
69+
}
70+
71+
// Display custom dialog box for the client certificate selection.
72+
ClientCertificateSelectionDialog dialog(
73+
m_appWindow->GetMainWindow(), L"Select a Certificate for authentication", host.get(), port, clientCertificates_);
74+
75+
if (dialog.confirmed)
76+
{
77+
int selectedIndex = dialog.selectedItem;
78+
if (selectedIndex >= 0)
79+
{
80+
CHECK_FAILURE(
81+
certificateCollection->GetValueAtIndex(selectedIndex, &certificate));
82+
// Continue with the selected certificate to respond to the server if `OK` is selected.
83+
CHECK_FAILURE(args->put_SelectedCertificate(certificate.get()));
84+
}
85+
}
86+
// Continue without a certificate to respond to the server if `CANCEL` is selected.
87+
CHECK_FAILURE(args->put_Handled(TRUE));
88+
}
89+
else
90+
{
91+
// Continue without a certificate to respond to the server if certificate collection is empty.
92+
CHECK_FAILURE(args->put_Handled(TRUE));
93+
}
94+
};
95+
96+
// Obtain a deferral for the event so that the CoreWebView2
97+
// doesn't examine the properties we set on the event args and
98+
// after we call the Complete method asynchronously later.
99+
wil::com_ptr<ICoreWebView2Deferral> deferral;
100+
CHECK_FAILURE(args->GetDeferral(&deferral));
101+
102+
// complete the deferral asynchronously.
103+
m_appWindow->RunAsync([deferral, showDialog]() {
104+
showDialog();
105+
CHECK_FAILURE(deferral->Complete());
106+
});
107+
108+
return S_OK;
109+
})
110+
.Get(),
111+
&m_ClientCertificateRequestedToken));
112+
113+
MessageBox(
114+
nullptr, L"Custom Client Certificate selection dialog will be used next when WebView2 "
115+
L"is making a request to an HTTP server that needs a client certificate.",
116+
L"Client certificate selection", MB_OK);
117+
}
118+
else
119+
{
120+
FeatureNotAvailable();
121+
}
122+
//! [ClientCertificateRequested2]
119123
}
120124

121125
static PCWSTR NameOfCertificateKind(COREWEBVIEW2_CLIENT_CERTIFICATE_KIND kind)
122126
{
123-
switch (kind)
124-
{
125-
case COREWEBVIEW2_CLIENT_CERTIFICATE_KIND_SMART_CARD:
126-
return L"Smart Card";
127-
case COREWEBVIEW2_CLIENT_CERTIFICATE_KIND_PIN:
128-
return L"PIN";
129-
default:
130-
return L"Other";
131-
}
127+
switch (kind)
128+
{
129+
case COREWEBVIEW2_CLIENT_CERTIFICATE_KIND_SMART_CARD:
130+
return L"Smart Card";
131+
case COREWEBVIEW2_CLIENT_CERTIFICATE_KIND_PIN:
132+
return L"PIN";
133+
default:
134+
return L"Other";
135+
}
132136
}
133137

134138
ScenarioClientCertificateRequested::~ScenarioClientCertificateRequested()
135139
{
136-
CHECK_FAILURE(
137-
m_webViewExperimental->remove_ClientCertificateRequested(m_ClientCertificateRequestedToken));
138-
}
140+
if (m_webView2_5)
141+
{
142+
CHECK_FAILURE(
143+
m_webView2_5->remove_ClientCertificateRequested(m_ClientCertificateRequestedToken));
144+
}
145+
}

SampleApps/WebView2APISample/ScenarioClientCertificateRequested.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ScenarioClientCertificateRequested : public ComponentBase
1818
private:
1919
AppWindow* m_appWindow = nullptr;
2020
wil::com_ptr<ICoreWebView2> m_webView;
21-
wil::com_ptr<ICoreWebView2Experimental3> m_webViewExperimental;
21+
wil::com_ptr<ICoreWebView2_5> m_webView2_5;
2222
EventRegistrationToken m_ClientCertificateRequestedToken = {};
2323
std::vector<ClientCertificate> clientCertificates_;
2424
};

0 commit comments

Comments
 (0)