|
| 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 `IsForSingleAppHost` 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 `IsForSingleAppHost` 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 FALSE, meaning that other processes can create WebView objects sharing the same browser process instance. |
| 9 | + |
| 10 | +# Examples |
| 11 | +## Win32 C++ |
| 12 | +```cpp |
| 13 | + auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>(); |
| 14 | + CHECK_FAILURE(options->put_IsForSingleAppHost(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.IsForSingleAppHost = 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 | + /// Whether other processes can create WebView2 sharing the same WebView browser |
| 36 | + /// process instance by using WebView2Environment created with the same user data folder. |
| 37 | + /// Default is FALSE, meaning that other processes can create WebView objects |
| 38 | + /// sharing the same browser process instance. |
| 39 | + [propget] HRESULT IsForSingleAppHost([out, retval] BOOL* value); |
| 40 | + |
| 41 | + /// Sets the `ForSingleAppHost` property. |
| 42 | + /// When set as TRUE, no other process can create WebView sharing the same browser |
| 43 | + /// process instance. When another process tries to create WebView2Controller from |
| 44 | + /// an WebView2Environment objct created with the same user data folder, it will fail |
| 45 | + /// with `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`. |
| 46 | + /// When set to TRUE, `TrySuspend` could potentially do more optimization on reducing |
| 47 | + /// CPU usage for suspended WebViews. |
| 48 | + [propput] HRESULT IsForSingleAppHost([in] BOOL value); |
| 49 | + |
| 50 | +} |
| 51 | + |
| 52 | +``` |
| 53 | +## WinRT and .NET |
| 54 | +```c# |
| 55 | +unsealed runtimeclass CoreWebView2EnvironmentOptions |
| 56 | +{ |
| 57 | + // .. |
| 58 | + bool IsForSingleAppHost { get; set; }; |
| 59 | +} |
| 60 | +``` |
0 commit comments