Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
91049ab
Make <input type=file> and downloads work in the embedded frontends (…
ambroise-leclerc Nov 2, 2026
aaf8a36
Fix the CI failures and address the review of #451
ambroise-leclerc Nov 2, 2026
51b268d
Remove the qualification report job and fix two WKWebView download ca…
ambroise-leclerc Nov 2, 2026
839b8fb
Keep a replaced download's outcome, resolve the download folder with …
ambroise-leclerc Nov 2, 2026
7194ca6
Qualify WebView2 file services on Windows
ambroise-leclerc Nov 2, 2026
6436a53
Avoid GCC warning in CEF download verification
ambroise-leclerc Nov 2, 2026
11e8bcc
Qualify WKWebView file services on macOS
ambroise-leclerc Nov 2, 2026
a3da18f
Test the GLib download folder and closing WebKitGTK's window over its…
ambroise-leclerc Nov 2, 2026
2e6e12c
Keep WKWebView's panel answers independent of the session and judge a…
ambroise-leclerc Nov 2, 2026
bb60002
Correct the list of engines that test closing over a dialog (#451)
ambroise-leclerc Nov 2, 2026
4651583
Create the WebKitGTK download folder, cancel WKDownloads on close, re…
ambroise-leclerc Nov 2, 2026
3db2c49
Reserve download destinations so concurrent downloads never share a p…
ambroise-leclerc Nov 3, 2026
bc3f3f3
Key a WKWebView download by its own pointer when the save panel answe…
ambroise-leclerc Nov 3, 2026
effe73c
Record the manual qualification of the macOS save panel (#451)
ambroise-leclerc Nov 3, 2026
109db0f
Remove the incomplete files of the downloads a closing session cancel…
ambroise-leclerc Nov 3, 2026
158ceb5
Fix failed download cleanup and file-service CI regressions (#451)
ambroise-leclerc Nov 3, 2026
52d8c68
Preserve unrelated files during WKWebView downloads
ambroise-leclerc Nov 3, 2026
ac3b738
Fix macOS staging declaration and clarify validation evidence (#451)
ambroise-leclerc Nov 3, 2026
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)
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)
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)
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)
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
3 changes: 2 additions & 1 deletion cmake/WebView2Support.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ function(webfront_add_webview2_tests)
"${webtest_source_dir}/WebView2HeaderConsumer.cpp")
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)
closed-startup-timeout failed-startup-timeout late-navigation-failure runtime-ready
file-choose file-cancel file-download)
add_test(NAME WebView2Lifecycle-${mode} COMMAND webview2_lifecycle ${mode})
webfront_set_browser_test_properties("WebView2Lifecycle-${mode}" "${webtest_source_dir}" 45)
endforeach()
Expand Down
10 changes: 10 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

## Unreleased

- 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
now passes the navigation policy, so a generated Blob can be downloaded. Test injection points answer the chooser and the
download without a dialog (`docs/FRONTENDS.md`). On Windows, WebView2 tests exercise chooser selection and cancellation
through DevTools and verify completed downloads on disk; the native dialog UI itself remains unqualified.
WKWebView stages downloads privately and preserves a destination created during transfer; failed downloads remove their
incomplete files. Automatic destination selection cancels instead of reusing
an occupied path when all 10,000 candidate names are taken.

