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 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:
Vector and HashMap, smart pointers such as Ref, RefPtr and WeakPtr, and the RunLoop that drives every thread's event handling.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, 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:

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.
Each step below tells you where to look in the tree (paths are under Source/):
WebKit/NetworkProcess, WebCore/platform/network.WebCore/html/parser, WebCore/css/parser, JavaScriptCore.WebCore/style, WebCore/rendering.WebCore/rendering.WebCore/platform/graphics (the interface), WebCore/platform/graphics/haiku (Haiku's version).WebKit/WebProcess/WebPage/CoordinatedGraphics.WebKit/WebProcess/WebPage/CoordinatedGraphics (DrawingAreaCoordinatedGraphics), WebKit/UIProcess/CoordinatedGraphics (DrawingAreaProxyCoordinatedGraphics), WebCore/platform/graphics (ShareableBitmap).WebKit/UIProcess/API/haiku.widget(1).png)
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.

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 |
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:
haiku/ folders, and its sibling gtk/ and wpe/ folders show how another port solved the same problem.PlatformHaiku.cmake. Each of Source/WebCore and Source/WebKit has one that lists which Haiku files are compiled.UIProcess (what the user sees), WebProcess (the page) and the IPC between them, as in the zoom example below.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:
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:
WebPageProxy in the UIProcess; its header lists what a port can ask a page to do.WebViewBase.h, and PageClient.h, the interface a port implements.WebPageProxy method it calls.grep -rn on the method name across Source/WebKit/UIProcess, and git log -S to find the commit that introduced it.The next section applies this method to one feature.

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.
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.
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).
What was missing is the interface:
BrowserWindow::MessageReceived();BWebView that forwards to WebPageProxy, so the window never touches WebKit internals;The path of one key press then looks like this:
BMessage to the window.BrowserWindow::MessageReceived() handles it and calls the BWebView.BWebView calls WebPageProxy::setPageZoomFactor() with the new factor.WebPageProxy sends the IPC message to the WebProcess.Steps 4 and 5 are the process boundary from the WebKit2 section above: the port never sees them.
widget(2).png)
MiniBrowser is a test browser, not a replacement for WebPositive.
Statuses below are those of mid-November.
|
Area |
What is missing |
Status |
|
Forms |
The |
Not implemented |
|
Pages |
Tooltips |
In progress |
|
Windows |
Open Link in New Window and |
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:

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.
GraphicsContextHaiku. 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, |
|
IPC |
Inter-process communication: the messages that the UIProcess, WebProcess and NetworkProcess exchange. |
|
|
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, |
|
port |
The platform-specific part of WebKit: drawing, input, network, menus. Haiku's lives in the |
|
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 |