Skip to content

Commit 3a1973f

Browse files
yunateWebView2GithubBotpeiche-ms
authored
Smoketest/1.0.1340 testing (#146)
* Updates for Win32, WPF and WinForms sample apps from 105.0.1340.0 * Updated package version for Win32, WPF and WinForms sample apps to 1.0.1340-prerelease * Fix snippet Co-authored-by: WebView2 Github Bot <[email protected]> Co-authored-by: Jessica Chen <[email protected]>
1 parent 30e6fd2 commit 3a1973f

22 files changed

+496
-65
lines changed

SampleApps/WebView2APISample/AppWindow.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@
3232
#include "ScenarioClientCertificateRequested.h"
3333
#include "ScenarioCookieManagement.h"
3434
#include "ScenarioCustomDownloadExperience.h"
35+
#include "ScenarioCustomScheme.h"
36+
#include "ScenarioCustomSchemeNavigate.h"
3537
#include "ScenarioDOMContentLoaded.h"
3638
#include "ScenarioIFrameDevicePermission.h"
3739
#include "ScenarioNavigateWithWebResourceRequest.h"
40+
#include "ScenarioSharedWorkerWRR.h"
3841
#include "ScenarioVirtualHostMappingForPopUpWindow.h"
3942
#include "ScenarioVirtualHostMappingForSW.h"
4043
#include "ScenarioWebMessage.h"
@@ -43,6 +46,7 @@
4346
#include "SettingsComponent.h"
4447
#include "TextInputDialog.h"
4548
#include "ViewComponent.h"
49+
4650
using namespace Microsoft::WRL;
4751
static constexpr size_t s_maxLoadString = 100;
4852
static constexpr UINT s_runAsyncWindowMessage = WM_APP;
@@ -531,6 +535,21 @@ bool AppWindow::ExecuteWebViewCommands(WPARAM wParam, LPARAM lParam)
531535
NewComponent<ScenarioCookieManagement>(this);
532536
return true;
533537
}
538+
case IDM_SCENARIO_CUSTOM_SCHEME:
539+
{
540+
NewComponent<ScenarioCustomScheme>(this);
541+
return true;
542+
}
543+
case IDM_SCENARIO_CUSTOM_SCHEME_NAVIGATE:
544+
{
545+
NewComponent<ScenarioCustomSchemeNavigate>(this);
546+
return true;
547+
}
548+
case IDM_SCENARIO_SHARED_WORKER:
549+
{
550+
NewComponent<ScenarioSharedWorkerWRR>(this);
551+
return true;
552+
}
534553
case IDM_SCENARIO_DOM_CONTENT_LOADED:
535554
{
536555
NewComponent<ScenarioDOMContentLoaded>(this);

SampleApps/WebView2APISample/DropTarget.cpp

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,11 @@ void DropTarget::Init(
2525
::RegisterDragDrop(m_window, this);
2626
}
2727

28-
wil::com_ptr<IDropTargetHelper> DropTarget::DropHelper() {
29-
if (!m_dropTargetHelper)
30-
{
31-
CoCreateInstance(
32-
CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER, IID_IDropTargetHelper,
33-
reinterpret_cast<void**>(&m_dropTargetHelper));
34-
}
35-
return m_dropTargetHelper;
36-
}
37-
3828
//! [DragEnter]
3929
HRESULT DropTarget::DragEnter(
4030
IDataObject* dataObject, DWORD keyState, POINTL cursorPosition, DWORD* effect)
4131
{
42-
POINT point = { cursorPosition.x, cursorPosition.y};
43-
// Tell the helper that we entered so it can update the drag image and get
44-
// the correct effect.
45-
wil::com_ptr<IDropTargetHelper> dropHelper = DropHelper();
46-
if (dropHelper)
47-
{
48-
dropHelper->DragEnter(GetHWND(), dataObject, &point, *effect);
49-
}
50-
32+
POINT point = {cursorPosition.x, cursorPosition.y};
5133
// Convert the screen point to client coordinates add the WebView's offset.
5234
m_viewComponent->OffsetPointToWebView(&point);
5335
return m_webViewExperimentalCompositionController3->DragEnter(
@@ -58,15 +40,7 @@ HRESULT DropTarget::DragEnter(
5840
//! [DragOver]
5941
HRESULT DropTarget::DragOver(DWORD keyState, POINTL cursorPosition, DWORD* effect)
6042
{
61-
POINT point = { cursorPosition.x, cursorPosition.y};
62-
// Tell the helper that we moved over it so it can update the drag image
63-
// and get the correct effect.
64-
wil::com_ptr<IDropTargetHelper> dropHelper = DropHelper();
65-
if (dropHelper)
66-
{
67-
dropHelper->DragOver(&point, *effect);
68-
}
69-
43+
POINT point = {cursorPosition.x, cursorPosition.y};
7044
// Convert the screen point to client coordinates add the WebView's offset.
7145
// This returns whether the resultant point is over the WebView visual.
7246
m_viewComponent->OffsetPointToWebView(&point);
@@ -78,13 +52,6 @@ HRESULT DropTarget::DragOver(DWORD keyState, POINTL cursorPosition, DWORD* effec
7852
//! [DragLeave]
7953
HRESULT DropTarget::DragLeave()
8054
{
81-
// Tell the helper that we moved out of it so it can update the drag image.
82-
wil::com_ptr<IDropTargetHelper> dropHelper = DropHelper();
83-
if (dropHelper)
84-
{
85-
dropHelper->DragLeave();
86-
}
87-
8855
return m_webViewExperimentalCompositionController3->DragLeave();
8956
}
9057
//! [DragLeave]
@@ -93,15 +60,7 @@ HRESULT DropTarget::DragLeave()
9360
HRESULT DropTarget::Drop(
9461
IDataObject* dataObject, DWORD keyState, POINTL cursorPosition, DWORD* effect)
9562
{
96-
POINT point = { cursorPosition.x, cursorPosition.y};
97-
// Tell the helper that we dropped onto it so it can update the drag image and
98-
// get the correct effect.
99-
wil::com_ptr<IDropTargetHelper> dropHelper = DropHelper();
100-
if (dropHelper)
101-
{
102-
dropHelper->Drop(dataObject, &point, *effect);
103-
}
104-
63+
POINT point = {cursorPosition.x, cursorPosition.y};
10564
// Convert the screen point to client coordinates add the WebView's offset.
10665
// This returns whether the resultant point is over the WebView visual.
10766
m_viewComponent->OffsetPointToWebView(&point);

SampleApps/WebView2APISample/DropTarget.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ class DropTarget : public Microsoft::WRL::RuntimeClass<
4141
// Returns the hosting HWND.
4242
HWND GetHWND() { return m_window; }
4343

44-
wil::com_ptr<IDropTargetHelper> DropHelper();
45-
wil::com_ptr<IDropTargetHelper> m_dropTargetHelper;
46-
4744
// The HWND of the source. This HWND is used to determine coordinates for
4845
// mouse events that are sent to the renderer notifying various drag states.
4946
HWND m_window;
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Copyright (C) Microsoft Corporation. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
#include "stdafx.h"
5+
6+
#include "ScenarioCustomScheme.h"
7+
8+
#include "AppWindow.h"
9+
#include "CheckFailure.h"
10+
11+
#include <Shlwapi.h>
12+
13+
using namespace Microsoft::WRL;
14+
15+
ScenarioCustomScheme::ScenarioCustomScheme(AppWindow* appWindow) : m_appWindow(appWindow)
16+
{
17+
CHECK_FAILURE(m_appWindow->GetWebView()->AddWebResourceRequestedFilter(
18+
L"custom-scheme*", COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL));
19+
CHECK_FAILURE(m_appWindow->GetWebView()->add_WebResourceRequested(
20+
Callback<ICoreWebView2WebResourceRequestedEventHandler>(
21+
[this](ICoreWebView2* sender, ICoreWebView2WebResourceRequestedEventArgs* args)
22+
{
23+
wil::com_ptr<ICoreWebView2WebResourceRequest> request;
24+
wil::com_ptr<ICoreWebView2WebResourceResponse> response;
25+
CHECK_FAILURE(args->get_Request(&request));
26+
wil::unique_cotaskmem_string uri;
27+
CHECK_FAILURE(request->get_Uri(&uri));
28+
if (wcsncmp(uri.get(), L"custom-scheme", ARRAYSIZE(L"custom-scheme") - 1) == 0)
29+
{
30+
std::wstring assetsFilePath = L"assets/";
31+
assetsFilePath += wcsstr(uri.get(), L":") + 1;
32+
wil::com_ptr<IStream> stream;
33+
SHCreateStreamOnFileEx(
34+
assetsFilePath.c_str(), STGM_READ, FILE_ATTRIBUTE_NORMAL, FALSE,
35+
nullptr, &stream);
36+
if (stream)
37+
{
38+
CHECK_FAILURE(
39+
m_appWindow->GetWebViewEnvironment()->CreateWebResourceResponse(
40+
stream.get(), 200, L"OK",
41+
L"Content-Type: application/json\nAccess-Control-Allow-Origin: "
42+
L"*",
43+
&response));
44+
CHECK_FAILURE(args->put_Response(response.get()));
45+
}
46+
else
47+
{
48+
CHECK_FAILURE(
49+
m_appWindow->GetWebViewEnvironment()->CreateWebResourceResponse(
50+
nullptr, 404, L"Not Found", L"", &response));
51+
CHECK_FAILURE(args->put_Response(response.get()));
52+
}
53+
return S_OK;
54+
}
55+
56+
return S_OK;
57+
})
58+
.Get(),
59+
&m_webResourceRequestedToken));
60+
61+
m_appWindow->GetWebView()->add_NavigationCompleted(
62+
Callback<ICoreWebView2NavigationCompletedEventHandler>(
63+
[this](ICoreWebView2* sender, ICoreWebView2NavigationCompletedEventArgs* args)
64+
{
65+
// The following XHR will execute in the context of https://www.example.com page
66+
// and will succeed. WebResourceRequested event will be raised for this request
67+
// as *.example.com is in the allowed origin list of custom-scheme. Since the
68+
// response header provided in WebResourceRequested handler allows all origins
69+
// for CORS the XHR succeeds.
70+
CHECK_FAILURE(m_appWindow->GetWebView()->ExecuteScript(
71+
L"function reqListener(e) { console.log(e.data) };"
72+
L"function errListener(e) { console.log(e.error) };"
73+
L"var oReq = new XMLHttpRequest();"
74+
L"oReq.addEventListener(\"load\", reqListener);"
75+
L"oReq.addEventListener(\"error\", errListener);"
76+
L"oReq.open(\"GET\", \"custom-scheme:ScenarioCustomScheme.json\");"
77+
L"oReq.send();",
78+
Callback<ICoreWebView2ExecuteScriptCompletedHandler>(
79+
[](HRESULT error, PCWSTR result) -> HRESULT { return S_OK; })
80+
.Get()));
81+
// The following XHR will fail because *.example.com is not in the allowed
82+
// origin list of custom-scheme2. The WebResourceRequested event will not be
83+
// raised for this request.
84+
CHECK_FAILURE(m_appWindow->GetWebView()->ExecuteScript(
85+
L"var oReq = new XMLHttpRequest();"
86+
L"oReq.addEventListener(\"load\", reqListener);"
87+
L"oReq.addEventListener(\"error\", errListener);"
88+
L"oReq.open(\"GET\", "
89+
L"\"custom-scheme-not-in-allowed-origins://"
90+
L"ScenarioCustomScheme.json\");"
91+
L"oReq.send();",
92+
Callback<ICoreWebView2ExecuteScriptCompletedHandler>(
93+
[](HRESULT error, PCWSTR result) -> HRESULT { return S_OK; })
94+
.Get()));
95+
CHECK_FAILURE(m_appWindow->GetWebView()->remove_NavigationCompleted(
96+
m_navigationCompletedToken));
97+
m_navigationCompletedToken = {0};
98+
return S_OK;
99+
})
100+
.Get(),
101+
&m_navigationCompletedToken);
102+
m_appWindow->GetWebView()->Navigate(L"https://www.example.com");
103+
}
104+
105+
ScenarioCustomScheme::~ScenarioCustomScheme()
106+
{
107+
CHECK_FAILURE(
108+
m_appWindow->GetWebView()->remove_WebResourceRequested(m_webResourceRequestedToken));
109+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (C) Microsoft Corporation. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#pragma once
6+
#include "stdafx.h"
7+
8+
#include <string>
9+
10+
#include "AppWindow.h"
11+
#include "ComponentBase.h"
12+
13+
class ScenarioCustomScheme : public ComponentBase
14+
{
15+
public:
16+
ScenarioCustomScheme(AppWindow* appWindow);
17+
~ScenarioCustomScheme() override;
18+
19+
private:
20+
EventRegistrationToken m_webResourceRequestedToken = {};
21+
EventRegistrationToken m_navigationCompletedToken = {};
22+
23+
AppWindow* m_appWindow = nullptr;
24+
};
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright (C) Microsoft Corporation. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
#include "stdafx.h"
5+
6+
#include "ScenarioCustomSchemeNavigate.h"
7+
8+
#include "AppWindow.h"
9+
#include "CheckFailure.h"
10+
11+
#include <Shlwapi.h>
12+
13+
using namespace Microsoft::WRL;
14+
15+
ScenarioCustomSchemeNavigate::ScenarioCustomSchemeNavigate(AppWindow* appWindow)
16+
: m_appWindow(appWindow)
17+
{
18+
CHECK_FAILURE(m_appWindow->GetWebView()->AddWebResourceRequestedFilter(
19+
L"wv2rocks*", COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL));
20+
CHECK_FAILURE(m_appWindow->GetWebView()->add_WebResourceRequested(
21+
Callback<ICoreWebView2WebResourceRequestedEventHandler>(
22+
[this](ICoreWebView2* sender, ICoreWebView2WebResourceRequestedEventArgs* args)
23+
{
24+
wil::com_ptr<ICoreWebView2WebResourceRequest> request;
25+
wil::com_ptr<ICoreWebView2WebResourceResponse> response;
26+
CHECK_FAILURE(args->get_Request(&request));
27+
wil::unique_cotaskmem_string uri;
28+
CHECK_FAILURE(request->get_Uri(&uri));
29+
if (wcsncmp(uri.get(), L"wv2rocks", ARRAYSIZE(L"wv2rocks") - 1) == 0)
30+
{
31+
std::wstring assetsFilePath = L"assets/";
32+
assetsFilePath += wcsstr(uri.get(), L":") + 1;
33+
wil::com_ptr<IStream> stream;
34+
SHCreateStreamOnFileEx(
35+
assetsFilePath.c_str(), STGM_READ, FILE_ATTRIBUTE_NORMAL, FALSE,
36+
nullptr, &stream);
37+
if (stream)
38+
{
39+
std::wstring headers;
40+
if (assetsFilePath.substr(assetsFilePath.find_last_of(L".") + 1) ==
41+
L"html")
42+
{
43+
headers = L"Content-Type: text/html";
44+
}
45+
else if (
46+
assetsFilePath.substr(assetsFilePath.find_last_of(L".") + 1) ==
47+
L"jpg")
48+
{
49+
headers = L"Content-Type: image/jpeg";
50+
}
51+
else if (
52+
assetsFilePath.substr(assetsFilePath.find_last_of(L".") + 1) ==
53+
L"png")
54+
{
55+
headers = L"Content-Type: image/png";
56+
}
57+
else if (
58+
assetsFilePath.substr(assetsFilePath.find_last_of(L".") + 1) ==
59+
L"css")
60+
{
61+
headers = L"Content-Type: text/css";
62+
}
63+
else if (
64+
assetsFilePath.substr(assetsFilePath.find_last_of(L".") + 1) ==
65+
L"js")
66+
{
67+
headers = L"Content-Type: application/javascript";
68+
}
69+
70+
CHECK_FAILURE(
71+
m_appWindow->GetWebViewEnvironment()->CreateWebResourceResponse(
72+
stream.get(), 200, L"OK", headers.c_str(), &response));
73+
CHECK_FAILURE(args->put_Response(response.get()));
74+
}
75+
else
76+
{
77+
CHECK_FAILURE(
78+
m_appWindow->GetWebViewEnvironment()->CreateWebResourceResponse(
79+
nullptr, 404, L"Not Found", L"", &response));
80+
CHECK_FAILURE(args->put_Response(response.get()));
81+
}
82+
return S_OK;
83+
}
84+
85+
return S_OK;
86+
})
87+
.Get(),
88+
&m_webResourceRequestedToken));
89+
90+
m_appWindow->GetWebView()->Navigate(L"wv2rocks:ScenarioCustomScheme.html");
91+
}
92+
93+
ScenarioCustomSchemeNavigate::~ScenarioCustomSchemeNavigate()
94+
{
95+
CHECK_FAILURE(
96+
m_appWindow->GetWebView()->remove_WebResourceRequested(m_webResourceRequestedToken));
97+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (C) Microsoft Corporation. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#pragma once
6+
#include "stdafx.h"
7+
8+
#include <string>
9+
10+
#include "AppWindow.h"
11+
#include "ComponentBase.h"
12+
13+
class ScenarioCustomSchemeNavigate : public ComponentBase
14+
{
15+
public:
16+
ScenarioCustomSchemeNavigate(AppWindow* appWindow);
17+
~ScenarioCustomSchemeNavigate() override;
18+
19+
private:
20+
EventRegistrationToken m_webResourceRequestedToken = {};
21+
EventRegistrationToken m_navigationCompletedToken = {};
22+
23+
AppWindow* m_appWindow = nullptr;
24+
};

0 commit comments

Comments
 (0)