Clone wiki

cef / Architecture

This Wiki page provides an overview of the CEF architecture.

Note to Editors: Changes made to this Wiki page without prior approval via the CEF Forum or Issue Tracker may be lost or reverted.



Background

The Chromium Embedded Framework (CEF) is an open source project founded by Marshall Greenblatt in 2008 to develop a Web browser control based on the Google Chromium project. CEF currently supports a range of programming languages and operating systems and can be easily integrated into both new and existing applications. It was designed from the ground up with both performance and ease of use in mind. The base framework includes C and C++ programming interfaces exposed via native libraries that insulate the host application from Chromium and Blink implementation details. It provides close integration between the browser control and the host application including support for custom plugins, protocols, JavaScript objects and JavaScript extensions. The host application can optionally control resource loading, navigation, context menus, printing and more, while taking advantage of the same performance and HTML5 technologies available in the Google Chrome Web browser.

Dependencies

The CEF project depends on a number of other projects maintained by third parties. The major projects that CEF depends on are:

  • Chromium - Provides general functionality like network stack, threading, message loop, logging and process control needed to create a fully functional Web browser. Implements "platform" code that allows Blink to communicate with V8 and Skia. Many Chromium design documents can be found at http://dev.chromium.org/developers.
  • Blink (formerly WebKit) - The rendering implementation used by Chromium. Provides DOM parsing, layout, event handling, rendering and HTML5 JavaScript APIs. Some HTML5 implementations are split between the Blink and Chromium code bases.
  • V8 - JavaScript engine.
  • Skia - 2D graphics library used for rendering non-accelerated content. More information on how Chromium integrates Skia is available here.
  • Angle - 3D graphics translation layer for Windows that converts GLES calls to DirectX. More information about accelerated compositing is available here.

Versions

There have been three versions of CEF to date.

  • CEF1 - Single process implementation using the Chromium WebKit API.
  • CEF2 - Multi process implementation built on the Chromium browser.
  • CEF3 - Multi process implementation using the Chromium Content API.

Only the CEF3 version is currently developed and supported. See the BranchesAndBuilding Wiki page for development information.

Common API Usage

All versions of CEF expose a simple, easy-to-use API designed to insulate users from the underlying Chromium and Blink code complexity. Common usage is as follows:

  1. Initialize CEF by calling CefInitialize().

  2. Perform work on the UI message loop by calling CefRunMessageLoop() or CefDoMessageLoopWork().

  3. Create a browser window by calling CreateBrowser() or CreateBrowserSync() and passing in a CefClient instance.

  4. Shut down CEF by calling CefShutdown() before the application exits.

C Wrapper API

The libcef shared library exports a C API that isolates the user from the CEF runtime and code base. The libcef_dll_wrapper project, which is distributed in source code form as part of the binary release, wraps this exported C API in a C++ API that is then linked into the client application. The code for this C/C++ API translation layer is automatically generated by the translator tool. Direct usage of the C API is described on the UsingTheCAPI Wiki page.

CEF1 (Discontinued)

CEF1 was discontinued when Google forked the WebKit project and subsequently deleted the Chromium WebKit API. The single process architecture used by CEF1 integrates Chromium and WebKit directly into the client application. Advantages to the single process arcitecture include reduced memory usage and closer integration with the client application. Disadvantages include reduced performance with certain types of accelerated content and crashes due to plugins like Flash running in the same process.

API Usage

Below is an overview of the main CEF1 interfaces and their uses. For more information on specific supported features and interfaces visit the GeneralUsage Wiki page or browse the CEF1 include files.

  • CefApp - This interface is passed to CefInitialize() and allows the application to customize global functionality like resource loading and proxy handling.
  • CefClient - This interface is passed to CefCreateBrowser() or CefCreateBrowserSync() and acts as the connection between an individual CEF browser instance and the client application. Additional interfaces for request handling, display handling, etc. are exposed via this interface.
  • CefBrowser - Exposes capabilities provided by the browser. This includes back/forward navigation, source retrieval, request loading, etc. A single CefBrowser may have one or more child CefFrame objects.

Threading Considerations

CEF1 includes UI, IO and FILE threads. The UI thread creates browser windows and is used for all interaction with WebKit and V8. The IO thread is used for handling schema and network requests. The FILE thread is used for the application cache and other miscellaneous activities.

When using CEF1 you should keep the following threading considerations in mind:

  • Do not perform blocking operations on the UI thread. This can lead to serious performance issues.
  • The UI thread will be the same as the main application thread if CefInitialize() is called with a CefSettings.multi_threaded_message_loop value of false.
  • All WebKit and V8 interation must take place on the UI thread. Consequently, some CEF API functions can only be called on the UI thread. Functions that have this limitation will be documented accordingly in the associated CEF header file.
  • The CefPostTask method can be used to post tasks asnychronously between the various threads.

Implementation Details

CEF1 has the following major implementation classes:

  • CefContext - Represents the global CEF context. A single CefContext object is created by CefInitialize() and destroyed by CefShutdown().
  • CefProcess - Used by CefContext to create and manage the CEF threads.
  • BrowserWebKitInit - Manages the global WebKit environment as exposed by the Chromium WebKit API.
  • WebViewHost - Provides the native window "wrapper" implementation for a WebView. This class extends WebWidgetHost which provides functionality shared in common with popup widgets (like select menus) on some platforms.
  • CefBrowserImpl - Implements the CefBrowser interface, creates the WebViewHost and provides the glue code for a single browser instance.
  • BrowserWebViewDelegate - Implements the WebKit interfaces that provide communication between CefBrowserImpl and the underlying WebView.

CEF2 (Discontinued)

CEF2 was discontinued when Chromium announced support for the Content API. Information about CEF2 can be found here.

CEF3

CEF3 has been the recommended and supported version of CEF since January 2013. It uses the same multi process architecture as the Chromium Web browser via the Chromium Content API. This architecture provides a number of advantages over the single process architecture used by CEF1:

  • Support for multi-process run mode.
  • More code sharing with the Chromium browser.
  • Improved performance and less breakage due to use of the "supported" code path.
  • Faster access to new features.

In most cases CEF3 will have the same performance and stability characteristics as the Chromium Web browser.

API Usage

See the GeneralUsage Wiki page for detailed API usage instructions.

Process Considerations

See the Processes section of the GeneralUsage Wiki page for details.

Threading Considerations

See the Threads section of the GeneralUsage Wiki page for details.

Implementation Details

CEF3 has the following major implementation classes:

  • CefMainDelegate - Implements the common process bootstrap logic.
  • CefContentClient - Implements the Content API callbacks that are common to all processes.
  • CefContext - Represents the global CEF context in the browser process. A single CefContext object is created by CefInitialize() and destroyed by CefShutdown().
  • CefBrowserMainParts - Implements the browser process bootstrap logic.
  • CefContentBrowserClient - Implements the Content API callbacks for the browser process.
  • CefBrowserHostImpl - Implements the CefBrowser and CefBrowserHost interfaces in the browser process. Provides the glue code and implements interfaces for communicating with the RenderViewHost.
  • CefContentRendererClient - Implements the Content API callbacks for the render process.
  • CefBrowserImpl - Implements the CefBrowser interface in the render process. Provides the glue code and implements interfaces for communicating with the RenderView.

Updated