Skip to content

Gérer alert, confirm, prompt et beforeunload dans les frontends intégrés (#452) - #486

Merged
AM-L merged 5 commits into
developfrom
452-script-dialogs
Nov 3, 2026
Merged

AM-L merged 5 commits into
developfrom
452-script-dialogs

Conversation

@ambroise-leclerc

@ambroise-leclerc ambroise-leclerc commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Épique #446, tâche #452 (ADR-020, règle 6).

Contenu

  • WKWebView : les trois méthodes de panneau de WKUIDelegate (sans elles, ces appels ne faisaient rien) affichent une feuille NSAlert attachée à la fenêtre ; seules les frames de l'origine de l'application sont servies, les autres sont rejetées. beforeunload n'est pas pris en charge sous WKWebView : le délégué public n'a pas de méthode pour lui et il ne passe pas par confirm (il emprunte un sélecteur privé, non implémenté). Une page qui en dépend peut perdre des modifications non enregistrées ; limite documentée.
  • WebKitGTK (script-dialog), CEF (CefJSDialogHandler), WebView2 (ScriptDialogOpening) : dialogues du moteur par défaut, avec un point d'injection de test.
  • frontend/ScriptDialogs.hpp : types partagés (ScriptDialog, ScriptDialogAnswer, ScriptDialogHandler).
  • Fermer la fenêtre avec une boîte ouverte ne bloque pas.
  • Docs : docs/FRONTENDS.md, docs/CHANGELOG.md, ADR-020 version 1.2.

Validation

  • Exécutés ici (Linux) : WebKitGTKAdapter-script-dialogs, -close-with-script-dialog, CEFFileServices-dialogs, -hold ; 437 tests hors intégration web.
  • Non exécutés ici : les scénarios WKWebView et WebView2 (écrits, non compilés sur cette machine) ; la CI macOS et Windows en fait la première validation.
  • beforeunload : câblé sous WebKitGTK, CEF et WebView2, jamais déclenché par un scénario (le moteur exige un geste utilisateur) ; non pris en charge sous WKWebView.

Après fusion, il restera à dispatcher BuildAndTest.yml sur la branche (CEF GCC et Clang).

…nds (#452)

WKWebView implements the three WKUIDelegate panel methods with an NSAlert sheet
(without them these calls did nothing); WebKitGTK, CEF and WebView2 keep their
engine's dialogs. A shared injection point (frontend/ScriptDialogs.hpp) answers
the dialogs in each frontend for tests, and closing the window with a box open
dismisses it. Scenarios cover WebKitGTK and CEF locally; WKWebView and WebView2
scenarios are added but not run on this machine.
Copilot AI balanced review requested due to automatic review settings November 3, 2026 15:18
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 48 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6d6cb1ee-c695-4aae-b895-f8921106cb14
Commits

Reviewing files that changed from the base of the PR and between 3cad03b and e1f7703.

Files selected for processing: 6
  • cmake/WKWebViewSupport.cmake
  • docs/FRONTENDS.md
  • docs/adr/ADR-020-services-systeme.md
  • include/webfront/frontend/WKWebView.hpp
  • test/web/WKWebViewLifecycle.cpp
  • test/web/script-dialogs.html
Walkthrough

La PR ajoute un contrat commun et la gestion des dialogues JavaScript dans WKWebView, WebKitGTK, CEF et WebView2. Elle ajoute des tests pour les réponses injectées et la fermeture d’une fenêtre avec un dialogue ouvert, ainsi que l’enregistrement des scénarios et leur documentation.

Changes: Dialogues scriptés dans les frontends intégrés

Layer / File(s) Summary
Contrat partagé et gestion CEF/WebKitGTK
include/webfront/frontend/ScriptDialogs.hpp, include/webfront/frontend/CEF.hpp, include/webfront/frontend/WebKitGTK.hpp
Un contrat commun définit les dialogues, les réponses et le gestionnaire injectable. CEF et WebKitGTK transmettent les dialogues au gestionnaire lorsqu’il est configuré.
Gestion des dialogues dans WKWebView
include/webfront/frontend/WKWebView.hpp
WKWebView transmet les dialogues à un gestionnaire injectable ou présente une feuille NSAlert. Il annule les demandes provenant d’une origine autre que celle de l’application.
Gestion des dialogues dans WebView2
include/webfront/frontend/WebView2.hpp
WebView2 désactive les dialogues natifs et enregistre un gestionnaire lorsque l’injection est configurée.
Scénarios, enregistrement et documentation
test/web/*, cmake/*Support.cmake, docs/CHANGELOG.md, docs/FRONTENDS.md, docs/adr/*
Les tests vérifient les dialogues et la fermeture avec un dialogue ouvert. CMake ajoute les modes de test, dont file-download pour WebView2. Les documents décrivent la prise en charge et ses limites.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant PageJavaScript
  participant Frontend
  participant GestionnaireInjecte
  PageJavaScript->>Frontend: ouvre un dialogue scripté
  Frontend->>GestionnaireInjecte: transmet ScriptDialog
  GestionnaireInjecte-->>Frontend: retourne ScriptDialogAnswer
  Frontend-->>PageJavaScript: applique la réponse
Loading

Possibly related issues

Possibly related PRs

Suggested reviewers: am-l

Merge Risk: Low · previous review 3cad0

The new dialog handling works as designed, but the documentation overstates beforeunload support under WebView2. Closing the window directly does not trigger it, so pages can lose unsaved changes. Document that limit in docs/FRONTENDS.md and in the ADR before or shortly after merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed Le titre décrit clairement la gestion de alert, confirm, prompt et beforeunload dans les frontends intégrés. Il correspond au changement principal.
Description check Passed La description est directement liée aux changements. Elle couvre les frontends concernés, les limites de WKWebView, les tests et la documentation.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 16 functions across 9 files. (4 skipped: 4 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3f7be8f0-39ca-4738-b4b7-fd21867974da
Commits

Reviewing files that changed from the base of the PR and between 4e3bacb and 3cad03b.

Files selected for processing: 10
  • docs/CHANGELOG.md
  • docs/FRONTENDS.md
  • docs/adr/ADR-020-services-systeme.md
  • docs/adr/README.md
  • include/webfront/frontend/CEF.hpp
  • include/webfront/frontend/ScriptDialogs.hpp
  • include/webfront/frontend/WKWebView.hpp
  • include/webfront/frontend/WebView2.hpp
  • test/web/CEFFileServices.cpp
  • test/web/WebKitGTKLifecycle.cpp
Files skipped from review as they are similar to previous changes: 4
  • docs/CHANGELOG.md
  • include/webfront/frontend/CEF.hpp
  • include/webfront/frontend/ScriptDialogs.hpp
  • include/webfront/frontend/WebView2.hpp

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

🟡 Changes recommended

A misleading API comment in include/webfront/frontend/ScriptDialogs.hpp incorrectly states that beforeunload dialog text is empty despite implementations passing through engine-provided text, so the documentation must be corrected before approval.

1 open issue
What changed in this PR

This pull request implements support for JavaScript alert, confirm, prompt, and beforeunload across the integrated frontends (WKWebView, WebKitGTK, CEF, WebView2), adds a shared dialog API, extends frontend integration tests, and updates documentation/ADR notes.

Changes:

  • Introduces shared script-dialog types (ScriptDialog, ScriptDialogAnswer, ScriptDialogHandler) and wires a test injection hook into each frontend.
  • Implements/bridges engine-specific dialog handlers: WKWebView (WKUIDelegate + NSAlert sheet), WebKitGTK (script-dialog), CEF (CefJSDialogHandler), WebView2 (ScriptDialogOpening).
  • Adds/extends integration tests and CMake/CTest registration, plus documentation updates (FRONTENDS, CHANGELOG, ADR-020 v1.2).
File Summary
test/​web/​WKWebViewLifecycle.cpp Adds WKWebView lifecycle scenarios covering script dialogs and closing behavior with a dialog open.
test/​web/​WebView2Lifecycle.cpp Adds a WebView2 scenario validating script dialog handling via ScriptDialogOpening and injected answers.
test/​web/​WebKitGTKLifecycle.cpp Adds WebKitGTK scenarios for script dialogs and close-with-dialog behavior.
test/​web/​script-dialogs.html Adds an HTML fixture that triggers alert/confirm/prompt (and hold mode) and encodes results via document title.
test/​web/​CMakeLists.txt Registers additional web test modes (including CEF dialog-related modes) in the test matrix.
test/​web/​CEFFileServices.cpp Extends CEF file-services tests with dialog/hold modes and assertions around dialog behavior.
include/​webfront/​frontend/​WKWebView.hpp Implements WKUIDelegate dialog callbacks, adds answerScriptDialog injection hook, and WKWebView-specific dialog presentation logic.
include/​webfront/​frontend/​WebView2.hpp Wires WebView2 ScriptDialogOpening handling and optional injection-based answering.
include/​webfront/​frontend/​WebKitGTK.hpp Hooks WebKitGTK script-dialog signal, supports injected answers, and tracks dialog-open events for tests.
include/​webfront/​frontend/​ScriptDialogs.hpp Introduces shared dialog types/handler interface used by all integrated frontends.
include/​webfront/​frontend/​CEF.hpp Adds a CEF JS dialog handler with optional injected answering and default engine dialog fallback behavior.
docs/​FRONTENDS.md Documents per-frontend dialog behavior and related test scenarios.
docs/​CHANGELOG.md Adds an unreleased changelog entry for integrated-frontend script dialog support.
docs/​adr/​ADR-020-services-systeme.md Updates ADR-020 to v1.2 reflecting the status/progress tied to this task.
cmake/​WKWebViewSupport.cmake Registers WKWebView script-dialog-related tests in CTest.
cmake/​WebView2Support.cmake Registers the WebView2 script-dialog test mode in CTest.
cmake/​WebKitGTKSupport.cmake Registers WebKitGTK script-dialog and close-with-dialog test modes in CTest.

This pull request requires changes.

Review effort: Balanced

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

Comment thread docs/adr/ADR-020-services-systeme.md Resolved

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

Comment thread docs/FRONTENDS.md Resolved
@ambroise-leclerc

Copy link
Copy Markdown
Collaborator Author

Origine opaque sous WKWebView : corrigé dans e1f7703. effectiveFrameUrl() juge toujours le frame par son securityOrigin (plus par l'URL de sa requête) ; une origine opaque (protocole ou hôte vide) n'est jamais celle de l'application. Le scénario WKWebViewLifecycle-sandboxed-script-dialog couvre un iframe sandbox="allow-scripts allow-modals" chargé depuis l'URL de l'application : son confirm est refusé, l'injection ne voit que le dialogue du parent. Ce scénario n'a pas été exécuté localement (macOS) ; la CI macOS le validera.

@AM-L
AM-L merged commit e1e33a2 into develop Nov 3, 2026
9 checks passed
@AM-L
AM-L deleted the 452-script-dialogs branch November 3, 2026 19:01
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.

3 participants