Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Denghui Yu committed Jan 5, 2023
1 parent e834d1e commit 70e7a7f
Showing 1 changed file with 81 additions and 22 deletions.
103 changes: 81 additions & 22 deletions specs/MultiProfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,24 @@ HRESULT AppWindow::DeleteProfile(ICoreWebView2* webView2)

void AppWindow::RegisterEventHandlers()
{
CHECK_FAILURE(m_webView->add_ProfileDeleted(
Microsoft::WRL::Callback<ICoreWebView2ProfileDeletedEventHandler>(
[this](ICoreWebView2_9* sender, IUnknown* args) {
CloseAppWindow();
CHECK_FAILURE(m_webView->add_Closed(
Microsoft::WRL::Callback<ICoreWebView2ClosedEventHandler>(
[this](ICoreWebView2_20* sender, ICoreWebView2EventArgs* args)
{
COREWEBVIEW2_CLOSED_REASON reason;
CHECK_FAILURE(args->get_Reason(&reason));
if (reason == COREWEBVIEW2_CLOSED_REASON::COREWEBVIEW2_CLOSED_REASON_PROFILE_DELETED)
{
RunAsync( [this]()
{
std::wstring message =
L"The webview2 has been closed and the reason is profile "
L"has been marked as deleted.";
MessageBox(
m_mainWindow, message.c_str(), L"webview2 closed", MB_OK);
CloseAppWindow();
});
}
return S_OK;
}).Get(), nullptr));
}
Expand Down Expand Up @@ -260,12 +274,20 @@ public DeleteProfile(CoreWebView2Controller controller)

void WebView_CoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
{
webView.CoreWebView2.ProfileDeleted += CoreWebView2_ProfileDeleted;
webView.CoreWebView2.Closed += CoreWebView2_Closed;
}

private void CoreWebView2_ProfileDeleted(object sender, object e)
private void CoreWebView2_Closed(object sender, CoreWebView2ClosedEventArgs e)
{
Close();
if (e.Reason == CoreWebView2ClosedReason.ProfileDeleted)
{
this.Dispatcher.InvokeAsync(() =>
{
String message = "The webview2 has been closed and the reason is profile has been marked as deleted";
MessageBox.Show(message);
Close();
});
}
}
```

Expand All @@ -277,9 +299,13 @@ private void CoreWebView2_ProfileDeleted(object sender, object e)
interface ICoreWebView2ControllerOptions;
interface ICoreWebView2Environment5;
interface ICoreWebView2_7;
interface ICoreWebView2_9;
interface ICoreWebView2Profile;
interface ICoreWebView2Profile2;
interface ICoreWebView2Profile3;
interface ICoreWebView2Profile4;
interface ICoreWebView2ClosedEventHandler;
interface ICoreWebView2ClosedEventArgs;
/// 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 @@ -376,15 +402,12 @@ interface ICoreWebView2Profile2 : ICoreWebView2Profile {
[uuid(2765B8BD-7C57-4B76-B8AA-1EC940FE92CC), object, pointer_default(unique)]
interface ICoreWebView2Profile4 : IUnknown {
/// After the API is called, the profile will be marked for deletion. The
/// local profiles directory will be tried to delete at browser process
/// 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.
/// 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.
/// The corresponding webview2s will be auto closed and its Closed event
/// handle function will be triggered with the reason is
/// COREWEBVIEW2_CLOSED_REASON.COREWEBVIEW2_CLOSED_REASON_PROFILE_DELETED.
/// 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).
Expand All @@ -393,17 +416,43 @@ interface ICoreWebView2Profile4 : IUnknown {
[uuid(cc39bea3-f6f8-471b-919f-fa253e2fff03), object, pointer_default(unique)]
interface ICoreWebView2_9 : IUnknown {
/// The `ProfileDeleted` event is raised when its corresponding Profile's
/// Delete API is called. When this event has been raised, continue to use
/// the profile or its corresponding webviews is an undefined behavior.
HRESULT add_ProfileDeleted(
[in] ICoreWebView2ProfileDeletedEventHandler* eventHandler,
/// Add an event handler for the `Closed` event. `Closed` enent handle runs
/// when the webview2 is closed passivly. When this event is raised, the
/// webview2 cannot be used anymore.
HRESULT add_Closed(
[in] ICoreWebView2ClosedEventHandler* eventHandler,
[out] EventRegistrationToken* token);
/// Remove an event handler previously added with `add_ProfileDeleted`.
HRESULT remove_ProfileDeleted(
/// Remove an event handler previously added with `add_Closed`.
HRESULT remove_Closed(
[in] EventRegistrationToken token);
}
/// The reason of webview2 closed.
[v1_enum]
typedef enum COREWEBVIEW2_CLOSED_REASON {
/// Indicates that the reason of webview2 closed is its corresponding
/// Profile has been or marked as deleted.
COREWEBVIEW2_CLOSED_REASON_PROFILE_DELETED,
} COREWEBVIEW2_CLOSED_REASON;
/// Receives the webview2 `Closed` event.
[uuid(970BB7E0-A257-4A76-BE15-5BDEB00B5673), object, pointer_default(unique)]
interface ICoreWebView2ClosedEventHandler : IUnknown {
/// Called to provide the implementer with the event args for the
/// corresponding event.
HRESULT Invoke([in] ICoreWebView2_20* sender,
[in] ICoreWebView2ClosedEventArgs* args);
}
/// This is the event args interface for webview2 `Closed` event handle.
[uuid(0e1730c1-03df-4ad2-b847-be4d63adf777), object, pointer_default(unique)]
interface ICoreWebView2ClosedEventArgs : IUnknown {
/// webview2 closed reason.
[propget] HRESULT Reason([out, retval]
COREWEBVIEW2_CLOSED_REASON* value);
}
```

## .NET and WinRT
Expand Down Expand Up @@ -447,9 +496,19 @@ namespace Microsoft.Web.WebView2.Core

[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2_9")]
{
event Windows.Foundation.TypedEventHandler<CoreWebView2, Object> ProfileDeleted;
event Windows.Foundation.TypedEventHandler<CoreWebView2, CoreWebView2ClosedEventArgs> Closed;
}
}

enum CoreWebView2ClosedReason
{
ProfileDeleted = 0,
};

runtimeclass CoreWebView2ClosedEventArgs
{
CoreWebView2ClosedReason Reason { get; };
}

runtimeclass CoreWebView2Profile
{
Expand Down

0 comments on commit 70e7a7f

Please sign in to comment.