|
| 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. Developers want to be able to clear data between each of their customers, clear space, and to clear data on the fly. |
| 3 | + |
| 4 | +Currently developers can delete the entire User Data Folder to clear this data. This has a few drawbacks: it removes the entire User Data Folder instead of specific parts which incurs performance costs later on, the WebView must be shutdown fully and then re-initialized, and deleting the entire User Data Folder is a complex process. |
| 5 | +We are creating an API that will allow developers to clear the browsing data programatically in which the developer can specify the data kind to clear. |
| 6 | + |
| 7 | +In this document we describe the updated API. We'd appreciate your feedback. |
| 8 | + |
| 9 | + |
| 10 | +# Description |
| 11 | +We expose browsing data clearing in three asynchronous APIs: |
| 12 | +```IDL |
| 13 | +HRESULT ClearBrowsingData( |
| 14 | + [in] COREWEBVIEW2_BROWSING_DATA_KINDS dataKinds, |
| 15 | + [in] ICoreWebView2ClearBrowsingDataCompletedHandler* handler); |
| 16 | +
|
| 17 | +HRESULT ClearBrowsingDataInTimeRange( |
| 18 | + [in] COREWEBVIEW2_BROWSING_DATA_KINDS dataKinds, |
| 19 | + [in] double startTime, |
| 20 | + [in] double endTime, |
| 21 | + [in] ICoreWebView2ClearBrowsingDataCompletedHandler* handler); |
| 22 | +
|
| 23 | +HRESULT ClearBrowsingDataAll( |
| 24 | + [in] ICoreWebView2ClearBrowsingDataCompletedHandler* handler); |
| 25 | +``` |
| 26 | +The first method takes `COREWEBVIEW2_BROWSING_DATA_KINDS` which corresponds to the data type(s) to clear as well as a handler which will indicate if the proper data has been cleared successfully. This method clears the data regardless of timestamp. |
| 27 | + |
| 28 | +The second method takes the same parameters for the dataKinds and handler, as well as a start and end time in which the API should clear the corresponding data between. The time parameters correspond to how many seconds have passed since the UNIX epoch. Passing in a value of zero or less than zero (up to negative infinity) will clear the corresponding data for any time before the `endTime`. Passing in a value of the current time or greater (up to positive infinity) will clear the corresponding data for any time after the `startTime`. For example passing in negative infinity and positive infinity as the time parameters will clear the entirety of the corresponding data. The timestamp represents the time at which the data was created. |
| 29 | + |
| 30 | +The third method only takes one parameter, the handler. This method clears the data regardless of timestamp and will clear all of the data included in the profile data kind listed below. |
| 31 | + |
| 32 | +All methods clear the data for the associated profile in which the method is called on. |
| 33 | + |
| 34 | +# Examples |
| 35 | + |
| 36 | +## Win32 C++ |
| 37 | +```cpp |
| 38 | + |
| 39 | +// Function to clear the autofill data from the last hour |
| 40 | +void ClearAutofillData() |
| 41 | +{ |
| 42 | + wwil::com_ptr<ICoreWebView2> coreWebView2; |
| 43 | + CHECK_FAILURE(m_controller->get_CoreWebView2(&coreWebView2)); |
| 44 | + |
| 45 | + auto webview7 = coreWebView2.try_query<ICoreWebView2_7>(); |
| 46 | + if (webview7) |
| 47 | + { |
| 48 | + wil::com_ptr<ICoreWebView2Profile> profile; |
| 49 | + CHECK_FAILURE(webview7->get_Profile(&profile)); |
| 50 | + double endTime = (double)std::time(nullptr); |
| 51 | + double startTime = endTime - 3600; |
| 52 | + // Get the current time and offset the current time by 3600 seconds to clear the data |
| 53 | + // from the start time (one hour ago), until the end time (present time). |
| 54 | + // This will clear the data for the last hour. |
| 55 | + COREWEBVIEW2_BROWSING_DATA_KINDS dataKinds = (COREWEBVIEW2_BROWSING_DATA_KINDS) |
| 56 | + (COREWEBVIEW2_BROWSING_DATA_KINDS_GENERAL_AUTOFILL | |
| 57 | + COREWEBVIEW2_BROWSING_DATA_KINDS_PASSWORD_AUTOSAVE); |
| 58 | + CHECK_FAILURE(profile->ClearBrowsingDataInTimeRange( |
| 59 | + dataKinds, startTime, endTime, |
| 60 | + Callback<ICoreWebView2ClearBrowsingDataCompletedHandler>( |
| 61 | + [this](HRESULT error) |
| 62 | + -> HRESULT { |
| 63 | + return S_OK; |
| 64 | + }) |
| 65 | + .Get())); |
| 66 | + } |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +### .NET, WinRT |
| 71 | +```c# |
| 72 | + |
| 73 | +private void ClearAutofillData() |
| 74 | +{ |
| 75 | + CoreWebView2Profile profile; |
| 76 | + if (webView.CoreWebView2 != null) |
| 77 | + { |
| 78 | + profile = webView.CoreWebView2.Profile; |
| 79 | + // Get the current time, the time in which the browsing data will be cleared until. |
| 80 | + System.DateTime endTime = DateTime.Now; |
| 81 | + System.DateTime startTime = DateTime.Now.AddHours(-1); |
| 82 | + // Offset the current time by one hour to clear the browsing data from the last hour. |
| 83 | + CoreWebView2BrowsingDataKinds dataKinds = (CoreWebView2BrowsingDataKinds)(CoreWebView2BrowsingDataKinds.GeneralAutofill | CoreWebView2BrowsingDataKinds.PasswordAutosave); |
| 84 | + await profile.ClearBrowsingDataAsync(dataKinds, startTime, endTime); |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +``` |
| 89 | + |
| 90 | +# API Notes |
| 91 | +See [API Details](#api-details) section below for API reference. |
| 92 | + |
| 93 | + |
| 94 | +# API Details |
| 95 | + |
| 96 | +## Win32 C++ |
| 97 | + |
| 98 | +```IDL |
| 99 | +interface ICoreWebView2ClearBrowsingDataCompletedHandler; |
| 100 | +
|
| 101 | +/// Specifies the datatype for the |
| 102 | +/// `ICoreWebView2Profile::ClearBrowsingData` method. |
| 103 | +[v1_enum] |
| 104 | +typedef enum COREWEBVIEW2_BROWSING_DATA_KINDS { |
| 105 | + /// Specifies data stored by the AppCache DOM feature. |
| 106 | + COREWEBVIEW2_BROWSING_DATA_KINDS_APP_CACHE = 1 << 0, |
| 107 | +
|
| 108 | + /// Specifies file systems data. |
| 109 | + COREWEBVIEW2_BROWSING_DATA_KINDS_FILE_SYSTEMS = 1 << 1, |
| 110 | +
|
| 111 | + /// Specifies data stored by the IndexedDB DOM feature. |
| 112 | + COREWEBVIEW2_BROWSING_DATA_KINDS_INDEXED_DB = 1 << 2, |
| 113 | +
|
| 114 | + /// Specifies data stored by the localStorage DOM API. |
| 115 | + COREWEBVIEW2_BROWSING_DATA_KINDS_LOCAL_STORAGE = 1 << 3, |
| 116 | +
|
| 117 | + /// Specifies data stored by the Web SQL database DOM API. |
| 118 | + COREWEBVIEW2_BROWSING_DATA_KINDS_WEB_SQL = 1 << 4, |
| 119 | +
|
| 120 | + /// Specifies data stored by the CacheStorge DOM API. |
| 121 | + COREWEBVIEW2_BROWSING_DATA_KINDS_CACHE_STORAGE = 1 << 5, |
| 122 | +
|
| 123 | + /// Specifies DOM storage data, now and future. This browsing data kind is |
| 124 | + /// inclusive of COREWEBVIEW2_BROWSING_DATA_KINDS_APP_CACHE, |
| 125 | + /// COREWEBVIEW2_BROWSING_DATA_KINDS_FILE_SYSTEMS, |
| 126 | + /// COREWEBVIEW2_BROWSING_DATA_KINDS_INDEXED_DB, |
| 127 | + /// COREWEBVIEW2_BROWSING_DATA_KINDS_LOCAL_STORAGE, |
| 128 | + /// COREWEBVIEW2_BROWSING_DATA_KINDS_WEB_SQL, |
| 129 | + /// COREWEBVIEW2_BROWSING_DATA_KINDS_CACHE_STORAGE. |
| 130 | + /// New DOM storage data types may be added to this data kind in the future. |
| 131 | + COREWEBVIEW2_BROWSING_DATA_KINDS_ALL_DOM_STORAGE = 1 << 6, |
| 132 | +
|
| 133 | + /// Specifies HTTP cookies data. |
| 134 | + COREWEBVIEW2_BROWSING_DATA_KINDS_COOKIES = 1 << 7, |
| 135 | +
|
| 136 | + /// Specifies all site data, now and future. This browsing data kind |
| 137 | + /// is inclusive of COREWEBVIEW2_BROWSING_DATA_KINDS_ALL_DOM_STORAGE and |
| 138 | + /// COREWEBVIEW2_BROWSING_DATA_KINDS_COOKIES. New site data types |
| 139 | + /// may be added to this data kind in the future. |
| 140 | + COREWEBVIEW2_BROWSING_DATA_KINDS_ALL_SITE = 1 << 8, |
| 141 | +
|
| 142 | + /// Specifies disk cache. |
| 143 | + COREWEBVIEW2_BROWSING_DATA_KINDS_DISK_CACHE = 1 << 9, |
| 144 | +
|
| 145 | + /// Specifies download history data. |
| 146 | + COREWEBVIEW2_BROWSING_DATA_KINDS_DOWNLOAD_HISTORY = 1 << 10, |
| 147 | +
|
| 148 | + /// Specifies general autofill form data. |
| 149 | + /// This excludes password information and includes information like: |
| 150 | + /// names, street and email addresses, phone numbers, and arbitrary input. |
| 151 | + /// This also includes payment data. |
| 152 | + COREWEBVIEW2_BROWSING_DATA_KINDS_GENERAL_AUTOFILL = 1 << 11, |
| 153 | +
|
| 154 | + /// Specifies password autosave data. |
| 155 | + COREWEBVIEW2_BROWSING_DATA_KINDS_PASSWORD_AUTOSAVE = 1 << 12, |
| 156 | +
|
| 157 | + /// Specifies browsing history data. |
| 158 | + COREWEBVIEW2_BROWSING_DATA_KINDS_BROWSING_HISTORY = 1 << 13, |
| 159 | +
|
| 160 | + /// Specifies settings data. |
| 161 | + COREWEBVIEW2_BROWSING_DATA_KINDS_SETTINGS = 1 << 14, |
| 162 | +
|
| 163 | + /// Specifies profile data that should be wiped to make it look like a new profile. |
| 164 | + /// This does not delete account-scoped data like passwords but will remove access |
| 165 | + /// to account-scoped data by signing the user out. |
| 166 | + /// Specifies all profile data, now and future. New profile data types may be added |
| 167 | + /// to this data kind in the future. |
| 168 | + /// This browsing data kind is inclusive of COREWEBVIEW2_BROWSING_DATA_KINDS_ALL_SITE, |
| 169 | + /// COREWEBVIEW2_BROWSING_DATA_KINDS_DISK_CACHE, |
| 170 | + /// COREWEBVIEW2_BROWSING_DATA_KINDS_DOWNLOAD_HISTORY, |
| 171 | + /// COREWEBVIEW2_BROWSING_DATA_KINDS_GENERAL_AUTOFILL, |
| 172 | + /// COREWEBVIEW2_BROWSING_DATA_KINDS_PASSWORD_AUTOSAVE, |
| 173 | + /// COREWEBVIEW2_BROWSING_DATA_KINDS_BROWSING_HISTORY, and |
| 174 | + /// COREWEBVIEW2_BROWSING_DATA_KINDS_SETTINGS. |
| 175 | + COREWEBVIEW2_BROWSING_DATA_KINDS_ALL_PROFILE = 1 << 15, |
| 176 | +} COREWEBVIEW2_BROWSING_DATA_KINDS; |
| 177 | +
|
| 178 | +[uuid(DAF8B1F9-276D-410C-B481-58CBADF85C9C), object, pointer_default(unique)] |
| 179 | +interface ICoreWebView2Profile : IUnknown { |
| 180 | +
|
| 181 | + /// Clear browsing data based on a data type. This method takes two parameters, |
| 182 | + /// the first being a mask of one or more `COREWEBVIEW2_BROWSING_DATA_KINDS`. OR operation(s) |
| 183 | + /// can be applied to multiple `COREWEBVIEW2_BROWSING_DATA_KINDS` to create a mask |
| 184 | + /// representing those data types. The browsing data kinds that are supported |
| 185 | + /// are listed below. These data kinds follow a hierarchical structure in which |
| 186 | + /// nested bullet points are included in their parent bullet point's data kind. |
| 187 | + /// Ex: DOM storage is encompassed in site data which is encompassed in the profile data. |
| 188 | + /// * All Profile |
| 189 | + /// * All Site Data |
| 190 | + /// * All DOM Storage: App Cache, File Systems, Indexed DB, Local Storage, Web SQL, Cache |
| 191 | + /// Storage |
| 192 | + /// * Cookies |
| 193 | + /// * Disk Cache |
| 194 | + /// * Download History |
| 195 | + /// * General Autofill |
| 196 | + /// * Password Autosave |
| 197 | + /// * Browsing History |
| 198 | + /// * Settings |
| 199 | + /// The completed handler will be invoked when the browsing data has been cleared and |
| 200 | + /// will indicate if the specified data was properly cleared. |
| 201 | + /// Because this is an asynchronous operation, code that is dependent on the cleared |
| 202 | + /// data must be placed in the callback of this operation. |
| 203 | + /// If the WebView object is closed before the clear browsing data operation |
| 204 | + /// has completed, the handler will be released, but not invoked. In this case |
| 205 | + /// the clear browsing data operation may or may not be completed. |
| 206 | + /// ClearBrowsingData clears the `dataKinds` regardless of timestamp. |
| 207 | +
|
| 208 | + HRESULT ClearBrowsingData( |
| 209 | + [in] COREWEBVIEW2_BROWSING_DATA_KINDS dataKinds, |
| 210 | + [in] ICoreWebView2ClearBrowsingDataCompletedHandler* handler); |
| 211 | + |
| 212 | + /// ClearBrowsingDataInTimeRange behaves like ClearBrowsingData except that it |
| 213 | + /// takes in two additional parameters for the start and end time for which it |
| 214 | + /// should clear the data between. The `startTime` and `endTime` |
| 215 | + /// parameters correspond to the number of seconds since the UNIX epoch. |
| 216 | + /// The `startTime` will be offset by -1.0 and the `endTime` will be offset by +1.0 |
| 217 | + /// to ensure the last fractional second is cleared on each respective end. |
| 218 | + /// `startTime` is inclusive while `endTime` is exclusive, therefore the data will |
| 219 | + /// clear [startTime, endTime). |
| 220 | + |
| 221 | + HRESULT ClearBrowsingDataInTimeRange( |
| 222 | + [in] COREWEBVIEW2_BROWSING_DATA_KINDS dataKinds, |
| 223 | + [in] double startTime, |
| 224 | + [in] double endTime, |
| 225 | + [in] ICoreWebView2ClearBrowsingDataCompletedHandler* handler); |
| 226 | +
|
| 227 | + /// ClearBrowsingDataAll behaves like ClearBrowsingData except that it |
| 228 | + /// clears the entirety of the data associated with the profile it is called on. |
| 229 | + /// It clears the data regardless of timestamp. |
| 230 | +
|
| 231 | + HRESULT ClearBrowsingDataAll( |
| 232 | + [in] ICoreWebView2ClearBrowsingDataCompletedHandler* handler); |
| 233 | +} |
| 234 | +
|
| 235 | +/// The caller implements this interface to receive the `ClearBrowsingData` result. |
| 236 | +[uuid(27676699-FE17-4E2B-8C1B-267395A04ED5), object, pointer_default(unique)] |
| 237 | +interface ICoreWebView2ClearBrowsingDataCompletedHandler : IUnknown { |
| 238 | + |
| 239 | + /// Provide the completion status of the corresponding asynchronous method. |
| 240 | + HRESULT Invoke([in] HRESULT errorCode); |
| 241 | +} |
| 242 | +
|
| 243 | +``` |
| 244 | +### .NET, WinRT |
| 245 | +```c# |
| 246 | +namespace Microsoft.Web.WebView2.Core |
| 247 | +{ |
| 248 | + [Flags] enum CoreWebView2BrowsingDataKinds |
| 249 | + { |
| 250 | + AppCache = 1, |
| 251 | + FileSystems = 2, |
| 252 | + IndexedDb = 4, |
| 253 | + LocalStorage = 8, |
| 254 | + WebSql = 16, |
| 255 | + CacheStorage = 32, |
| 256 | + AllDomStorage = 64, |
| 257 | + Cookies = 128, |
| 258 | + AllSite = 256, |
| 259 | + DiskCache = 512, |
| 260 | + DownloadHistory = 1024, |
| 261 | + GeneralAutofill = 2048, |
| 262 | + PasswordAutosave = 4096, |
| 263 | + BrowsingHistory = 8192, |
| 264 | + Settings = 16384, |
| 265 | + AllProfile = 32768, |
| 266 | + }; |
| 267 | + |
| 268 | + public partial class CoreWebView2Profile |
| 269 | + { |
| 270 | + public async Task ClearBrowsingDataAsync(CoreWebView2BrowsingDataKinds dataKinds); |
| 271 | + /// .NET and WinRT will take the official DateTime object for start and end time parameters. |
| 272 | + public async Task ClearBrowsingDataAsync(CoreWebView2BrowsingDataKinds dataKinds, DateTime startTime, DateTime endTime); |
| 273 | + public async Task ClearBrowsingDataAsync(); |
| 274 | + } |
| 275 | +} |
| 276 | +``` |
0 commit comments