You are here

Using Chromium as a general-purpose toolkit

Objectives : use the Chromium libraries to compile sample C++ programs.

Chromium is the open-source flavor of the well-known Google Chrome browser.
Cross-platform, feature-full and written mostly in C++, it is also used as a basis for Chromium OS, a full-featured operating system which Google rebrands as Chrome OS and bundles with its Chromebooks.

Obviously, Chromium has everything needed to display windows, play music, manage files, handle multithreading and internationalization... to say the least. Plus, it is nicely split into sub-libraries and third parties : base for generic helper functions, skia for canvas management, views for UI widgets...

So, why not just use Chromium as a toolkit, just like we do on a daily basis with GTK+, EFL, Qt.... ?

Well, there are two main causes for this :
- Chromium's build system is primarily designed to produce a massive binary, the chrome executable ; everything is compiled statically in it to ease redistribution. This can be modified, though.
- Google devs do not guarantee API stability over time. Typically, each release may break some functions or change the way they implement an actual functionality.

This does not mean we cannot play with it, to have a taste at a powerful framework ! So if you are interested, please follow me !

1) Install Chromium, "component build" archive version

Chromium can be built in a mode where, instead of producing an enormous chrome binary, you actually split the build into separate .so objects such as, I have compiled it for Linux, validated that it runs under the latest Tizen Common and Ubuntu 14.04 LTS releases (Debian 7.0 stable will not work, sorry), added the header files, and put everything in a archive.

a) Download Chromium for Ubuntu 14 LTS/Tizen Common :

- chromium-38.0.2067.0-cpb+oz-wl-UBUNTU14.tar.bz2 (71,3 Mb) (32-bit)
- chromium-38.0.2067.0-cpb+oz-wl-UBUNTU14-AMD64.tar.bz2 (114,0 Mb) (64-bit)

b) Extract the archive on your computer :
tar xfvj chromium-38.0.2067.0-UBUNTU14.tar.bz2

This will create 3 new folders in your current directory : "bin", "include" and "lib".

2) (optional) Execute the browser (requires Wayland)

This version of Chromium has been built with Ozone-Wayland, a wonderful backend which permits to run it under Wayland with accelerated EGL/GLESv2 support (software mode is not supported yet). If you do not have such an installation, do not worry, it is not needed to build and run our samples ! If you have it, however, here is how to browse the web with Wayland :

export XDG_RUNTIME_DIR=/run/user/$UID
./lib/chromium/content_shell --no-sandbox

Here is a video of it running under Weston.

3) Compile and run the code samples

Please grab the following C++ samples.

You will need the G++ compiler ; here is how to install it under Ubuntu :
sudo apt-get install g++
The compile command itself is :
g++ -std=c++11 -o program -I./include/chromium ./lib/chromium/lib/

Description of the source files

- : implements log messages with the base::Logging class


- : manipulates files with the base::FilePath class

auto filepath = base::FilePath ("test.txt");
auto dirpath = base::FilePath ("/home/bob");
base::CopyFile (filepath, dirpath);
base::DeleteFile (filepath);

- : manage command line arguments with the base::CommandLine class

auto cmdline = base::CommandLine (argc, argv);
if (cmdline.HasSwitch ("help") && cmdline.GetArgs().empty()) {
// print help text

- : manage callback functions with the base::Callback class

base::Callback callback = base::Bind (&my_function);
callback.Run ();

- : handle delayed and threaded function management with the base::MessageLoop class

base::Callback callback_delayed = base::Bind (&my_function);
auto duration = base::TimeDelta::FromSeconds (seconds);
main_loop.PostDelayedTask (FROM_HERE, callback_delayed, duration);

Here we go !

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.