Skip to content

Commit eeb4d7c

Browse files
authored
Merge pull request #297 from MicrosoftEdge/smoketest/1.0.4126-testing
Smoketest/1.0.4126 testing
2 parents 7fa88fc + e188ab0 commit eeb4d7c

11 files changed

Lines changed: 334 additions & 6 deletions

SampleApps/WebView2APISample/AppWindow.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "ScenarioServiceWorkerPostMessage.h"
5454
#include "ScenarioServiceWorkerPostMessageSetting.h"
5555
#include "ScenarioSharedWorkerManager.h"
56+
#include "ScenarioOriginConfigurationAPI.h"
5657
#include "ScenarioSaveAs.h"
5758
#include "ScenarioScreenCapture.h"
5859
#include "ScenarioSensitivityLabel.h"
@@ -833,6 +834,20 @@ bool AppWindow::ExecuteWebViewCommands(WPARAM wParam, LPARAM lParam)
833834
component->ToggleServiceWorkerJsApiSetting();
834835
return true;
835836
}
837+
case IDM_SCENARIO_SET_ORIGIN_FEATURES:
838+
{
839+
auto* const trustedOriginComponent =
840+
GetOrCreateComponent<ScenarioOriginConfigurationAPI>();
841+
trustedOriginComponent->SetOriginFeatures();
842+
return true;
843+
}
844+
case IDM_SCENARIO_GET_ORIGIN_FEATURES:
845+
{
846+
auto* const trustedOriginComponent =
847+
GetOrCreateComponent<ScenarioOriginConfigurationAPI>();
848+
trustedOriginComponent->GetOriginFeatures();
849+
return true;
850+
}
836851
case IDM_SCENARIO_SCREEN_CAPTURE:
837852
{
838853
NewComponent<ScenarioScreenCapture>(this);

SampleApps/WebView2APISample/ProcessComponent.cpp

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) Microsoft Corporation. All rights reserved.
1+
// Copyright (C) Microsoft Corporation. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

@@ -121,6 +121,70 @@ ProcessComponent::ProcessComponent(AppWindow* appWindow)
121121
<< L"Process description: " << processDescription.get() << std::endl
122122
<< (failedModule ? L"Failed module: " : L"")
123123
<< (failedModule ? failedModule.get() : L"");
124+
125+
//! [CrashReport]
126+
// Query for the crash report (available when Crashpad handled
127+
// the crash; nullptr for __fastfail / WER-only crashes).
128+
auto experimentalArgs2 =
129+
args.try_query<ICoreWebView2ExperimentalProcessFailedEventArgs2>();
130+
if (experimentalArgs2)
131+
{
132+
wil::com_ptr<ICoreWebView2ExperimentalCrashReport> crashReport;
133+
CHECK_FAILURE(experimentalArgs2->get_CrashReport(&crashReport));
134+
if (crashReport)
135+
{
136+
wil::unique_cotaskmem_string crashReportId;
137+
if (SUCCEEDED(crashReport->get_CrashReportId(&crashReportId)) &&
138+
crashReportId)
139+
{
140+
message << L"\nCrash Report ID: " << crashReportId.get();
141+
}
142+
143+
UINT32 exceptionCode;
144+
if (SUCCEEDED(crashReport->get_ExceptionCode(&exceptionCode)))
145+
{
146+
message << L"\nException Code: 0x" << std::hex << exceptionCode
147+
<< std::dec;
148+
}
149+
150+
wil::unique_cotaskmem_string faultingModuleName;
151+
if (SUCCEEDED(
152+
crashReport->get_FaultingModuleName(&faultingModuleName)) &&
153+
faultingModuleName)
154+
{
155+
message << L"\nFaulting Module: " << faultingModuleName.get();
156+
}
157+
158+
wil::unique_cotaskmem_string faultingModuleVersion;
159+
if (SUCCEEDED(crashReport->get_FaultingModuleVersion(
160+
&faultingModuleVersion)) &&
161+
faultingModuleVersion)
162+
{
163+
message << L"\nModule Version: " << faultingModuleVersion.get();
164+
}
165+
166+
UINT64 faultOffset;
167+
if (SUCCEEDED(crashReport->get_FaultOffset(&faultOffset)))
168+
{
169+
message << L"\nFault Offset: 0x" << std::hex << faultOffset
170+
<< std::dec;
171+
}
172+
173+
wil::unique_cotaskmem_string bucketId;
174+
if (SUCCEEDED(crashReport->get_BucketId(&bucketId)) && bucketId)
175+
{
176+
message << L"\nCrash Bucket: " << bucketId.get();
177+
}
178+
179+
UINT64 reportTime;
180+
if (SUCCEEDED(crashReport->get_ReportTime(&reportTime)))
181+
{
182+
message << L"\nReport Time: " << reportTime;
183+
}
184+
}
185+
}
186+
//! [CrashReport]
187+
124188
m_appWindow->AsyncMessageBox( std::move(message.str()), L"Child process failed");
125189
}
126190
return S_OK;

