@@ -8,21 +8,23 @@ In this document we describe the updated API. We'd appreciate your feedback.
88
99
1010# Description
11- We expose browsing data clearing in two different asynchronous APIs:
11+ We expose browsing data clearing in two asynchronous APIs:
1212``` IDL
1313HRESULT ClearBrowsingData(
1414 [in] uint64 dataKinds,
15- [in] ICoreWebView2ClearBrowsingDataCompletedHandler * handler);
15+ [in] ICoreWebView2ClearBrowsingDataCompletedHandler* handler);
1616
1717HRESULT ClearBrowsingDataInTimeRange(
1818 [in] uint64 dataKinds,
1919 [in] double startTime,
2020 [in] double endTime,
21- [in] ICoreWebView2ClearBrowsingDataCompletedHandler * handler);
21+ [in] ICoreWebView2ClearBrowsingDataCompletedHandler* handler);
2222```
2323The first method takes a uint64 parameter that consists of one or more COREWEBVIEW2_BROWSING_DATA_KIND passed in as well as a handler which will indicate if the proper data has been cleared successfully. The handler will respond with one of three results, which indicate that the method was successful, interrupted, or failed. This method clears the data for all time.
2424
2525The 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 double time parameters correspond to how many seconds since the UNIX epoch.
26+
27+ Both methods clear the data with the associated profile in which the method is called on.
2628
2729The browsing data kinds that are supported are listed below. These data kinds follow a hierarchical structure in which nested bullet points are included in their parent bullet point's data kind.
2830Ex: DOM storage is included in site data which is included in the profile data. Each of the following bullets correspond to a COREWEBVIEW2_BROWSING_DATA_KIND.
@@ -44,38 +46,32 @@ Ex: DOM storage is included in site data which is included in the profile data.
4446## Win32 C++
4547``` cpp
4648
47- // / Function to clear the autofill data
49+ // / Function to clear the autofill data from the last hour
4850bool EnvironmentComponent::ClearAutofillData ()
4951{
50- wil::com_ptr<ICoreWebView2Environment5> environment;
51- webView->get_Environment(&environment);
52- uint64_t data_kinds = COREWEBVIEW2_BROWSING_DATA_KIND_GENERAL_AUTOFILL |
53- COREWEBVIEW2_BROWSING_DATA_KIND_PASSWORD_AUTOSAVE;
54- CHECK_FAILURE (environment->ClearBrowsingData(
55- data_kinds,
56- Callback<ICoreWebView2ClearBrowsingDataCompletedHandler >(
57- [ this] (HRESULT error, COREWEBVIEW2_CLEAR_BROWSING_DATA_RESULT_KIND result_kind)
58- -> HRESULT {
59- LPCWSTR result;
60- switch (result_kind)
61- {
62- case COREWEBVIEW2_CLEAR_BROWSING_DATA_RESULT_KIND_SUCCEEDED:
63- result = L"Succeeded";
64- break;
65- case COREWEBVIEW2_CLEAR_BROWSING_DATA_RESULT_KIND_INTERRUPTED:
66- result = L"Interrupted";
67- break;
68- case COREWEBVIEW2_CLEAR_BROWSING_DATA_RESULT_KIND_FAILED:
69- result = L"Failed";
70- break;
71- default:
72- result = L"Failed";
73- break;
74- }
75- MessageBox(nullptr, result, L"Clear Browsing Data", MB_OK);
76- return S_OK;
77- })
78- .Get()));
52+ wwil::com_ptr<ICoreWebView2> coreWebView2;
53+ CHECK_FAILURE (m_controller->get_CoreWebView2(&coreWebView2));
54+
55+ auto webview7 = coreWebView2.try_query<ICoreWebView2_7>();
56+ if (webview7)
57+ {
58+ wil::com_ptr<ICoreWebView2Profile> profile;
59+ CHECK_FAILURE (webview7->get_Profile(&profile));
60+ double end_time = (double)std::time(nullptr);
61+ double start_time = end_time - 3600;
62+ CHECK_FAILURE(profile->ClearBrowsingDataInTimeRange(
63+ data_kinds, start_time, end_time,
64+ Callback<ICoreWebView2StagingClearBrowsingDataCompletedHandler >(
65+ [ this] (HRESULT error, bool is_successful)
66+ -> HRESULT {
67+ LPCWSTR result = is_successful ? L"Succeeded" : L"Failed";
68+ RunAsync([ this, result] ( ) {
69+ MessageBox(nullptr, result, L"Clear Browsing Data", MB_OK);
70+ });
71+ return S_OK;
72+ })
73+ .Get()));
74+ }
7975}
8076```
8177
@@ -84,12 +80,15 @@ bool EnvironmentComponent::ClearAutofillData()
8480
8581private void ClearAutofillData ()
8682{
87- var environment = webView2Control .CoreWebView2 .Environment ;
88- try
89- {
90- CoreWebView2BrowsingDataKind dataKinds = CoreWebView2BrowsingDataKind .GeneralAutofill | CoreWebView2BrowsingDataKind .PasswordAutosave ;
91- await environment .ClearBrowsingDataAsync ((UInt64 )dataKinds );
92- }
83+ CoreWebView2Profile profile ;
84+ profile = webView .CoreWebView2 .Profile ;
85+ double endTime = DateTimeOffset .Now .ToUnixTimeSeconds ();
86+ double startTime = endTime - 3600 ;
87+ bool isSuccessful = await WebViewProfile .ClearBrowsingDataAsync ((UInt64 )dataKind , startTime , endTime );
88+ MessageBox .Show (this ,
89+ (isSuccessful ) ? " Succeeded" : " Failed" ,
90+ " Clear Browsing Data" );
91+
9392}
9493
9594```
@@ -103,47 +102,31 @@ See [API Details](#api-details) section below for API reference.
103102## Win32 C++
104103
105104``` IDL
106- interface ICoreWebView2Environment5
105+ interface ICoreWebView2Profile
107106interface ICoreWebView2ClearBrowsingDataCompletedHandler;
108107
109- [v1_enum]
110- typedef enum COREWEBVIEW2_CLEAR_BROWSING_DATA_RESULT_KIND {
111- /// Specifies success, all of the specified data kinds
112- /// were cleared.
113- COREWEBVIEW2_CLEAR_BROWSING_DATA_RESULT_KIND_SUCCEEDED,
114-
115- /// Specifies interruption, not all of the specified data kinds
116- /// were cleared, although a subset of the data kinds may
117- /// have been cleared before the method call was interrupted.
118- COREWEBVIEW2_CLEAR_BROWSING_DATA_RESULT_KIND_INTERRUPTED,
119-
120- /// Specifies failure, not all of the specified data kinds were
121- /// cleared.
122- COREWEBVIEW2_CLEAR_BROWSING_DATA_RESULT_KIND_FAILED,
123- } COREWEBVIEW2_CLEAR_BROWSING_DATA_RESULT_KIND;
124-
125108/// Specifies the datatype for the
126- /// `ICoreWebView2Environment2 ::ClearBrowsingData` method.
109+ /// `ICoreWebView2Profile ::ClearBrowsingData` method.
127110[v1_enum]
128111typedef enum COREWEBVIEW2_BROWSING_DATA_KIND {
129- /// Specifies data stored by the AppCache DOM API .
130- COREWEBVIEW2_BROWSING_DATA_KIND_APP_CACHE = 1<< 0,
112+ /// Specifies data stored by the AppCache DOM feature .
113+ COREWEBVIEW2_BROWSING_DATA_KIND_APP_CACHE = 1 << 0,
131114
132- /// Specifies data stored by the FileSystems DOM API .
133- COREWEBVIEW2_BROWSING_DATA_KIND_FILE_SYSTEMS = 1<< 1,
115+ /// Specifies file systems data .
116+ COREWEBVIEW2_BROWSING_DATA_KIND_FILE_SYSTEMS = 1 << 1,
134117
135- /// Specifies data stored by the IndexedDB DOM API .
136- COREWEBVIEW2_BROWSING_DATA_KIND_INDEXED_DB = 1<< 2,
118+ /// Specifies data stored by the IndexedDB DOM feature .
119+ COREWEBVIEW2_BROWSING_DATA_KIND_INDEXED_DB = 1 << 2,
137120
138- /// Specifies data stored by the LocalStorage DOM API.
139- COREWEBVIEW2_BROWSING_DATA_KIND_LOCAL_STORAGE = 1<< 3,
121+ /// Specifies data stored by the localStorage DOM API.
122+ COREWEBVIEW2_BROWSING_DATA_KIND_LOCAL_STORAGE = 1 << 3,
140123
141124 /// Specifies data stored by the Web SQL database DOM API.
142- COREWEBVIEW2_BROWSING_DATA_KIND_WEB_SQL = 1<< 4,
125+ COREWEBVIEW2_BROWSING_DATA_KIND_WEB_SQL = 1 << 4,
143126
144127 /// Specifies cache storage which stores the network requests
145- /// and responses from the CacheStorage DOM API.
146- COREWEBVIEW2_BROWSING_DATA_KIND_CACHE_STORAGE = 1<< 5,
128+ /// and responses.
129+ COREWEBVIEW2_BROWSING_DATA_KIND_CACHE_STORAGE = 1 << 5,
147130
148131 /// Specifies DOM storage data. This browsing data kind is inclusive
149132 /// of COREWEBVIEW2_BROWSING_DATA_KIND_APP_CACHE,
@@ -152,13 +135,16 @@ typedef enum COREWEBVIEW2_BROWSING_DATA_KIND {
152135 /// COREWEBVIEW2_BROWSING_DATA_KIND_LOCAL_STORAGE,
153136 /// COREWEBVIEW2_BROWSING_DATA_KIND_WEB_SQL,
154137 /// COREWEBVIEW2_BROWSING_DATA_KIND_CACHE_STORAGE.
155- COREWEBVIEW2_BROWSING_DATA_KIND_DOM_STORAGE = COREWEBVIEW2_BROWSING_DATA_KIND_APP_CACHE|
156- COREWEBVIEW2_BROWSING_DATA_KIND_FILE_SYSTEMS | COREWEBVIEW2_BROWSING_DATA_KIND_INDEXED_DB |
157- COREWEBVIEW2_BROWSING_DATA_KIND_LOCAL_STORAGE | COREWEBVIEW2_BROWSING_DATA_KIND_WEB_SQL |
138+ COREWEBVIEW2_BROWSING_DATA_KIND_DOM_STORAGE =
139+ COREWEBVIEW2_BROWSING_DATA_KIND_APP_CACHE|
140+ COREWEBVIEW2_BROWSING_DATA_KIND_FILE_SYSTEMS |
141+ COREWEBVIEW2_BROWSING_DATA_KIND_INDEXED_DB |
142+ COREWEBVIEW2_BROWSING_DATA_KIND_LOCAL_STORAGE |
143+ COREWEBVIEW2_BROWSING_DATA_KIND_WEB_SQL |
158144 COREWEBVIEW2_BROWSING_DATA_KIND_CACHE_STORAGE,
159145
160146 /// Specifies HTTP cookies data.
161- COREWEBVIEW2_BROWSING_DATA_KIND_COOKIES = 1<< 6,
147+ COREWEBVIEW2_BROWSING_DATA_KIND_COOKIES = 1 << 6,
162148
163149 /// Specifies site data. This browsing data kind
164150 /// is inclusive of COREWEBVIEW2_BROWSING_DATA_KIND_DOM_STORAGE and
@@ -167,50 +153,56 @@ typedef enum COREWEBVIEW2_BROWSING_DATA_KIND {
167153 COREWEBVIEW2_BROWSING_DATA_KIND_COOKIES,
168154
169155 /// Specifies content in the HTTP cache including images and other files.
170- COREWEBVIEW2_BROWSING_DATA_KIND_HTTP_CACHE = 1<< 7,
156+ COREWEBVIEW2_BROWSING_DATA_KIND_HTTP_CACHE = 1 << 7,
171157
172158 /// Specifies download history data.
173- COREWEBVIEW2_BROWSING_DATA_KIND_DOWNLOAD_HISTORY = 1<< 8,
159+ COREWEBVIEW2_BROWSING_DATA_KIND_DOWNLOAD_HISTORY = 1 << 8,
174160
175161 /// Specifies general autofill form data.
176162 /// This excludes password information and includes information like:
177163 /// names, street and email addresses, phone numbers, and arbitrary input.
178164 /// This also includes payment data.
179- COREWEBVIEW2_BROWSING_DATA_KIND_GENERAL_AUTOFILL = 1<< 9,
165+ COREWEBVIEW2_BROWSING_DATA_KIND_GENERAL_AUTOFILL = 1 << 9,
180166
181167 /// Specifies password autosave data.
182- COREWEBVIEW2_BROWSING_DATA_KIND_PASSWORD_AUTOSAVE = 1<< 10,
168+ COREWEBVIEW2_BROWSING_DATA_KIND_PASSWORD_AUTOSAVE = 1 << 10,
183169
184170 /// Specifies browsing history data.
185- COREWEBVIEW2_BROWSING_DATA_KIND_BROWSING_HISTORY = 1<< 11,
171+ COREWEBVIEW2_BROWSING_DATA_KIND_BROWSING_HISTORY = 1 << 11,
186172
187173 /// Specifies settings data.
188- COREWEBVIEW2_BROWSING_DATA_KIND_SETTINGS = 1<< 12,
174+ COREWEBVIEW2_BROWSING_DATA_KIND_SETTINGS = 1 << 12,
189175
190176 /// Specifies profile data that should be wiped to make it look like a new profile.
177+ /// This does not delete account-scoped data like passwords but will remove access
178+ /// to account-scoped data by signing the user out.
191179 /// This browsing data kind is inclusive of COREWEBVIEW2_BROWSING_DATA_KIND_SITE,
192180 /// COREWEBVIEW2_BROWSING_DATA_KIND_HTTP_CACHE,
193181 /// COREWEBVIEW2_BROWSING_DATA_KIND_DOWNLOAD_HISTORY,
194182 /// COREWEBVIEW2_BROWSING_DATA_KIND_GENERAL_AUTOFILL,
195183 /// COREWEBVIEW2_BROWSING_DATA_KIND_PASSWORD_AUTOSAVE,
196184 /// COREWEBVIEW2_BROWSING_DATA_KIND_BROWSING_HISTORY, and
197185 /// COREWEBVIEW2_BROWSING_DATA_KIND_SETTINGS.
198- COREWEBVIEW2_BROWSING_DATA_KIND_PROFILE = COREWEBVIEW2_BROWSING_DATA_KIND_SITE |
199- COREWEBVIEW2_BROWSING_DATA_KIND_HTTP_CACHE | COREWEBVIEW2_BROWSING_DATA_KIND_DOWNLOAD_HISTORY |
200- COREWEBVIEW2_BROWSING_DATA_KIND_GENERAL_AUTOFILL | COREWEBVIEW2_BROWSING_DATA_KIND_PASSWORD_AUTOSAVE
201- | COREWEBVIEW2_BROWSING_DATA_KIND_BROWSING_HISTORY | COREWEBVIEW2_BROWSING_DATA_KIND_SETTINGS,
186+ COREWEBVIEW2_BROWSING_DATA_KIND_PROFILE =
187+ COREWEBVIEW2_BROWSING_DATA_KIND_SITE |
188+ COREWEBVIEW2_BROWSING_DATA_KIND_HTTP_CACHE |
189+ COREWEBVIEW2_BROWSING_DATA_KIND_DOWNLOAD_HISTORY |
190+ COREWEBVIEW2_BROWSING_DATA_KIND_GENERAL_AUTOFILL |
191+ COREWEBVIEW2_BROWSING_DATA_KIND_PASSWORD_AUTOSAVE |
192+ COREWEBVIEW2_BROWSING_DATA_KIND_BROWSING_HISTORY |
193+ COREWEBVIEW2_BROWSING_DATA_KIND_SETTINGS,
202194} COREWEBVIEW2_BROWSING_DATA_KIND;
203195
204- [uuid(4ecfcb16-dd09-4464-9a71-fd8e2d3ac0a2), object, pointer_default(unique)]
205- interface ICoreWebView2Environment2 : ICoreWebView2Environment {
196+ [uuid(DAF8B1F9-276D-410C-B481-58CBADF85C9C), object, pointer_default(unique)]
197+ interface ICoreWebView2Profile : IUnknown {
198+
206199 /// Clear browsing data based on a data type. This method takes two parameters,
207- /// the first being a mask of one or more COREWEBVIEW2_BROWSING_DATAKIND. Multiple
208- /// COREWEBVIEW2_BROWSING_DATA_KIND values can be orred together to create a mask
200+ /// the first being a mask of one or more COREWEBVIEW2_BROWSING_DATAKIND values. OR operation(s)
201+ /// can be applied to multiple COREWEBVIEW2_BROWSING_DATA_KIND values to create a mask
209202 /// representing multiple data types. The browsing data kinds that are supported
210203 /// are listed below. These data kinds follow a hierarchical structure in which
211204 /// nested bullet points are included in their parent bullet point's data kind.
212205 /// Ex: DOM storage is encompassed in site data which is encompassed in the profile data.
213- /// Each of the following bullets correspond to a COREWEBVIEW2_BROWSING_DATA_KIND.
214206 /// * Profile
215207 /// * Site Data
216208 /// * DOM Storage: App Cache, File Systems, Indexed DB, Local Storage, Web SQL, Cache
@@ -224,43 +216,42 @@ interface ICoreWebView2Environment2 : ICoreWebView2Environment {
224216 /// * Settings
225217 /// The completed handler will be invoked when the browsing data has been cleared and will
226218 /// indicate if the specified data was properly cleared.
227- /// ClearBrowsingData clears the dataKinds for all time.
219+ /// If the WebView object is closed before the clear browsing data operation
220+ /// has completed, the handler will be released, but not invoked. In this case
221+ /// the clear browsing data operation may or may not be completed.
222+ /// ClearBrowsingData clears the `dataKinds` for all time.
228223 HRESULT ClearBrowsingData(
229- [in] uint64 dataKinds,
230- [in] ICoreWebView2ClearBrowsingDataCompletedHandler * handler);
231-
224+ [in] UINT64 dataKinds,
225+ [in] ICoreWebView2ClearBrowsingDataCompletedHandler* handler);
226+
232227 /// ClearBrowsingDataInTimeRange takes in two additional parameters for the
233228 /// start and end time for which it should clear the data between. The startTime and endTime
234229 /// parameters correspond to the number of seconds since the UNIX epoch.
230+ ///
231+ /// \snippet AppWindow.cpp ClearBrowsingData
235232 HRESULT ClearBrowsingDataInTimeRange(
236- [in] uint64 dataKinds,
233+ [in] UINT64 dataKinds,
237234 [in] double startTime,
238235 [in] double endTime,
239- [in] ICoreWebView2ClearBrowsingDataCompletedHandler * handler);
236+ [in] ICoreWebView2ClearBrowsingDataCompletedHandler* handler);
240237}
241238
242239/// The caller implements this interface to receive the ClearBrowsingData result.
243- [uuid(c2b78e49-5bf5-4d38-a535-668a8a8a30d9 ), object, pointer_default(unique)]
240+ [uuid(27676699-FE17-4E2B-8C1B-267395A04ED5 ), object, pointer_default(unique)]
244241interface ICoreWebView2ClearBrowsingDataCompletedHandler : IUnknown {
245242 /// Provide the completion status and result of the corresponding
246243 /// asynchronous method. The result indicates if the ClearBrowsingData
247- /// call succeeded, was interrupted, or failed .
244+ /// call has completed successfully and all intended data has been cleared .
248245 HRESULT Invoke(
249246 [in] HRESULT errorCode,
250- [in] COREWEBVIEW2_CLEAR_BROWSING_DATA_RESULT_KIND result );
247+ [in] BOOL isSuccessful );
251248}
249+
252250```
253251### .NET, WinRT
254252``` c#
255253namespace Microsoft .Web .WebView2 .Core
256254{
257- enum CoreWebView2ClearBrowsingDataResultKind
258- {
259- Succeeded = 0 ,
260- Interrupted = 1 ,
261- Failed = 2 ,
262- };
263-
264255 [Flags ] enum CoreWebView2BrowsingDataKind
265256 {
266257 AppCache = 1 ,
@@ -283,8 +274,11 @@ namespace Microsoft.Web.WebView2.Core
283274
284275 public partial class CoreWebView2Environment
285276 {
277+ /// The ClearBrowsingDataAsync method may be overloaded to take either one parameter - dataKinds, or three parameters - dataKinds, startTime, and endTime.
278+ /// We're taking ulong here because we need to accept orred enum values like HttpCache | DownloadHistory which isn't a value in the DataKind enum.
279+ /// We need to take ulong to get the proper masked thru, s it OK to take the enum as the parameter type here in COM, WinRT, and .NET?
286280 public async Task <CoreWebView2ClearBrowsingDataResultKind > ClearBrowsingDataAsync (ulong dataKinds );
287- public async Task <CoreWebView2ClearBrowsingDataResultKind > ClearBrowsingDataInTimeRangeAsync (ulong dataKinds , double startTime , double endTime );
281+ public async Task <CoreWebView2ClearBrowsingDataResultKind > ClearBrowsingDataAsync (ulong dataKinds , double startTime , double endTime );
288282 }
289283}
290284```
0 commit comments