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
51 changes: 20 additions & 31 deletions docs/CHANGELOG.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/DEVELOPER_ENVIRONMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ above). Rows before 0.9 were reconstructed from the header of each tag; 0.4.0 pr
| Library | Environment | Minimum api |
| --- | --- | --- |
| unreleased | 1.3.0 | 1 |
| 1.3.0 | 1.3.0 | 1 |
| 1.2.0 | 1.2.0 | 1 |
| 1.1.1 | 1.0.1 | 1 |
| 1.1.0 | 1.0.1 | 1 |
Expand Down
2 changes: 1 addition & 1 deletion include/webfront/WebFront.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct PageRegistration;
template <typename App>
class BasicSpace;

inline constexpr std::string_view version = "1.2.0";
inline constexpr std::string_view version = "1.3.0";

namespace testing {
/// Test-only access to the connection identifiers of an application; not part of the API.
Expand Down
8 changes: 4 additions & 4 deletions include/webfront/frontend/WebKitGTK.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ inline void initialize(SandboxMode mode = SandboxMode::development) {
const bool repairing = inheritedSnapToolkitPaths();
if (repairing) {
const auto threads = processThreadCount();
const auto message = threads == 1 ? snapRepairMessage(scrubInheritedSnapEnvironment())
: snapRepairSkippedMessage(snapOverriddenNames(), threads);
const auto message = threads == 1 ? snapRepairMessage(scrubInheritedSnapEnvironment()) : snapRepairSkippedMessage(snapOverriddenNames(), threads);
std::fwrite(message.data(), 1, message.size(), stderr);
}
// Looked up whether or not something was repaired: one unmarked variable (GIO_MODULE_DIR) can break WebKit alone.
Expand All @@ -207,8 +206,9 @@ inline void initialize(SandboxMode mode = SandboxMode::development) {
std::string names;
for (const auto& name : unmarked)
names += (names.empty() ? "" : ", ") + name;
log::warn("WebKitGTK: " + names + " hold Snap paths that no editor marked as inherited; left unchanged, see "
"docs/WEBKITGTK.md if WebKit fails to start");
log::warn("WebKitGTK: " + names
+ " hold Snap paths that no editor marked as inherited; left unchanged, see "
"docs/WEBKITGTK.md if WebKit fails to start");
}
}
}
Expand Down
51 changes: 25 additions & 26 deletions include/webfront/frontend/WebKitGTKPolicy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// Created: 2026-10-19
//
// WebFront — frontend
// Role: Navigation, new-window and response decisions of the WebKitGTK frontend, applying the bound content policy, and the repair of an inherited Snap environment.
// Role: Navigation, new-window and response decisions of the WebKitGTK frontend (bound content policy); repair of an inherited Snap environment.
// Thread: ui-loop | Alloc: heap-init
// LLM: decision logic kept free of GTK calls so unit tests can reach it; scrubInheritedSnapEnvironment() mutates the process environment, so it runs on the main thread before the toolkit starts and before other threads read the environment
// LLM: GTK-free decisions for unit tests; scrubInheritedSnapEnvironment() mutates the environment: main thread, before the toolkit and other threads

#pragma once

