pub trait WebViewDelegate: Send + Sync {
// Required methods
fn on_navigation_event(&self, event: NavigationEvent);
fn handle_post_message(&self, msg: String);
fn log(&self, level: LogLevel, message: &str);
// Provided methods
fn on_webview_state_change(&self, _change: WebViewStateChange) { ... }
fn handle_native_component_message(&self, _message_json: String) { ... }
}Expand description
WebView delegate: typed navigation lifecycle, observable state, page
messaging, and logging for one WebView. Exactly one owner per WebView
(an lxapp PageInstance or a browser tab delegate); read-only watchers
use crate::events::normalizer::add_observer-registered observers.
Delivery contract (enforced by the event normalizer):
- events arrive by value, serially, synchronously on the submitting thread, flattened FIFO — a callback is never re-entered for the same WebView;
- callbacks may arrive on the WebView’s own UI thread; fire-and-forget
commands (
exec_js) are safe there, but result-awaiting APIs must not block the callback thread; - every
Startedgets exactly one terminal event; success owns a non-empty final URL; cancellation is control flow, never a load error; - state changes are snapshots, not lifecycle:
Locationalone is never evidence of a successful visit, andNoneclears title/favicon.
Fold navigation through crate::events::NavigationProgress and state
through crate::events::ObservedWebViewState instead of hand-rolling
attempt correlation:
fn on_navigation_event(&self, event: NavigationEvent) {
let mut progress = self.progress.lock().unwrap();
progress.apply(&event);
if let NavigationEvent::Succeeded { id, final_url } = &event
&& progress.is_current(*id)
{
self.loaded(final_url);
}
}Required Methods§
One correlated top-level navigation lifecycle event.
Required: after the typed-event migration every delegate must decide how it handles the lifecycle — a silent default would lose page loads.
Sourcefn handle_post_message(&self, msg: String)
fn handle_post_message(&self, msg: String)
Handles a postMessage from the page View(WebView)
Provided Methods§
Sourcefn on_webview_state_change(&self, _change: WebViewStateChange)
fn on_webview_state_change(&self, _change: WebViewStateChange)
One observable-state snapshot (location, title, favicon, back/forward availability), coalesced and generation-scoped by the normalizer.
Sourcefn handle_native_component_message(&self, _message_json: String)
fn handle_native_component_message(&self, _message_json: String)
Handles a native-component message posted by the page through the
embedded-component channel (window.NativeComponentBridge), where
the platform routes it in-process (currently Windows/WebView2).
message_json is the raw component message (component.mount,
component.update, …).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".