SampleApps/WebView2APISample/ScenarioOriginConfigurationAPI.cpp

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,197 @@
1010
#include "CheckFailure.h"
1111
#include "TextInputDialog.h"
1212
#include "Util.h"
13+
14+
#include "ScenarioOriginConfigurationAPI.h"
15+
16+
using namespace Microsoft::WRL;
17+
18+
static constexpr int kEnhancedSecurityModeValue = 1;
19+
static constexpr int kSmartScreenValue = 2;
20+
21+
ScenarioOriginConfigurationAPI::ScenarioOriginConfigurationAPI(AppWindow* appWindow)
22+
: m_appWindow(appWindow)
23+
{
24+
CHECK_FAILURE(m_appWindow ? S_OK : E_POINTER);
25+
wil::com_ptr<ICoreWebView2> webView = m_appWindow->GetWebView();
26+
CHECK_FAILURE(webView ? S_OK : E_POINTER);
27+
auto webView2_13 = webView.try_query<ICoreWebView2_13>();
28+
CHECK_FAILURE(webView2_13 ? S_OK : E_POINTER);
29+
CHECK_FAILURE(webView2_13->get_Profile(&m_webviewProfile));
30+
}
31+
32+
ScenarioOriginConfigurationAPI::~ScenarioOriginConfigurationAPI() = default;
33+
34+
std::wstring ScenarioOriginConfigurationAPI::FeatureToString(
35+
COREWEBVIEW2_ORIGIN_FEATURE feature)
36+
{
37+
switch (feature)
38+
{
39+
case COREWEBVIEW2_ORIGIN_FEATURE_ENHANCED_SECURITY_MODE:
40+
return L"EnhancedSecurityMode";
41+
case COREWEBVIEW2_ORIGIN_FEATURE_REPUTATION_CHECKING:
42+
return L"ReputationChecking";
43+
default:
44+
return L"Unknown";
45+
}
46+
}
47+
48+
void ScenarioOriginConfigurationAPI::SetFeatureForOrigins(
49+
const std::vector<std::wstring>& originPatterns,
50+
const std::vector<
51+
std::pair<COREWEBVIEW2_ORIGIN_FEATURE, COREWEBVIEW2_ORIGIN_FEATURE_STATE>>& features)
52+
{
53+
auto experimentalProfile16 =
54+
m_webviewProfile.try_query<ICoreWebView2ExperimentalProfile16>();
55+
CHECK_FEATURE_RETURN_EMPTY(experimentalProfile16);
56+
57+
// featureSettings holds wil::com_ptr for COM lifetime management (keeps refcount > 0).
58+
// featureSettingsRaw holds raw pointers extracted from featureSettings to pass to the API.
59+
// Both are needed because the API requires a pointer array, but we need smart pointers to
60+
// prevent premature COM object destruction.
61+
std::vector<wil::com_ptr<ICoreWebView2ExperimentalOriginFeatureSetting>> featureSettings;
62+
std::vector<ICoreWebView2ExperimentalOriginFeatureSetting*> featureSettingsRaw;
63+
64+
for (const auto& [featureKind, featureState] : features)
65+
{
66+
wil::com_ptr<ICoreWebView2ExperimentalOriginFeatureSetting> setting;
67+
CHECK_FAILURE(experimentalProfile16->CreateOriginFeatureSetting(
68+
featureKind, featureState, &setting));
69+
featureSettings.push_back(setting);
70+
featureSettingsRaw.push_back(setting.get());
71+
}
72+
73+
std::vector<LPCWSTR> origins;
74+
for (const auto& pattern : originPatterns)
75+
{
76+
origins.push_back(pattern.c_str());
77+
}
78+
79+
CHECK_FAILURE(experimentalProfile16->SetOriginFeatures(
80+
static_cast<UINT32>(origins.size()), origins.data(),
81+
static_cast<UINT32>(featureSettingsRaw.size()), featureSettingsRaw.data()));
82+
}
83+
84+
void ScenarioOriginConfigurationAPI::GetOriginFeatures()
85+
{
86+
auto experimentalProfile16 =
87+
m_webviewProfile.try_query<ICoreWebView2ExperimentalProfile16>();
88+
CHECK_FEATURE_RETURN_EMPTY(experimentalProfile16);
89+
90+
TextInputDialog inputDialog(
91+
m_appWindow->GetMainWindow(), L"Get Trusted Origin Features",
92+
L"Enter the origin to retrieve feature settings for:", L"Origin:",
93+
std::wstring(L"https://www.microsoft.com"),
94+
false); // not read-only
95+
96+
if (inputDialog.confirmed)
97+
{
98+
std::wstring origin = inputDialog.input;
99+
100+
CHECK_FAILURE(experimentalProfile16->GetEffectiveFeaturesForOrigin(
101+
origin.c_str(),
102+
Callback<ICoreWebView2ExperimentalGetEffectiveFeaturesForOriginCompletedHandler>(
103+
[appWindow = m_appWindow, origin](
104+
HRESULT errorCode,
105+
ICoreWebView2ExperimentalOriginFeatureSettingCollectionView* result)
106+
-> HRESULT
107+
{
108+
if (SUCCEEDED(errorCode))
109+
{
110+
UINT32 count = 0;
111+
CHECK_FAILURE(result->get_Count(&count));
112+
113+
std::wstring message = L"Features for origin: " + origin + L"\n";
114+
for (UINT32 i = 0; i < count; i++)
115+
{
116+
wil::com_ptr<ICoreWebView2ExperimentalOriginFeatureSetting> setting;
117+
CHECK_FAILURE(result->GetValueAtIndex(i, &setting));
118+
119+
COREWEBVIEW2_ORIGIN_FEATURE feature;
120+
COREWEBVIEW2_ORIGIN_FEATURE_STATE featureState;
121+
CHECK_FAILURE(setting->get_Feature(&feature));
122+
CHECK_FAILURE(setting->get_State(&featureState));
123+
124+
message +=
125+
L"Feature: " + FeatureToString(feature) + L", Enabled: " +
126+
(featureState == COREWEBVIEW2_ORIGIN_FEATURE_STATE_ENABLED
127+
? L"True"
128+
: L"False") +
129+
L"\n";
130+
}
131+
132+
MessageBoxW(
133+
appWindow->GetMainWindow(), message.c_str(),
134+
L"Trusted Origin Features", MB_OK);
135+
}
136+
else
137+
{
138+
ShowFailure(
139+
errorCode,
140+
L"Failed to get effective features for origin: " + origin);
141+
}
142+
return S_OK;
143+
})
144+
.Get()));
145+
}
146+
}
147+
148+
void ScenarioOriginConfigurationAPI::SetOriginFeatures()
149+
{
150+
static constexpr wchar_t kOriginPatternsLabel[] = L"Enter origin patterns separated with ;";
151+
static constexpr wchar_t kFeaturesGroupLabel[] = L"Select features to enable:";
152+
153+
// Builder with text area for origin input and checkbox for feature selection.
154+
auto enhancedDialog =
155+
TextInputDialog::Builder(
156+
m_appWindow->GetMainWindow(), L"Configure Trusted Origin",
157+
L"Trusted Origin Configuration:")
158+
.AddTextArea(kOriginPatternsLabel, L"https://www.microsoft.com")
159+
.AddCheckBoxGroup(
160+
kFeaturesGroupLabel,
161+
{{L"Enable Enhanced Security Mode", kEnhancedSecurityModeValue, true},
162+
{L"Disable Reputation Checking", kSmartScreenValue, false}})
163+
.Build();
164+
165+
if (enhancedDialog.confirmed)
166+
{
167+
// Retrieve the origin text area. Skip if the control is missing.
168+
auto textAreaIt = enhancedDialog.results.find(kOriginPatternsLabel);
169+
if (textAreaIt == enhancedDialog.results.end())
170+
return;
171+
auto& textArea = std::get<TextArea>(textAreaIt->second);
172+
std::wstring input = textArea.input;
173+
174+
// Retrieve the feature checkbox group. Skip if the control is missing.
175+
std::vector<std::pair<COREWEBVIEW2_ORIGIN_FEATURE, COREWEBVIEW2_ORIGIN_FEATURE_STATE>>
176+
features;
177+
auto groupIt = enhancedDialog.results.find(kFeaturesGroupLabel);
178+
if (groupIt == enhancedDialog.results.end())
179+
return;
180+
auto& group = std::get<CheckBoxGroup>(groupIt->second);
181+
for (const auto& option : group.options)
182+
{
183+
if (option.isSelected && option.value == kEnhancedSecurityModeValue)
184+
{
185+
features.push_back(
186+
{COREWEBVIEW2_ORIGIN_FEATURE_ENHANCED_SECURITY_MODE,
187+
COREWEBVIEW2_ORIGIN_FEATURE_STATE_ENABLED});
188+
}
189+
if (option.isSelected && option.value == kSmartScreenValue)
190+
{
191+
// Disabling SmartScreen for the origin = allow-listing it.
192+
features.push_back(
193+
{COREWEBVIEW2_ORIGIN_FEATURE_REPUTATION_CHECKING,
194+
COREWEBVIEW2_ORIGIN_FEATURE_STATE_DISABLED});
195+
}
196+
}
197+
198+
std::vector<std::wstring> origins = Util::SplitString(input, L';');
199+
200+
// Set features for all origins in a single call.
201+
if (!features.empty())
202+
{
203+
SetFeatureForOrigins(origins, features);
204+
}
205+
}
206+
}

