Skip to content

refactor: federate flutter_cef for cross-platform (macOS + platform_interface; Windows/Linux-ready)#2

Merged
wenkaifan0720 merged 5 commits into
mainfrom
refactor/federated-cross-platform
Jun 10, 2026
Merged

refactor: federate flutter_cef for cross-platform (macOS + platform_interface; Windows/Linux-ready)#2
wenkaifan0720 merged 5 commits into
mainfrom
refactor/federated-cross-platform

Conversation

@wenkaifan0720

Copy link
Copy Markdown
Collaborator

Restructures flutter_cef into a federated Flutter plugin so a Windows or
Linux implementation can be added later as an independent, endorsed package —
without touching the app-facing API or the macOS implementation. No behavior
change; the public API and consumers' imports are unchanged.

Plan + rationale: specs/cross-platform/PLAN.md. Porting contract: PORTING.md.

Structure

flutter_cef/                         # app-facing package (re-exports the API)
  packages/
    flutter_cef_platform_interface/  # shared Dart types + the method-channel contract
    flutter_cef_macos/               # endorsed macOS impl (Swift plugin + cef_host)
    flutter_cef_windows/  _linux/    # <- a future port adds these

Phases (each landed behind a green gate)

  • P1 — extract flutter_cef_platform_interface: shared DTOs (cef_events,
    cef_input, moved with history) + FlutterCefPlatform (PlatformInterface) +
    default MethodChannelFlutterCef. Root re-exports the types so
    package:flutter_cef/flutter_cef.dart is unchanged. Gate: analyze + 94 tests.
  • P2 — move the macOS impl (Swift macos/, native/cef_host, tool/) into
    the endorsed flutter_cef_macos package; root declares
    default_package: flutter_cef_macos. The example's GeneratedPluginRegistrant
    now auto-resolves flutter_cef_macos — proof the endorsement is correct.
    Gate: example macOS build + cef_host rebuild/bundle from the new path + render
    smoke (1 host + 6 helper subprocesses).
  • P3 — native core/+platform/ code-split deferred by design: a
    platform abstraction designed without a second consumer guesses the seam wrong.
    The seam is mapped precisely in PORTING.md instead; the split is the first
    step of the first real port.
  • P4PORTING.md (Dart side + host-plugin duties + the cef_host
    platform-seam map with main.mm file:line refs), README/CHANGELOG, bump to
    0.1.3.

Verification

  • flutter analyze clean across all three packages.
  • flutter test — 94 pass.
  • Example builds on macOS via the federated plugin; cef_host builds + bundles
    from its new location; renders (helper subprocesses spawn).

🤖 Generated with Claude Code

wenkaifan0720 and others added 5 commits June 9, 2026 16:16
First phase of the federated cross-platform restructure (see
specs/cross-platform/PLAN.md). Adds packages/flutter_cef_platform_interface
holding the shared Dart types (cef_events, cef_input — moved here, history
preserved) and the FlutterCefPlatform contract: a PlatformInterface whose
default MethodChannelFlutterCef exposes the 'flutter_cef' method channel. The
cross-platform contract is that method-channel protocol, which each platform's
native plugin speaks.

Root flutter_cef now depends on the interface package; the controller reads its
channel from FlutterCefPlatform.instance, and the public library re-exports the
shared types so consumers' `package:flutter_cef/flutter_cef.dart` imports are
unchanged. macOS plugin stays at root for now (moves in P2).

Gate: flutter analyze clean (both packages); 94 tests pass.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…kage

Second phase of the federated restructure. Relocates the entire macOS
implementation — the Swift plugin (macos/), the cef_host native tree
(native/), and the bundling tool (tool/) — into
packages/flutter_cef_macos, and wires the federation:

- New flutter_cef_macos package: implements: flutter_cef, with
  pluginClass: FlutterCefPlugin + dartPluginClass: FlutterCefMacos (the Dart
  side just endorses the default method-channel instance).
- Podspec renamed flutter_cef.podspec -> flutter_cef_macos.podspec (s.name +
  repo-root LICENSE path updated). Source files / resources unchanged.
- Root flutter_cef pubspec now declares
  `platforms: macos: default_package: flutter_cef_macos` and depends on it, so a
  plain dependency on flutter_cef still provides macOS.
