Skip to main content

Module WebviewProvider

Module WebviewProvider 

Source
Expand description

WebviewProvider: creates and manages sandboxed webview panels.

§WebviewProvider (Environment)

Implements the WebviewProvider trait for MountainEnvironment, providing the core logic for creating, managing, and securing Webview panels.

§Architecture

Extension → CreateWebviewPanel → WebviewProvider → Tauri WebviewWindow
                    │                              │
                    └→ IPC → Cocoon ◄───────────┘

§Webview types

  • Panel - sidebar or panel webview (non-floating)
  • Editor - webview as custom editor (full editor area)
  • Modal - modal dialog webview (blocks interaction)
  • Widget - small embedded webview (e.g., diff viewer)

§Lifecycle

  1. CreateWebviewPanel - build Tauri WebviewWindow, set up event handlers, record in ApplicationState.Feature.Webviews.
  2. SetWebviewHTML / SetWebviewOptions - configure content and title.
  3. RevealWebviewPanel - show and focus.
  4. PostMessageToWebview - bidirectional IPC between host and webview.
  5. DisposeWebviewPanel - close window and clean up state.

§Security

Webview runs in a sandboxed process (no Node.js). All postMessage calls are validated; origins are checked to prevent XSS. Memory footprint is ~50-100 MB per webview - reuse panels when possible.

§VS Code reference

  • vs/workbench/contrib/webview/browser/webviewService.ts
  • vs/workbench/api/browser/mainThreadWebview.ts

Modules§

Configuration 🔒
WebviewProvider - Configuration Operations
Lifecycle 🔒
WebviewProvider - Lifecycle Operations
Messaging 🔒
WebviewProvider - Messaging Operations
WebviewLifecycleState
Lifecycle state of a webview panel. Roughly mirrors the VS Code webview state machine (Unloaded → Loading → Loaded → Visible / Hidden → Disposed).
WebviewMessage
Webview message envelope: identifier, type tag, payload, and an optional source identifier. Used for host ↔ webview message passing routed through the Tauri event bus.

Structs§

WebviewMessageContext 🔒
Webview message handler context. Private - only the dispatch machinery in Messaging.rs consumes it.