Skip to content

Commit c138421

Browse files
Diana QuDiana Qudavid-risneyMikeHillbergvickiez
authored
Add Spec: Critical Restart Required (#4657)
* Add Spec: Critical Kill Switch (#4574) * add critical api --------- Co-authored-by: Diana Qu <xiaqu@microsoft.com> Co-authored-by: David Risney <dave@deletethis.net> * Sample code update Co-authored-by: MikeHillberg <18429489+MikeHillberg@users.noreply.github.com> * Fix typo Co-authored-by: Viktoria Zlatinova <vizlatin@microsoft.com> * renaming API and update doc * renaming md file --------- Co-authored-by: Diana Qu <xiaqu@microsoft.com> Co-authored-by: David Risney <dave@deletethis.net> Co-authored-by: MikeHillberg <18429489+MikeHillberg@users.noreply.github.com> Co-authored-by: Viktoria Zlatinova <vizlatin@microsoft.com>
1 parent baf2c3e commit c138421

1 file changed

Lines changed: 107 additions & 0 deletions

File tree

specs/RestartRequested.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
Critical Update Available
2+
===
3+
4+
# Background
5+
As WebView2 developers, we often have to author ECS (experimentation and configuration service -
6+
used to perform A/B testing or remotely disable features) configurations to toggle feature flags.
7+
However, once these payloads are received, there is no way to restart the WebView2 and apply the
8+
payload. The purpose of this API is to detect such critical payloads and inform the end developer
9+
so they may restart their app or their WebView2 or other appropriate action.
10+
11+
# Examples
12+
## WinRT and .NET
13+
```c#
14+
void WebView_CoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
15+
{
16+
if (e.IsSuccess)
17+
{
18+
// ...
19+
webView.CoreWebView2.Environment.RestartRequested += WebView_RestartRequested;
20+
}
21+
}
22+
23+
void WebView_RestartRequested(CoreWebView2Environment sender, object e)
24+
{
25+
// Depending on your app experience, you may or may not
26+
// want to prompt user to restart the app.
27+
RestartIfSelectedByUser();
28+
}
29+
```
30+
31+
## Win32 C++
32+
```cpp
33+
wil::com_ptr<ICoreWebView2Environment> m_webViewEnvironment;
34+
void CoreWebView2InitializationCompleted() {
35+
auto env10 = m_webViewEnvironment.try_query<ICoreWebView2Environment10>();
36+
if (env10) {
37+
CHECK_FAILURE(env10->add_RestartRequested(
38+
Callback<ICoreWebView2RestartRequestedEventHandler>(
39+
[this](ICoreWebView2Environment* sender, IUnknown* args) -> HRESULT
40+
{
41+
// Depending on your app experience, you may or may not
42+
// want to prompt user to restart the app.
43+
RestartIfSelectedByUser();
44+
return S_OK;
45+
})
46+
.Get(),
47+
nullptr));
48+
}
49+
}
50+
```
51+
52+
# API Notes
53+
54+
See [API Details](#api-details) section below for API reference.
55+
56+
# API Details
57+
## Win32 C++
58+
59+
```IDL
60+
interface ICoreWebView2Environment10;
61+
interface ICoreWebView2RestartRequestedEventHandler;
62+
63+
[uuid(62cb67c6-b6a9-4209-8a12-72ca093b9547), object, pointer_default(unique)]
64+
interface ICoreWebView2RestartRequestedEventHandler : IUnknown {
65+
/// Provides the event args for the corresponding event. No event args exist
66+
/// and the `args` parameter is set to `null`.
67+
HRESULT Invoke([in] ICoreWebView2Environment* sender, [in] IUnknown* args);
68+
}
69+
70+
[uuid(ef7632ec-d86e-46dd-9d59-e6ffb5c87878), object, pointer_default(unique)]
71+
interface ICoreWebView2Environment10 : IUnknown {
72+
/// Add an event handler for the `RestartRequested` event.
73+
/// `RestartRequested` event is raised when there is an urgent need to
74+
/// restart the WebView2 process in order to enable or disable
75+
/// features that are causing WebView2 reliability or performance to drop critically.
76+
/// `RestartRequested` gives you the awareness of these necessary WebView2 restarts,
77+
/// allowing you to resolve issues faster than waiting for your end users to restart the app.
78+
/// Depending on your app you may want to prompt your end users in some way to give
79+
/// them a chance to save their state before you restart the WebView2.
80+
///
81+
/// For apps with multiple processes that host WebView2s that share the same user data folder you
82+
/// need to make sure all WebView2 instances are closed and the associated WebView2 Runtime
83+
/// browser process exits. See `BrowserProcessExited` for more details.
84+
// MSOWNERS: xiaqu@microsoft.com
85+
HRESULT add_RestartRequested(
86+
[in] ICoreWebView2RestartRequestedEventHandler* eventHandler,
87+
[out] EventRegistrationToken* token);
88+
89+
/// Remove an event handler previously added with `add_RestartRequested`.
90+
// MSOWNERS: xiaqu@microsoft.com
91+
HRESULT remove_RestartRequested(
92+
[in] EventRegistrationToken token);
93+
}
94+
```
95+
s
96+
## .NET and WinRT
97+
98+
```c#
99+
namespace Microsoft.Web.WebView2.Core
100+
{
101+
runtimeclass CoreWebView2Environment
102+
{
103+
// ...
104+
event Windows.Foundation.TypedEventHandler<CoreWebView2Environment, Object> RestartRequested;
105+
}
106+
}
107+
```

0 commit comments

Comments
 (0)