-
Notifications
You must be signed in to change notification settings - Fork 57
Multiprofile's Delete API modify #3069
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
base: MultipleFile_Delete
Are you sure you want to change the base?
Changes from 2 commits
3b46d95
710afd2
3a0c4aa
e834d1e
70e7a7f
4e428e2
33cda74
767d420
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,21 +169,27 @@ void ScenarioCookieManagement::DeleteAllCookies() | |
### Delete profile | ||
|
||
```cpp | ||
HRESULT AppWindow::DeleteProfile(ICoreWebView2Controller* controller) | ||
HRESULT AppWindow::DeleteProfile(ICoreWebView2* webView2) | ||
{ | ||
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()); | ||
} | ||
} | ||
wil::com_ptr<ICoreWebView2Profile> profile; | ||
CHECK_FAILURE(webView2->get_Profile(&profile)); | ||
CHECK_FAILURE(profile2->Delete()); | ||
} | ||
|
||
EventRegistrationToken m_profileDeletedEventToken = {}; | ||
void AppWindow::AddProfileDeleted(ICoreWebView2* webView2) | ||
{ | ||
CHECK_FAILURE(webView2->add_ProfileDeleted( | ||
Microsoft::WRL::Callback<ICoreWebView2StagingProfileDeletedEventHandler>( | ||
[this](ICoreWebView2Staging9* sender, IUnknown* args) { | ||
CloseAppWindow(); | ||
return S_OK; | ||
}).Get(), &m_profileDeletedEventToken)); | ||
} | ||
|
||
void AppWindow::RemoveProfileDeleted(ICoreWebView2* webView2) | ||
{ | ||
CHECK_FAILURE(webView2->remove_ProfileDeleted(m_profileDeletedEventToken)); | ||
} | ||
``` | ||
|
||
|
@@ -253,10 +259,25 @@ public DeleteProfile(CoreWebView2Controller controller) | |
{ | ||
// Get the profile object. | ||
CoreWebView2Profile profile = controller.CoreWebView2.Profile; | ||
|
||
// Delete current profile. | ||
profile.Delete(); | ||
} | ||
|
||
private void AddProfileDeleted(object sender, object e) | ||
{ | ||
webView.CoreWebView2.ProfileDeleted += CoreWebView2_ProfileDeleted; | ||
} | ||
|
||
private void RemoveProfileDeleted(object sender, object e) | ||
{ | ||
webView.CoreWebView2.ProfileDeleted -= CoreWebView2_ProfileDeleted; | ||
} | ||
|
||
private void CoreWebView2_ProfileDeleted(object sender, object e) | ||
{ | ||
Close(); | ||
} | ||
``` | ||
|
||
# API Details | ||
|
@@ -363,16 +384,36 @@ interface ICoreWebView2Profile2 : ICoreWebView2Profile { | |
[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. | ||
/// After the Delete() call completes, 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. Webview2 creation will fail with the HRESULT is ERROR_INVALID_STATE(0x8007139FL) | ||
/// if you create it with the same name as a profile that is being deleted. | ||
HRESULT Delete(); | ||
[uuid(2765B8BD-7C57-4B76-B8AA-1EC940FE92CC), object, pointer_default(unique)] | ||
interface ICoreWebView2StagingProfile4 : IUnknown { | ||
/// After the API is called, the profile will be marked for deletion. The | ||
/// local profile’s directory will be tried to delete at browser process | ||
/// exit, if fail to delete, it will recursively try to delete at next | ||
/// browser process start until successful. | ||
/// The corresponding user's `ProfileDeleted` event handle function will | ||
/// be triggered. After the function is triggered, continuing to use the | ||
/// profile or its corresponding webviews is an undefined behavior. | ||
david-risney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// For each WebView of the same profile, the WebView will be auto closed. | ||
/// If the user has registered an event handler for ProfileDeleted event, | ||
/// the event handle will be invoked before WebView is closed. | ||
/// If create a new profile with the same name as the profile that has been | ||
/// marked as deleted will be failure with the HRESULT:ERROR_INVALID_STATE | ||
/// (0x8007139FL). | ||
HRESULT Delete(); | ||
} | ||
|
||
[uuid(cc39bea3-f6f8-471b-919f-fa253e2fff03), object, pointer_default(unique)] | ||
interface ICoreWebView2Staging9 : IUnknown { | ||
yunate marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// The `ProfileDeleted` event is raised when its corresponding Profile's | ||
/// Delete API is called. When this event has been raised, continue to use | ||
yunate marked this conversation as resolved.
Show resolved
Hide resolved
david-risney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// the profile or its corresponding webviews is an undefined behavior. | ||
HRESULT add_ProfileDeleted( | ||
david-risney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[in] ICoreWebView2StagingProfileDeletedEventHandler* eventHandler, | ||
[out] EventRegistrationToken* token); | ||
|
||
/// Remove an event handler previously added with `add_ProfileDeleted`. | ||
HRESULT remove_ProfileDeleted( | ||
[in] EventRegistrationToken token); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In addition we should add a property where you can check if the CoreWebView2 is closed or not. This way end dev's asynchronous code that may be in progress when the profile is deleted can check if the CoreWebView2 has closed and take appropriate action.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think do not need this function. Because, close webview and Closed event handle function called are in a same therad and a same loop. So, if the Closed event handle function called, the user has known the webview has been closed, they can record a flag in this function; if before Closed event handle function called, the webview is always still alive. |
||
``` | ||
|
||
|
@@ -414,6 +455,11 @@ namespace Microsoft.Web.WebView2.Core | |
{ | ||
// ... | ||
CoreWebView2Profile Profile { get; }; | ||
|
||
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2Staging9")] | ||
{ | ||
event Windows.Foundation.TypedEventHandler<CoreWebView2, Object> ProfileDeleted; | ||
} | ||
} | ||
|
||
runtimeclass CoreWebView2Profile | ||
|
@@ -426,9 +472,9 @@ namespace Microsoft.Web.WebView2.Core | |
|
||
CoreWebView2CookieManager CookieManager { get; }; | ||
|
||
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2Profile3")] | ||
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2StagingProfile4")] | ||
yunate marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
// ICoreWebView2Profile3 members | ||
// ICoreWebView2StagingProfile4 members | ||
void Delete(); | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.