Blink: Chromium's Rendering Engine
Blink is Google's fork of the WebKit browser engine, which in turn is Apple's fork of KDE's KHTML engine.
WebKit Legacy
WebKit (the precursor of Blink) was designed to be platform-independent, and was successfully ported to many platforms, such as Mac OS and iOS (using Cocoa), Windows, Linux (using GTK), and Android. Chromium was also designed to be ported to multiple platforms, and adds another platform-independent layer on top of the Blink rendering engine, called the content module. So, from the WebKit code perspective, Blink sits on top of a single platform, called "chromium".
The WebKit project contains a rendering engine (WebCore), a JavaScript engine (JavaScriptCore), and an embedding layer. Blink adopted WebCore, but uses the V8 JavaScript Engine instead of JavaScriptCore, and dropped the embedding layer in favor of having its content layer talk directly to WebCore.
Code Layout
Blink's source code is at
third_party/WebKit
in the Chromium source tree. The top-level
directories are as follows.
public/
contains the header files makeing up the API between Blink and Chromium's content layer.Source
contains the actual Blink source code.LayoutTests
has automated tests for the engine's features.Tools
contains scripts for building and running the code.Tools/Scripts
is heavily referenced in WebKit's old
I have not explored the
PerformanceTests
or
ManualTests
directories. They appear to be described by the
WebKit Wiki's Performance Tests page
and
WebKit Wiki's Manual Testing page.
At the time of this writing,
WebKit's source tree has the same
top-level structure. Comparing the Source/
directories shows the top-level
differences between Blink and WebKit.
The Public API
The headers in
public/
are relatively well-commented, so they make a great starting point for
understanding a part of Chromium.
The public APIs fall into two big categories.
public/web
contains the API implemented by Blink and called by Chromium's content layerpublic/platform
has the lower-level API used by Blink and implemented by the content layer
The classes in the public APIs usually have easy-to-guess corresponding classes
in the implementation. For example, the WebView
abstract class, defined in
public/web/WebView.h
,
has one concrete implementation, WebViewImpl
, which is defined in
Source/web/WebViewImpl.h
.
Source/web/WebViewImpl.cpp
contains both the WebViewImpl
implementation, as well as the definitions for
WebView
's static members.
The Source Code
Blink's implementation is split into the following top-level directories.
Source/web
has the implementations of the public APIs inpublic/web
Source/core
has the WebCore implementation, and is the meat of the projectSource/wtf
defines primitive types that abstract over differences in the C++ compilers and standard libraries that Blink supports; wtf stands for Web Template FrameworkSource/platform
contains some lower-level code used by WebCoreSource/modules
has implementations for some W3C specifications; for example, the Geolocation API Spefication is implemented inSource/modules/geolocation
Source/bindings
has the code that produces the glue connecting JavaScript code running inside the browser and WebCore; for example, this is what makes document.querySelectorAll inside JavaScript call into the WebCore::Node::querySelectorAll method in WebCoreSource/inspector
contains the specification of the Chrome remote debugging protocol, and the source code for the Chrome DevTools, which are implemented as a Web application that uses the remote debugging protocolSource/testing
has the source for the special binary used to run the Blink layout tests; this binary has additional JavaScript interfaces exposing Blink internals, to facilitate testingSource/build
has an assortment of scripts used by the build process
The Layout Tests
Blink's regression tests are Web pages that are loaded in a content layer that is hacked to output textual representations of the pages. This is really convenient, because a Web application developer can contribute a failing test for a bug or feature without having to learn C++ or Blink's inner workings.
To get a taste of what tests look like, skim LayoutTests/fast/xmlhttprequest-get.xhtml and the corresponding LayoutTests/fast/xmlhttprequest-get-expected.txt.
Building and Testing
The all_webkit
target contains the Blink-related deliverables.
Blink cannot run on its own, due to its dependency on Chromium's content layer. The Content Shell offers a rudimentary UI on top of the content layer, and is a low-overhead way of getting Blink up and running.
Further Reading
At the time of this writing, the Technical Articles in the WebKit blog and many of the entries on the WebKit Wiki are still relevant and worth the time spent reading them.