Skip to content

Conversation

Dimoshka
Copy link

@Dimoshka Dimoshka commented Sep 13, 2025

Refactor and enhance webview_cef: Linux dialogs, init options, GPU toggle, Dart readiness fixes

Summary

This PR improves stability and usability across platforms with a focus on Linux. It adds native GTK file dialogs, exposes initialization options (userAgent, cachePath, persistence flags, enableGPU), fixes a Linux frame-id mismatch, hardens shutdown, and cleans up Dart code for stronger typing and null-safety. Build tooling on Linux now tolerates missing Debug CEF bundles by falling back to Release binaries. Documentation is updated accordingly.

Key changes

Dart

  • Add explicit types and null-safe callback invocations throughout the library.
  • Gate JS/eval APIs on controller readiness to avoid early-call assertions.
  • Coalesce high-frequency input events (hover/drag/scroll) and debounce size reporting to reduce redundant platform traffic.
  • Improve listener wiring and event routing in WebviewManager.
  • Tests: initialize test bindings properly and modernize mock handlers.

Native/C++

  • Linux: implement native file dialogs via GTK through CEF’s dialog handler (Open/Save/Select Folder; multi-select; simple filters).
  • Normalize frame-id comparisons on Linux by converting CefFrame::GetIdentifier() to a consistent int64_t before comparisons.
  • Threading: ensure operations run on the correct CEF threads (UI/IO) for input, cookies, and lifecycle; add helper for posting lambdas.
  • Shutdown: close all browsers on the CEF UI thread and clear references before CefShutdown to avoid atexit teardowns and fatal asserts.
  • DevTools shortcut routing and lifecycle counters for safe shutdown after last browser closes.

Build/CMake (Linux)

  • Add DOWNLOAD_CEF_FLAVOR option (standard | minimal) to control prebuilt size.
  • If Debug CEF binaries are missing, fall back to Release libcef.so and resources to enable Debug builds of the plugin.

Initialization options

New runtime options (Dart WebviewManager.initialize → native CEF settings):

  • userAgent: product string appended to the default UA.
  • cachePath: writable directory for on-disk cache and preferences.
  • persistSessionCookies: persist session cookies (requires non-empty cachePath).
  • persistUserPreferences: persist user preferences (requires non-empty cachePath).
  • enableGPU: toggle GPU acceleration (applies command-line switches accordingly).

Documentation

  • README: document Linux native file dialogs, Debug→Release fallback, CEF flavor option, and initialization options with examples and notes.

Cross-platform notes

  • cachePath, persistSessionCookies, and enableGPU are applied across platforms (subject to CEF constraints).
  • persistUserPreferences may depend on CEF build exposure; if unavailable on a platform, it’s ignored safely.
  • Linux dialogs are native GTK; no extra Flutter plugin is required.

Verification

  • Dart analyzer: clean (no missing type annotations; null-safety observed).
  • Linux: example builds and runs; dialogs functional; early JS/eval no longer assert; Debug builds succeed with Release CEF fallback.
  • Manual QA: navigation, console messages, devtools open, pointer/scroll input, IME composition updates rendered and routed to Flutter.

Breaking changes

  • None expected. The new init options are optional and default to previous behavior when omitted.

Migration

  • Optional: call WebviewManager().initialize({...}) early in app startup if you want custom UA, persistent cache/cookies, or to enable GPU.

Next steps (optional)

  • Consider exposing a Flutter-side file picker override for apps that prefer a custom UI.
  • Stress-test shutdown across repeated create/close cycles on Windows and macOS.

- Updated `webview_plugin.h` to improve class structure and added new methods for CEF initialization and browser lifecycle tracking.
- Modified `main.dart` to replace print statements with debugPrint for better logging.
- Updated `pubspec.yaml` to allow Dart SDK version up to 4.0.0 and upgraded flutter_lints to version 6.0.0.
- Refactored `webview.dart` for improved readability and consistency in method calls.
- Cleaned up `webview_inject_user_script.dart` and `webview_javascript.dart` for better formatting and clarity.
- Enhanced `webview_manager.dart` with detailed comments and improved method signatures for better understanding.
- Updated `webview_textinput.dart` to include proper method signatures and debugPrint for state changes.
- Improved `webview_tooltip.dart` for better overlay handling.
- Added missing export for `webview_inject_user_script.dart` in `webview_cef.dart`.
- Updated method channel implementation in `webview_cef_method_channel.dart` for better readability.
- Enhanced CMake configuration in `CMakeLists.txt` and `download.cmake` to allow for minimal or standard CEF flavor downloads.
- Refactored `webview_cef_plugin.cc` to improve memory management and method invocation handling.
- Updated tests in `webview_cef_method_channel_test.dart` and `webview_cef_test.dart` for better mock handling and removed unused test file `webview_main_test.dart`.
@Dimoshka Dimoshka marked this pull request as ready for review September 15, 2025 08:27
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