Version: 3.3.0
wxWebViewConfiguration Class Reference

#include <wx/webview.h>

Detailed Description

This class allows access to web view configuration options and settings, that have to be specified before placing a webview in a window with wxWebView::Create().

Since
3.3.0

Library:  wxWebView
Category:  WebView
See also
wxWebView::NewConfiguration()

Public Member Functions

virtual void * GetNativeConfiguration () const
 Return the pointer to the native configuration used during creation of a wxWebView. More...
 
wxString GetBackend () const
 Returns the backend identifier for which this configuration was created. More...
 
void SetDataPath (const wxString &path)
 Set the data path for the webview. More...
 
wxString GetDataPath () const
 Returns the data path for the webview. More...
 
bool EnablePersistentStorage (bool enable)
 Allows to disable persistent storage for the webview. More...
 

Member Function Documentation

◆ EnablePersistentStorage()

bool wxWebViewConfiguration::EnablePersistentStorage ( bool  enable)

Allows to disable persistent storage for the webview.

The default is to enable it. When the webview is created without persistent storage the data is stored in memory and is lost when the webview is destroyed. In browsers this is equivalent to "private browsing" or "incognito mode".

Returns
true if the backend supports to modify this setting. false if the setting is not supported by the backend.
Note
This is only implemented on the Edge, WebKit2GTK+ and macOS backends.
Since
3.3.0

◆ GetBackend()

wxString wxWebViewConfiguration::GetBackend ( ) const

Returns the backend identifier for which this configuration was created.

◆ GetDataPath()

wxString wxWebViewConfiguration::GetDataPath ( ) const

Returns the data path for the webview.

This is the path where the webview stores its data, such as cookies, local storage, etc.

Returns
The path to the data directory.
Note
This is used by Edge, WebKit2GTK+ and Chromium backends and always returns empty string for the other ones.

◆ GetNativeConfiguration()

virtual void* wxWebViewConfiguration::GetNativeConfiguration ( ) const
inlinevirtual

Return the pointer to the native configuration used during creation of a wxWebView.

When using two-step creation this method can be used to customize configuration options not available via GetNativeBackend() after using Create().

Additional instances of wxWebView must be created using the same wxWebViewConfiguration instance.

All settings must be set before creating a new web view with wxWebView::New().

The return value needs to be down-casted to the appropriate type depending on the platform:

The following pseudo code shows how to use this method with two-step creation to set no user action requirement to play video in a web view:

#if defined(__WXMSW__)
#include "webview2EnvironmentOptions.h"
#elif defined(__WXOSX__)
#import "WebKit/WebKit.h"
#endif
#if defined(__WXMSW__)
ICoreWebView2EnvironmentOptions* webViewOptions =
(ICoreWebView2EnvironmentOptions*) config->GetNativeConfiguration();
webViewOptions->put_AdditionalBrowserArguments("--autoplay-policy=no-user-gesture-required");
#elif defined(__WXOSX__)
WKWebViewConfiguration* webViewConfiguration =
(WKWebViewConfiguration*) config->GetNativeConfiguration();
webViewConfiguration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
#endif
wxWebView* webView = wxWebView::New(config);
webView->Create(this, wxID_ANY, "https://www.wxwidgets.org");
This class allows access to web view configuration options and settings, that have to be specified be...
Definition: webview.h:274
virtual void * GetNativeConfiguration() const
Return the pointer to the native configuration used during creation of a wxWebView.
Definition: webview.h:328
This control may be used to render web (HTML / CSS / JavaScript) documents.
Definition: webview.h:989
static wxWebView * New(const wxString &backend=wxWebViewBackendDefault)
Factory function to create a new wxWebView with two-step creation, wxWebView::Create should be called...
static wxWebViewConfiguration NewConfiguration(const wxString &backend=wxWebViewBackendDefault)
Create a new wxWebViewConfiguration object.
virtual bool Create(wxWindow *parent, wxWindowID id, const wxString &url=wxWebViewDefaultURLStr, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxWebViewNameStr)=0
Creation function for two-step creation.
@ wxID_ANY
Any id: means that we don't care about the id, whether when installing an event handler or when creat...
Definition: defs.h:590

◆ SetDataPath()

void wxWebViewConfiguration::SetDataPath ( const wxString path)

Set the data path for the webview.

This is the path where the webview stores its data, such as cookies, local storage, etc.

Parameters
pathThe path to the data directory.
Note
This is used by Edge, WebKit2GTK+ and Chromium backends (the latter creates "UserData" subdirectory under the given path).