Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API:CoreWebView2Profile.Delete #2565

Open
wants to merge 1 commit into
base: MultipleFile_Erase
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions specs/ExtendedProcessFailed.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ std::wstring ProcessComponent::ProcessFailedReasonToString(
REASON_ENTRY(COREWEBVIEW2_PROCESS_FAILED_REASON_CRASHED);
REASON_ENTRY(COREWEBVIEW2_PROCESS_FAILED_REASON_LAUNCH_FAILED);
REASON_ENTRY(COREWEBVIEW2_PROCESS_FAILED_REASON_OUT_OF_MEMORY);
REASON_ENTRY(COREWEBVIEW2_PROCESS_FAILED_REASON_PROFILE_DELETED);

#undef REASON_ENTRY
}
Expand Down Expand Up @@ -544,6 +545,9 @@ typedef enum COREWEBVIEW2_PROCESS_FAILED_REASON {

/// The process died due to running out of memory.
COREWEBVIEW2_PROCESS_FAILED_REASON_OUT_OF_MEMORY,

/// The process exited because its corresponding profile was deleted.
COREWEBVIEW2_PROCESS_FAILED_REASON_PROFILE_DELETED,
} COREWEBVIEW2_PROCESS_FAILED_REASON;

/// A continuation of `ICoreWebView2ProcessFailedEventArgs` interface.
Expand Down
49 changes: 49 additions & 0 deletions specs/MultiProfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,28 @@ void ScenarioCookieManagement::DeleteAllCookies()
CHECK_FAILURE(m_cookieManager->DeleteAllCookies();
}
```

### Delete profile

```cpp
HRESULT AppWindow::DeleteProfile(ICoreWebView2Controller* controller)
{
wil::com_ptr<ICoreWebView2> coreWebView2;
CHECK_FAILURE(controller->get_CoreWebView2(&coreWebView2));
auto webview7 = coreWebView2.try_query<ICoreWebView2_7>();
if (webview7)
{
wil::com_ptr<ICoreWebView2Profile> profile;
CHECK_FAILURE(webview7->get_Profile(&profile));
auto profile2 = profile.try_query<ICoreWebView2StagingProfile4>;
if (profile2)
{
CHECK_FAILURE(profile2->Delete());
}
}
}
```

## .NET and WinRT

### Create WebView2 with a specific profile, then access the profile property of WebView2
Expand Down Expand Up @@ -226,6 +248,17 @@ void DeleteAllCookies()
}
```

```csharp
public DeleteProfile(CoreWebView2Controller controller)
{
// Get the profile object.
CoreWebView2Profile profile = controller.CoreWebView2.Profile;

// Delete current profile.
profile.Delete();
}
```

# API Details

## Win32 C++
Expand All @@ -236,6 +269,7 @@ interface ICoreWebView2Environment5;
interface ICoreWebView2_7;
interface ICoreWebView2Profile;
interface ICoreWebView2Profile2;
interface ICoreWebView2Profile3;

/// This interface is used to manage profile options that created by 'CreateCoreWebView2ControllerOptions'.
[uuid(C2669A3A-03A9-45E9-97EA-03CD55E5DC03), object, pointer_default(unique)]
Expand Down Expand Up @@ -328,6 +362,15 @@ interface ICoreWebView2Profile2 : ICoreWebView2Profile {
/// See ICoreWebView2CookieManager.
[propget] HRESULT CookieManager([out, retval] ICoreWebView2CookieManager** cookieManager);
}

[uuid(1c1ae2cc-d5c2-ffe3-d3e7-7857035d23b7), object, pointer_default(unique)]
interface ICoreWebView2Profile3 : ICoreWebView2Profile2 {
/// All webviews on this profile will be closed, and the profile will be marked for deletion.
/// The render process of webviews on this profile will asynchronously exit with the reason `COREWEBVIEW2_PROCESS_FAILED_REASON_PROFILE_DELETED`. See 'COREWEBVIEW2_PROCESS_FAILED_REASON::COREWEBVIEW2_PROCESS_FAILED_REASON_PROFILE_DELETED' for more details.
/// The profile directory on disk will be actually deleted when the browser process exits.
/// Profile creation will fail if you create a new profile with the same name as a profile that is being deleted.
HRESULT Delete();
}
```

## .NET and WinRT
Expand Down Expand Up @@ -379,6 +422,12 @@ namespace Microsoft.Web.WebView2.Core
String ProfilePath { get; };

CoreWebView2CookieManager CookieManager { get; };

[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2Profile3")]
{
// ICoreWebView2Profile3 members
void Delete();
}
}
}
```
Expand Down