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
CreateWebviewPanel- build TauriWebviewWindow, set up event handlers, record inApplicationState.Feature.Webviews.SetWebviewHTML/SetWebviewOptions- configure content and title.RevealWebviewPanel- show and focus.PostMessageToWebview- bidirectional IPC between host and webview.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.tsvs/workbench/api/browser/mainThreadWebview.ts
Modules§
- Configuration 🔒
- WebviewProvider - Configuration Operations
- Lifecycle 🔒
- WebviewProvider - Lifecycle Operations
- Messaging 🔒
- WebviewProvider - Messaging Operations
- Webview
Lifecycle State - Lifecycle state of a webview panel. Roughly mirrors the VS Code webview state machine (Unloaded → Loading → Loaded → Visible / Hidden → Disposed).
- Webview
Message - 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§
- Webview
Message 🔒Context - Webview message handler context. Private - only the dispatch
machinery in
Messaging.rsconsumes it.