| Version: 3.3.1

Public Member Functions | List of all members
wxWebViewHandler Class Reference
Class List by Category » WebView

`#include <wx/webview.h>`

Inheritance diagram for wxWebViewHandler:
[legend]

## Detailed Description

The base class for handling custom schemes in wxWebView, for example to allow virtual file system support.

A new handler should either implement GetFile() or if a more detailed request handling is required (access to headers, post data) StartRequest() has to be implemented.

Since
  2.9.3

  ##

Library: wxWebView
Category: WebView

See also
  wxWebView

## Public Member Functions
| wxWebViewHandler (const wxString &scheme)
| Constructor. More...
virtual wxFSFile * | GetFile (const wxString &uri)
virtual wxString | GetName () const
virtual void | SetSecurityURL (const wxString &url)
| Sets a custom security URL. More...
virtual wxString | GetSecurityURL () const
virtual void | SetVirtualHost (const wxString &host)
| When using the edge backend handler urls are https urls with a virtual host. More...
virtual wxString | GetVirtualHost () const
virtual void | StartRequest (const wxWebViewHandlerRequest &request, wxSharedPtr< wxWebViewHandlerResponse > response)
| Implementing this method allows for more control over requests from the backend than GetFile(). More...

## Constructor & Destructor Documentation

## ◆ wxWebViewHandler()

wxWebViewHandler::wxWebViewHandler | ( | const wxString & | scheme | ) |

Constructor.

Takes the name of the scheme that will be handled by this class for example `file` or `zip`.

## Member Function Documentation

## ◆ GetFile()

virtual wxFSFile* wxWebViewHandler::GetFile | ( | const wxString & | uri | ) |
| virtual

Returns
  A pointer to the file represented by `uri`.

Reimplemented in wxWebViewFSHandler, and wxWebViewArchiveHandler.

## ◆ GetName()

virtual wxString wxWebViewHandler::GetName | ( |  | ) | const
| virtual

Returns
  The name of the scheme, as passed to the constructor.

## ◆ GetSecurityURL()

virtual wxString wxWebViewHandler::GetSecurityURL | ( |  | ) | const
| virtual

Returns
  The custom security URL. Only used by wxWebViewIE.

Since
  3.1.5

## ◆ GetVirtualHost()

virtual wxString wxWebViewHandler::GetVirtualHost | ( |  | ) | const
| virtual

Returns
  The virtual host of this handler

See also
  SetVirtualHost()

Since
  3.3.0

## ◆ SetSecurityURL()

virtual void wxWebViewHandler::SetSecurityURL | ( | const wxString & | url | ) |
| virtual

Sets a custom security URL.

Only used by wxWebViewIE.

Since
  3.1.5

## ◆ SetVirtualHost()

virtual void wxWebViewHandler::SetVirtualHost | ( | const wxString & | host | ) |
| virtual

When using the edge backend handler urls are https urls with a virtual host.

As default `name.wxsite` is used as the virtual hostname. If you customize this host, use a non existing site (ideally a reserved subdomain of a domain you control). If `localassests.domain.example` is used the handlers content will be available under https://localassets.domain.example/

This has to be set before registering the handler via wxWebView::RegisterHandler().

Since
  3.3.0

## ◆ StartRequest()

virtual void wxWebViewHandler::StartRequest | ( | const wxWebViewHandlerRequest & | request,
|  | wxSharedPtr< wxWebViewHandlerResponse > | response
| ) |  |
| virtual

Implementing this method allows for more control over requests from the backend than GetFile().

More details of the request are available from the request object which allows access to URL, method, postdata and headers.

A response can be send via the response object. The response does not have to be finished from this method and it's possible to be finished asynchronously via wxWebViewHandlerResponse::Finish().

The following pseudo code demonstrates a typical implementation:

void StartRequest(const wxWebViewHandlerRequest& request,
wxSharedPtr<wxWebViewHandlerResponse> response) override
{
// Set common headers allowing access from XMLHTTPRequests()
response->SetHeader("Access-Control-Allow-Origin", "*");
response->SetHeader("Access-Control-Allow-Headers", "*");
// Handle options request
if (request.GetMethod().IsSameAs("options", false))
{
response->Finish("");
return;
}
// Check the post data type
if (!request.GetHeader("Content-Type").StartsWith("application/json"))
{
response->FinishWithError();
return;
}
// Process input data
wxString postData = request.GetDataString();
...
// Send result
response->SetContentType("application/json");
response->Finish("{ result: true }");
}
wxString
String class for passing textual data to or receiving it from wxWidgets.
Definition: string.h:372
wxString::StartsWith
bool StartsWith(const wxString &prefix, wxString *rest=nullptr) const
This function can be used to test if the string starts with the specified prefix.
wxString::IsSameAs
bool IsSameAs(const wxString &s, bool caseSensitive=true) const
Test whether the string is equal to another string s.
wxWebViewHandler::StartRequest
virtual void StartRequest(const wxWebViewHandlerRequest &request, wxSharedPtr< wxWebViewHandlerResponse > response)
Implementing this method allows for more control over requests from the backend than GetFile().
wxWebViewHandlerRequest
A class giving access to various parameters of a webview request.
Definition: webview.h:413
wxWebViewHandlerRequest::GetDataString
virtual wxString GetDataString(const wxMBConv &conv=wxConvUTF8) const
wxWebViewHandlerRequest::GetHeader
virtual wxString GetHeader(const wxString &name) const =0
Returns a header from the request or an empty string if the header could not be found.
wxWebViewHandlerRequest::GetMethod
virtual wxString GetMethod() const =0

Note
  This is only used by macOS, Chromium, and the Edge backend.

See also
  GetFile()

Since
  3.3.0