Blink is cleanly separated from Chromium’s content layer. This article gives a
quick overview of Blink’s interface. Most code references in this article are
relative to Blink’s root directory,
This article is likely to get updated and grow as my understanding of the Blink codebase improves.
The Web and Platform APIs
The interface is defined by the files in the following directories:
public/web/has headers for the classes implemented by Blink and used by the content layer; these classes are implemented in
public/platform/has classes implemented by the content layer and used by Blink; these classes are implemented in Chrome’s content layer, in the
content/directory in Chrome’s source tree
Blink’s public interface classes are all defined in the
blink namespace, and
Web prefix in their name. In fact, when reading Blink code, it is
safe to assume that any class whose name starts with
Web belongs to Blink’s
Wrappers and Pointers
public/ are not allowed to include files outside of the
directory. This implies that all the
blink::Web classes and structures can
only use internal classes via pointers or references.
Some classes hold raw pointers to the internal classes that they wrap. For
WebDatabase (defined in
holds a raw pointer to the
WebCore::DatabaseBackendBase instance that it
wraps. However, most classes use a smart pointer. For example,
WebPrivatePtr smart pointer class to reference the
instance that it wraps.
WebPrivatePtr, declared and completely defined in
is the most popular smart pointer class. It is used for wrapping
reference-counted classes, and automatically calls
deref(), etc. on
the wrapped instance. The header has a very useful block comment right above
WebPrivatePtr class declaration. On a first read, I’d skip the
boilerplate at the beginning of the file and go straight for the block comment.
WebPrivateOwnPtr, declared and completely defined in
is used for wrapping classes that are allocated on the heap, but do not use
reference-counting. The smart pointer automatically destructs the wrapped
instance. This class' header also has a very useful block comment.
The Platform Object
The entry point to the implementations of the classes and functions defined in
public/platform headers is the
blink::Platform class, defined in
and implemented in
in the Chromium souce tree.
Blink code obtains a reference to the current platform by calling the
blink::Platform::current() static function, and then calls a
virtual method. Many methods are used to obtain instances of platform classes.