@@ -175,6 +175,22 @@ HRESULT AppWindow::DeleteProfile(ICoreWebView2* webView2)
175
175
CHECK_FAILURE(webView2->get_Profile(&profile));
176
176
CHECK_FAILURE(profile2->Delete());
177
177
}
178
+
179
+ EventRegistrationToken m_profileDeletedEventToken = {};
180
+ void AppWindow::AddProfileDeleted(ICoreWebView2* webView2)
181
+ {
182
+ CHECK_FAILURE(webView2->add_ProfileDeleted(
183
+ Microsoft::WRL::Callback<ICoreWebView2StagingProfileDeletedEventHandler >(
184
+ [ this] (ICoreWebView2Staging9* sender, IUnknown* args) {
185
+ CloseAppWindow();
186
+ return S_OK;
187
+ }).Get(), &m_profileDeletedEventToken));
188
+ }
189
+
190
+ void AppWindow::RemoveProfileDeleted(ICoreWebView2* webView2)
191
+ {
192
+ CHECK_FAILURE(webView2->remove_ProfileDeleted(m_profileDeletedEventToken));
193
+ }
178
194
```
179
195
180
196
## .NET and WinRT
@@ -247,6 +263,21 @@ public DeleteProfile(CoreWebView2Controller controller)
247
263
// Delete current profile.
248
264
profile .Delete ();
249
265
}
266
+
267
+ private void AddProfileDeleted (object sender , object e )
268
+ {
269
+ webView .CoreWebView2 .ProfileDeleted += CoreWebView2_ProfileDeleted ;
270
+ }
271
+
272
+ private void RemoveProfileDeleted (object sender , object e )
273
+ {
274
+ webView .CoreWebView2 .ProfileDeleted -= CoreWebView2_ProfileDeleted ;
275
+ }
276
+
277
+ private void CoreWebView2_ProfileDeleted (object sender , object e )
278
+ {
279
+ Close ();
280
+ }
250
281
```
251
282
252
283
# API Details
@@ -353,8 +384,8 @@ interface ICoreWebView2Profile2 : ICoreWebView2Profile {
353
384
[propget] HRESULT CookieManager([out, retval] ICoreWebView2CookieManager** cookieManager);
354
385
}
355
386
356
- [uuid(1c1ae2cc-d5c2-ffe3-d3e7-7857035d23b7 ), object, pointer_default(unique)]
357
- interface ICoreWebView2Profile3 : ICoreWebView2Profile2 {
387
+ [uuid(2765B8BD-7C57-4B76-B8AA-1EC940FE92CC ), object, pointer_default(unique)]
388
+ interface ICoreWebView2StagingProfile4 : IUnknown {
358
389
/// After the API is called, the profile will be marked for deletion. The
359
390
/// local profile’s directory will be tried to delete at browser process
360
391
/// exit, if fail to delete, it will recursively try to delete at next
@@ -370,6 +401,20 @@ interface ICoreWebView2Profile3 : ICoreWebView2Profile2 {
370
401
/// (0x8007139FL).
371
402
HRESULT Delete();
372
403
}
404
+
405
+ [uuid(cc39bea3-f6f8-471b-919f-fa253e2fff03), object, pointer_default(unique)]
406
+ interface ICoreWebView2Staging9 : IUnknown {
407
+ /// The `ProfileDeleted` event is raised when its corresponding Profile's
408
+ /// Delete API is called. When this event has been raised, continue to use
409
+ /// the profile or its corresponding webviews is an undefined behavior.
410
+ HRESULT add_ProfileDeleted(
411
+ [in] ICoreWebView2StagingProfileDeletedEventHandler* eventHandler,
412
+ [out] EventRegistrationToken* token);
413
+
414
+ /// Remove an event handler previously added with `add_ProfileDeleted`.
415
+ HRESULT remove_ProfileDeleted(
416
+ [in] EventRegistrationToken token);
417
+ }
373
418
```
374
419
375
420
## .NET and WinRT
@@ -410,6 +455,11 @@ namespace Microsoft.Web.WebView2.Core
410
455
{
411
456
// ...
412
457
CoreWebView2Profile Profile { get ; };
458
+
459
+ [interface_name (" Microsoft.Web.WebView2.Core.ICoreWebView2Staging9" )]
460
+ {
461
+ event Windows .Foundation .TypedEventHandler < CoreWebView2 , Object > ProfileDeleted ;
462
+ }
413
463
}
414
464
415
465
runtimeclass CoreWebView2Profile
@@ -422,9 +472,9 @@ namespace Microsoft.Web.WebView2.Core
422
472
423
473
CoreWebView2CookieManager CookieManager { get ; };
424
474
425
- [interface_name (" Microsoft.Web.WebView2.Core.ICoreWebView2Profile3 " )]
475
+ [interface_name (" Microsoft.Web.WebView2.Core.ICoreWebView2StagingProfile4 " )]
426
476
{
427
- // ICoreWebView2Profile3 members
477
+ // ICoreWebView2StagingProfile4 members
428
478
void Delete ();
429
479
}
430
480
}
0 commit comments