use thiserror::Error;
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum WebViewError {
#[error("WebView error: {0}")]
WebView(String),
#[error("Invalid WebView create options: {0}")]
InvalidCreateOptions(String),
}
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum WebViewScriptError {
#[error("JavaScript error: {0}")]
Js(String),
#[error("JavaScript evaluation timed out")]
Timeout,
#[error("JavaScript evaluation unsupported: {0}")]
Unsupported(&'static str),
#[error("WebView destroyed during JavaScript evaluation")]
Destroyed,
#[error("Navigation changed during JavaScript evaluation")]
NavigationChanged,
#[error("Platform JavaScript evaluation error: {0}")]
Platform(String),
}
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum WebViewInputError {
#[error(transparent)]
Script(#[from] WebViewScriptError),
#[error("Element not found: {0}")]
ElementNotFound(String),
#[error("Element not interactable: {0}")]
ElementNotInteractable(String),
#[error("Input unsupported: {0}")]
Unsupported(&'static str),
#[error("WebView destroyed during input handling")]
Destroyed,
#[error("Navigation changed during input handling")]
NavigationChanged,
#[error("Platform input error: {0}")]
Platform(String),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LogLevel {
Verbose,
Debug,
Info,
Warn,
Error,
}
mod input_helper;
mod traits;
mod webview;
#[cfg(target_os = "android")]
mod android;
#[cfg(any(target_os = "ios", target_os = "macos"))]
mod apple;
#[cfg(all(target_os = "linux", target_env = "ohos"))]
mod harmony;
pub use traits::{
ClickOptions, DownloadRequest, FileChooserFile, FileChooserRequest, FileChooserResponse,
FillOptions, LoadDataRequest, LoadError, LoadErrorKind, NavigationPolicy, NewWindowPolicy,
PressOptions, SchemeOutcome, ScrollOptions, SystemPipeReader, TypeOptions, WebResourceBody,
WebResourceResponse, WebViewController, WebViewCookie, WebViewCookieSameSite,
WebViewCookieSetRequest, WebViewDelegate, WebViewInputController,
};
pub use webview::{
BrowserWebViewBuilder, ProxyActivation, ProxyApplyReport, ProxyApplyStatus, ProxyConfig,
StrictWebViewBuilder, WebTag, WebView, WebViewBuilder, WebViewCreateStage, WebViewEvent,
WebViewEventSubscription, WebViewSession,
};
pub mod runtime {
use std::sync::Arc;
use crate::webview;
use crate::{ProxyApplyReport, ProxyConfig, WebTag, WebView, WebViewError};
pub fn find_webview(webtag: &WebTag) -> Option<Arc<WebView>> {
webview::find_webview(webtag)
}
pub fn list_webviews() -> Vec<WebTag> {
webview::list_webviews()
}
pub fn destroy_webview(webtag: &WebTag) {
webview::destroy_webview(webtag);
}
pub fn configure_proxy_for_new_webviews(
config: Option<ProxyConfig>,
) -> Result<(), WebViewError> {
webview::configure_proxy_for_new_webviews(config)
}
pub fn apply_proxy_to_current_runtime(
config: Option<ProxyConfig>,
) -> Result<ProxyApplyReport, WebViewError> {
webview::apply_proxy_to_current_runtime(config)
}
pub fn configured_proxy_for_new_webviews() -> Option<ProxyConfig> {
webview::configured_proxy_for_new_webviews()
}
}
pub mod platform {
#[cfg(target_os = "android")]
pub mod android {
pub use crate::android::{initialize_jni, with_env};
}
#[cfg(target_os = "macos")]
pub mod apple {
pub use crate::apple::toggle_webview_devtools_by_swift_ptr;
}
#[cfg(all(target_os = "linux", target_env = "ohos"))]
pub mod harmony {
pub use crate::harmony::{
check_navigation_policy, on_file_chooser_requested,
schemehandler::register_custom_schemes, tsfn, webview_controller_created,
webview_controller_destroyed,
};
#[doc(hidden)]
pub fn on_load_error(webtag: &str, url: &str, error_code: i32, description: &str) {
crate::harmony::on_load_error(webtag, url, error_code, description);
}
#[doc(hidden)]
pub fn on_download_start(
webtag_str: &str,
url: &str,
user_agent: &str,
content_disposition: &str,
mime_type: &str,
content_length: i64,
) -> bool {
crate::harmony::on_download_start(
webtag_str,
url,
user_agent,
content_disposition,
mime_type,
content_length,
)
}
}
}