Skip to content

Commit 240d575

Browse files
authored
Merge pull request #2746 from MicrosoftEdge/MultipleFile_Delete
Multiple profile: add delete API
2 parents e3a9586 + 28355a2 commit 240d575

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

specs/ExtendedProcessFailed.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ std::wstring ProcessComponent::ProcessFailedReasonToString(
6666
REASON_ENTRY(COREWEBVIEW2_PROCESS_FAILED_REASON_CRASHED);
6767
REASON_ENTRY(COREWEBVIEW2_PROCESS_FAILED_REASON_LAUNCH_FAILED);
6868
REASON_ENTRY(COREWEBVIEW2_PROCESS_FAILED_REASON_OUT_OF_MEMORY);
69+
REASON_ENTRY(COREWEBVIEW2_PROCESS_FAILED_REASON_PROFILE_DELETED);
6970

7071
#undef REASON_ENTRY
7172
}
@@ -544,6 +545,9 @@ typedef enum COREWEBVIEW2_PROCESS_FAILED_REASON {
544545

545546
/// The process died due to running out of memory.
546547
COREWEBVIEW2_PROCESS_FAILED_REASON_OUT_OF_MEMORY,
548+
549+
/// The process exited because its corresponding profile was deleted.
550+
COREWEBVIEW2_PROCESS_FAILED_REASON_PROFILE_DELETED,
547551
} COREWEBVIEW2_PROCESS_FAILED_REASON;
548552

549553
/// A continuation of `ICoreWebView2ProcessFailedEventArgs` interface.
@@ -709,6 +713,8 @@ namespace Microsoft.Web.WebView2.Core
709713
LaunchFailed,
710714
/// The process died due to running out of memory.
711715
OutOfMemory,
716+
/// The process exited because its corresponding profile was deleted.
717+
ProfiledDeleted,
712718
};
713719

714720
runtimeclass CoreWebView2ProcessFailedEventArgs

specs/MultiProfile.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,28 @@ void ScenarioCookieManagement::DeleteAllCookies()
165165
CHECK_FAILURE(m_cookieManager->DeleteAllCookies();
166166
}
167167
```
168+
169+
### Delete profile
170+
171+
```cpp
172+
HRESULT AppWindow::DeleteProfile(ICoreWebView2Controller* controller)
173+
{
174+
wil::com_ptr<ICoreWebView2> coreWebView2;
175+
CHECK_FAILURE(controller->get_CoreWebView2(&coreWebView2));
176+
auto webview7 = coreWebView2.try_query<ICoreWebView2_7>();
177+
if (webview7)
178+
{
179+
wil::com_ptr<ICoreWebView2Profile> profile;
180+
CHECK_FAILURE(webview7->get_Profile(&profile));
181+
auto profile2 = profile.try_query<ICoreWebView2StagingProfile4>();
182+
if (profile2)
183+
{
184+
CHECK_FAILURE(profile2->Delete());
185+
}
186+
}
187+
}
188+
```
189+
168190
## .NET and WinRT
169191
170192
### Create WebView2 with a specific profile, then access the profile property of WebView2
@@ -226,6 +248,17 @@ void DeleteAllCookies()
226248
}
227249
```
228250

251+
```csharp
252+
public DeleteProfile(CoreWebView2Controller controller)
253+
{
254+
// Get the profile object.
255+
CoreWebView2Profile profile = controller.CoreWebView2.Profile;
256+
257+
// Delete current profile.
258+
profile.Delete();
259+
}
260+
```
261+
229262
# API Details
230263

231264
## Win32 C++
@@ -236,6 +269,7 @@ interface ICoreWebView2Environment5;
236269
interface ICoreWebView2_7;
237270
interface ICoreWebView2Profile;
238271
interface ICoreWebView2Profile2;
272+
interface ICoreWebView2Profile3;
239273
240274
/// This interface is used to manage profile options that created by 'CreateCoreWebView2ControllerOptions'.
241275
[uuid(C2669A3A-03A9-45E9-97EA-03CD55E5DC03), object, pointer_default(unique)]
@@ -328,6 +362,18 @@ interface ICoreWebView2Profile2 : ICoreWebView2Profile {
328362
/// See ICoreWebView2CookieManager.
329363
[propget] HRESULT CookieManager([out, retval] ICoreWebView2CookieManager** cookieManager);
330364
}
365+
366+
[uuid(1c1ae2cc-d5c2-ffe3-d3e7-7857035d23b7), object, pointer_default(unique)]
367+
interface ICoreWebView2Profile3 : ICoreWebView2Profile2 {
368+
/// All webviews on this profile will be closed, and the profile will be marked for deletion.
369+
/// After the Delete() call completes, The render process of webviews on this profile will
370+
/// asynchronously exit with the reason:`COREWEBVIEW2_PROCESS_FAILED_REASON_PROFILE_DELETED`.
371+
/// See 'COREWEBVIEW2_PROCESS_FAILED_REASON::COREWEBVIEW2_PROCESS_FAILED_REASON_PROFILE_DELETED'
372+
/// for more details. The profile directory on disk will be actually deleted when the browser
373+
/// process exits. Webview2 creation will fail with the HRESULT is ERROR_INVALID_STATE(0x8007139FL)
374+
/// if you create it with the same name as a profile that is being deleted.
375+
HRESULT Delete();
376+
}
331377
```
332378

333379
## .NET and WinRT
@@ -379,6 +425,12 @@ namespace Microsoft.Web.WebView2.Core
379425
String ProfilePath { get; };
380426

381427
CoreWebView2CookieManager CookieManager { get; };
428+
429+
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2Profile3")]
430+
{
431+
// ICoreWebView2Profile3 members
432+
void Delete();
433+
}
382434
}
383435
}
384436
```

0 commit comments

Comments
 (0)