1- // BrowserView is a non-wasm-only render surface; many of its helpers
2- // (persistence import, internal model accessor) compile on wasm but
3- // the WKWebView-driven code paths that consume them don't.
1+ // BrowserView is a non-wasm-only render surface; some helpers compile on
2+ // wasm even though the WKWebView-driven code paths that consume them don't.
43#![ cfg_attr( target_family = "wasm" , allow( dead_code, unused_imports) ) ]
54
65use std:: collections:: HashMap ;
@@ -47,7 +46,6 @@ use super::browser_model::{BrowserModel, TabId, DEFAULT_BROWSER_URL};
4746#[ cfg( not( target_family = "wasm" ) ) ]
4847use super :: data_dir;
4948use super :: find:: FindState ;
50- use super :: persistence;
5149use super :: url_input:: { resolve_with_engine, Resolved } ;
5250#[ cfg( not( target_family = "wasm" ) ) ]
5351use super :: webview_host:: SharedWebContext ;
@@ -284,6 +282,11 @@ pub struct BrowserView {
284282 /// per wry's docs). `None` on wasm.
285283 #[ cfg( not( target_family = "wasm" ) ) ]
286284 web_context : Option < SharedWebContext > ,
285+ /// Stable per-pane UUID that keys this pane's WebKit data dir. Captured
286+ /// at construction (fresh `Uuid::v4` for new panes; restored from
287+ /// `BrowserPaneSnapshot` for rehydrated panes) so the data dir at
288+ /// `<warp_home>/browser/data/<session_id>/` survives app restarts.
289+ session_id : String ,
287290 /// Per-tab UI mouse states keyed by stable [`TabId`] so they survive tab
288291 /// closures (which shift indices).
289292 tab_ui_states : HashMap < TabId , TabUiState > ,
@@ -314,6 +317,11 @@ impl BrowserView {
314317 pub ( crate ) fn model ( & self ) -> & BrowserModel {
315318 & self . model
316319 }
320+
321+ /// Stable per-pane session id. Empty on wasm (no WebKit data store).
322+ pub ( crate ) fn session_id ( & self ) -> & str {
323+ & self . session_id
324+ }
317325}
318326
319327impl BrowserView {
@@ -322,6 +330,8 @@ impl BrowserView {
322330 #[ cfg( not( target_family = "wasm" ) ) ] session_id : & str ,
323331 ctx : & mut ViewContext < Self > ,
324332 ) -> Self {
333+ #[ cfg( not( target_family = "wasm" ) ) ]
334+ let session_id = data_dir:: normalize_session_id ( session_id) ;
325335 let model = BrowserModel :: new ( initial_url. unwrap_or_default ( ) ) ;
326336 let pane_configuration =
327337 ctx. add_model ( |_ctx| PaneConfiguration :: new ( model. display_title ( ) ) ) ;
@@ -334,7 +344,7 @@ impl BrowserView {
334344 // WKWebsiteDataStore default store regardless (wry 0.38
335345 // limitation, see `data_dir`), but creating the directory keeps
336346 // the layout consistent for future macOS plumbing.
337- let dir = data_dir:: browser_data_dir ( session_id) ;
347+ let dir = data_dir:: browser_data_dir ( & session_id) ;
338348 // Construct the WebContext even when dir is None — wry handles
339349 // the missing-dir case internally with its platform default.
340350 Some ( Rc :: new ( RefCell :: new ( wry:: WebContext :: new ( dir) ) ) )
@@ -414,6 +424,10 @@ impl BrowserView {
414424 event_tx,
415425 #[ cfg( not( target_family = "wasm" ) ) ]
416426 web_context,
427+ #[ cfg( not( target_family = "wasm" ) ) ]
428+ session_id,
429+ #[ cfg( target_family = "wasm" ) ]
430+ session_id : String :: new ( ) ,
417431 tab_ui_states,
418432 workspace_tab_visible : true ,
419433 back_button_mouse_state : MouseStateHandle :: default ( ) ,
@@ -443,14 +457,15 @@ impl BrowserView {
443457 session_id : & str ,
444458 ctx : & mut ViewContext < Self > ,
445459 ) -> Self {
460+ let session_id = data_dir:: normalize_session_id ( session_id) ;
446461 let model = BrowserModel :: restore ( state) ;
447462 let pane_configuration =
448463 ctx. add_model ( |_ctx| PaneConfiguration :: new ( model. display_title ( ) ) ) ;
449464 let ( event_tx, event_rx) = async_channel:: unbounded :: < NativeWebViewEvent > ( ) ;
450465
451466 let web_context: Option < SharedWebContext > = {
452467 // Per-session data dir; see `Self::new` for the platform notes.
453- let dir = data_dir:: browser_data_dir ( session_id) ;
468+ let dir = data_dir:: browser_data_dir ( & session_id) ;
454469 Some ( Rc :: new ( RefCell :: new ( wry:: WebContext :: new ( dir) ) ) )
455470 } ;
456471
@@ -531,6 +546,7 @@ impl BrowserView {
531546 webviews,
532547 event_tx,
533548 web_context,
549+ session_id,
534550 tab_ui_states,
535551 workspace_tab_visible : true ,
536552 back_button_mouse_state : MouseStateHandle :: default ( ) ,
@@ -935,14 +951,6 @@ impl BrowserView {
935951 } ) ;
936952 }
937953
938- #[ cfg( not( target_family = "wasm" ) ) ]
939- fn persist_open_state ( & self , open : bool ) {
940- let state = self . model . snapshot ( open) ;
941- if let Err ( err) = persistence:: save_to_default_dir ( & state) {
942- log:: warn!( "failed to persist browser state: {err}" ) ;
943- }
944- }
945-
946954 #[ allow( clippy:: too_many_arguments) ]
947955 fn render_toolbar_button (
948956 & self ,
@@ -1557,7 +1565,6 @@ impl BackingView for BrowserView {
15571565 for webview in & self . webviews {
15581566 webview. borrow_mut ( ) . detach_native ( ) ;
15591567 }
1560- self . persist_open_state ( false ) ;
15611568 }
15621569 ctx. emit ( BrowserViewEvent :: Pane ( PaneEvent :: Close ) ) ;
15631570 }
0 commit comments