SampleApps/WebView2APISample/ScenarioOriginConfigurationAPI.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,31 @@
33
// found in the LICENSE file.
44

55
#pragma once
6+
7+
#include <string>
8+
#include <vector>
9+
10+
#include "AppWindow.h"
11+
#include "ComponentBase.h"
12+
13+
// Demonstrates configuring trusted origins via WebView2 profile.
14+
class ScenarioOriginConfigurationAPI : public ComponentBase
15+
{
16+
public:
17+
ScenarioOriginConfigurationAPI(AppWindow* appWindow);
18+
~ScenarioOriginConfigurationAPI() override;
19+
20+
void SetFeatureForOrigins(
21+
const std::vector<std::wstring>& originPattern,
22+
const std::vector<
23+
std::pair<COREWEBVIEW2_ORIGIN_FEATURE, COREWEBVIEW2_ORIGIN_FEATURE_STATE>>&
24+
features);
25+
void GetOriginFeatures();
26+
void SetOriginFeatures();
27+
28+
private:
29+
static std::wstring FeatureToString(COREWEBVIEW2_ORIGIN_FEATURE feature);
30+
31+
AppWindow* const m_appWindow; // Non-owning, guaranteed non-null.
32+
wil::com_ptr<ICoreWebView2Profile> m_webviewProfile;
33+
};