Expand Down Expand Up @@ -136,18 +136,18 @@ struct SnapSensitiveVariable {
// `<NAME>_VSCODE_SNAP_ORIG` are repaired. GIO_MODULE_DIR alone is enough
// to break WebKit's network process: the Snap's GIO modules carry an RPATH to /snap/core20, which loads its libpthread.
inline constexpr std::array snapSensitiveVariables = {
SnapSensitiveVariable{ "LD_LIBRARY_PATH", ":;"},
SnapSensitiveVariable{ "LD_PRELOAD", ": "},
SnapSensitiveVariable{ "GIO_MODULE_DIR", ""},
SnapSensitiveVariable{ "GTK_PATH", ":"},
SnapSensitiveVariable{ "GTK_EXE_PREFIX", ""},
SnapSensitiveVariable{ "GTK_IM_MODULE_FILE", ""},
SnapSensitiveVariable{"GSETTINGS_SCHEMA_DIR", ""},
SnapSensitiveVariable{ "LOCPATH", ":"},
SnapSensitiveVariable{ "LD_LIBRARY_PATH", ":;"},
SnapSensitiveVariable{ "LD_PRELOAD", ": "},
SnapSensitiveVariable{ "GIO_MODULE_DIR", ""},
SnapSensitiveVariable{ "GTK_PATH", ":"},
SnapSensitiveVariable{ "GTK_EXE_PREFIX", ""},
SnapSensitiveVariable{ "GTK_IM_MODULE_FILE", ""},
SnapSensitiveVariable{ "GSETTINGS_SCHEMA_DIR", ""},
SnapSensitiveVariable{ "LOCPATH", ":"},
SnapSensitiveVariable{"GDK_PIXBUF_MODULE_FILE", ""},
SnapSensitiveVariable{"GDK_PIXBUF_MODULEDIR", ""},
SnapSensitiveVariable{ "XDG_DATA_DIRS", ":"},
SnapSensitiveVariable{ "XDG_CONFIG_DIRS", ":"}
SnapSensitiveVariable{ "GDK_PIXBUF_MODULEDIR", ""},
SnapSensitiveVariable{ "XDG_DATA_DIRS", ":"},
SnapSensitiveVariable{ "XDG_CONFIG_DIRS", ":"}
};

inline const char* savedSnapOriginal(const SnapSensitiveVariable& variable) {
Expand Down Expand Up @@ -194,7 +194,7 @@ inline std::string withoutSnapPaths(std::string_view value, std::string_view sep
if (!containsSnapPath(part)) {
if (!first)
kept += separators.front();
kept += part;
kept += part;
first = false;
keptEmpty = keptEmpty || part.empty();
}
Expand All @@ -212,16 +212,15 @@ inline std::string snapRepairMessage(const std::vector<std::string>& names) {
std::string list;
bool loader = false;
for (const auto& name : names) {
list += (list.empty() ? "" : ", ") + name;
list += (list.empty() ? "" : ", ") + name;
loader = loader || name == "LD_LIBRARY_PATH" || name == "LD_PRELOAD";
}
// The dynamic loader read these two at startup: changing them cannot unload or redirect what this process has.
return "WebFront: inherited Snap environment would break WebKit's processes; repaired " + list
+ " for this process and the processes it starts"
+ (loader ? " (LD_LIBRARY_PATH and LD_PRELOAD do not change the libraries this process already loaded or searches "
"with dlopen; start it from a cleaned environment if it still fails)"
: "")
+ " (see docs/WEBKITGTK.md, \"Snap-hosted editor terminals\")\n";
return "WebFront: inherited Snap environment would break WebKit's processes; repaired " + list + " for this process and the processes it starts"
+ (loader ? " (LD_LIBRARY_PATH and LD_PRELOAD do not change the libraries this process already loaded or searches "
"with dlopen; start it from a cleaned environment if it still fails)"
: "")
+ " (see docs/WEBKITGTK.md, \"Snap-hosted editor terminals\")\n";
}

/// Names `scrubInheritedSnapEnvironment()` would change, without changing anything.
Expand Down Expand Up @@ -259,9 +258,9 @@ inline std::string snapRepairSkippedMessage(const std::vector<std::string>& name
const auto why = threads ? "this process already runs " + std::to_string(*threads) + " threads"
: std::string("this process cannot tell how many threads it runs (/proc/self/task is unreadable)");
return "WebFront: inherited Snap environment would break WebKit's processes (" + list + "), but " + why
+ " and changing the environment is only safe with one, so nothing was repaired; construct the WebKitGTK "
"frontend before starting threads, or start the application with those variables cleaned (see "
"docs/WEBKITGTK.md, \"Snap-hosted editor terminals\")\n";
+ " and changing the environment is only safe with one, so nothing was repaired; construct the WebKitGTK "
"frontend before starting threads, or start the application with those variables cleaned (see "
"docs/WEBKITGTK.md, \"Snap-hosted editor terminals\")\n";
}

/// The note for Snap paths no editor marked: left unchanged, but they can still break WebKit on their own.
Expand All @@ -270,8 +269,8 @@ inline std::string snapUnmarkedMessage(const std::vector<std::string>& names) {
for (const auto& name : names)
list += (list.empty() ? "" : ", ") + name;
return "WebFront: " + list
+ " hold Snap paths that no editor marked as inherited and were left unchanged; if WebKit still fails to start, "
"clean them (see docs/WEBKITGTK.md, \"Snap-hosted editor terminals\")\n";
+ " hold Snap paths that no editor marked as inherited and were left unchanged; if WebKit still fails to start, "
"clean them (see docs/WEBKITGTK.md, \"Snap-hosted editor terminals\")\n";
}

/// Repairs the variables that name Snap paths, for the application and the processes WebKit launches. A Snap-packaged
Expand Down
14 changes: 13 additions & 1 deletion test/cmake/RunWfDriver.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,20 @@ if(EXPECT_FILE)
endif()
string(REPLACE "|" ";" command "${COMMAND}")
list(APPEND arguments --)
# Files, not pipes: a web content process that outlives the driver (a page it blocked) inherits them, and a pipe would keep
# execute_process waiting until that process ends, which WebKit decides alone.
if(WORK)
set(outputs "${WORK}")
elseif(PROFILE)
set(outputs "${PROFILE}")
else()
set(outputs "${CMAKE_CURRENT_BINARY_DIR}/wf-driver-output")
endif()
file(MAKE_DIRECTORY "${outputs}")
execute_process(COMMAND "${DRIVER}" ${arguments} ${command}
RESULT_VARIABLE status OUTPUT_VARIABLE output ERROR_VARIABLE errors)
RESULT_VARIABLE status OUTPUT_FILE "${outputs}/driver.out" ERROR_FILE "${outputs}/driver.err")
file(READ "${outputs}/driver.out" output)
file(READ "${outputs}/driver.err" errors)
set(text "${output}${errors}")
message(STATUS "exit status ${status}\n${text}")
if(NOT status EQUAL EXPECT_STATUS)
Expand Down
30 changes: 10 additions & 20 deletions test/unit/InspectorDistribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,16 @@ const Scenario inspectorsAbsent{"A distribution build registers no inspector fun
app.bootstrap("developer", {.environment = "https://example.test/env.tgz", .integrity = "sha512-abc"});
then("the environment's callbacks exist, and no webfront.inspector.* function", [&] {
require(app.hasCppFunction("webfront.developer.config"));
for (const auto* name : {"webfront.inspector.containers",
"webfront.inspector.embedded",
"webfront.inspector.watches",
"webfront.inspector.functions",
"webfront.inspector.jsFunctions",
"webfront.inspector.browsers",
"webfront.inspector.bridgeSource",
"webfront.inspector.publishBridge",
"webfront.inspector.bridge",
"webfront.inspector.readPreferences",
"webfront.inspector.savePreferences",
"webfront.inspector.openWindow",
"webfront.inspector.closeWindow",
"webfront.inspector.limits",
"webfront.inspector.children",
"webfront.inspector.changes",
"webfront.inspector.value",
"webfront.inspector.fold",
"webfront.inspector.reset",
"webfront.inspector.write"})
for (const auto* name : {"webfront.inspector.containers", "webfront.inspector.embedded",
"webfront.inspector.watches", "webfront.inspector.functions",
"webfront.inspector.jsFunctions", "webfront.inspector.browsers",
"webfront.inspector.bridgeSource", "webfront.inspector.publishBridge",
"webfront.inspector.bridge", "webfront.inspector.readPreferences",
"webfront.inspector.savePreferences", "webfront.inspector.openWindow",
"webfront.inspector.closeWindow", "webfront.inspector.limits",
"webfront.inspector.children", "webfront.inspector.changes",
"webfront.inspector.value", "webfront.inspector.fold",
"webfront.inspector.reset", "webfront.inspector.write"})
require(!app.hasCppFunction(name));
});
then("native code gets no reads of the inspectors either (ADR-027, section 10)", [&] {
Expand Down
13 changes: 7 additions & 6 deletions test/unit/WatchTreeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1068,22 +1068,23 @@ const Scenario watchBoundedFormatting{"A value is written into a bounded receive
{"inspector"},
[] {
Bench bench;
then("a string of 100 MiB is copied up to the bound only", [&] {
std::vector<std::string> texts{std::string(100u * 1024 * 1024, 's')};
then("a string longer than the snapshot bound is copied up to the bound only", [&] {
bench.limits.maxSnapshotBytes = 64 * 1024; // the bound, not its default of 16 MiB, is what is tested
std::vector<std::string> texts{std::string(bench.limits.maxSnapshotBytes + 4096, 's')};
const auto id = bench.watch("texts", visiting(texts));
const auto page = bench.open(id);
const auto& node = nodesOf(page)[1];
require(valueOf(node).size() <= inspect::maxTextBytes);
require(valueOf(node).ends_with("\xE2\x80\xA6"));
requireEqual(flagsOf(node), flag::truncated); // cut, hence not writable
const auto answer = bench.value(id, "/#0");
requireEqual(std::get<1>(answer), static_cast<double>(inspect::maxSnapshotBytes));
requireEqual(std::get<1>(answer), static_cast<double>(bench.limits.maxSnapshotBytes));
require(std::get<3>(answer));
});
then("a formatter that writes more than 1 GiB to the output iterator is cut, and the cut is told", [&] {
then("a formatter that writes far beyond every bound to the output iterator is cut, and the cut is told", [&] {
std::vector<Wide> wides{
Wide{.size = (std::size_t{1} << 30) + 5, .failing = false},
Wide{ .size = 3, .failing = false}
Wide{.size = inspect::maxSnapshotBytes + 5, .failing = false}, // beyond the largest bound
Wide{ .size = 3, .failing = false}
};
const auto id = bench.watch("wides", visiting(wides));
const auto page = bench.open(id);
Expand Down
Loading
Loading