Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/WKWebViewSupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function(webfront_add_wkwebview_tests)
add_executable(wkwebview_lifecycle "${webtest_source_dir}/WKWebViewLifecycle.cpp"
"${webtest_source_dir}/WKWebViewHeaderConsumer.cpp")
target_link_libraries(wkwebview_lifecycle PRIVATE WebFront WebFront_warnings WebFront_options)
foreach(mode repeated-show main-thread native-close quit navigation-diagnostic startup-timeout settings redirect-policy missing-response committed-navigation agent-application download choose-file cancel-choose replaced-download choose-in-blank choose-in-srcdoc close-with-open-panel close-with-save-panel)
foreach(mode repeated-show main-thread native-close quit navigation-diagnostic startup-timeout settings redirect-policy missing-response committed-navigation agent-application download choose-file cancel-choose replaced-download choose-in-blank choose-in-srcdoc close-with-open-panel close-with-save-panel script-dialogs close-with-script-dialog sandboxed-script-dialog)
add_test(NAME WKWebViewLifecycle-${mode} COMMAND wkwebview_lifecycle ${mode})
webfront_set_browser_test_properties("WKWebViewLifecycle-${mode}" "${webtest_source_dir}" 90)
endforeach()
Expand Down
2 changes: 1 addition & 1 deletion cmake/WebKitGTKSupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function(webfront_add_webkitgtk_tests)
target_link_libraries(webkitgtk_lifecycle PRIVATE WebFront_test_hardening WebFront WebFront_warnings WebFront_options)
add_dependencies(webtest webkitgtk_lifecycle)
webfront_find_xvfb(display_runner)
foreach(mode no-display worker-thread native-close repeated-show http-error pre-run-failure profile-permissions window-title download download-user-dir choose-file cancel-choose close-with-dialog)
foreach(mode no-display worker-thread native-close repeated-show http-error pre-run-failure profile-permissions window-title download download-user-dir choose-file cancel-choose close-with-dialog script-dialogs close-with-script-dialog)
if(mode MATCHES "^(no-display|worker-thread|pre-run-failure|profile-permissions)$")
add_test(NAME WebKitGTKAdapter-${mode} COMMAND webkitgtk_lifecycle ${mode})
elseif(display_runner)
Expand Down
2 changes: 1 addition & 1 deletion cmake/WebView2Support.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function(webfront_add_webview2_tests)
target_link_libraries(webview2_lifecycle PRIVATE WebFront WebFront_warnings WebFront_options)
foreach(mode repeated-show native-early-close navigation-diagnostic mta missing-runtime
closed-startup-timeout failed-startup-timeout late-navigation-failure runtime-ready
file-choose file-cancel file-download)
file-choose file-cancel file-download script-dialogs)
add_test(NAME WebView2Lifecycle-${mode} COMMAND webview2_lifecycle ${mode})
webfront_set_browser_test_properties("WebView2Lifecycle-${mode}" "${webtest_source_dir}" 45)
endforeach()
Expand Down
5 changes: 5 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

