|
| 1 | +# Background |
| 2 | + |
| 3 | +[Edge SmartScreen](https://docs.microsoft.com/en-us/deployedge/microsoft-edge-security-smartscreen) helps you identify reported phishing and malware websites,also helps you make informed decisions about downloads. |
| 4 | + |
| 5 | +In the current version of the Edge browser, users can switch the state of SmartScreen at any time. However, the webview2 application can only be set at initialization. In order to add more flexibility to the webview2 application. This API is added to keep the SmartScreen setting consistent with the browser. Development Users can control the status of SmartScreen at any time. |
| 6 | + |
| 7 | +In this document we describe the new setting. We'd appreciate your feedback. |
| 8 | + |
| 9 | + |
| 10 | +# Description |
| 11 | +The configuration of SmartScreen is stored in the user data folder. So its configuration is bound to the environment. Users can use ICoreWebView2Environment to control it. |
| 12 | + |
| 13 | +The default value for `IsSmartScreenEnabled` is `true`. |
| 14 | +When this setting is set to `false`, It will turn off SmartScreen protection when visiting web pages. |
| 15 | + |
| 16 | +Disabling/Enabling `IsSmartScreenEnabled` will take effect immediately. |
| 17 | + |
| 18 | + |
| 19 | +# Examples |
| 20 | +```cpp |
| 21 | +wil::com_ptr<ICoreWebView2Environment> enviroment; |
| 22 | +void SettingsComponent::ToggleSmartScreenEnabled() |
| 23 | +{ |
| 24 | + wil::com_ptr<ICoreWebView2Environment11> coreWebView2Enviroment11; |
| 25 | + coreWebView2Enviroment11 = |
| 26 | + m_webViewEnvironment.try_query<ICoreWebView2Environment11>(); |
| 27 | + if(coreWebView2Enviroment11) |
| 28 | + { |
| 29 | + BOOL enabled; |
| 30 | + CHECK_FAILURE(coreWebView2Enviroment11->get_IsSmartScreenEnabled(&enabled)); |
| 31 | + CHECK_FAILURE(coreWebView2Enviroment11->put_IsSmartScreenEnabled(enabled ? FALSE : TRUE)); |
| 32 | + } |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +```c# |
| 37 | +void ToggleSmartScreenEnabled() |
| 38 | +{ |
| 39 | + var coreWebView2Enviroment = webView.CoreWebView2.Environment; |
| 40 | + coreWebView2Enviroment.IsSmartScreenEnabled = !coreWebView2Enviroment.IsSmartScreenEnabled; |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +# Remarks |
| 45 | + All WebViews using the same user data folder share the same SmartScreen setting. When it is changed, the change will be applied to all WebViews using the same user data folder. |
| 46 | + |
| 47 | +# API Notes |
| 48 | + |
| 49 | +See [API Details](#api-details) section below for API reference. |
| 50 | + |
| 51 | +# API Details |
| 52 | + |
| 53 | +## Win32 C++ |
| 54 | +```cpp |
| 55 | +[uuid(dc7ee01f-1fbf-440c-a11a-64472d18a27e), object, pointer_default(unique)] |
| 56 | +interface ICoreWebView2Environment11 : ICoreWebView2Environment10 { |
| 57 | + /// SmartScreen helps you identify reported phishing and malware websites |
| 58 | + /// also helps you make informed decisions about downloads. |
| 59 | + /// `IsSmartScreenEnabled` is used to control whether SmartScreen is turned on or not. |
| 60 | + /// All WebViews using the same user data folder share the same SmartScreen setting. |
| 61 | + /// When it is changed, the change will be applied to all WebViews using the |
| 62 | + /// same user data folder. |
| 63 | + /// \snippet SettingsComponent.cpp ToggleSmartScreenEnabled. |
| 64 | + /// Get the IsSmartScreenEnabled property needs to be used after |
| 65 | + /// CreateCoreWebView2Controller is called.Otherwise return E_ACCESSDENIED. |
| 66 | + [propget] HRESULT IsSmartScreenEnabled([out, retval] BOOL* value); |
| 67 | + |
| 68 | + /// Set the IsSmartScreenEnabled property. |
| 69 | + /// This configuration will be saved. |
| 70 | + /// The configuration from the last exit will be used on the next open |
| 71 | + [propput] HRESULT IsSmartScreenEnabled([in] BOOL value); |
| 72 | + |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +## .NET and WinRT |
| 77 | + |
| 78 | +```c# |
| 79 | +namespace Microsoft.Web.WebView2.Core |
| 80 | +{ |
| 81 | + public partial class CoreWebView2Environment |
| 82 | + { |
| 83 | + public bool IsSmartScreenEnabled { get; set; }; |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +``` |
0 commit comments