Struct dioxus_mobile::wry::webview::WebViewBuilder [−]
pub struct WebViewBuilder<'a> {
pub webview: WebViewAttributes,
// some fields omitted
}
Expand description
Builder type of WebView
.
WebViewBuilder
/ WebView
are the basic building blocks to constrcut WebView contents and
scripts for those who prefer to control fine grained window creation and event handling.
WebViewBuilder
privides ability to setup initialization before web engine starts.
Fields
webview: WebViewAttributes
Implementations
impl<'a> WebViewBuilder<'a>
impl<'a> WebViewBuilder<'a>
pub fn new(window: Window) -> Result<WebViewBuilder<'a>, Error>
pub fn new(window: Window) -> Result<WebViewBuilder<'a>, Error>
Create WebViewBuilder
from provided Window
.
pub fn with_transparent(self, transparent: bool) -> WebViewBuilder<'a>
pub fn with_transparent(self, transparent: bool) -> WebViewBuilder<'a>
Sets whether the WebView should be transparent.
pub fn with_visible(self, visible: bool) -> WebViewBuilder<'a>
pub fn with_visible(self, visible: bool) -> WebViewBuilder<'a>
Sets whether the WebView should be transparent.
pub fn with_initialization_script(self, js: &str) -> WebViewBuilder<'a>
pub fn with_initialization_script(self, js: &str) -> WebViewBuilder<'a>
Initialize javascript code when loading new pages. When webview load a new page, this
initialization code will be executed. It is guaranteed that code is executed before
window.onload
.
pub fn with_custom_protocol<F>(
self,
name: String,
handler: F
) -> WebViewBuilder<'a> where
F: 'static + Fn(&Request) -> Result<Response, Error>,
pub fn with_custom_protocol<F>(
self,
name: String,
handler: F
) -> WebViewBuilder<'a> where
F: 'static + Fn(&Request) -> Result<Response, Error>,
Register custom file loading protocols with pairs of scheme uri string and a handling closure.
The closure takes a url string slice, and returns a two item tuple of a vector of bytes which is the content and a mimetype string of the content.
Warning
Pages loaded from custom protocol will have different Origin on different platforms. And
servers which enforce CORS will need to add exact same Origin header in Access-Control-Allow-Origin
if you wish to send requests with native fetch
and XmlHttpRequest
APIs. Here are the
different Origin headers across platforms:
- macOS:
<scheme_name>://<path>
(so it will bewry://examples
incustom_protocol
example) - Linux: Though it’s same as macOS, there’s a bug that Origin header in the request will be
empty. So the only way to pass the server is setting
Access-Control-Allow-Origin: *
. - Windows:
https://<scheme_name>.<path>
(so it will behttps://wry.examples
incustom_protocol
example)
pub fn with_rpc_handler<F>(self, handler: F) -> WebViewBuilder<'a> where
F: 'static + Fn(&Window, RpcRequest) -> Option<RpcResponse>,
pub fn with_rpc_handler<F>(self, handler: F) -> WebViewBuilder<'a> where
F: 'static + Fn(&Window, RpcRequest) -> Option<RpcResponse>,
Set the RPC handler to Communicate between the host Rust code and Javascript on webview.
The communication is done via JSON-RPC. Users can use this to register an incoming
request handler and reply with responses that are passed back to Javascript. On the Javascript
side the client is exposed via window.rpc
with two public methods:
- The
call()
function accepts a method name and parameters and expects a reply. - The
notify()
function accepts a method name and parameters but does not expect a reply.
Both functions return promises but notify()
resolves immediately.
pub fn with_file_drop_handler<F>(self, handler: F) -> WebViewBuilder<'a> where
F: 'static + Fn(&Window, FileDropEvent) -> bool,
pub fn with_file_drop_handler<F>(self, handler: F) -> WebViewBuilder<'a> where
F: 'static + Fn(&Window, FileDropEvent) -> bool,
Set a handler closure to process incoming FileDropEvent
of the webview.
Blocking OS Default Behavior
Return true
in the callback to block the OS’ default behavior of handling a file drop.
Note, that if you do block this behavior, it won’t be possible to drop files on <input type="file">
forms.
Also note, that it’s not possible to manually set the value of a <input type="file">
via JavaScript for security reasons.
pub fn with_url(self, url: &str) -> Result<WebViewBuilder<'a>, Error>
pub fn with_url(self, url: &str) -> Result<WebViewBuilder<'a>, Error>
Load the provided URL when the builder calling WebViewBuilder::build
to create the
WebView
. The provided URL must be valid.
Load the provided HTML string when the builder calling WebViewBuilder::build
to create the
WebView
. This will be ignored if url
is already provided.
Warning
The Page loaded from html string will have different Origin on different platforms. And
servers which enforce CORS will need to add exact same Origin header in Access-Control-Allow-Origin
if you wish to send requests with native fetch
and XmlHttpRequest
APIs. Here are the
different Origin headers across platforms:
- macOS:
http://localhost
- Linux:
http://localhost
- Windows:
null
pub fn with_web_context(
self,
web_context: &'a mut WebContext
) -> WebViewBuilder<'a>
pub fn with_web_context(
self,
web_context: &'a mut WebContext
) -> WebViewBuilder<'a>
Set the web context that can share with multiple WebView
s.