- Developer environment: the distribution is served from `https://dist.webfront.fr/` (#478, ADR-021). The sources advance to 0.6.5, the
first version published under that address; `site.mjs` writes the `CNAME` file of the Pages branch and `wf run pin`
checks the pinned archive where it is served now. Libraries and environments up to 0.6.4 pin the former
Expand Down
48 changes: 48 additions & 0 deletions docs/FRONTENDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,54 @@ startup failures before any window is created. Coordination waits have a 30-seco
`test/unit/WebFrontTests.cpp` also checks initialization once per frontend type, retry after failed
initialization, frontend selection and unavailable-engine diagnostics. These tests need no GUI.

## File chooser and downloads

The embedded frontends use their engine's file chooser and download handling without a WebFront API (ADR-020, rule 6).
Coverage varies by engine and does not yet qualify all native dialogs, `accept` filters or directory selection. A `blob:` URL of an
admitted origin passes the navigation policy (`webfront::detail::blobOriginUrl`); a `blob:` URL of any other origin does not.

| Frontend | Chooser | Download | Test injection |
| --- | --- | --- | --- |
| WebKitGTK | default `run-file-chooser` dialog (portal under Flatpak) | `download-started` / `decide-destination`: the user's XDG download folder, the page's name reduced to its last component, never overwriting (`name (1).ext`), also between downloads that run at the same time (`DownloadReservations`) | `Session::chooseFiles`, `downloadDirectory`, `downloadFinished` |
| CEF (Chrome runtime) | the runtime's dialog | the runtime's download handling | `SimpleCEFClient::chooseFiles` (`CefDialogHandler::OnFileDialog`), `downloadDirectory`, `downloadFinished`. The runtime itself turns a suggested name `../x` into `_x` |
| WKWebView | `runOpenPanelWithParameters` shows an `NSOpenPanel` sheet of the window; only frames admitted by the policy | `WKDownload` (macOS 11.3+): a save panel proposes the name | `WKWebViewOptions::chooseFiles`, `downloadDirectory`, `downloadFinished` |
| WebView2 | the engine's native chooser | the engine's native download UI | DevTools intercepts the chooser in tests; `DownloadStarting` redirects the download to a private path |

The engines require a user gesture to open a chooser, so the native scenarios click with a real pointer event (XTest under
Xvfb for WebKitGTK), a `Runtime.evaluate` with `userGesture` (CEF) or `evaluateJavaScript`, which WebKit treats as a user
gesture (WKWebView). The WKWebView scenarios (`WKWebViewLifecycle-download`, `-choose-file`, `-cancel-choose`,
`-replaced-download`) use the test injections of `WKWebViewOptions`: they qualify the delegate wiring, the blob download
policy, the destination handling and the replace-on-success logic, not the system `NSOpenPanel`/`NSSavePanel` themselves.
The real panels were driven by hand on macOS before the private staging change in `52d8c68` (accessibility actions, a
local slow server, no automated test): saving and the
"Replace" choice report the finished download and leave no `.part` file; cancelling the save sheet creates nothing; an
`<input webkitdirectory>` panel offers folders only; two simultaneous downloads of one name get `same.bin` and
`same (1).bin`; closing the window cancels the downloads in progress and removes their incomplete files; a response the
engine cannot display (`application/octet-stream`) is saved as a download.
These earlier manual results do not qualify the private staging implementation; the PR records subsequent validation
separately. Native dialog qualification remains incomplete.
WebKit reduces a suggested name such as `../x.txt` to `_x.txt` before the frontend sees it.
If all 10,000 candidate names are occupied, automatic destination selection fails and cancels the download.
WKWebView writes each download in a private staging directory beside the destination. On success it installs the file;
if a destination that was free appears during the download, it preserves that file and discards the download. Failed and
cancelled downloads remove their staging directory. Installing a new destination requires hard-link support on its filesystem.

### Tests

`ConsumerJasmine-file-services` (all engines) checks that files reach the page as `File` objects, that the `accept` and
`webkitdirectory` properties keep their values (filtering and directory selection themselves are not exercised), and
that offering a generated Blob leaves the page and the bridge working. `WebKitGTKAdapter-download|choose-file|cancel-choose`
and `CEFFileServices-download|choose|cancel` drive the dialog and the download through the injection points.
`WebKitGTKAdapter-download-user-dir` checks that, without a configured folder, the download lands in GLib's user download
directory (read from `user-dirs.dirs`, not from an environment variable). `WebKitGTKAdapter-close-with-dialog` opens the
real system dialog with a pointer click, closes the window under it and requires a clean exit; CEF and WebView2 do not
test that case. `WKWebViewLifecycle-close-with-open-panel|close-with-save-panel` close the window under an
`NSOpenPanel` / `NSSavePanel` sheet, and `choose-in-blank|choose-in-srcdoc` open a chooser from `about:blank` and `srcdoc`
frames, which WKWebView judges by their inherited origin.
`WebView2Lifecycle-file-choose|file-cancel|file-download` verifies the engine's chooser request, selection and cancellation
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.

## 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
22 changes: 20 additions & 2 deletions docs/adr/ADR-020-services-systeme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
| Version | Date | État | Auteur | Évolution | Révision Git |
| --- | --- | --- | --- | --- | --- |
| 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` |

## État et chronologie

**Proposée** le **2026-10-31**. Aucun code n'est livré avec cette version : elle fixe le cadre des services
système et leurs préalables (épiques #446 à #450) avant l'implémentation du premier d'entre eux (sélection de fichiers). Elle passera à « Acceptée » quand les
**Proposée** le **2026-10-31**. La version 1.0 ne livrait aucun code : elle fixe le cadre des services
système et leurs préalables (épiques #446 à #450) avant l'implémentation du premier d'entre eux (sélection de fichiers). La version 1.1 livre une partie de l'étape 1 (#451) ; la décision reste proposée. Elle passera à « Acceptée » quand les
critères de la section dédiée seront démontrés.

## Contexte
Expand Down Expand Up @@ -352,6 +353,23 @@ Le code vérifié le 2026-10-31 ne permet pas encore d'implémenter ces règles.
| 4 | [#449](https://github.com/ambroise-leclerc/WebFront/issues/449) Stockage modifiable et livraison des services | [#460](https://github.com/ambroise-leclerc/WebFront/issues/460) stockage sous racines déclarées, confiné pendant la résolution (révision de l'ADR-002) ; [#461](https://github.com/ambroise-leclerc/WebFront/issues/461) paquet `@webfront/services` | sélecteur HTML et écritures (règles 2 à 4) |
| 5 | [#450](https://github.com/ambroise-leclerc/WebFront/issues/450) Intégration native des frontends | [#462](https://github.com/ambroise-leclerc/WebFront/issues/462) exécuteur du thread d'interface, y compris le navigateur système ; [#463](https://github.com/ambroise-leclerc/WebFront/issues/463) fenêtre native et correspondance avec les connexions | backend natif seulement |

État de l'étape 1 (#451), preuves disponibles au 2026-11-03 : sélecteur et téléchargements implémentés dans les quatre
moteurs, avec des validations de provenance et de révision distinctes. Les résultats suivants ne valent que pour les
révisions indiquées ; ils ne qualifient pas automatiquement les changements ultérieurs.

| Moteur | Source de validation | Révision et portée |
| --- | --- | --- |
| WebKitGTK | [CI Linux](https://github.com/ambroise-leclerc/WebFront/actions/runs/41628819255/job/125892906278) | `52d8c68` : suite CTest, dont sélection, annulation et téléchargements. |
| WebView2 | [CI Windows](https://github.com/ambroise-leclerc/WebFront/actions/runs/41628819255/job/125892850205) | `52d8c68` : suite CTest ; sélection interceptée par DevTools et téléchargements redirigés, sans qualification des dialogues natifs. Les 538 tests MSVC Release locaux rapportés dans la [PR #484](https://github.com/ambroise-leclerc/WebFront/pull/484) constituent une preuve locale distincte. |
| CEF | [CI étendue GCC et Clang](https://github.com/ambroise-leclerc/WebFront/actions/runs/41614144327) | `158ceb5`, antérieure au stockage privé WKWebView : scénarios CEF de fichiers et suite Jasmine. Les essais Linux locaux rapportés dans la PR sont distincts de cette exécution CI. |
| WKWebView | [CI macOS](https://github.com/ambroise-leclerc/WebFront/actions/runs/41614129707/job/125843186922) | `158ceb5`, antérieure au stockage privé ajouté dans `52d8c68` : scénarios automatisés de sélection, téléchargement, remplacement et fermeture sous un panneau. |
| WKWebView, panneaux réels | Essais manuels locaux rapportés dans la [PR #484](https://github.com/ambroise-leclerc/WebFront/pull/484) et `docs/FRONTENDS.md` | Réalisés avant `52d8c68` ; la révision exacte de chaque essai n'est pas consignée. Ces résultats ne qualifient pas le nouveau stockage privé. |

À 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.

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
des tableaux typés en morceaux ; leur ajout au serveur, utile aux très gros envois en flux et aux formulaires sans
Expand Down
18 changes: 18 additions & 0 deletions include/webfront/ContentPolicy.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <algorithm>
#include <cctype>
#include <optional>
#include <stdexcept>
#include <string>
Expand Down Expand Up @@ -130,6 +131,21 @@ inline std::optional<std::string> contentOrigin(std::string_view url, bool origi
return serializedContentOrigin(parts->scheme, authority->host, *port, defaultPort);
}

/**
* @brief The URL a `blob:` URL was minted for (`blob:http://host:port/id` gives `http://host:port/id`), or empty.
*
* A page downloads a generated `Blob` by navigating to such a URL; its content always belongs to the page's own origin,
* so the origin it names is the one the navigation policy must judge.
*/
inline std::string_view blobOriginUrl(std::string_view url) {
constexpr std::string_view scheme = "blob:";
if (url.size() <= scheme.size() || !std::ranges::equal(url.substr(0, scheme.size()), scheme, [](char a, char b) {
return std::tolower(static_cast<unsigned char>(a)) == b;
}))
return {};
return url.substr(scheme.size());
}

/** @brief Validated snapshot shared by the HTTP and embedded-frontend policy hooks. */
class BoundContentPolicy {
public:
Expand All @@ -147,6 +163,8 @@ class BoundContentPolicy {
}

bool allowsNavigation(std::string_view url) const {
if (const auto inner = blobOriginUrl(url); !inner.empty())
url = inner; // A Blob of an admitted origin (a generated download) is that origin's own content.
const auto origin = contentOrigin(url);
return origin && (policy.allowAnyNavigation || *origin == applicationOrigin || contains(policy.navigationAllowedOrigins, *origin));
}
Expand Down
Loading
Loading