Trait webview2_sys::ICoreWebView2Environment[][src]

pub trait ICoreWebView2Environment: IUnknown {
    unsafe fn create_core_web_view2_controller(
        &self,
        parent_window: HWND,
        handler: *mut *mut ICoreWebView2CreateCoreWebView2ControllerCompletedHandlerVTable
    ) -> HRESULT;
unsafe fn create_web_resource_response(
        &self,
        content: *mut *mut IStreamVTable,
        status_code: i32,
        reason_phrase: LPCWSTR,
        headers: LPCWSTR,
        response: *mut *mut *mut ICoreWebView2WebResourceResponseVTable
    ) -> HRESULT;
unsafe fn get_browser_version_string(
        &self,
        version_info: *mut LPWSTR
    ) -> HRESULT;
unsafe fn add_new_browser_version_available(
        &self,
        event_handler: *mut *mut ICoreWebView2NewBrowserVersionAvailableEventHandlerVTable,
        token: *mut EventRegistrationToken
    ) -> HRESULT;
unsafe fn remove_new_browser_version_available(
        &self,
        token: EventRegistrationToken
    ) -> HRESULT; }
Expand description

Represents the WebView2 Environment. WebViews created from an environment run on the browser process specified with environment parameters and objects created from an environment should be used in the same environment. Using it in different environments are not guaranteed to be compatible and may fail.

Required methods

Asynchronously create a new WebView.

parentWindow is the HWND in which the WebView should be displayed and from which receive input. The WebView adds a child window to the provided window during WebView creation. Z-order and other things impacted by sibling window order are affected accordingly.

It is recommended that the app set Application User Model ID for the process or the app window. If none is set, during WebView creation a generated Application User Model ID is set to root window of parentWindow.

\snippet AppWindow.cpp CreateCoreWebView2Controller

It is recommended that the app handles restart manager messages, to gracefully restart it in the case when the app is using the WebView2 Runtime from a certain installation and that installation is being uninstalled. For example, if a user installs a version of the WebView2 Runtime and opts to use another version of the WebView2 Runtime for testing the app, and then uninstalls the 1st version of the WebView2 Runtime without closing the app, the app restarts to allow un-installation to succeed.

\snippet AppWindow.cpp RestartManager

When the app retries CreateCoreWebView2Controller upon failure, it is recommended that the app restarts from creating a new WebView2 Environment. If an WebView2 Runtime update happens, the version associated with a WebView2 Environment may have been removed and causing the object to no longer work. Creating a new WebView2 Environment works since it uses the latest version.

WebView creation fails if a running instance using the same user data folder exists, and the Environment objects have different EnvironmentOptions. For example, if a WebView was created with one language, an attempt to create a WebView with a different language using the same user data folder fails.

Create a new web resource response object. The headers parameter is the raw response header string delimited by newline. It is also possible to create this object with null headers string and then use the ICoreWebView2HttpResponseHeaders to construct the headers line by line. For more information about other parameters, navigate to [ICoreWebView2WebResourceResponse][MicrosoftEdgeWebview2ReferenceWin32Icorewebview2webresourceresponse].

\snippet SettingsComponent.cpp WebResourceRequested0 \snippet SettingsComponent.cpp WebResourceRequested1

[MicrosoftEdgeWebview2ReferenceWin32Icorewebview2webresourceresponse]: /microsoft-edge/webview2/reference/win32/icorewebview2webresourceresponse “interface ICoreWebView2WebResourceResponse | Microsoft Docs”

The browser version info of the current ICoreWebView2Environment, including channel name if it is not the WebView2 Runtime. It matches the format of the GetAvailableCoreWebView2BrowserVersionString API. Channel names are beta, dev, and canary.

\snippet AppWindow.cpp GetBrowserVersionString

Add an event handler for the NewBrowserVersionAvailable event. NewBrowserVersionAvailable runs when a newer version of the WebView2 Runtime is installed and available using WebView2. To use the newer version of the browser you must create a new environment and WebView. The event only runs for new version from the same WebView2 Runtime from which the code is running. When not running with installed WebView2 Runtime, no event is run.

Because a user data folder is only able to be used by one browser process at a time, if you want to use the same user data folder in the WebView using the new version of the browser, you must close the environment and instance of WebView that are using the older version of the browser first. Or simply prompt the user to restart the app.

\snippet AppWindow.cpp NewBrowserVersionAvailable

Remove an event handler previously added with add_NewBrowserVersionAvailable.

Trait Implementations

A COM compatible V-Table

The interface that this interface inherits from

The associated id for this interface

Check whether a given IID is in the inheritance hierarchy of this interface

Get the vtable for a particular COM interface

Implementations on Foreign Types

Implementors