Nacre/Plans/08 WebKit engine/S044-engine-seam.md

4.3 KiB

S044 — Engine seam: pure logic out of the Servo files

Category 08 WebKit engine · Model: Opus · Effort: medium · Depends on: — · Size: M · Human: no · cargo (main target/) Files touched: src/hub.rs, src/net/privacy.rs (new), src/adblock.rs, src/tabs.rs, src/app.rs, src/actions.rs, src/selftest.rs, src/store/cookies.rs, Cargo.toml (no dep changes)

Goal

First step of docs/engine/servo-removal.md §7: everything that must survive Servo moves out of Servo-typed code, and the event surface the glue produces becomes engine-neutral, so S045 can swap the engine without touching app logic. The app still builds and runs on Servo at the end of this plan.

Read

  • docs/engine/servo-removal.md §3 (all), §7.
  • src/hub.rs (whole), src/tabs.rs (types), src/app.rs handle_event (547–800), the hub:: uses in src/actions.rs (grep).

Steps

  • Move privacy_headers, strip_tracking, the Firefox-style language list and third-party matching (from hub.rs / net::nacre callers) into src/net/privacy.rs with their unit tests (privacy_language_list_is_firefox_style, privacy_headers_follow_the_settings_and_reach_requests, third_party_matching_keeps_same_site_subdomains); Servo code calls the new module.
  • Move HubConfig and the request decision (HTTPS-only upgrade, tracking strip, image permission, ad-block verdict → Decision enum with Block/Replace/Redirect/Allow) out of Hub::decide into an engine-neutral fn decide(cfg, req) -> Decision (pure, unit-tested); load_web_resource becomes a thin adapter.
  • Give tabs a Nacre-owned view id (ViewId(u64), reuse new_tab_id) and make hub::Event carry it instead of WebViewId; one map WebViewId → ViewId lives in the Servo glue only. — moved to S045 (orchestrator, 2026-11-13, D-041)
  • Replace Servo payload types in Event and tabs.rs (LoadStatus, JSValue, ContextMenu, EmbedderControl, PermissionRequest, ConsoleLogLevel, …) by small Nacre enums/structs (LoadState, JsValue = serde_json::Value, PageMenuRequest, Control, PermissionAsk, …) holding a glue-side handle (boxed responder closure) where Servo needs an answer object. — moved to S045 (orchestrator, 2026-11-13, D-041)
  • Port selftest.rs JS-result matches and fakeload to the neutral types. — moved to S045 (orchestrator, 2026-11-13, D-041)
  • nice cargo build --release -j 2 green; nice cargo test --release -j 2 green (new tests counted).
  • Smoke on Servo still green: tools/smoke.sh tests/smoke/launch.txt, basics.txt, input.txt (hidden).
  • PROGRESS entry, INDEX line, tracker, commit S044: …, push.

WIP — stopped here (2026-11-13, context limit of the spike session)

  • Done (boxes 1–2): src/net/privacy.rs (privacy headers, tracking strip, language list + tests), src/net/policy.rs (HubConfig, Request, Outcome, pure decide() + 4 tests); Hub::decide is a thin Servo adapter. The third-party test stays in hub.rs (it tests vendored servo-net; WebKit's cookie policy replaces it). Note: Outcome, not Decision (name taken by store::permissions).
  • Verified on the WIP: release build green, cargo test 74 green (was 70), smokes launch, basics, input, net-adblock, net-privacy exit 0 (hidden, Servo).
  • Not done: boxes 3–4 (ViewId, neutral payload types). Finding: 56 uses of Servo payload types outside hub.rs plus 14 WebViewId sites in app/actions; converting them now means new Servo adapters that S045/S048 delete again. Recommendation for the orchestrator: fold boxes 3–4 into S045 (Event surface defined there directly on WebKit, with the payload types S047/S048 need), then tick 5–7 here on what exists and close S044.

End criteria

  • grep -rn "servo::" src --include=*.rs | grep -v -E "src/(hub|window|app|resources)\.rs" lists only glue adapters (each named in PROGRESS); src/net/privacy.rs has no servo import.
  • cargo test green, launch/basics/input smokes green.

Pitfalls

  • No behaviour change: this is a move, not a rewrite (CLAUDE.md §3). Keep the hub::Event-after-spin design.
  • Servo needs answers synchronously in load_web_resource; keep the decision pure and fast.
  • One cargo user per target/ (CLAUDE.md §4).

Handoff (→ PROGRESS.md)

List the neutral types and where the glue adapters live; S045 implements the same Event surface on WebKit.