Skip to content

Commit e24ee2b

Browse files
authored
Merge pull request #1546 from MicrosoftEdge/SingleAppHost
WebView API ExclusiveUserDataFolderAccess
2 parents 2e48a4b + 1dd821e commit e24ee2b

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Background
2+
WebViews which use the same user data folder can share browser processes. The `ExclusiveUserDataFolderAccess` property specifies that the WebView environment obtains exclusive access to the user data folder. If the user data folder is already being used by another WebView environment, the WebView creation will fail. Setting exclusive data folder access therefore has the effect of preventing the browser processes from being shared with WebViews associated with other WebView environments.
3+
4+
# Description
5+
The `ExclusiveUserDataFolderAccess` property specifies whether other WebViews can be created with the same user data folder. Setting exclusive access prevents the WebView browser processes from being shared with those belonging to other environments because sharing occurs only between instances that use the same user data folder and the same exclusive access setting.
6+
Default is FALSE.
7+
8+
# Examples
9+
## Win32 C++
10+
```cpp
11+
auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
12+
// Don't allow any other WebView environments to use the same user data folder.
13+
// This prevents other processes from sharing WebView browser process instances with our WebView.
14+
CHECK_FAILURE(options->put_ExclusiveUserDataFolderAccess(TRUE));
15+
HRESULT hr = CreateCoreWebView2EnvironmentWithOptions(
16+
nullptr, m_userDataFolder.c_str(), options.Get(),
17+
Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
18+
this, &AppWindow::OnCreateEnvironmentCompleted).Get());
19+
```
20+
## WinRT and .NET
21+
```c#
22+
auto options = new CoreWebView2EnvironmentOptions();
23+
options.ExclusiveUserDataFolderAccess = true;
24+
auto environment = await CoreWebView2Environment.CreateAsync(BrowserExecutableFolder, UserDataFolder, options);
25+
```
26+
27+
# Remarks
28+
See API details.
29+
30+
# API Details
31+
## Win32 C++
32+
```cpp
33+
interface ICoreWebView2EnvironmentOptions_2 : IUnknown
34+
{
35+
36+
/// Whether other processes can create WebView2 from WebView2Environment created with the
37+
/// same user data folder and therefore sharing the same WebView browser process instance.
38+
/// Default is FALSE.
39+
[propget] HRESULT ExclusiveUserDataFolderAccess([out, retval] BOOL* value);
40+
41+
/// Sets the `ExclusiveUserDataFolderAccess` property.
42+
/// The `ExclusiveUserDataFolderAccess` property specifies that the WebView environment
43+
/// obtains exclusive access to the user data folder.
44+
/// If the user data folder is already being used by another WebView environment with
45+
/// different value for `ExclusiveUserDataFolderAccess` property, the creation of WebView2Controller
46+
/// using the environmen object will fail with `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`.
47+
/// When set as TRUE, no other WebView can be created from other process using WebView2Environment
48+
/// objects with the same UserDataFolder. This prevents other processes from creating WebViews
49+
/// which share the same browser process instance, since sharing is performed among
50+
/// WebViews that have the same UserDataFolder. When another process tries to create
51+
/// WebView2Controller from an WebView2Environment objct created with the same user data folder,
52+
/// it will fail with `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`.
53+
/// Exclusive data folder access also opens optimization opportunities, such as more aggressive
54+
/// CPU reduction for suspended WebViews.
55+
[propput] HRESULT ExclusiveUserDataFolderAccess([in] BOOL value);
56+
57+
}
58+
59+
```
60+
## WinRT and .NET
61+
```c#
62+
unsealed runtimeclass CoreWebView2EnvironmentOptions
63+
{
64+
// ..
65+
bool ExclusiveUserDataFolderAccess { get; set; };
66+
}
67+
```

0 commit comments

Comments
 (0)