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
94 changes: 44 additions & 50 deletions Documentation/Plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,66 +284,60 @@ image:

## 8. Web views

`LinuxWebKit` implements `WebContent` (AppRuntime's `WebKit.md`) with WPE
WebKit, and the player draws `WebView` nodes. It follows Perry's
(`Sources/PerryUIKit/WPE.swift` there):

- **No WebKit at build time.** The host opens libwpe, WPEBackend-fdo,
libwayland-server, `libWPEWebKit-2.0.so.1`, GLib and GObject when a page
is first made, locally, so their symbols stand in for no others. Without
them a page loads nothing, and fails each load saying so. Debian 13
packages WPE 2.48 (`libwpewebkit-2.0-1`, `libwpebackend-fdo-1.0-1`);
Ubuntu 26.04 doesn't, so the development image and CI moved to Debian 13.
- **Frames in shared memory.** WPEBackend-fdo runs in its SHM mode
(`wpe_fdo_initialize_shm`), and each page's exportable view backend hands
over every frame the web process draws as a `wl_shm` buffer: premultiplied
BGRA, turned into RGBA for Cacao's `Image(pixels:)`. WebKit draws on the
CPU; there's no GL.
- **GLib's context** runs on the main loop every 8 ms while there are pages:
their signals, script results and frames all come through it.
- **The contract** maps onto `WebKitWebView`:
- `load-changed`, `load-failed` and `load-failed-with-tls-errors` give
loading, finishing and failing;
- `notify::` on `uri`, `title` and `estimated-load-progress`, and the
history after each commit, give the rest;
- `uri` changes as soon as a load is asked for, and before a history
navigation is decided, so it's reported only once the navigation
commits or follows a redirect, as the contract wants;
- cancelled and replaced navigations aren't failures.
- **Errors** come as GErrors and map to `WebError.Code`: WebKit's network
and policy errors, GIO's (a timeout is `timedOut`, the rest `network`),
the resolver's, and TLS (`security`).
- **`decide-policy`** asks `shouldNavigate` for each navigation and new
window, except the guest's own `load`, `loadHTML` and `loadResource`. A
new window loads in the same page. WPE doesn't say which frame a
navigation is in, so `isMainFrame` is always true.
- **Without `network`**:
- a remote `load`, or a navigation to a remote URL, fails with
`notPermitted` before it starts;
- every other request goes through a proxy on a `.invalid` host (RFC
2606), which never resolves, so remote subresources don't load.
- **`loadResource`** loads a `file://` URL in the bundle's `resources/`,
refusing paths that leave it.
- **The view** (`Sources/LinuxUI/HostWebView.swift`):
- It gives the page its size in points and the display's scale, and
makes it visible while it's on screen. The page stays loaded when the
view goes.
- A drag is the primary button, and hovering moves the pointer.
- A click focuses the page. Keys go to it as XKB keysyms, which WPE turns
into text.
`LinuxWebKit` implements `WebContent` (AppRuntime's `WebKit.md`) over
PureSwift/WebKit, whose `WPEWebKit` drives WPE WebKit, and the player shows
`WebView` nodes with its `CacaoWebKit`. PureSwift/WebKit's own plan
(`Documentation/Plan.md` there) has the engine's details; here is what the
host adds:

- **No WebKit at build time.** `WPEWebKit` opens libwpe, WPEBackend-fdo,
libwayland-server, `libWPEWebKit-2.0.so.1`, GLib, GObject, GIO and
libsoup when a page is first made, locally, so their symbols stand in for
no others. Without them a page loads nothing, and fails each load saying
so. Debian 13 packages WPE 2.48 (`libwpewebkit-2.0-1`,
`libwpebackend-fdo-1.0-1`); Ubuntu 26.04 doesn't, so the development
image and CI moved to Debian 13.
- **The contract's page** (`LinuxWebContent`) makes a `WPEWebContent`,
whose delegate already has the contract's methods and numbers, and
passes what it hears to the guest's delegate. It refuses a load of what
isn't a URL, or of a remote URL without `network`, before anything
starts, with WPE or without; and it loads `loadResource`'s `file://` URL
from the bundle's `resources/`, refusing paths that leave it. The rest
is `WPEWebContent`'s:
- loading, finishing and failing from `load-changed`, `load-failed` and
`load-failed-with-tls-errors`, and the URL only once a navigation
commits; cancelled and replaced navigations aren't failures;
- GErrors mapped to `WebError.Code`;
- `decide-policy` asking `shouldNavigate` about each navigation and new
window but the guest's own loads, a new window loading in the same
page, and `isMainFrame` always true, as WPE doesn't say;
- without `network`, every other request going through a proxy on a
`.invalid` host (RFC 2606), which never resolves.
- **GLib's context** runs on the main loop: `WPEEngine.pump()` there when
the engine says its pages have work (`WPEEngine.onReady`), so nothing
polls. A guest's call sets off a pump on the loop's next turn, so the
guest doesn't hear from a page while it's calling it.
- **Frames** come from WPEBackend-fdo's SHM mode as premultiplied BGRA, and
go to the page's Cacao `ExternalSurface` as they are: no conversion, one
copy. WebKit draws on the CPU; there's no GL.
- **The view** (`Sources/LinuxUI/HostWebView.swift`) is CacaoWebKit's
`WebView(content:)` over the page its node names:
- it attaches the page at its size in points and the display's scale
while it's on screen, and the page stays loaded when it goes;
- Cacao's input goes to the page: the pointer with its buttons, hover,
the wheel and smooth scrolling, a finger's tap as a click and its drag
as a scroll, keys, typed text with the keyboard's layout, and focus.
- **The sandbox.** WebKit starts its web and network processes under
bubblewrap, which can't make namespaces in a container, so the
development image and CI set `WEBKIT_DISABLE_SANDBOX_THIS_IS_DANGEROUS=1`
for their test pages. The host leaves the sandbox on. Inside a launcher's
own sandbox (AppRuntime's §7.8) it's still the open question `WebKit.md`
names.
- **Not yet**:
- The wheel: Cacao sends it only to its scroll views. Pages scroll with
the arrow keys, Page Up and Page Down, and Space.
- `alert`, `confirm` and `prompt`: WebKit's defaults apply, which show
nothing.
- Permission requests: WebKit denies them by default.
- Touches, and buttons other than the primary.
- More than one finger: a pinch doesn't zoom.
- Reading files beside a bundled page only: WebKit's file-URL rules
apply.

Expand Down
26 changes: 21 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import PackageDescription
/// The environment:
///
/// - `APPRUNTIME_PATH`: a local AppRuntime checkout instead of GitHub;
/// `CACAO_PATH` likewise for PureSwift/Cacao.
/// `CACAO_PATH` likewise for PureSwift/Cacao, and `WEBKIT_PATH` for
/// PureSwift/WebKit.
let environment = ProcessInfo.processInfo.environment

let appRuntime: Package.Dependency = {
Expand All @@ -31,13 +32,23 @@ let cacao: Package.Dependency = {
return .package(url: "https://github.com/PureSwift/Cacao.git", branch: "develop")
}()

/// PureSwift/WebKit: WPE WebKit's pages, and the `WebView` that shows them
/// in Cacao. `WEBKIT_PATH` points at a local checkout.
let webKit: Package.Dependency = {
if let path = environment["WEBKIT_PATH"] {
return .package(name: "WebKit", path: path)
}
return .package(url: "https://github.com/PureSwift/WebKit.git", branch: "master")
}()

/// The player is DarwinAppRuntime's SwiftUI renderer: on Linux its
/// `import SwiftUI` and `import Combine` are Cacao's modules of those names.
#if os(Linux)
let swiftUI: [Target.Dependency] = [
.product(name: "SwiftUI", package: "Cacao"),
.product(name: "Combine", package: "Cacao"),
.product(name: "Cacao", package: "Cacao"),
.product(name: "CacaoWebKit", package: "WebKit"),
]
#else
let swiftUI: [Target.Dependency] = []
Expand Down Expand Up @@ -79,6 +90,7 @@ let package = Package(
dependencies: [
appRuntime,
cacao,
webKit,
// D-Bus, in Swift without libdbus, which Bluetooth talks to BlueZ
// over, and Location to GeoClue; it has no releases.
.package(url: "https://github.com/PureSwift/DBus.git", revision: "d34567d64bb553a35e5b263f344c6963a5170ca3"),
Expand Down Expand Up @@ -137,10 +149,12 @@ let package = Package(

// MARK: - Web views

// WPE WebKit, loaded at run time: the host links no WebKit.
// WPE WebKit through PureSwift/WebKit, which loads it at run time:
// the host links no WebKit.
.target(
name: "LinuxWebKit",
dependencies: ["LinuxHost", runtime("DynamicWebKit"), runtime("DynamicRuntime"), runtime("RuntimeABI")],
dependencies: ["LinuxHost", runtime("DynamicWebKit"), runtime("DynamicRuntime"), runtime("RuntimeABI"),
.product(name: "WPEWebKit", package: "WebKit")],
swiftSettings: host
),

Expand Down Expand Up @@ -277,7 +291,8 @@ let package = Package(
swiftSettings: host),
.testTarget(
name: "LinuxUITests",
dependencies: ["LinuxUI", runtime("DynamicUI"), runtime("DynamicRuntime"), .product(name: "Cacao", package: "Cacao")] + swiftUI,
dependencies: ["LinuxUI", "LinuxWebKit", runtime("DynamicUI"), runtime("DynamicRuntime"), runtime("DynamicWebKit"),
.product(name: "Cacao", package: "Cacao")] + swiftUI,
swiftSettings: host
),
.testTarget(name: "LinuxBluetoothTests", dependencies: ["LinuxBluetooth"], swiftSettings: host),
Expand All @@ -302,7 +317,8 @@ let package = Package(
.testTarget(name: "LinuxMediaTests", dependencies: ["LinuxMedia", runtime("DynamicMedia"), runtime("RuntimeMedia"), runtime("RuntimeHost")],
swiftSettings: host),
.testTarget(name: "LinuxMotionTests", dependencies: ["LinuxMotion", runtime("DynamicMotion")], swiftSettings: host),
.testTarget(name: "LinuxWebKitTests", dependencies: ["LinuxWebKit", runtime("DynamicWebKit")], swiftSettings: host),
.testTarget(name: "LinuxWebKitTests", dependencies: ["LinuxWebKit", runtime("DynamicWebKit"), .product(name: "WPEWebKit", package: "WebKit")],
swiftSettings: host),
.testTarget(name: "LinuxPackagerTests", dependencies: ["LinuxPackager", "LinuxHostApp", runtime("RuntimeNetworking")]),
]
)
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ added to its database between launches:
| `LinuxUI` | The SwiftUI player: DarwinAppRuntime's `DarwinUI`, copied by `Scripts/sync-darwinui.sh`, over Cacao's `SwiftUI` |
| `LinuxBluetooth` | `BluetoothCentral`, `BluetoothPeripheral`, `BluetoothService`, `BluetoothCharacteristic`, `BluetoothDescriptor` and `BluetoothAdvertisement` over BlueZ, through `LinuxDBus` |
| `LinuxGraphics` | `Surface`: GLES 2.0 drawn in EGL pbuffers, loaded at run time, and read back into the player's `GLSurface` view ([plan](Documentation/Plan.md) §7) |
| `LinuxWebKit` | `WebContent`: WPE WebKit pages, loaded at run time, drawn into shared memory and shown by the player's `WebView` view ([plan](Documentation/Plan.md) §8) |
| `LinuxWebKit` | `WebContent`: WPE WebKit pages through [PureSwift/WebKit](https://github.com/PureSwift/WebKit), loaded at run time and shown by the player's `WebView` view, CacaoWebKit's ([plan](Documentation/Plan.md) §8) |
| `LinuxCoreModel` | `LinuxModelStore`: the app's CoreModel stores in SQLite, through AppRuntime's `HostModelStore` and CoreModel-SQLite ([plan](Documentation/Plan.md) §9) |
| `LinuxDevice` | `Device`: the machine, its battery, power mode and heat, from `/etc`, DMI, the device tree and sysfs, and its orientation and proximity from iio-sensor-proxy ([plan](Documentation/Plan.md) §10) |
| `LinuxDBus` | `Bus`: the system and session buses for the modules that talk to system services, over PureSwift/DBus, with calls, properties and signals delivered on the main loop ([plan](Documentation/Plan.md) §11.1) |
Expand Down Expand Up @@ -101,9 +101,9 @@ with this checkout at `/src`:
Scripts/docker.sh swift test --scratch-path .build/linux
```

AppRuntime and Cacao (its `develop` branch) come from GitHub.
`APPRUNTIME_PATH` and `CACAO_PATH` point at local checkouts instead, and
`Scripts/docker.sh` mounts them.
AppRuntime, Cacao (its `develop` branch) and PureSwift/WebKit come from
GitHub. `APPRUNTIME_PATH`, `CACAO_PATH` and `WEBKIT_PATH` point at local
checkouts instead, and `Scripts/docker.sh` mounts them.
`Scripts/sync-darwinui.sh` updates the player from a DarwinAppRuntime
checkout beside this one.

Expand Down
7 changes: 5 additions & 2 deletions Scripts/docker.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh
# Runs a command in the Linux development image (Dockerfile), with this
# checkout at /src and, if APPRUNTIME_PATH is set, that AppRuntime checkout at
# /AppRuntime; likewise CACAO_PATH at /Cacao. Builds go to .build/linux, apart
# from a Mac's .build.
# /AppRuntime; likewise CACAO_PATH at /Cacao, and WEBKIT_PATH, PureSwift/WebKit,
# at /WebKit. Builds go to .build/linux, apart from a Mac's .build.
#
# Scripts/docker.sh swift test --scratch-path .build/linux
# APPRUNTIME_PATH=~/Developer/AppRuntime Scripts/docker.sh swift build --scratch-path .build/linux
Expand All @@ -26,6 +26,9 @@ fi
if [ -n "$CACAO_PATH" ]; then
set -- "$@" -v "$CACAO_PATH:/Cacao" -e CACAO_PATH=/Cacao
fi
if [ -n "$WEBKIT_PATH" ]; then
set -- "$@" -v "$WEBKIT_PATH:/WebKit" -e WEBKIT_PATH=/WebKit
fi
exec docker run --rm \
-v "$root:/src" -w /src \
-v linuxappruntime-swiftpm:/root/.cache \
Expand Down
Loading
Loading