- The build/bundle scripts moved together with native/, so their relative paths
  (build_cef_host.sh -> cef_host, bundle_cef_host.sh -> ../native) still resolve.

App-facing API and the example are unchanged. The example's
GeneratedPluginRegistrant now auto-resolves `import flutter_cef_macos` +
FlutterCefPlugin.register — proof the endorsement is correct.

Gate: analyze clean (all 3 packages); example macOS build succeeds; cef_host
rebuilds + bundles from the new path; render smoke = 1 host + 6 helper
subprocesses spawn, clean quit.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Final phase of the federated restructure. Adds PORTING.md — the contract for a
Windows/Linux implementation: the small Dart/package side (pubspec endorsement +
registerWith), the host-plugin responsibilities, and a precise platform-seam map
for cef_host (shared surface / IPC transport / app loop / sandbox / framework
path) with main.mm file:line references and the macOS reference for each.

Documents the decision to DEFER the native core/platform code-split until the
first real non-macOS port (a platform abstraction designed without a second
consumer guesses the seam wrong; the seam is mapped in PORTING.md instead).

Updates README (federated layout, moved build/bundle paths, Windows/Linux
roadmap → PORTING.md) + example README paths. Bumps all four packages to 0.1.3.

Gate: analyze clean (all 3 packages); git diff --check clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Final-audit remediation (batch 1 of 2): the one real security defect + the
publishability/packaging gaps.

Security (MEDIUM):
- bundle_cef_host.sh selected the dev entitlements.plist (with get-task-allow)
  unconditionally, so a distributable bundle re-signed with a real identity
  silently re-added get-task-allow (a task-port priv-esc on a JIT process, and a
  notarization hard-fail). Now: ad-hoc ("-") keeps the dev plist; a real identity
  uses entitlements.release.plist; CEF_HOST_ENTITLEMENTS overrides.

Packaging hygiene (MEDIUM/LOW) for the new federated sub-packages:
- Add LICENSE, README.md, CHANGELOG.md, analysis_options.yaml to both
  flutter_cef_platform_interface and flutter_cef_macos (pana/pub.dev require
  per-package; the missing analysis_options meant their code wasn't linted).
- Fix the podspec license path '../../../LICENSE' -> '../LICENSE' (the old path
  escaped the package tree and broke `pod lib lint` on a standalone extraction).
- Add topics: + issue_tracker: to both sub-package pubspecs.
- Document the publish procedure (path -> hosted constraint swap, bottom-up) in
  the root pubspec; keep path deps (correct for the source/path/git consumption
  Campus uses) and silence the analyzer's invalid_dependency warning with that
  rationale.

Gate: flutter analyze clean across all three packages (whole-package).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Final-audit remediation, batch 2 — verified, no behavior change.

Dart:
- cef_web_view: `_ensureSession` now bails on `!mounted` first, so the
  post-frame callback can't read a deactivated MediaQuery or resize a torn-down
  session after a same-frame removal.
- Clarifying comments: the empty `_onPointerPanZoomStart` (required to route
  pan-zoom updates), `currentTextEditingValue` returning the empty scratch state
  by design (the page owns the text), and the process-global, never-torn-down
  static method-call handler.

Native (cef_host main.mm):
- Header `Args:`/opcode-range comments updated for `--allowed-schemes` and
  kOpLoadTrusted (0x34).
- Gate the three informational bring-up `fprintf(stderr)`s behind
  FLUTTER_CEF_DEBUG (genuine error prints kept); a release no longer logs noise.
- Close `g_ipc_fd` at teardown under the write mutex (was leaked) and clear it.
- Document the benign identical-URL trusted-load edge.

Swift:
- Replace the stale FlutterCefPlugin header verb list (6 of ~27) with a pointer
  to the switch + PORTING.md as the authoritative protocol reference.

Gate: analyze clean; 94 tests pass; cef_host rebuilds clean (0 errors); render
smoke OK (host + helpers spawn, clean teardown).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@wenkaifan0720 wenkaifan0720 merged commit bc4d7e4 into main Jun 10, 2026
1 check failed
@wenkaifan0720 wenkaifan0720 deleted the refactor/federated-cross-platform branch June 10, 2026 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant