pub trait WebViewDelegate: Send + Sync {
// Required methods
fn on_navigation_event(&self, event: NavigationEvent);
fn handle_post_message(&self, message: IncomingWebMessage);
fn log(&self, level: LogLevel, message: &str);
// Provided methods
fn on_webview_state_change(&self, _change: WebViewStateChange) { ... }
fn on_document_committed(
&self,
_native_view: NativeWebViewId,
_generation: DocumentGeneration,
_navigation_id: NavigationId,
) { ... }
fn on_trusted_document_admitted(&self, _admission: TrustedDocumentAdmission) { ... }
fn on_web_content_process_terminated(&self, _native_view: NativeWebViewId) { ... }
fn on_document_restored(&self, _native_view: NativeWebViewId, _url: &str) { ... }
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, message: IncomingWebMessage)
fn handle_post_message(&self, message: IncomingWebMessage)
Handles a postMessage from the page View(WebView).
The context is assembled only by the platform adapter and must travel with the payload through any bridge admission decision.
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 on_document_committed(
&self,
_native_view: NativeWebViewId,
_generation: DocumentGeneration,
_navigation_id: NavigationId,
)
fn on_document_committed( &self, _native_view: NativeWebViewId, _generation: DocumentGeneration, _navigation_id: NavigationId, )
A top-level document binding minted from reliable, non-stale commit evidence. It is never emitted for duplicate or ambiguous commits.
Sourcefn on_trusted_document_admitted(&self, _admission: TrustedDocumentAdmission)
fn on_trusted_document_admitted(&self, _admission: TrustedDocumentAdmission)
A trusted native HTML load that reached a reliably committed document.
This is stricter than Self::on_document_committed: it is emitted
only when the platform returned the exact native navigation key for a
direct native load and the normalizer bound that key to this accepted
navigation. The data and base URL used for the load are not authority.
Sourcefn on_web_content_process_terminated(&self, _native_view: NativeWebViewId)
fn on_web_content_process_terminated(&self, _native_view: NativeWebViewId)
The platform terminated this exact WebView’s content process. Only adapters with native evidence emit it; consumers must revoke any document authority before allowing a replacement to load.
Sourcefn on_document_restored(&self, _native_view: NativeWebViewId, _url: &str)
fn on_document_restored(&self, _native_view: NativeWebViewId, _url: &str)
A backend proved that a previously committed document was restored without a fresh native start/commit chain (for example from BFCache). The adapter revokes its generation before invoking this hook.
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".