Class: Wx::WEB::WebViewHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/wx/doc/gen/web/web_view_handler.rb

Overview

Note:

This class is untracked and should not be derived from nor instances extended!

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

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

Category: WebView

See Also:

Requires:

  • USE_WEBVIEW

Direct Known Subclasses

WebViewArchiveHandler, WebViewFSHandler

Instance Method Summary collapse

Constructor Details

#initialize(scheme) ⇒ Wx::WEB::WebViewHandler

Constructor.

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

Parameters:

  • scheme (String)


29
# File 'lib/wx/doc/gen/web/web_view_handler.rb', line 29

def initialize(scheme) end

Instance Method Details

#get_file(uri) ⇒ Wx::FSFile Also known as: file

A pointer to the file represented by uri.

Parameters:

  • uri (String)

Returns:



36
# File 'lib/wx/doc/gen/web/web_view_handler.rb', line 36

def get_file(uri) end

#get_nameString Also known as: name

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

Returns:

  • (String)


43
# File 'lib/wx/doc/gen/web/web_view_handler.rb', line 43

def get_name; end

#get_security_urlString Also known as: security_url

The custom security URL. Only used by Wx::WebViewIE.

Returns:

  • (String)


58
# File 'lib/wx/doc/gen/web/web_view_handler.rb', line 58

def get_security_url; end

#get_virtual_hostString Also known as: virtual_host

The virtual host of this handler

Returns:

  • (String)

See Also:



75
# File 'lib/wx/doc/gen/web/web_view_handler.rb', line 75

def get_virtual_host; end

#set_security_url(url) ⇒ void Also known as: security_url=

This method returns an undefined value.

Sets a custom security URL.

Only used by Wx::WebViewIE.

Parameters:

  • url (String)


51
# File 'lib/wx/doc/gen/web/web_view_handler.rb', line 51

def set_security_url(url) end

#set_virtual_host(host) ⇒ void Also known as: virtual_host=

This method returns an undefined value.

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 Wx::WEB::WebView#register_handler.

Parameters:

  • host (String)


67
# File 'lib/wx/doc/gen/web/web_view_handler.rb', line 67

def set_virtual_host(host) end

#start_request(request, response) ⇒ void

This method returns an undefined value.

Implementing this method allows for more control over requests from the backend than #get_file.

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 Wx::WEB::WebViewHandlerResponse#finish. The following pseudo code demonstrates a typical implementation:

def start_request(request, response)
   # Set common headers allowing access from XMLHTTPRequests()
   response.set_header("Access-Control-Allow-Origin", "*")
   response.set_header("Access-Control-Allow-Headers", "*")

   # Handle options request
   if request.get_method.casecmp("options") == 0
     response.finish("")
     return
   end

   # Check the post data type
   unless request.get_header("Content-Type").start_with?("application/json")
     response.finish_with_error
     return;
   end

   # Process input data
   postData = request.get_data_string

   #...

   # Send result
   response.set_content_type("application/json")
   response.finish("{ result: true }")
end
Note:

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

Parameters:

See Also:



121
# File 'lib/wx/doc/gen/web/web_view_handler.rb', line 121

def start_request(request, response) end