Class: Wx::WEB::WebViewHandler
- Inherits:
-
Object
- Object
- Wx::WEB::WebViewHandler
- Defined in:
- lib/wx/doc/gen/web/web_view_handler.rb
Overview
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
Direct Known Subclasses
Instance Method Summary collapse
-
#get_file(uri) ⇒ Wx::FSFile
(also: #file)
A pointer to the file represented by uri.
-
#get_name ⇒ String
(also: #name)
The name of the scheme, as passed to the constructor.
-
#get_security_url ⇒ String
(also: #security_url)
The custom security URL.
-
#get_virtual_host ⇒ String
(also: #virtual_host)
The virtual host of this handler.
-
#initialize(scheme) ⇒ Wx::WEB::WebViewHandler
constructor
Constructor.
-
#set_security_url(url) ⇒ void
(also: #security_url=)
Sets a custom security URL.
-
#set_virtual_host(host) ⇒ void
(also: #virtual_host=)
When using the edge backend handler urls are https urls with a virtual host.
-
#start_request(request, response) ⇒ void
Implementing this method allows for more control over requests from the backend than #get_file.
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.
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.
36 |
# File 'lib/wx/doc/gen/web/web_view_handler.rb', line 36 def get_file(uri) end |
#get_name ⇒ String Also known as: name
The name of the scheme, as passed to the constructor.
43 |
# File 'lib/wx/doc/gen/web/web_view_handler.rb', line 43 def get_name; end |
#get_security_url ⇒ String Also known as: security_url
The custom security URL. Only used by Wx::WebViewIE.
58 |
# File 'lib/wx/doc/gen/web/web_view_handler.rb', line 58 def get_security_url; end |
#get_virtual_host ⇒ String Also known as: virtual_host
The virtual host of this handler
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.
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.
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
This is only used by macOS, Chromium, and the Edge backend.
121 |
# File 'lib/wx/doc/gen/web/web_view_handler.rb', line 121 def start_request(request, response) end |