- Embedded frontends: `alert`, `confirm`, `prompt` and `beforeunload` (`beforeunload` is not handled under WKWebView, see `docs/FRONTENDS.md`; #452, ADR-020 rule 6). WKWebView implements the three
`WKUIDelegate` panel methods (an `NSAlert` sheet of the window; without them these calls did nothing); WebKitGTK, CEF and
WebView2 keep their engine's dialogs. A shared test injection (`frontend/ScriptDialogs.hpp`) answers the dialogs in each
frontend, and closing the window with a box open dismisses it. See `docs/FRONTENDS.md` for the engine-by-engine coverage.

- Embedded frontends: `<input type="file">` and downloads (#451, ADR-020 rule 6). WebKitGTK saves downloads to the user's
download folder (name reduced to its last component, never overwritten); WKWebView gets `runOpenPanelWithParameters` and
`WKDownload`; CEF and WebView2 use the engine's own handling. A `blob:` URL of an admitted origin
Expand Down
38 changes: 38 additions & 0 deletions docs/FRONTENDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,44 @@ frames, which WKWebView judges by their inherited origin.
events, and the bytes written by a completed Blob download. It intercepts the chooser with DevTools and suppresses the download UI,
so it does not qualify the native dialogs themselves or closing the window while one is open.

## Script dialogs

`alert`, `confirm` and `prompt` work in every embedded frontend, and `beforeunload` in all but WKWebView, without a WebFront API (ADR-020, rule 6, #452).
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
All four engines use the system's or the engine's own box attached to the window by default; each frontend also has a test
injection that answers without a box, with the shared types of `frontend/ScriptDialogs.hpp` (`ScriptDialog`,
`ScriptDialogAnswer`, `ScriptDialogHandler`). Closing the window with a box open never waits for an answer. Under WKWebView the sheet's completion handler answers dismissed (`false` for `confirm`, `null` for `prompt`);
under the other engines the page is gone with the window, and the value its call would have returned is not observable.

| Frontend | Dialogs | Test injection |
| --- | --- | --- |
| WebKitGTK | `script-dialog` signal; the default handler shows WebKitGTK's dialog on the window | `Session::answerScriptDialog` (`scriptDialogOpened` reports the default dialog) |
| CEF (Chrome runtime) | `CefJSDialogHandler` (`OnJSDialog`, `OnBeforeUnloadDialog`) answered only by the injection; otherwise the runtime's own dialogs | `SimpleCEFClient::answerScriptDialog` |
| WKWebView | the three `WKUIDelegate` panel methods (alert, confirm, prompt; not `beforeunload`, see below) show an `NSAlert` sheet of the window (an accessory text field for `prompt`); only frames whose security origin is the application's, others (including a sandboxed frame without `allow-same-origin`, whose origin is opaque even at the application's URL) are dismissed | `WKWebViewOptions::answerScriptDialog` |
| WebView2 | the engine's own dialogs, until the injection turns them off and answers `ScriptDialogOpening` (kinds alert, confirm, prompt, beforeunload) | `Session::answerScriptDialog` (adapter-internal, set from a `prepare` hook) |

Origin filtering differs: WKWebView answers dismissed for a frame outside the application's origin, because its code shows the
box itself. WebKitGTK, CEF and WebView2 leave the decision to the engine's own dialog (or to the injection), without a
WebFront origin check; the content policy that already restricts navigation to admitted origins is the guard there.

**Limit: closing the window does not ask `beforeunload`.** Closing the window itself is not a page navigation. Under WebView2
the window's `WM_CLOSE` ends in `ICoreWebView2Controller::Close`, which does not raise `beforeunload`; navigations and reloads
can reach the handler. Under WebKitGTK and CEF this was not verified. A page can therefore lose unsaved changes when the user
closes the window; the application must save its state itself (for example on `visibilitychange`).

**Limit: WKWebView does not handle `beforeunload`.** The public `WKUIDelegate` has no method for it; WebKit routes it through a
private selector (`_webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:`), not through the confirm
method, and WebFront does not implement a private selector. A page that asks for a confirmation before leaving can therefore
lose unsaved changes under WKWebView; the application must save its state itself (for example on `visibilitychange`). This was
not verified on macOS: support through the private selector, if wanted, needs a decision and a check on a real system. The other
three engines report `ScriptDialog::Kind::beforeUnload`.

Tests: `WebKitGTKAdapter-script-dialogs` and `CEFFileServices-dialogs` check that each dialog reaches the injection with its
message and default text, that a confirmed `confirm` returns `true`, an accepted `prompt` returns its text and a dismissed
one returns `null`. `WebKitGTKAdapter-close-with-script-dialog` and `CEFFileServices-hold` close the window under an open
alert; `WKWebViewLifecycle-script-dialogs|close-with-script-dialog|sandboxed-script-dialog` (the last: a sandboxed opaque-origin frame's `confirm` is dismissed, never shown) and `WebView2Lifecycle-script-dialogs` cover the same
on their engines (the WebView2 case has no close-under-dialog scenario). No scenario triggers a real `beforeunload` (the
engines show it only after a user gesture on the page); its wiring is implemented but not exercised end to end.

## Adding a frontend

1. Implement the type in `include/webfront/frontend/` following the contract above and include it from `Frontend.hpp`. Keep platform headers behind the option's macro.
Expand Down
3 changes: 2 additions & 1 deletion docs/adr/ADR-020-services-systeme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
| --- | --- | --- | --- | --- | --- |
| 1.0 | 2026-10-31 | Proposée | Ambroise Leclerc | Décision initiale : distinction hôte/client, préalables regroupés en épiques (#446 à #450), confinement des racines pendant la résolution et hypothèse de confiance face au déplacement d'un répertoire ouvert ou de la racine, autorisation attachée à l'emplacement déclaré, propriétaires admissibles des répertoires et des ancêtres, transport du navigateur système déclaré (`loopbackAttested`) plutôt que prouvé par un secret de lancement, jetons de lecture réutilisables liés à la connexion par un cookie, exposition des jetons et transport des lectures distantes, exception de confiance explicite, liaison HTTP par profil de navigateur avec cookies nommés par client, contenu actif neutralisé, transport déclaré et association de lancement du navigateur système, racines déclarées accessibles à tout script admis, services en composants facultatifs, sélection par l'utilisateur valant autorisation (poignées plutôt que chemins), backends natif, HTML et navigateur choisis par connexion, contenu des fichiers par HTTP à jeton ; état de l'art et inventaire des autres services. | À renseigner après intégration. |
| 1.1 | 2026-11-02 | Proposée, partiellement livrée | Ambroise Leclerc | Livraison partielle de l'étape 1 pour #451 (sélecteur de fichiers et téléchargements sous WebKitGTK, CEF, WKWebView et WebView2) ; #452 reste à faire. La section « État de l'étape 1 » distingue les preuves de validation par moteur et par révision ; `docs/FRONTENDS.md` précise les limites de couverture. | Branche `451-file-chooser-downloads` (PR #484), implémentation initiale `91049ab`, stockage privé WKWebView `52d8c68` |
| 1.2 | 2026-11-03 | Proposée, partiellement livrée | Ambroise Leclerc | Livraison de #452 (`alert`, `confirm`, `prompt` partout ; `beforeunload` sauf sous WKWebView, qui n'a pas de délégué public pour lui) : l'étape 1 n'est complète qu'avec cette limite. `docs/FRONTENDS.md` précise la couverture par moteur (WKWebView et WebView2 non exécutés localement ; `beforeunload` non exercé de bout en bout et jamais demandé à la fermeture de la fenêtre). | Branche `452-script-dialogs` |

## État et chronologie

Expand Down Expand Up @@ -368,7 +369,7 @@ révisions indiquées ; ils ne qualifient pas automatiquement les changements ul
À la révision `52d8c68`, le nouveau stockage privé WKWebView n'avait pas été exécuté sur macOS : la compilation CI avait
échoué avant les tests. Le correctif et les validations ultérieures sont consignés dans la PR #484. La qualification
des dialogues natifs reste partielle ; les injections de test ne la remplacent pas. `docs/FRONTENDS.md` détaille les
limites par moteur. #452 reste à faire et l'ADR reste proposée.
limites par moteur. #452 est livré dans la version 1.2 (`beforeunload` n'est pas pris en charge sous WKWebView ; sous WebView2, la fermeture de la fenêtre elle-même ne le déclenche pas non plus, seules les navigations et les rechargements le font ; non vérifié sous WebKitGTK et CEF, voir `docs/FRONTENDS.md`) ; l'ADR reste proposée.

Après l'étape 4, le premier service (sélecteur HTML, poignées, import et export côté client) fera l'objet de sa propre
épique ; les dialogues natifs suivront l'étape 5. `PUT`/`POST` ne sont pas des préalables : les écritures passent par
Expand Down
2 changes: 1 addition & 1 deletion docs/adr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ verification evidence remain in [PROJECT_STATUS](../PROJECT_STATUS.md).
| [ADR-017](ADR-017-acces-direct-aux-frontends.md) | Direct access to embedded frontends, with HTML kept normative | Proposed | 2026-10-24 | 1.1 — 2026-10-25 |
| [ADR-018](ADR-018-acces-au-dom.md) | DOM access from C++ through a bounded mutation stream, without contesting the DOM of UI libraries | Proposed, partially superseded, partially delivered | 2026-10-26 | 1.5 — 2026-10-30 |
| [ADR-019](ADR-019-developpement-automatisable-et-agents.md) | Automating the developer environment through shared operations and an optional local MCP adapter | Accepted | 2026-10-28 | 1.2 — 2026-10-29 |
| [ADR-020](ADR-020-services-systeme.md) | System services (files, clipboard, shell, notifications…) through optional C++ portals with per-connection backends, granting handles rather than paths | Proposed | 2026-10-31 | 1.0 — 2026-10-31 |
| [ADR-020](ADR-020-services-systeme.md) | System services (files, clipboard, shell, notifications…) through optional C++ portals with per-connection backends, granting handles rather than paths | Proposed | 2026-10-31 | 1.2 — 2026-11-03 |
| [ADR-021](ADR-021-publication-de-l-environnement-developpeur.md) | Simplifying the publication of the developer environment: automate the release, keep pinned hashes, no dedicated server | Accepted (domain delivered; phase 1 to implement) | 2026-11-02 | 1.0 — 2026-11-02 |

Numbering follows the reading topics; milestones and individual file histories provide
Expand Down
42 changes: 41 additions & 1 deletion include/webfront/frontend/CEF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Capture.hpp"
#include "DefaultBrowser.hpp"
#include "Downloads.hpp"
#include "ScriptDialogs.hpp"
#include "Url.hpp"
#include "Window.hpp"

Expand Down Expand Up @@ -499,7 +500,8 @@ class SimpleCEFClient : public CefClient,
public CefContextMenuHandler,
public CefCommandHandler,
public CefDownloadHandler,
public CefDialogHandler {
public CefDialogHandler,
public CefJSDialogHandler {
public:
explicit SimpleCEFClient(webfront::detail::BoundContentPolicy policy = webfront::detail::BoundContentPolicy{}, browser::Launcher launch = browser::launch)
: contentPolicy(std::move(policy)), popupLauncher(launch) { }
Expand Down Expand Up @@ -535,6 +537,33 @@ class SimpleCEFClient : public CefClient,
CefRefPtr<CefDialogHandler> GetDialogHandler() override {
return this;
}
/// Test injection: answers alert, confirm, prompt and beforeunload without a dialog. Unset keeps the engine's own dialogs.
frontend::ScriptDialogHandler answerScriptDialog;
CefRefPtr<CefJSDialogHandler> GetJSDialogHandler() override {
return this;
}
bool OnJSDialog(CefRefPtr<CefBrowser>,
const CefString&,
JSDialogType type,
const CefString& message,
const CefString& defaultText,
CefRefPtr<CefJSDialogCallback> callback,
bool&) override { // suppress_message stays false: the injection is the answer.
if (!answerScriptDialog)
return false;
frontend::ScriptDialog dialog;
dialog.kind = type == JSDIALOGTYPE_CONFIRM ? frontend::ScriptDialog::Kind::confirm
: type == JSDIALOGTYPE_PROMPT ? frontend::ScriptDialog::Kind::prompt
: frontend::ScriptDialog::Kind::alert;
dialog.message = message.ToString();
dialog.defaultText = defaultText.ToString();
return answer(dialog, callback);
}
bool OnBeforeUnloadDialog(CefRefPtr<CefBrowser>, const CefString& message, bool, CefRefPtr<CefJSDialogCallback> callback) override {
if (!answerScriptDialog)
return false;
return answer({frontend::ScriptDialog::Kind::beforeUnload, message.ToString(), {}}, callback);
}
bool OnFileDialog(CefRefPtr<CefBrowser>,
FileDialogMode,
const CefString&,
Expand Down Expand Up @@ -705,6 +734,17 @@ class SimpleCEFClient : public CefClient,
}

private:
bool answer(const frontend::ScriptDialog& dialog, CefRefPtr<CefJSDialogCallback> callback) {
frontend::ScriptDialogAnswer reply;
try {
reply = answerScriptDialog(dialog);
} catch (...) {
reply = {}; // A failing injection dismisses the dialog; the page must not wait for it.
}
callback->Continue(reply.accepted, reply.text);
return true;
}

webfront::detail::BoundContentPolicy contentPolicy;
browser::Launcher popupLauncher;
bool loadingInitialPage = true;
Expand Down
31 changes: 31 additions & 0 deletions include/webfront/frontend/ScriptDialogs.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <functional>
#include <string>

namespace webfront::frontend {

/** @brief A JavaScript dialog the page asked an embedded frontend to show: `alert`, `confirm`, `prompt` or `beforeunload`. */
struct ScriptDialog {
enum class Kind { alert, confirm, prompt, beforeUnload };

Kind kind{Kind::alert};
std::string message{}; ///< The page's text; for `beforeunload`, whatever text the engine supplies (possibly empty, often a fixed phrase).
std::string defaultText{}; ///< The initial value of a `prompt`.
};

/** @brief The answer to a ScriptDialog. `accepted` is `confirm`'s result, `prompt`'s non-null result, and a `beforeunload` that lets the page go. */
struct ScriptDialogAnswer {
bool accepted{false};
std::string text{}; ///< The string a `prompt` returns when accepted.
};

/**
* @brief Test injection shared by the embedded frontends: answers script dialogs without showing a box.
*
* It runs on the thread of the frontend's window and must return promptly. When unset, each frontend shows the system's box
* attached to its window; closing the window with a box open answers it as dismissed, so the window never blocks on it.
*/
using ScriptDialogHandler = std::function<ScriptDialogAnswer(const ScriptDialog&)>;

} // namespace webfront::frontend
Loading
Loading