WebKit for dummies

WebKit for dummies

  • mdo  Administrator
  •   Dev
  •   November 30, 2026

Eight months ago, Haiku's WebKit2 port was very buggy and crashed when quitting it or pressing Back. Today MiniBrowser has tabs, a Web Inspector, find-in-page, zoom, fullscreen and a download manager.

This article explains how WebKit is put together, lists what the port can do today, then follows one feature, zoom in and out. The aim is to show what the work looks like in the source, and not only in the feature list.

A note on scope: WebPositive still runs on WebKit1 (WebKitLegacy). Everything below is about the WebKit2 port, currently tested through MiniBrowser on the haiku-webkit2 branch of haikuwebkit.

WebKit in 5 minutes

WebKit is an open-source web browser engine: it turns HTML, CSS and JavaScript into pixels and behavior, and leaves windows, tabs and menus to the application around it.

It is the framework behind Safari, Mail and many other applications on macOS and iOS.

The code is mostly C++, and each component lives in its own directory under Source:

  • WTF (Web Template Framework) is the template library the rest of WebKit is built on: containers such as Vector and HashMap, smart pointers such as Ref, RefPtr and WeakPtr, and the RunLoop that drives every thread's event handling.
  • JavaScriptCore (JSC) is the JavaScript engine. It compiles JavaScript to bytecode and runs it through four tiers, from a simple interpreter to an optimizing JIT compiler.
  • WebCore is the largest component. It implements the HTML, XML and CSS parsers, the HTML, SVG and MathML elements, and most Web APIs. It works on two trees: the DOM, built from the parsed HTML, and the render tree, which holds each element's computed style and layout geometry.
  • WebCore/platform and PAL are the platform abstraction layer, which keeps the rest of WebCore independent of the operating system.
  • WebKitLegacy (WebKit1) and WebKit (WebKit2) connect WebCore to the rest of the system. 
  • Web Inspector is the developer tool.

Everything that depends on the operating system lives in the port: how to draw, how to receive keyboard and mouse events, which network library to use (curl, on Haiku), how to show a menu or a file picker.

A port is the glue between WebKit and the platform's native toolkit. On Haiku it talks to the BeAPI (BView, BWindow, BMessage).

WebKit1 and WebKit2

WebKit1, called WebKitLegacy in the tree, runs the engine inside the application's own process. It is simple, but a crash in a page takes the whole browser down. This is what WebPositive uses today.

WebKit2 implements a multi-process architecture:

  • UIProcess: the application itself (MiniBrowser). It owns windows, tabs, menus and the URL bar.
  • WebProcess: loads and runs the code of websites, with WebCore and JavaScriptCore. A browser typically gives each tab its own, so tabs stay responsive and pages are isolated from each other.
  • NetworkProcess: handles network requests and storage. All WebProcesses of a session share one.

The three processes and their links: the browser application talks to both engine processes, and they talk to each other.

They exchange messages over IPC (on Unix-like systems, a socket pair). In return for a crash-isolated, more secure, more responsive browser, every feature that touches the interface has to cross a process boundary. A porter therefore writes two kinds of code: implementations of the UI-side "client" interfaces in the UIProcess, and small platform hooks in the WebProcess.

From HTML to pixels

