|
| 1 | +# Background |
| 2 | +While WebViews from different app processes normally don't share the same WebView browser process instance, app processes from the same product suite may share the same webview browser process |
| 3 | +instance by specifying the same user data folder when creating WebView2Environment object. |
| 4 | +The `AreMultipleHostProcessesAllowed` property is for the developer to express the sharing intent, so that we could provide optimized security and performance according expected usage. |
| 5 | + |
| 6 | +# Description |
| 7 | +The `AreMultipleHostProcessesAllowed` property indicates whether other processes can create WebView2 sharing the same WebView browser process instance by using WebView2Environment created with the same user data folder. |
| 8 | +Default is TRUE. |
| 9 | + |
| 10 | +# Examples |
| 11 | +## Win32 C++ |
| 12 | +```cpp |
| 13 | + auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>(); |
| 14 | + // Don't expect any other process to share the WebView browser process instance. |
| 15 | + CHECK_FAILURE(options->put_AreMultipleHostProcessesAllowed(FALSE); |
| 16 | + HRESULT hr = CreateCoreWebView2EnvironmentWithOptions( |
| 17 | + nullptr, m_userDataFolder.c_str(), options.Get(), |
| 18 | + Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>( |
| 19 | + this, &AppWindow::OnCreateEnvironmentCompleted).Get()); |
| 20 | +``` |
| 21 | +## WinRT and .NET |
| 22 | +```c# |
| 23 | +auto options = new CoreWebView2EnvironmentOptions(); |
| 24 | +options.AreMultipleHostProcessesAllowed = false; |
| 25 | +auto environment = await CoreWebView2Environment.CreateAsync(BrowserExecutableFolder, UserDataFolder, options); |
| 26 | +``` |
| 27 | + |
| 28 | +# Remarks |
| 29 | +See API details. |
| 30 | + |
| 31 | +# API Details |
| 32 | +## Win32 C++ |
| 33 | +```cpp |
| 34 | +interface ICoreWebView2EnvironmentOptions_2 : IUnknown |
| 35 | +{ |
| 36 | + |
| 37 | + /// Whether other processes can create WebView2 sharing the same WebView browser |
| 38 | + /// process instance by using WebView2Environment created with the same user data folder. |
| 39 | + /// Default is TRUE. |
| 40 | + [propget] HRESULT AreMultipleHostProcessesAllowed([out, retval] BOOL* value); |
| 41 | + |
| 42 | + /// Sets the `AreMultipleHostProcessesAllowed` property. |
| 43 | + /// When set as FALSE, no other process can create WebView sharing the same browser |
| 44 | + /// process instance. When another process tries to create WebView2Controller from |
| 45 | + /// an WebView2Environment objct created with the same user data folder, it will fail |
| 46 | + /// with `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`. |
| 47 | + /// When set to FALSE, `TrySuspend` could potentially do more optimization on reducing |
| 48 | + /// CPU usage for suspended WebViews. |
| 49 | + [propput] HRESULT AreMultipleHostProcessesAllowed([in] BOOL value); |
| 50 | + |
| 51 | +} |
| 52 | + |
| 53 | +``` |
| 54 | +## WinRT and .NET |
| 55 | +```c# |
| 56 | +unsealed runtimeclass CoreWebView2EnvironmentOptions |
| 57 | +{ |
| 58 | + // .. |
| 59 | + bool AreMultipleHostProcessesAllowed { get; set; }; |
| 60 | +} |
| 61 | +``` |
0 commit comments