From d967f2a539fd6b49216cc0f74b573105075162cb Mon Sep 17 00:00:00 2001 From: astar76 Date: Sat, 14 Nov 2026 07:49:56 -0600 Subject: [PATCH] S051: WIP profile folder nacre-browser, sealed WebKit cookie store on tmpfs Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 2 +- .../S051-profile-cookies-media.md | 5 +- src/app.rs | 19 +- src/engine/host.rs | 7 + src/engine/mod.rs | 2 + src/paths.rs | 90 +++- src/store/cookies.rs | 421 ++++++++++++++---- tests/smoke/integ-spell.txt | 4 +- tests/smoke/sliders.txt | 2 +- tests/smoke/stores-vault-check.sh | 2 +- 10 files changed, 446 insertions(+), 108 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index f7f5634..a3f6604 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -68,7 +68,7 @@ Never modify: `~/Documents/Apps/Nacre` (the original Python Nacre, reference onl | `nacre://gallery` + `SMOKE_SIZE=1400x2800 tools/smoke.sh tests/smoke/gallery.txt` | every design token and widget, dark and light (+ new tab and settings shots); read the PNGs | now (S015) | | `SMOKE_SIZE=1400x1200 tools/smoke.sh tests/smoke/newtab.txt` | new tab page dark/light, nothing playing and a video playing, weather failed state, tall/narrow/phone widths (offline); `tests/smoke/newtab-weather.txt` shoots the real weather card (needs internet); read the PNGs | now (S017) | | `SMOKE_SIZE=1400x900 tools/smoke.sh tests/smoke/backgrounds.txt` | every new tab background with the pointer, Customize panel dark/light, image + blur, GIF frames; `perf-*-a/b.json` `frames` (median/max draw ms, `drawn` count) per background at Lots/Fast, hidden tab, still, Motion off. Selftest `pointer x y`, `customize`; `@PAGESDIR@` = path of tests/smoke/pages | now (S018) | -| `tools/smoke.sh tests/smoke/settings.txt` (+ `SMOKE_SIZE=1280x1100`) | every settings section and sub-page dark and light, search results (`nacre://settings/?search=…`), narrow width; `settings-write.txt` (hidden, `SMOKE_SIZE=1280x1100`, fresh outdir) taps controls with selftest `tap x y`, then check `home/.config/nacre-servo/Default/settings.json` (expected values in its header) | now (S019) | +| `tools/smoke.sh tests/smoke/settings.txt` (+ `SMOKE_SIZE=1280x1100`) | every settings section and sub-page dark and light, search results (`nacre://settings/?search=…`), narrow width; `settings-write.txt` (hidden, `SMOKE_SIZE=1280x1100`, fresh outdir) taps controls with selftest `tap x y`, then check `home/.config/nacre-browser/Default/settings.json` (expected values in its header) | now (S019) | | `SMOKE_SIZE=1280x1600 tools/smoke.sh tests/smoke/sliders.txt` | controls hold still (R1-21): Interface size drag (value label while held, applied on release), Contrast live, Style chip pick; `SMOKE_VISIBLE=1 tools/smoke.sh tests/smoke/sliders-visible.txt` the same plus scrolling for the user's window (~772 px). Selftest `press`/`drag`/`release`, `scroll x y dy`; read the PNGs | now (R1-21) | | `python3 tests/smoke/net/server.py &` + `tools/smoke.sh tests/smoke/net-{privacy,adblock,downloads}.txt` | network pass, offline: secure DNS through a local DoH stub (`*.nacre.test` → 127.0.0.1), HTTPS-only + certificate warning, tracking params, ad blocker with a local list, downloads + download manager stubs; the server's `/log` has requests, DNS names, Range headers, manager calls. `cache-restart.txt` with `SMOKE_HOME=/home`: disk cache. `net-real.txt` needs internet. `@HOME@` in scripts = the throwaway home | now (S007) | | `SMOKE_TIMEOUT=400 tools/smoke.sh tests/smoke/mse.txt`, `…/mse-player.txt` | plain MSE tests on WebKit: chunk-appended fMP4, WebM and split A/V play; `mse-spec.html` spec cases (attach/detach, duration, buffered/seekable, remove, removeSourceBuffer, changeType, abort, reopen, sequence); player integration (attach, seeks, rate, ended, decode error, garbage append; `?only=` in the page URL for one case). Offline, start `python3 -m http.server 8765 --bind 127.0.0.1 --directory tests/smoke/pages &` first (MSE needs an http origin). `youtube-mse.txt` is an internet probe | S022, S027, S028, S053 | diff --git a/Plans/08 WebKit engine/S051-profile-cookies-media.md b/Plans/08 WebKit engine/S051-profile-cookies-media.md index 7228c63..48846b8 100644 --- a/Plans/08 WebKit engine/S051-profile-cookies-media.md +++ b/Plans/08 WebKit engine/S051-profile-cookies-media.md @@ -13,7 +13,7 @@ one MPRIS player. - D-019, D-037, D-038, D-039; `docs/engine/servo-removal.md` §3.8, §3.9; `src/paths.rs`, `src/store/cookies.rs` (whole); `tests/smoke/cookies.txt` header. ## Steps -- [ ] `paths.rs`: `APP_DIR = "nacre-browser"`; migration (rename config/data/cache once if new missing and old present; delete Servo-only engine files after; log it); unit test with temp dirs; `~/.config/nacre` never touched. +- [x] `paths.rs`: `APP_DIR = "nacre-browser"`; migration (rename config/data/cache once if new missing and old present; delete Servo-only engine files after; log it); unit test with temp dirs; `~/.config/nacre` never touched. - [ ] Cookies: persistent storage path in `$XDG_RUNTIME_DIR/nacre-/cookies.sqlite`; at start decrypt `cookies.bin` → `add_cookie` (or write the SQLite) ; seal at quit and 60 s after `changed`; no keyring → run-only; convert Servo-era `cookies.bin` when it parses, else move aside. - [ ] Clear data / clear on exit / site info flyout on `WebsiteDataManager` (types + since-time) and `CookieManager::get_cookies`; drop the "Servo keeps no dates" text. - [ ] Incognito: ephemeral session, nothing written; check the throwaway home after a run. @@ -30,3 +30,6 @@ one MPRIS player. ## Handoff (→ PROGRESS.md) Migration behaviour, seal timing, MPRIS outcome (which player). + +## Resume note (WIP) +- Box 2 code done (store/cookies.rs: tmpfs `nacre--/cookies.sqlite` written with rusqlite from cookies.bin, sealed by reading the DB; engine `Setup::cookie_db`, `Event::CookiesChanged`, App `cookies` tick/finish); unit tests green. Next: release build, cookies smokes to verify box 2, then box 3. diff --git a/src/app.rs b/src/app.rs index 1cf4dd0..b14b5b9 100644 --- a/src/app.rs +++ b/src/app.rs @@ -238,6 +238,8 @@ pub struct App { last_tick: Instant, last_save: Instant, last_slow: Instant, + /// Sealed cookies (D-037), `None` when they are kept for the run only. + cookies: Option, last_presence: Instant, pub crashed_last_time: bool, pub instance: Option, @@ -362,6 +364,7 @@ impl App { last_tick: Instant::now(), last_save: Instant::now(), last_slow: Instant::now() - Duration::from_secs(3600), + cookies: None, last_presence: Instant::now(), crashed_last_time, instance: None, @@ -399,6 +402,8 @@ impl App { fn start_engine(&mut self) { let settings = self.shared.settings.borrow().clone(); let dark = self.web_dark(); + // WebKit's cookie store on tmpfs, sealed into cookies.bin (D-037); without it cookies stay in memory. + self.cookies = crate::store::cookies::start(&self.shared.paths.data, &self.shared.paths.profile, self.shared.incognito); let paths = &self.shared.paths; let setup = crate::engine::host::Setup { dirs: (!self.shared.incognito).then(|| (paths.webkit_data(), paths.webkit_cache())), @@ -408,9 +413,8 @@ impl App { developer_extras: true, remote_inspector: settings.web.remote_debugging.then(|| "127.0.0.1:6080".to_owned()), filter_store: paths.cache.join("content-filters"), + cookie_db: self.cookies.as_ref().map(|c| c.db().to_path_buf()), }; - // Cookies stay in WebKit's memory for the run until S051 seals them (D-037); never plain on disk. - crate::store::cookies::start(&self.shared.paths.data, &self.shared.paths.engine(), self.shared.incognito); let engine = Engine::new(self.hub.clone(), &setup); { use crate::store::permissions::{Decision, Kind}; @@ -808,6 +812,11 @@ impl App { Event::Notification(id, notification) => self.on_notification(id, notification), Event::Page(id, message) => self.on_page_message(id, message), Event::Find(id, count) => self.on_find(id, count), + Event::CookiesChanged => { + if let Some(cookies) = &mut self.cookies { + cookies.changed(Instant::now()); + } + }, } } @@ -1152,6 +1161,9 @@ impl App { self.last_slow = now; self.slow_tick(); } + if let Some(cookies) = &mut self.cookies { + cookies.tick(now); + } } fn update_media_now(&mut self) { @@ -1645,6 +1657,9 @@ impl App { self.shared.settings.borrow_mut().adblock.total += total; self.save_settings(); self.clear_on_exit(); + if let Some(cookies) = self.cookies.take() { + cookies.finish(self.shared.settings.borrow().privacy.clear_on_exit.iter().any(|w| w == "cookies")); + } self.flush_stores(); for control in self.download_controls.values() { control.store(download::PAUSE, Ordering::Relaxed); diff --git a/src/engine/host.rs b/src/engine/host.rs index 7c8b3f7..c5e4d36 100644 --- a/src/engine/host.rs +++ b/src/engine/host.rs @@ -27,6 +27,8 @@ pub struct Setup { pub remote_inspector: Option, /// Where WebKit keeps the compiled ad blocker filters. pub filter_store: std::path::PathBuf, + /// WebKit's SQLite cookie store (on tmpfs, sealed by `store::cookies`); `None` = cookies in memory only. + pub cookie_db: Option, } pub struct Engine { @@ -135,6 +137,11 @@ impl Engine { if let Some(manager) = session.website_data_manager() { manager.set_favicons_enabled(true); } + if let (Some(db), Some(cookies)) = (&setup.cookie_db, session.cookie_manager()) { + cookies.set_persistent_storage(&db.to_string_lossy(), webkit::CookiePersistentStorage::Sqlite); + let hub = hub.clone(); + cookies.connect_changed(move |_| hub.push(Event::CookiesChanged)); + } // Everything goes through Nacre's bridge except this machine's own addresses (the bridge would only send // them straight back). SOCKS5: its login is part of the handshake, so plain http works too (S050). if let Some(proxy) = &setup.proxy { diff --git a/src/engine/mod.rs b/src/engine/mod.rs index c2759ee..52cdc70 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -87,6 +87,8 @@ pub enum Event { Page(ViewId, PageMessage), /// Find in page: how many matches the last search or step found (0: none). Find(ViewId, u32), + /// A cookie was added, changed or deleted. + CookiesChanged, } /// A user style sheet (`store::scripts`), added at author level so it acts like the page's own last `