|
| 1 | +# Background |
| 2 | +The WebView2 team has been asked for an API to allow end developers to clear the browsing data that is stored in the User Data Folder. We are creating an api that will allow developers to clear the browsing data programtically in which the developer can specify the data type to clear. |
| 3 | + |
| 4 | +In this document we describe the updated API. We'd appreciate your feedback. |
| 5 | + |
| 6 | + |
| 7 | +# Description |
| 8 | +The clear browsing data api is an asyncrhonous api that clears data based on the browsing data kind that is passed in as a parameter. |
| 9 | + |
| 10 | + |
| 11 | +# Examples |
| 12 | + |
| 13 | +## Win32 C++ |
| 14 | +```cpp |
| 15 | +/// Function to clear the password form data |
| 16 | +bool EnvironmentComponent::ClearPasswordAutofillData() |
| 17 | +{ |
| 18 | + wil::com_ptr<ICoreWebView2Environment2> environment; |
| 19 | + webView->get_Environment(&environment); |
| 20 | + CHECK_FAILURE(environment->ClearBrowsingData(COREWEBVIEW2_BROWSING_DATA_KIND_PASSWORD_AUTOFILL, |
| 21 | + Callback<ICoreWebView2ClearBrowsingDataHandler>( |
| 22 | + [this](HRESULT error, bool success) -> HRESULT { |
| 23 | + if (success){ |
| 24 | + return true; |
| 25 | + } else { |
| 26 | + return false; |
| 27 | + } |
| 28 | + return S_OK; |
| 29 | + }) |
| 30 | + .Get())); |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +### .NET, WinRT |
| 35 | +```c# |
| 36 | +webView2Control.NavigationStarting += ClearPasswordAutofillData; |
| 37 | + |
| 38 | +private void ClearPasswordAutofillData() |
| 39 | +{ |
| 40 | + var environment = webView2Control.CoreWebView2.Environment; |
| 41 | + try |
| 42 | + { |
| 43 | + await environment.ClearBrowsingDataAsync(dataKind); |
| 44 | + } |
| 45 | + catch (System.Runtime.InteropServices.COMException exception) |
| 46 | + { |
| 47 | + // An exception occured |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +``` |
| 52 | + |
| 53 | +# API Notes |
| 54 | +See [API Details](#api-details) section below for API reference. |
| 55 | + |
| 56 | + |
| 57 | +# API Details |
| 58 | + |
| 59 | +## Win32 C++ |
| 60 | + |
| 61 | +```IDL |
| 62 | +interface ICoreWebView2Environment5 |
| 63 | +interface ICoreWebView2ClearBrowsingDataCompletedHandler; |
| 64 | +
|
| 65 | +/// Specifies the datatype for the |
| 66 | +/// `ICoreWebView2StagingEnvironment2::ClearBrowsingData` method. |
| 67 | +[v1_enum] |
| 68 | +typedef enum COREWEBVIEW2_BROWSING_DATA_KIND { |
| 69 | + /// Specifies app cache data. |
| 70 | + COREWEBVIEW2_BROWSING_DATA_KIND_APP_CACHE = 0X01, |
| 71 | +
|
| 72 | + /// Specifies file systems data. |
| 73 | + COREWEBVIEW2_BROWSING_DATA_KIND_FILE_SYSTEMS = 0X02, |
| 74 | +
|
| 75 | + /// Specifies indexeddb data. |
| 76 | + COREWEBVIEW2_BROWSING_DATA_KIND_INDEXEDDB = 0X03, |
| 77 | +
|
| 78 | + /// Specifies local storage data. |
| 79 | + COREWEBVIEW2_BROWSING_DATA_KIND_LOCAL_STORAGE = 0X04, |
| 80 | +
|
| 81 | + /// Specifies web SQL data. |
| 82 | + COREWEBVIEW2_BROWSING_DATA_KIND_WEB_SQL = 0X05, |
| 83 | +
|
| 84 | + /// Specifies cache storage. |
| 85 | + COREWEBVIEW2_BROWSING_DATA_KIND_CACHE_STORAGE = 0X06, |
| 86 | +
|
| 87 | + /// Specifies dom storage data. This browsing data kind is inclusive |
| 88 | + /// of COREWEBVIEW2_BROWSING_DATA_KIND_APP_CACHE, COREWEBVIEW2_BROWSING_DATA_KIND_FILE_SYSTEMS, |
| 89 | + /// COREWEBVIEW2_BROWSING_DATA_KIND_INDEXEDDB, COREWEBVIEW2_BROWSING_DATA_KIND_LOCAL_STORAGE, |
| 90 | + /// COREWEBVIEW2_BROWSING_DATA_KIND_WEB_SQL, COREWEBVIEW2_BROWSING_DATA_KIND_CACHE_STORAGE. |
| 91 | + /// In addition to these data kinds, dom storage also includese embedder dom storage and |
| 92 | + /// background fetch. |
| 93 | + COREWEBVIEW2_BROWSING_DATA_KIND_DOM_STORAGE = 0x07, |
| 94 | + |
| 95 | + /// Specifies http cookies data. |
| 96 | + COREWEBVIEW2_BROWSING_DATA_KIND_COOKIES = 0x08, |
| 97 | +
|
| 98 | + /// Specifies media licenses. |
| 99 | + COREWEBVIEW2_BROWSING_DATA_KIND_MEDIA_LICENSES = 0X09, |
| 100 | + |
| 101 | + /// Specifies plugin data. |
| 102 | + COREWEBVIEW2_BROWSING_DATA_KIND_PLUGIN = 0X10, |
| 103 | +
|
| 104 | + /// Specifies site usage data. |
| 105 | + COREWEBVIEW2_BROWSING_DATA_KIND_SITE_USAGE = 0X11, |
| 106 | +
|
| 107 | + /// Specifies durable permissions data. |
| 108 | + COREWEBVIEW2_BROWSING_DATA_KIND_DURABLE_PERMISSIONS = 0X12, |
| 109 | +
|
| 110 | + /// Specifies external protocols data. |
| 111 | + COREWEBVIEW2_BROWSING_DATA_KIND_EXTERNAL_PROTOCOLS = 0X013, |
| 112 | +
|
| 113 | + /// Specifies isolated origins data. |
| 114 | + COREWEBVIEW2_BROWSING_DATA_KIND_ISOLATED_ORIGINS = 0X14, |
| 115 | +
|
| 116 | + /// Specifies trust tokens data. |
| 117 | + COREWEBVIEW2_BROWSING_DATA_KIND_TRUST_TOKENS = 0X15, |
| 118 | +
|
| 119 | + /// Specifies conversions data (the completion of meaningful user action on |
| 120 | + /// the advertiser's web site by a user who has interacted with an ad from that advertiser). |
| 121 | + COREWEBVIEW2_BROWSING_DATA_KIND_CONVERSIONS = 0X16, |
| 122 | +
|
| 123 | + /// Specifies site data. This browsing data kind |
| 124 | + /// is inclusive of COREWEBVIEW2_BROWSING_DATA_KIND_DOM_STORAGE, |
| 125 | + /// COREWEBVIEW2_BROWSING_DATA_KIND_COOKIES, COREWEBVIEW2_BROWSING_DATA_KIND_MEDIA_LICENSES, |
| 126 | + /// COREWEBVIEW2_BROWSING_DATA_KIND_PLUGIN, COREWEBVIEW2_BROWSING_DATA_KIND_SITE_USAGE, |
| 127 | + /// COREWEBVIEW2_BROWSING_DATA_KIND_DURABLE_PERMISSIONS, COREWEBVIEW2_BROWSING_DATA_KIND_EXTERNAL_PROTOCOLS, |
| 128 | + /// COREWEBVIEW2_BROWSING_DATA_KIND_ISOLATED_ORIGINS, COREWEBVIEW2_BROWSING_DATA_KIND_TRUST_TOKENS, and |
| 129 | + /// COREWEBVIEW2_BROWSING_DATA_KIND_CONVERSIONS. If on an android OS, site data also includes web app data. |
| 130 | + COREWEBVIEW2_BROWSING_DATA_KIND_SITE = 0x17, |
| 131 | +
|
| 132 | + /// Specifies content in in the HTTP cache including images and other files. |
| 133 | + COREWEBVIEW2_BROWSING_DATA_KIND_HTTP_CACHE = 0x18, |
| 134 | +
|
| 135 | + /// Specifies download history data. |
| 136 | + COREWEBVIEW2_BROWSING_DATA_KIND_DOWNLOAD_HISTORY = 0x19, |
| 137 | +
|
| 138 | + /// Specifies general autofill form data. |
| 139 | + /// This excludes password forms and includes information like: |
| 140 | + /// names, street and email addresses, phone numbers, and arbitrary input. |
| 141 | + COREWEBVIEW2_BROWSING_DATA_KIND_GENERAL_AUTOFILL = 0x20, |
| 142 | +
|
| 143 | + /// Specifies password autofill forms data. |
| 144 | + COREWEBVIEW2_BROWSING_DATA_KIND_PASSWORD_AUTOFILL = 0x21, |
| 145 | +
|
| 146 | + /// Specifies browsing history data. |
| 147 | + COREWEBVIEW2_BROWSING_DATA_KIND_BROWSING_HISTORY = 0x22, |
| 148 | +
|
| 149 | + /// Specifies bookmarks data. |
| 150 | + COREWEBVIEW2_BROWSING_DATA_KIND_BOOKMARKS = 0x23, |
| 151 | +
|
| 152 | + /// Specifies settings data. |
| 153 | + COREWEBVIEW2_BROWSING_DATA_KIND_SETTINGS = 0x24, |
| 154 | +
|
| 155 | + /// Specifies content settings data. |
| 156 | + COREWEBVIEW2_BROWSING_DATA_KIND_CONTENT_SETTINGS = 0x25, |
| 157 | +
|
| 158 | + /// Specifies local custom dictionary data. |
| 159 | + COREWEBVIEW2_BROWSING_DATA_KIND_LOCAL_CUSTOM_DICTIONARY = 0x26, |
| 160 | +
|
| 161 | + /// Specifies profile data that should be wiped to make it look like a new profile. |
| 162 | + /// This does not delete account-scoped data like passwords but will remove access |
| 163 | + /// to account-scoped data by signing the user out. |
| 164 | + /// This browsing data kind if inclusive of COREWEBVIEW2_BROWSING_DATA_KIND_SITE, |
| 165 | + /// COREWEBVIEW2_BROWSING_DATA_KIND_HTTP_CACHE, COREWEBVIEW2_BROWSING_DATA_KIND_DOWNLOAD_HISTORY, |
| 166 | + /// COREWEBVIEW2_BROWSING_DATA_KIND_GENERAL_AUTOFILL, COREWEBVIEW2_BROWSING_DATA_KIND_PASSWORD_AUTOFILL, |
| 167 | + /// COREWEBVIEW2_BROWSING_DATA_KIND_BROWSING_HISTORY, COREWEBVIEW2_BROWSING_DATA_KIND_CONTENT_SETTINGS, |
| 168 | + /// COREWEBVIEW2_BROWSING_DATA_KIND_BOOKMARKS, COREWEBVIEW2_BROWSING_DATA_KIND_SETTINGS, |
| 169 | + /// COREWEBVIEW2_BROWSING_DATA_KIND_LOCAL_CUSTOM_DICTIONARY. |
| 170 | + COREWEBVIEW2_BROWSING_DATA_KIND_PROFILE = 0X27, |
| 171 | +} COREWEBVIEW2_BROWSING_DATA_KIND; |
| 172 | +
|
| 173 | +[uuid(4ecfcb16-dd09-4464-9a71-fd8e2d3ac0a2), object, pointer_default(unique)] |
| 174 | +interface ICoreWebView2SEnvironment5 : ICoreWebView2Environment { |
| 175 | + /// Clear browsing data based on a specific data type and time duration. Specify the |
| 176 | + /// data type with the `dataType` parameter. The `start_time` parameter specifies |
| 177 | + /// the beginning time to clear the data and the `end_time` parameter specifies |
| 178 | + /// the ending time to stop clearing the data. |
| 179 | + /// The time parameters are the number of seconds since the UNIX epoch. |
| 180 | + HRESULT ClearBrowsingData( |
| 181 | + [in] COREWEBVIEW2_BROWSING_DATA_KIND dataKind, |
| 182 | + [in] ICoreWebView2ClearBrowsingDataCompletedHandler *handler); |
| 183 | +} |
| 184 | +
|
| 185 | +[uuid(c2b78e49-5bf5-4d38-a535-668a8a8a30d9), object, pointer_default(unique)] |
| 186 | +interface ICoreWebView2ClearBrowsingDataCompletedHandler : IUnknown { |
| 187 | + /// Provide the completion status and result of the corresponding |
| 188 | + /// asynchronous method. |
| 189 | + HRESULT Invoke([in] HRESULT errorCode, [in] BOOL isSuccessful); |
| 190 | +} |
| 191 | +``` |
| 192 | +### .NET, WinRT |
| 193 | +```c# |
| 194 | +namespace Microsoft.Web.WebView2.Core |
| 195 | +{ |
| 196 | + public partial class CoreWebView2Environment |
| 197 | + { |
| 198 | + public async Task<bool> ClearBrowsingDataAsync(CoreWebView2BrowsingDataKind dataKind); |
| 199 | + } |
| 200 | +} |
| 201 | +``` |
0 commit comments