Each step below tells you where to look in the tree (paths are under Source/):

  1. Fetch. The NetworkProcess downloads the HTML (with the port's network library, curl on Haiku) and hands the bytes to the WebProcess. Folders: WebKit/NetworkProcess, WebCore/platform/network.
  2. Parse. WebCore's HTML parser builds the DOM, and the CSS parser reads the style sheets. JavaScriptCore runs the page's scripts, which can change the DOM at any time. Folders: WebCore/html/parser, WebCore/css/parser, JavaScriptCore.
  3. Style and render tree. Each DOM element gets its computed style, and the visible ones become objects in the render tree. Folders: WebCore/style, WebCore/rendering.
  4. Layout. WebCore computes the position and size of every render object. Zoom, from the worked example below, changes the inputs of this step. Folder: WebCore/rendering.
  5. Paint. The render tree is turned into drawing commands: fill a rectangle, draw this text, draw this image. WebCore sends them to a platform-neutral drawing interface, and the port implements it. On Haiku this is the code in platform/graphics/haiku, such as GraphicsContextHaiku, which draws with the BeAPI. Folders: WebCore/platform/graphics (the interface), WebCore/platform/graphics/haiku (Haiku's version).
  6. Composite. WebKit can combine layers in a separate compositor thread, and the Haiku port already has the code for it (LayerTreeHostHaiku, ThreadedCompositorHaiku, AcceleratedSurfaceHaiku). Folder: WebKit/WebProcess/WebPage/CoordinatedGraphics.
  7. Transfer. The WebProcess has no window of its own, so it paints into memory shared with the UIProcess (a ShareableBitmap) and sends a short IPC message saying which area changed. Folders: WebKit/WebProcess/WebPage/CoordinatedGraphics (DrawingAreaCoordinatedGraphics), WebKit/UIProcess/CoordinatedGraphics (DrawingAreaProxyCoordinatedGraphics), WebCore/platform/graphics (ShareableBitmap).
  8. Display. The UIProcess draws that area inside the WebViewBase, the BView that holds the page, and the app_server puts it on screen. Folder: WebKit/UIProcess/API/haiku.

Input travels the other way: a click or a key press reaches the BView in the UIProcess, crosses the IPC to the WebProcess, and becomes a DOM event that the page's scripts can handle.

Steps 2 to 4 are the same on every platform. Steps 1 and 5 to 8 are where a port does its work, which is why the Haiku-specific code is concentrated in the network layer, in graphics, in the view classes and in event handling.

What MiniBrowser can do today

MiniBrowser now covers the everyday needs of a browser. Everything below is implemented in WebKit2.

Area

What works

Navigation

Tabs, URL bar, default and command-line URL, Back, Forward and Stop with their icons, loading indicator, keyboard focus navigation

Pages

Find in page, zoom, HTML5 fullscreen, context menu with submenus, Open Link in New Tab, cursors, Cut, Copy and Paste, scrollbar dragging

Forms and files

Typing in form fields, color and date pickers, file upload, dropping files from Tracker, a download manager

Media

Audio and video playback (limited)

Developer tools

<code spellcheck="false">Web Inspector, docked next to each tab's page

Solidity

Fixes for crashes on quit, back/forward, tab close, resize and compositing; IPC over SOCK_SEQPACKET; orderly shutdown with a shared process pool; x86 32-bit cross-compilation

Where things live in the source tree

The port touches only a handful of folders, and they are easy to find by name: each component keeps its platform code in a folder named after the port (haiku/, gtk/, wpe/, cocoa/).

Here are the ones that matter :

haikuwebkit/
├── Source/
│   ├── bmalloc/              memory allocator
│   ├── WTF/                  strings, containers, threads, RunLoop
│   │   └── wtf/haiku/          RunLoopHaiku.cpp (timers, event loop)
│   ├── JavaScriptCore/       the JavaScript engine
│   ├── WebCore/              HTML, CSS, DOM, layout, rendering
│   │   ├── platform/haiku/            keyboard, mouse, drag data, sound
│   │   ├── platform/graphics/haiku/   bitmaps, fonts, graphics layers
│   │   └── platform/network/haiku/    network support
│   ├── WebKitLegacy/         WebKit1: the engine inside the app
│   │   └── haiku/              the Haiku API used by WebPositive
│   ├── WebKit/               WebKit2: the multi-process layer
│   │   ├── UIProcess/          the application side
│   │   │   ├── API/haiku/        WebViewBase and the port's view classes
│   │   │   └── haiku/            port-specific UI code
│   │   ├── WebProcess/         runs the pages
│   │   │   ├── haiku/            process entry point
│   │   │   └── WebCoreSupport/haiku/   editing, errors, networking glue
│   │   ├── NetworkProcess/     network requests, cookies, cache
│   │   ├── Shared/             code used by all the processes
│   │   ├── Platform/IPC/       the messaging layer (unix/ = sockets)
│   │   └── PlatformHaiku.cmake   which Haiku files are built here
│   ├── WebInspectorUI/       the Inspector frontend (HTML, CSS, JS)
│   └── cmake/                build system (OptionsHaiku.cmake)
├── Tools/
│   ├── MiniBrowser/haiku/    the WebKit2 test browser
│   ├── HaikuLauncher/        the WebKit1 test browser
│   ├── WebKitTestRunner/     WebKit2 test runner, one folder per port
│   ├── DumpRenderTree/       WebKit1 test runner (legacy)
│   └── Scripts/              build-webkit
└── LayoutTests/              the rendering test suite

Three habits make this map useful:

  • Look for the folder with the port's name. Haiku's code is in the haiku/ folders, and its sibling gtk/ and wpe/ folders show how another port solved the same problem.
  • Read PlatformHaiku.cmake. Each of Source/WebCore and Source/WebKit has one that lists which Haiku files are compiled.
  • Follow the layers. A feature usually touches UIProcess (what the user sees), WebProcess (the page) and the IPC between them, as in the zoom example below.

There is no porting manual

WebKit has no official manual for writing a port: the documentation covers the overview and each port's public API, and stops where a porter's work begins.

What is documented:

  • docs.webkit.org has an introduction and a page on the multi-process architecture, but its sections on how IPC is set up and how to add a message are still marked FIXME.
  • WebKitGTK, WPE and Cocoa each publish a reference for their own public API, such as the WebKitGTK WebKitWebView class. These tell you what a call does, not what Haiku has to implement.

What is not documented is the internal layer a port talks to: WebPageProxy, the PageClient interface, and the port's own classes.

Take Haiku's WebViewBase, a BView that is also a WebKit API object. It holds a WebPageProxy and a PageClientImpl, and its page() accessor gives the rest of the port access to the page. No reference page lists it: the header is the documentation. 

How to explore the source without a manual:

  1. Start from the model. Every page has a WebPageProxy in the UIProcess; its header lists what a port can ask a page to do.
  2. Read the port's own headers, such as WebViewBase.h, and PageClient.h, the interface a port implements.
  3. Follow another port. Find the GTK or WPE equivalent of a feature and see which WebPageProxy method it calls.
  4. Search by symbol. Use grep -rn on the method name across Source/WebKit/UIProcess, and git log -S to find the commit that introduced it.
  5. Start from an observed behavior. A breakpoint or a crash backtrace shows the real chain of calls.

The next section applies this method to one feature.

How a feature gets implemented: zoom

Zoom took a small change, because WebKit already did most of the work. Checking what exists before writing code is the most useful habit of a porter, and zoom shows it in three steps.

1. Check the existing situation

A search of Tools/MiniBrowser/haiku/ found no zoom menu item and no shortcut.

The only related code was a Text menu (Increase size, Decrease size, Reset size) left from the first versions of MiniBrowser, with nothing behind it. The zoom change replaces it, and the Haiku side of zoom had to be written.

2. See what WebKit already provides

WebPageProxy, the UIProcess object that represents a page, offers pageZoomFactor(), setPageZoomFactor() and setPageAndTextZoomFactors() to every port.

Page zoom scales the whole layout; text zoom only the text.

The IPC message to the WebProcess and the rescaling in WebCore already exist, so a port does not implement zoom: it only has to ask for it. Other ports wrap the same call in their own API (the GTK and WPE web view classes have a zoom-level property).

3. Write only the Haiku side

What was missing is the interface:

  • a View menu with zoom in, zoom out and actual size, and the shortcuts Alt + (in), Alt - (out) and Alt 0 (actual size). 
  • the matching cases in BrowserWindow::MessageReceived();
  • a small method on BWebView that forwards to WebPageProxy, so the window never touches WebKit internals;
  • Alt plus the mouse wheel, handled where wheel events arrive;
  • the step per press, as a constant.

The path of one key press then looks like this:

  1. Alt + selects the menu item, which sends a BMessage to the window.
  2. BrowserWindow::MessageReceived() handles it and calls the BWebView.
  3. The BWebView calls WebPageProxy::setPageZoomFactor() with the new factor.
  4. WebPageProxy sends the IPC message to the WebProcess.
  5. WebCore lays the page out again, and the new frame comes back to the view.

Steps 4 and 5 are the process boundary from the WebKit2 section above: the port never sees them.

What is still missing

MiniBrowser is a test browser, not a replacement for WebPositive.

Statuses below are those of mid-November.

Area

What is missing

Status

Forms

The <select> drop-down menu and the datalist suggestion list

Not implemented

Pages

Tooltips

In progress

Windows

Open Link in New Window and window.open()

In progress

Content Blocker

Allow content blocking with user's rules

In progress

Video

Playback controls and their icons

In progress

Video

Reaching the end of a video, playback speed

Under investigation

Security

An error page for invalid TLS certificates, with an option to continue

Not implemented

Graphics

GPU-accelerated compositing; smooth scaling of images

Compositing is skipped today

There are also still some graphical bugs, like the SVG rendering shown below.

Here is an example of WebKit2 SVG display versus a correct SVG display:

What's next

The gaps in the previous section are part of the way there.

Four more things stand between today's MiniBrowser and fully working WebPositive using WebKit2, in the order that makes sense to tackle them.

  1. Reliable video. Playback works for simple cases, but the end of a video, the playback speed and the controls are not finished. Then comes streaming: the big video sites deliver adaptive streams through Media Source Extensions (MSE), so without MSE there is no HD playback on them. 
  2. Correct rendering. Some SVG images do not render properly. SVG is parsed and laid out by WebCore, the same code on every platform, so a bug that appears only on Haiku usually lives in how the port draws: paths, gradients, clipping or transforms in GraphicsContextHaiku. 
  3. Site compatibility. JavaScript and CSS support comes with WebCore, so a site that works in Safari or WebKitGTK but not on Haiku usually points to a missing port feature or to a platform bug. The practical tool is a list of the sites people use every day, each tested and marked, with every failure reduced to a small test case and filed.
  4. Packaging, then WebPositive. A 64-bit and a 32-bit test package are available for download on this site. The official HaikuPorts recipe still builds WebKit2 disabled. Once most of the list above is done comes the question of when WebPositive should move to WebKit2. The community discussion is open.

Keep an eye in the coming months on the news about WebKit2 for Haiku.

In case you need them, please find below the terms used in this article and in the source, in alphabetical order.

Happy WebKit:)

Term

Meaning

DOM

The tree of elements built from the HTML. Scripts read and change it.

GraphicsContext

WebCore's drawing interface. Each port implements it with its own toolkit (on Haiku, GraphicsContextHaiku).

IPC

Inter-process communication: the messages that the UIProcess, WebProcess and NetworkProcess exchange.

*.messages.in

Files that declare the IPC messages of a component. The build generates the sending and receiving code from them.

NetworkProcess

The process that handles network requests, cookies and cache.

PageClient

The interface through which the engine asks the application for things it cannot do alone (redraw an area, change the cursor, show a menu). A port implements it: on Haiku, PageClientImpl.

port

The platform-specific part of WebKit: drawing, input, network, menus. Haiku's lives in the haiku/ folders.

render tree

The tree of visible objects, with their computed style and geometry, built from the DOM.

UIProcess

The application process (MiniBrowser): windows, tabs, menus, URL bar.

WebCore

The component that parses, lays out and paints web content.

WebKit1 / WebKitLegacy

The older design, where the engine runs inside the application's own process. WebPositive uses it.

WebKit2

The multi-process design described in this article.

WebPageProxy

The UIProcess object that represents one page. A port calls it to ask the page to do something, such as zoom.

WebProcess

The process that loads and runs a page with WebCore and JavaScriptCore.

WebViewBase

Haiku's view class: a BView that is also a WebKit API object and holds the page.


Powered by Bludit - Hosted by Planet Hoster
© 2025 Haiku Insider