diff --git a/SampleApps/WebView2APISample/AppWindow.h b/SampleApps/WebView2APISample/AppWindow.h index 92d50a1..5b1cf2e 100644 --- a/SampleApps/WebView2APISample/AppWindow.h +++ b/SampleApps/WebView2APISample/AppWindow.h @@ -242,6 +242,7 @@ class AppWindow bool SuppressDefaultFindDialog(); bool IsCaseSensitive(); wil::com_ptr SetDefaultFindOptions(); + void SetupFindEventHandlers(wil::com_ptr webView2find); // Find on Page member std::wstring m_findOnPageLastSearchTerm; diff --git a/SampleApps/WebView2APISample/ScriptComponent.cpp b/SampleApps/WebView2APISample/ScriptComponent.cpp index 89ce9ee..62e9874 100644 --- a/SampleApps/WebView2APISample/ScriptComponent.cpp +++ b/SampleApps/WebView2APISample/ScriptComponent.cpp @@ -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( - [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( diff --git a/SampleApps/WebView2APISample/SettingsComponent.cpp b/SampleApps/WebView2APISample/SettingsComponent.cpp index 5e9d2cd..c0e5cea 100644 --- a/SampleApps/WebView2APISample/SettingsComponent.cpp +++ b/SampleApps/WebView2APISample/SettingsComponent.cpp @@ -1291,6 +1291,12 @@ 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] @@ -1298,6 +1304,7 @@ bool SettingsComponent::HandleWindowMessage( wil::com_ptr settings; settings = m_settings.try_query(); CHECK_FEATURE_RETURN(settings); + CHECK_FAILURE( settings->get_IsNonClientRegionSupportEnabled(&nonClientRegionSupportEnabled)); if (nonClientRegionSupportEnabled) @@ -1807,6 +1814,38 @@ void SettingsComponent::SetTrackingPreventionLevel(COREWEBVIEW2_TRACKING_PREVENT } //! [SetTrackingPreventionLevel] +//! [SetEnhancedSecurityModeLevel] +void SettingsComponent::SetEnhancedSecurityModeLevel( + COREWEBVIEW2_ENHANCED_SECURITY_MODE_LEVEL value) +{ + wil::com_ptr webView2_13; + webView2_13 = m_webView.try_query(); + + if (webView2_13) + { + wil::com_ptr profile; + CHECK_FAILURE(webView2_13->get_Profile(&profile)); + + auto experimentalProfile9 = profile.try_query(); + 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); diff --git a/SampleApps/WebView2APISample/SettingsComponent.h b/SampleApps/WebView2APISample/SettingsComponent.h index 6946d0f..109328b 100644 --- a/SampleApps/WebView2APISample/SettingsComponent.h +++ b/SampleApps/WebView2APISample/SettingsComponent.h @@ -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: diff --git a/SampleApps/WebView2APISample/WebView2APISample.rc b/SampleApps/WebView2APISample/WebView2APISample.rc index c3d206c..5904d53 100644 --- a/SampleApps/WebView2APISample/WebView2APISample.rc +++ b/SampleApps/WebView2APISample/WebView2APISample.rc @@ -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" diff --git a/SampleApps/WebView2APISample/WebView2APISample.vcxproj b/SampleApps/WebView2APISample/WebView2APISample.vcxproj index 8f85c4e..ec3c5d6 100644 --- a/SampleApps/WebView2APISample/WebView2APISample.vcxproj +++ b/SampleApps/WebView2APISample/WebView2APISample.vcxproj @@ -532,13 +532,13 @@ - + 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}. - + diff --git a/SampleApps/WebView2APISample/packages.config b/SampleApps/WebView2APISample/packages.config index 69420a6..f3a3bf6 100644 --- a/SampleApps/WebView2APISample/packages.config +++ b/SampleApps/WebView2APISample/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/SampleApps/WebView2APISample/resource.h b/SampleApps/WebView2APISample/resource.h index 89dd78b..d2474cd 100644 --- a/SampleApps/WebView2APISample/resource.h +++ b/SampleApps/WebView2APISample/resource.h @@ -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 diff --git a/SampleApps/WebView2WindowsFormsBrowser/WebView2WindowsFormsBrowser.csproj b/SampleApps/WebView2WindowsFormsBrowser/WebView2WindowsFormsBrowser.csproj index a53e961..a54a57f 100644 --- a/SampleApps/WebView2WindowsFormsBrowser/WebView2WindowsFormsBrowser.csproj +++ b/SampleApps/WebView2WindowsFormsBrowser/WebView2WindowsFormsBrowser.csproj @@ -25,7 +25,7 @@ AnyCPU - + diff --git a/SampleApps/WebView2WpfBrowser/MainWindow.xaml b/SampleApps/WebView2WpfBrowser/MainWindow.xaml index a36444f..55d27cc 100644 --- a/SampleApps/WebView2WpfBrowser/MainWindow.xaml +++ b/SampleApps/WebView2WpfBrowser/MainWindow.xaml @@ -78,6 +78,9 @@ found in the LICENSE file. + + + @@ -201,6 +204,12 @@ found in the LICENSE file. + + + + + + diff --git a/SampleApps/WebView2WpfBrowser/MainWindow.xaml.cs b/SampleApps/WebView2WpfBrowser/MainWindow.xaml.cs index a7f31cd..7d564f6 100644 --- a/SampleApps/WebView2WpfBrowser/MainWindow.xaml.cs +++ b/SampleApps/WebView2WpfBrowser/MainWindow.xaml.cs @@ -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(); @@ -1022,22 +1018,31 @@ void SetTrackingPreventionLevel(CoreWebView2TrackingPreventionLevel value) } // - 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 + // + void SetEnhancedSecurityModeLevel(CoreWebView2EnhancedSecurityModeLevel value) { + WebViewProfile.EnhancedSecurityModeLevel = value; + MessageBox.Show(this, "Enhanced security mode level is set successfully", "Enhanced Security Mode Level"); } + // +#endif + void WebRtcUdpPortConfigCommandExecuted(object target, ExecutedRoutedEventArgs e) { #if USE_WEBVIEW2_EXPERIMENTAL diff --git a/SampleApps/WebView2WpfBrowser/WebView2WpfBrowser.csproj b/SampleApps/WebView2WpfBrowser/WebView2WpfBrowser.csproj index 9e94ff2..ffde1d8 100644 --- a/SampleApps/WebView2WpfBrowser/WebView2WpfBrowser.csproj +++ b/SampleApps/WebView2WpfBrowser/WebView2WpfBrowser.csproj @@ -61,7 +61,7 @@ - +