Truly independent web browser
Documentation: Describe the UI and Hub processes
Andreas Kling6fc881d08a4f
diff --git a/Documentation/ProcessArchitecture.md b/Documentation/ProcessArchitecture.mdindex 6e3f8e9944f..b44a669eb09 100644--- a/Documentation/ProcessArchitecture.md+++ b/Documentation/ProcessArchitecture.md@@ -5,7 +5,9 @@ Ladybird uses a multi-process architecture to improve stability and security in## Process overview```- Browser+ UI+ |+ Hub|+----------+-------------+-------+----------------+| | | |@@ -19,11 +21,12 @@ Ladybird uses a multi-process architecture to improve stability and security inVideoDecoderServer```-**RequestServer** and **ImageDecoder** are shared by the renderers of a site, while the processes below the renderers each work for a single renderer. **Browser** launches all of them, because the sandboxes keep the others from spawning anything. It then connects them directly to each other, so that a renderer talks to its **RequestServer** or **ImageDecoder** without going through **Browser**.+**RequestServer** and **ImageDecoder** are shared by the renderers of a site, while the processes below the renderers each work for a single renderer. **Hub** launches all of them, because the sandboxes keep the others from spawning anything. It then connects them directly to each other, so that a renderer talks to its **RequestServer** or **ImageDecoder** without going through **Hub**.| Process | How many | Launched || --- | --- | --- |-| **Browser** | One | By the user |+| **UI** | One | By the user |+| **Hub** | One | By **UI**, as it starts || **Compositor** | One | At startup, and again if it crashes || **WebContent** | One per set of documents that must share a process, see [site isolation](#site-isolation) | When a document needs one, with a spare kept ready for the next tab || **RequestServer** | One per browsing session and top-level site, plus one per session with no site | The default session's one with no site at startup, the others on first use |@@ -33,13 +36,21 @@ Ladybird uses a multi-process architecture to improve stability and security in| **VideoDecoderServer** | One per MediaServer | When its **MediaServer** asks for one || **WebRTCClient** | One per **WebContent** process | When the renderer first needs one |-On macOS, the kernel does not end a process when its parent dies, so a small **ProcessReaper** helper ends the others when **Browser** is gone.+On macOS, the kernel does not end a process when its parent dies, so a small **ProcessReaper** helper ends the others when **Hub** is gone.++### Process: UI++This is the application itself, and the only process that talks to the window system. It draws windows, tabs and menus, shows the frames that the **Compositor** presents, and turns what the user does into input for **Hub**. It shows pages as rendered images and receives some of their text, but it never hosts a page's DOM or runs its JavaScript. It is not sandboxed yet.++**UI** and **Hub** talk over the protocols in `Services/Hub/HubServer.ipc` and `Services/Hub/HubClient.ipc`. **UI** may wait for **Hub** to answer, but **Hub** never waits for **UI**, which is why they cannot deadlock. Neither outlives the other: **Hub** ends once the connection closes, and **UI** ends with it if **Hub** is gone.++With `--headless`, **UI** has nothing to do, and **Hub** takes over its process. On macOS and Windows, **Hub** does not have a process of its own yet, and runs inside **UI** over the same protocols.-### Process: Browser+### Process: Hub-This is the application itself, and it is not sandboxed. It shows the user interface and owns the state that must outlive or be shared between renderers: cookies, web storage, blob URLs, permissions, browsing history and the fonts of the system. Other processes ask **Browser** for these over IPC.+This process launches and connects all the others, and it is not sandboxed yet. It owns the state that must outlive or be shared between renderers: cookies, web storage, blob URLs, permissions and the fonts of the system. Other processes ask **Hub** for these over IPC. Browsing history, bookmarks and favicons belong to **UI**.-**Browser** also keeps its own record of every tab's navigables and documents, and decides which process hosts each document.+**Hub** also keeps its own record of every tab's navigables and documents, and decides which process hosts each document.### Process: Compositor@@ -47,11 +58,11 @@ This process turns what renderers record into pixels. Renderers send it displayIt also runs animated images and scrolling, which keeps them moving while a renderer's main thread is busy. For animated images, it gets a connection of its own to the renderer's **ImageDecoder**.-If the **Compositor** crashes, **Browser** launches a new one and reconnects the renderers to it.+If the **Compositor** crashes, **Hub** launches a new one and reconnects the renderers to it.### Process: WebContent-This process hosts the main HTML/CSS engine (**LibWeb**) and runs JavaScript (**LibJS**). It gets input events from **Browser** and records its pages for the **Compositor**. It reaches the network only through **RequestServer**, and local files only through **Browser**.+This process hosts the main HTML/CSS engine (**LibWeb**) and runs JavaScript (**LibJS**). It gets input events from **Hub** and records its pages for the **Compositor**. It reaches the network only through **RequestServer**, and local files only through **Hub**.A process holds one page for each tab it has documents in.@@ -59,9 +70,9 @@ Web workers run in this process too, each on a thread of its own with its own Ja### Process: RequestServer-This process uses networking protocols (like HTTP or HTTPS) to make requests on behalf of renderers, and resolves DNS names itself. It asks **Browser** for the cookies of each request, and hands **Browser** the cookies it receives.+This process uses networking protocols (like HTTP or HTTPS) to make requests on behalf of renderers, and resolves DNS names itself. It asks **Hub** for the cookies of each request, and hands **Hub** the cookies it receives.-Each top-level site has a **RequestServer** of its own in each browsing session, which only makes and caches requests for that site's partitions. Its sandbox confines its cache to that site's directory, and the process rejects requests that a renderer is not bound to make. A session's **RequestServer** with no site serves **Browser** itself and requests made under no site. A site's **RequestServer** ends once it has been idle for a while.+Each top-level site has a **RequestServer** of its own in each browsing session, which only makes and caches requests for that site's partitions. Its sandbox confines its cache to that site's directory, and the process rejects requests that a renderer is not bound to make. A session's **RequestServer** with no site serves **Hub** itself and requests made under no site. A site's **RequestServer** ends once it has been idle for a while.### Process: ImageDecoder@@ -69,11 +80,11 @@ This process decodes images (PNG, JPEG, BMP, ICO, PBM, etc.) into bitmaps. It isA decoder sees the images of every process it serves, so a malicious image that takes one over gets at those images. With site isolation, the processes of a site share an **ImageDecoder**, because they hold nothing of any other site's that they could not fetch for themselves. The site is that of the documents a process hosts, not their top-level site, so a frame never shares a decoder with the site embedding it, unless it has an opaque origin, which keeps it in the process of the document that made it. Private browsing is kept apart. Any other process, such as one with no site, gets a decoder of its own, and a process that comes to host a second site leaves the decoder of the first.-**Browser** launches a decoder when a process first has an image to decode, and ends it once each process it serves is gone or has let go of it. A process lets go of its decoder once it has gone 30 seconds with nothing to decode and no animation playing. Like a process that loses its decoder to a crash, it asks for a new one when it next has an image to decode.+**Hub** launches a decoder when a process first has an image to decode, and ends it once each process it serves is gone or has let go of it. A process lets go of its decoder once it has gone 30 seconds with nothing to decode and no animation playing. Like a process that loses its decoder to a crash, it asks for a new one when it next has an image to decode.### Processes: MediaServer, AudioServer and VideoDecoderServer-**MediaServer** plays the media of a renderer. Its video decoders run in a **VideoDecoderServer**, which **Browser** launches on its request. **AudioServer** talks to the audio devices of the system, for both a renderer's **MediaServer** and its WebAudio output.+**MediaServer** plays the media of a renderer. Its video decoders run in a **VideoDecoderServer**, which **Hub** launches on its request. **AudioServer** talks to the audio devices of the system, for both a renderer's **MediaServer** and its WebAudio output.### Process: WebRTCClient@@ -93,24 +104,31 @@ Documents that can script each other synchronously belong to one agent, and an a## How processes are spawned-`WebView::Process` spawns every helper. It creates the IPC transport first, gives the helper its end, and passes it only the environment variables that the helper needs. On Linux, the transport is a socket pair, and the helper finds its end through the `SOCKET_TAKEOVER` environment variable. On macOS, it is a pair of Mach ports, which the helper fetches from **Browser** by name. On Windows, it is a pipe, along with a connection to a handle broker in **Browser**, since a pipe cannot carry handles.+`WebView::Process` spawns every helper. It creates the IPC transport first, gives the helper its end, and passes it only the environment variables that the helper needs. On Linux, the transport is a socket pair, and the helper finds its end through the `SOCKET_TAKEOVER` environment variable. On macOS, it is a pair of Mach ports, which the helper fetches from **Hub** by name. On Windows, it is a pipe, along with a connection to a handle broker in **Hub**, since a pipe cannot carry handles.-Once two processes need to talk, **Browser** creates a channel and hands an end to each of them as an `IPC::TransportHandle`. Helpers that serve several clients, such as **RequestServer** and **ImageDecoder**, have a separate control connection that only **Browser** speaks, which it uses to connect new clients.+Once two processes need to talk, **Hub** creates a channel and hands an end to each of them as an `IPC::TransportHandle`. Helpers that serve several clients, such as **RequestServer** and **ImageDecoder**, have a separate control connection that only **Hub** speaks, which it uses to connect new clients.-A renderer that needs a helper it does not have yet asks **Browser** for a connection to it over IPC.+A renderer that needs a helper it does not have yet asks **Hub** for a connection to it over IPC.## Sandboxing-Every process in the table above except **Browser** applies a sandbox to itself early in its startup, unless **Browser** was started with `--disable-sandbox`. Each one's sandbox allows only what that process needs, and can be found in the `Sandbox` files in its directory under `Services`. The one of **WebContent** is in `Services/RendererSandbox.h`.+Every process in the table above except **UI** and **Hub** applies a sandbox to itself early in its startup, unless **Hub** was started with `--disable-sandbox`. Each one's sandbox allows only what that process needs, and can be found in the `Sandbox` files in its directory under `Services`. The one of **WebContent** is in `Services/RendererSandbox.h`.On Linux, sandboxes are built from seccomp and Landlock. On macOS, they use the Seatbelt sandbox. Windows has no sandbox yet.## Class overview```-Browser process+UI process++ Ladybird::WebContentView The widget showing a tab+ Ladybird::RemoteView What the UI knows of the tab's view, and how it reaches it++ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -++Hub process- WebView::ViewImplementation The view showing a tab, such as Qt's WebContentView+ WebView::ViewImplementation The view of a tab, such as Hub::ViewWebView::WebContentPage A page in a WebContent processWebView::WebContentClient The client side of the IPC protocol, one per process@@ -131,9 +149,9 @@ LibWebWeb::DOM::Document The active document of a navigable, the root of the DOM tree```-In the **Browser** process, each kind of view derives from `WebView::ViewImplementation`, which shows a tab. A tab's documents may be spread over several processes, so a view reaches each of them through a `WebView::WebContentPage`, and each process through its `WebView::WebContentClient`. `WebView::WebWorkerClient` does the same for a worker on a thread of a **WebContent** process.+In the **Hub** process, each kind of view derives from `WebView::ViewImplementation`, which shows a tab. A tab's documents may be spread over several processes, so a view reaches each of them through a `WebView::WebContentPage`, and each process through its `WebView::WebContentClient`. `WebView::WebWorkerClient` does the same for a worker on a thread of a **WebContent** process.-`WebView::CanonicalTraversable`, `WebView::CanonicalNavigable` and `WebView::CanonicalDocument` are the record that **Browser** keeps of a tab's navigables and documents, whichever processes host them.+`WebView::CanonicalTraversable`, `WebView::CanonicalNavigable` and `WebView::CanonicalDocument` are the record that **Hub** keeps of a tab's navigables and documents, whichever processes host them.In the **WebContent** process, a `WebContent::ConnectionFromClient` speaks to the `WebView::WebContentClient`. It has a `WebContent::PageHost`, which holds a `WebContent::PageClient` for each page, and each of those owns a `Web::Page`.