SampleApps/WebView2APISample/WebView2APISample.rc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,11 @@ BEGIN
356356
MENUITEM "Toggle Suppress Default Find Dialog", IDC_SUPPRESS_DEFAULT_FIND_DIALOG
357357
MENUITEM "Toggle Should Match Word", IDC_SHOULD_MATCH_WHOLE_WORD
358358
END
359+
POPUP "Origin Configuration for Features"
360+
BEGIN
361+
MENUITEM "Set Feature Settings For Origins", IDM_SCENARIO_SET_ORIGIN_FEATURES
362+
MENUITEM "Get Feature Settings For Origins", IDM_SCENARIO_GET_ORIGIN_FEATURES
363+
END
359364
POPUP "Sensitivity Label"
360365
BEGIN
361366
MENUITEM "Set PIRM Allowlist", IDM_SCENARIO_PIRM_SET_ALLOWLIST

SampleApps/WebView2APISample/WebView2APISample.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,13 @@
536536
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
537537
<ImportGroup Label="ExtensionTargets">
538538
<Import Project="..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
539-
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.4071-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.4071-prerelease\build\native\Microsoft.Web.WebView2.targets')" />
539+
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.4126-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.4126-prerelease\build\native\Microsoft.Web.WebView2.targets')" />
540540
</ImportGroup>
541541
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
542542
<PropertyGroup>
543543
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
544544
</PropertyGroup>
545545
<Error Condition="!Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
546-
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.4071-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.4071-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
546+
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.4126-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.4126-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
547547
</Target>
548548
</Project>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Web.WebView2" version="1.0.4071-prerelease" targetFramework="native" />
3+
<package id="Microsoft.Web.WebView2" version="1.0.4126-prerelease" targetFramework="native" />
44
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.220201.1" targetFramework="native" />
55
</packages>

SampleApps/WebView2APISample/resource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@
222222
#define IDM_SCENARIO_SERVICE_WORKER_POST_MESSAGE 3010
223223
#define IDM_SCENARIO_WEBRTC_UDP_PORT_CONFIGURATION 3011
224224
#define IDM_TOGGLE_SERVICE_WORKER_JS_API_SETTING 3012
225+
#define IDM_SCENARIO_SET_ORIGIN_FEATURES 3013
226+
#define IDM_SCENARIO_GET_ORIGIN_FEATURES 3014
225227
// Base ID for dynamically created controls in TextInputDialog.
226228
// IDs 5000-5099 are reserved for dynamic controls (10 groups x 10 options).
227229
#define IDC_DYNAMIC_CONTROL_BASE 5000

SampleApps/WebView2WindowsFormsBrowser/WebView2WindowsFormsBrowser.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<PlatformTarget>AnyCPU</PlatformTarget>
2626
</PropertyGroup>
2727
<ItemGroup>
28-
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.4071-prerelease" />
28+
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.4126-prerelease" />
2929
</ItemGroup>
3030
<ItemGroup>
3131
<Folder Include="assets\" />

0 commit comments

Comments
 (0)