Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions SampleApps/WebView2APISample/AppWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class AppWindow
bool SuppressDefaultFindDialog();
bool IsCaseSensitive();
wil::com_ptr<ICoreWebView2FindOptions> SetDefaultFindOptions();

void SetupFindEventHandlers(wil::com_ptr<ICoreWebView2Find> webView2find);
// Find on Page member
std::wstring m_findOnPageLastSearchTerm;
Expand Down
27 changes: 0 additions & 27 deletions SampleApps/WebView2APISample/ScriptComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,33 +649,6 @@ void ScriptComponent::HandleCDPTargets()
.Get(),
&m_targetDetachedToken));
receiver.reset();
CHECK_FAILURE(
m_webView->GetDevToolsProtocolEventReceiver(L"Target.targetCreated", &receiver));
CHECK_FAILURE(receiver->add_DevToolsProtocolEventReceived(
Callback<ICoreWebView2DevToolsProtocolEventReceivedEventHandler>(
[this](
ICoreWebView2* sender,
ICoreWebView2DevToolsProtocolEventReceivedEventArgs* args) -> HRESULT
{
// Shared worker targets are not auto attached. Have to attach it explicitly.
wil::unique_cotaskmem_string jsonMessage;
CHECK_FAILURE(args->get_ParameterObjectAsJson(&jsonMessage));
std::wstring type = GetJSONStringField(jsonMessage.get(), L"type");
if (type == L"shared_worker")
{
std::wstring targetId = GetJSONStringField(jsonMessage.get(), L"targetId");
std::wstring parameters =
L"{\"targetId\":\"" + targetId + L"\",\"flatten\": true}";
// Call Target.attachToTarget and ignore returned value, let
// Target.attachedToTarget to handle the result.
m_webView->CallDevToolsProtocolMethod(
L"Target.attachToTarget", parameters.c_str(), nullptr);
}
return S_OK;
})
.Get(),
&m_targetCreatedToken));
receiver.reset();
CHECK_FAILURE(
m_webView->GetDevToolsProtocolEventReceiver(L"Target.targetInfoChanged", &receiver));
CHECK_FAILURE(receiver->add_DevToolsProtocolEventReceived(
Expand Down
39 changes: 39 additions & 0 deletions SampleApps/WebView2APISample/SettingsComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,13 +1291,20 @@ bool SettingsComponent::HandleWindowMessage(
case IDM_TRACKING_PREVENTION_LEVEL_STRICT:
SetTrackingPreventionLevel(COREWEBVIEW2_TRACKING_PREVENTION_LEVEL_STRICT);
return true;
case IDM_ENHANCED_SECURITY_MODE_LEVEL_OFF:
SetEnhancedSecurityModeLevel(COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL_OFF);
return true;
case IDM_ENHANCED_SECURITY_MODE_LEVEL_STRICT:
SetEnhancedSecurityModeLevel(COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL_STRICT);
return true;
case ID_SETTINGS_NON_CLIENT_REGION_SUPPORT_ENABLED:
{
//![ToggleNonClientRegionSupportEnabled]
BOOL nonClientRegionSupportEnabled;
wil::com_ptr<ICoreWebView2Settings9> settings;
settings = m_settings.try_query<ICoreWebView2Settings9>();
CHECK_FEATURE_RETURN(settings);

CHECK_FAILURE(
settings->get_IsNonClientRegionSupportEnabled(&nonClientRegionSupportEnabled));
if (nonClientRegionSupportEnabled)
Expand Down Expand Up @@ -1807,6 +1814,38 @@ void SettingsComponent::SetTrackingPreventionLevel(COREWEBVIEW2_TRACKING_PREVENT
}
//! [SetTrackingPreventionLevel]

//! [SetEnhancedSecurityModeLevel]
void SettingsComponent::SetEnhancedSecurityModeLevel(
COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL value)
{
wil::com_ptr<ICoreWebView2_13> webView2_13;
webView2_13 = m_webView.try_query<ICoreWebView2_13>();

if (webView2_13)
{
wil::com_ptr<ICoreWebView2Profile> profile;
CHECK_FAILURE(webView2_13->get_Profile(&profile));

auto experimentalProfile9 = profile.try_query<ICoreWebView2ExperimentalProfile9>();
if (experimentalProfile9)
{
CHECK_FAILURE(experimentalProfile9->put_EnhancedSecurityModeLevel(value));

const wchar_t* levelText = L"Off";
if (value == COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL_STRICT)
{
levelText = L"Strict";
}

MessageBox(
nullptr,
(std::wstring(L"Enhanced Security Mode level is set to ") + levelText).c_str(),
L"Enhanced Security Mode Level", MB_OK);
}
}
}
//! [SetEnhancedSecurityModeLevel]

SettingsComponent::~SettingsComponent()
{
m_webView->remove_NavigationStarting(m_navigationStartingToken);
Expand Down
2 changes: 2 additions & 0 deletions SampleApps/WebView2APISample/SettingsComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class SettingsComponent : public ComponentBase

void SetTrackingPreventionLevel(COREWEBVIEW2_TRACKING_PREVENTION_LEVEL value);

void SetEnhancedSecurityModeLevel(COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL value);

~SettingsComponent() override;

private:
Expand Down
5 changes: 5 additions & 0 deletions SampleApps/WebView2APISample/WebView2APISample.rc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ BEGIN
MENUITEM "Balanced", IDM_TRACKING_PREVENTION_LEVEL_BALANCED
MENUITEM "Strict", IDM_TRACKING_PREVENTION_LEVEL_STRICT
END
POPUP "Enhanced Security Mode Level"
BEGIN
MENUITEM "Off", IDM_ENHANCED_SECURITY_MODE_LEVEL_OFF
MENUITEM "Strict", IDM_ENHANCED_SECURITY_MODE_LEVEL_STRICT
END
MENUITEM "Toggle Non-Client Region Support", ID_SETTINGS_NON_CLIENT_REGION_SUPPORT_ENABLED
END
POPUP "&View"
Expand Down
4 changes: 2 additions & 2 deletions SampleApps/WebView2APISample/WebView2APISample.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,13 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<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')" />
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.3712-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.3712-prerelease\build\native\Microsoft.Web.WebView2.targets')" />
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.3796-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.3796-prerelease\build\native\Microsoft.Web.WebView2.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<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>
</PropertyGroup>
<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'))" />
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.3712-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.3712-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.3796-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.3796-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
</Target>
</Project>
2 changes: 1 addition & 1 deletion SampleApps/WebView2APISample/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Web.WebView2" version="1.0.3712-prerelease" targetFramework="native" />
<package id="Microsoft.Web.WebView2" version="1.0.3796-prerelease" targetFramework="native" />
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.220201.1" targetFramework="native" />
</packages>
2 changes: 2 additions & 0 deletions SampleApps/WebView2APISample/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
#define IDC_EDIT_SAVE_AS_FILENAME 262
#define IDC_CHECK_SAVE_AS_ALLOW_REPLACE 263
#define IDC_SAVE_AS_KIND 264
#define IDM_ENHANCED_SECURITY_MODE_LEVEL_OFF 265
#define IDM_ENHANCED_SECURITY_MODE_LEVEL_STRICT 266
#define IDM_TOGGLE_TOPMOST_WINDOW 300
#define IDM_PROCESS_EXTENDED_INFO 301
#define IDE_ADDRESSBAR 1000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3712-prerelease" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3796-prerelease" />
</ItemGroup>
<ItemGroup>
<Folder Include="assets\" />
Expand Down
9 changes: 9 additions & 0 deletions SampleApps/WebView2WpfBrowser/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ found in the LICENSE file.
<CommandBinding Command="{x:Static local:MainWindow.NewWindowWithOptionsCommand}" Executed="NewWindowWithOptionsCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.CreateNewThreadCommand}" Executed="CreateNewThreadCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.TrackingPreventionLevelCommand}" Executed="TrackingPreventionLevelCommandExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<!-- #if USE_WEBVIEW2_EXPERIMENTAL -->
<CommandBinding Command="{x:Static local:MainWindow.EnhancedSecurityModeLevelCommand}" Executed="EnhancedSecurityModeLevelCommandExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<!-- #endif -->
<CommandBinding Command="{x:Static local:MainWindow.PrintDialogCommand}" Executed="PrintDialogCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.PrintToDefaultPrinterCommand}" Executed="PrintToDefaultPrinterCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.PrintToPrinterCommand}" Executed="PrintToPrinterCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
Expand Down Expand Up @@ -201,6 +204,12 @@ found in the LICENSE file.
<MenuItem Header="_Balanced" Command="{x:Static local:MainWindow.TrackingPreventionLevelCommand}" CommandParameter="Balanced"/>
<MenuItem Header="_Strict" Command="{x:Static local:MainWindow.TrackingPreventionLevelCommand}" CommandParameter="Strict"/>
</MenuItem>
<!-- #if USE_WEBVIEW2_EXPERIMENTAL -->
<MenuItem Header="_Enhanced Security Mode Level">
<MenuItem Header="_Off" Command="{x:Static local:MainWindow.EnhancedSecurityModeLevelCommand}" CommandParameter="Off"/>
<MenuItem Header="_Strict" Command="{x:Static local:MainWindow.EnhancedSecurityModeLevelCommand}" CommandParameter="Strict"/>
</MenuItem>
<!-- #endif -->
<MenuItem Header="Toggle Non-Client Region Support" Command="{x:Static local:MainWindow.NonClientRegionSupportCommand}"/>
</MenuItem>
<MenuItem Header="_View">
Expand Down
35 changes: 20 additions & 15 deletions SampleApps/WebView2WpfBrowser/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ public partial class MainWindow : Window
public static RoutedCommand ExtensionsCommand = new RoutedCommand();
public static RoutedCommand TrackingPreventionLevelCommand = new RoutedCommand();
public static RoutedCommand EnhancedSecurityModeLevelCommand = new RoutedCommand();
public static RoutedCommand EnhancedSecurityModeGetBypassListCommand = new RoutedCommand();
public static RoutedCommand EnhancedSecurityModeSetBypassListCommand = new RoutedCommand();
public static RoutedCommand EnhancedSecurityModeGetEnforceListCommand = new RoutedCommand();
public static RoutedCommand EnhancedSecurityModeSetEnforceListCommand = new RoutedCommand();
public static RoutedCommand WebRtcUdpPortConfigCommand = new RoutedCommand();
public static RoutedCommand PrintDialogCommand = new RoutedCommand();
public static RoutedCommand PrintToDefaultPrinterCommand = new RoutedCommand();
Expand Down Expand Up @@ -1022,22 +1018,31 @@ void SetTrackingPreventionLevel(CoreWebView2TrackingPreventionLevel value)
}
// <SetTrackingPreventionLevel>


void EnhancedSecurityModeLevelCommandExecuted(object target, ExecutedRoutedEventArgs e)
{
#if USE_WEBVIEW2_EXPERIMENTAL
string level = e.Parameter.ToString();
if (level == "Off")
{
SetEnhancedSecurityModeLevel(CoreWebView2EnhancedSecurityModeLevel.Off);
}
else
{
SetEnhancedSecurityModeLevel(CoreWebView2EnhancedSecurityModeLevel.Strict);
}
#endif
}
void EnhancedSecurityModeGetBypassListCommandExecuted(object target, ExecutedRoutedEventArgs e)
{
}
void EnhancedSecurityModeSetBypassListCommandExecuted(object target, ExecutedRoutedEventArgs e)
{
}
void EnhancedSecurityModeGetEnforceListCommandExecuted(object target, ExecutedRoutedEventArgs e)
{
}
void EnhancedSecurityModeSetEnforceListCommandExecuted(object target, ExecutedRoutedEventArgs e)

#if USE_WEBVIEW2_EXPERIMENTAL
// <SetEnhancedSecurityModeLevel>
void SetEnhancedSecurityModeLevel(CoreWebView2EnhancedSecurityModeLevel value)
{
WebViewProfile.EnhancedSecurityModeLevel = value;
MessageBox.Show(this, "Enhanced security mode level is set successfully", "Enhanced Security Mode Level");
}
// <SetEnhancedSecurityModeLevel>
#endif

void WebRtcUdpPortConfigCommandExecuted(object target, ExecutedRoutedEventArgs e)
{
#if USE_WEBVIEW2_EXPERIMENTAL
Expand Down
2 changes: 1 addition & 1 deletion SampleApps/WebView2WpfBrowser/WebView2WpfBrowser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3712-prerelease" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3796-prerelease" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
</Project>
Loading