How have you been developing Chromium? I have often been asked what is the best tool to develop Chromium. I guess Chromium developers have been usually using vim, emacs, cscope, sublime text, eclipse, etc. And they have used GDB or console logs for debugging. But, in case of Windows, developers have used Visual Studio. Although Visual Studio supports powerful features to develop C/C++ programs, unfortunately, it couldn’t be used by other platform developers. However, recently I notice that Visual Studio Code also can support to develop Chromium with the nice editor, powerful debugging tools, and a lot of extensions. And, even it can work on Linux and Mac because it is based on Electron. Nowadays I’m developing Chromium with VS Code. I feel that VS Code is one of the very nice tools to develop Chromium. So I’d like to share my experience how to develop Chromium by using the Visual Studio Code on Ubuntu.

Toggle Header/Source – Toggles between .cc and .h with F4. The C/C++ extension supports this as well through Alt+O but sometimes chooses the wrong file when there are multiple files in the workspace that have the same name.

you-complete-me – YouCompleteMe code completion for VS Code. It works fairly well in Chromium. To install You-Complete-Me, enter these commands in a terminal:

* Ctrl+P: opens a search box to find and open a file.
* F1 or Ctrl+Shift+P: opens a search box to find a command
(e.g. Tasks: Run Task).
* Ctrl+K, Ctrl+S: opens the key bindings editor.
* Ctrl+`: toggles the built-in terminal.
* Ctrl+Shift+M: toggles the problems view (linter warnings,
compile errors and warnings). You'll swicth a lot between
terminal and problem view during compilation.
* Alt+O: switches between the source/header file.
* Ctrl+G: jumps to a line.
* F12: jumps to the definition of the symbol at the cursor
(also available on right-click context menu).
* Shift+F12 or F1: CodeSearchReferences, Return shows all
references of the symbol at the cursor.
* F1: CodeSearchOpen, Return opens the current file in
Code Search.
* Ctrl+D: selects the word at the cursor. Pressing it multiple
times multi-selects the next occurrences, so typing in one
types in all of them, and Ctrl+U deselects the last occurrence.
* Ctrl+K+Z: enters Zen Mode, a fullscreen editing mode with
nothing but the current editor visible.
* Ctrl+X: without anything selected cuts the current line.
Ctrl+V pastes the line.

(Optional) Color setting

Press Ctrl+Shift+P, color, Enter to pick a color scheme for the editor

Additional settings after the default settings.

Set workspaceRoot to .bashrc. (Because it will be needed for some extensions.)

export workspaceRoot=$HOME/chromium/src

Add new tasks to tasks.json in order to build Chromium by using ICECC.

I wrote a post about how to build Chromium by using ICECC in the previous post. Please setup it first.

Screenshot after the settings

Build Chromium with ICECC in VS Code

Select 1-build_chrome_debug_icecc. VS Code will show an integrated terminal when building Chromium as below, On the ICECC monitor, you can see that VS Code builds Chromium by using ICECC.

Start debugging in VS Code

After completing the build, now is time to start debugging Chromium.

Set a breakpoint

F9 button or just click the left side of line number

Launch debug

Press F5 button

Screen captures when debugger stopped at a breakpoint

Overview

Editor

Call stack

Variables

Watch

Breakpoints

Todo

In multiple processes model, VS Code can’t debug child processes yet (i.e. renderer process). According to C/C++ extension project site, they suggested us to add the below command to launch.json though, it didn’t work for Chromium when I tried.

If you’re a Chromium developer, I guess that you’ve suffered from the long build time of Chromium like me. Recently, I’ve set up the icecc build environment for Chromium in the Igalia Korea office. Although there have been some instructions how to build Chromium with ICECC, I think that someone might feel they are a bit difficult. So, I’d like to share my experience how to set up the environment to build Chromium on the icecc with Clang on Linux in order to speed up the build of Chromium.

Prerequisites in your environment

First, we should install the icecc on your all machines.

sudo apt-get install icecc ccache [icecc-monitor]

To build Chromium using icecc on the Clang, we have to use some configurations when generating the gn files. To do it as easily as possible, I made a script. So you just download it and register it to $PATH.

Create a clang toolchain from the patched Chromium version
I added the process to “sync” argument of buildChromiumICECC.sh. So please just execute the below command before starting compiling. Whenever you run it, clang.tar.gz will be updated every time with the latest Chromium version.

$ buildChromiumICECC.sh sync

Build

Run an icecc scheduler on a master machine,

sudo service icecc-scheduler start

Then, run an icecc daemon on each slave machine

sudo service iceccd start

If you run icemon, you can monitor the build status on the icecc.

Start building in chromium/src

$ buildChromiumICECC.sh Debug|Release

When you start building Chromium, you’ll see that the icecc works on the monitor!

Build Time

In my case, I’ve been using 1 laptop and 2 desktops for Chromium build. The HW information is as below,

Laptop (Dell XPS 15″ 9560)

CPU: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz

RAM: 16G

SSD

Desktop 1

CPU: Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz

RAM: 16G

SSD

Desktop 2

CPU: Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz

RAM: 16G

SSD

I’ve measured how long time I’ve spent to build Chromium with the script in below cases,

Laptop

Build time on Release with the jumbo build: About 84 min

Build time on Release without the jumbo build: About 203 min

Laptop + Desktop 1 + Desktop 2

Build time on Release with the jumbo build: About 35 min

Build time on Release without the jumbo build: About 73 min

But these builds haven’t applied any object caching by ccache yet. If ccache works next time, the build time will be reduced. Besides, the build time is depended on the count of build nodes and performance. So this time can differ from your environment.

The API is to give you the power to add your customized scheme(a.k.a. protocol) to your website or web application. If you register your own custom scheme, it can help you to avoid collisions with other DNS, or help other people use it correctly, and be able to claim the moral high ground if they use it incorrectly. In this post, I would like to introduce the feature with some examples, and what I’ve contributed to the feature.

Introduction

The registerProtocolHandler had been started discussing since 2006. Finally, it was introduced in HTML5 for the first time.

As this example, you can register a custom scheme with a URL that can be combined with the given URL(web+search:igalia)

However, you need to keep in mind some limitations when you use it.

URL should include %s placeholder.

You can register own custom handler only when the URL of the custom handler is same the website origin. If not, the browser will generate a security error.

There are pre-defined schemes in the specification. Except for these schemes, you’re only able to use “web+foo” style scheme. But, the length of “web+foo” is at least five characters including ‘web+’ prefix. If not, the browser will generate a security error.

FYI, other browsers based on Chromium (i.e. Opera, Yandex, Whale, etc.) have handled it similar to Chrome unless each vendor has own specific behavior.

Safari (WebKit)

Though WebKit has supported this feature in WebCore and WebProcess of WebKit2, no browsers based on WebKit have supported this feature with UI. Although I had tried to implement it in UIProcess of WebKit2 through the webkit-dev mailing list so that browsers based on WebKit can support it, Unfortunately, some of Apple engineers had doubts about this feature though there were some agreements to support it in WebKit. So I failed to implement it in UIProcess of WebKit2.

According to the specification, only first “%s” placeholder should be substituted, not substitute all placeholders. But, Chrome has substituted all placeholders with the given URL as below, even though Firefox has only substituted the first placeholder.

Summary

So far, we’ve looked at the navigator.registerProtcolHandler for your web application simply. The API can be useful if you want to make users use your web applications like a web-based email client or calendar.

Nowadays most of my projects have been using opensource or worked based on opensource. If we just needs to use it, I think it would be a good situation for you. However we usually have projects that keep the opensource over years for your products. So if you have to hack a lot of modules inside of opensource code, it can be a nightmare when you rebase current source base against the latest opensource after months or years. In this article I would like to share some of my experiences on how to make a downstream patch when we work using opensource.

Try to contribute your patch to the opensource project as much as possible

I think this is the best way to reduce our heavy burden that we should maintain in your downstream source code. Even if the opensource project you’re using is being developed fast, you will often face many conflicts during the rebase because it’s likely that original code or architecture have changed frequently in the meantime. To avoid the conflict, it would be best if you contribute your patch to the opensource project as much as possible.

Below documents are a good example to explain how to contribute your code to the opensource project.

Make your downstream port

We know well that #1 is the best way to reduce our downstream patches though, it is often hard to keep because downstream patches are often too hacky or unstable. Even if you submit a downstream patch to upstream, you might get many review comments or objections from the opensource maintainers. In such case, what else can you do ? In my experience, it was important to separate our downstream implementation from the original code. For example, we can make new TriangleFoo.h/cpp files instead of original Triangle.h/cpp files, then we can use them through the modification of few build scripts.

We can avoid some conflicts in the next rebase with the latest opensource in the Triangle.h/cpp files. However we still need to modify the TriangleFoo.h/cpp if Figure.h is changed. For example, when a new parameter is added or a return type is changed.

Use #if ~ #endif guard

When we only need to modify few lines or just to change logic inside a function, we can use #if ~ #else ~ #endif guard. The guard can help us to know what codes were added by us or modified by us. Besides it might be help us to check easily if the downstream patch generated side effects through turning it off. In my previous projects, most of issues have come from downstream patches because they lacked code review, missed test cases, or were too hacky against original architecture. In such cases, you can check the issue just by turning the guard off. However, if you use #if ~ #endif guard in many places, the usages can mess your code up. So I’d like to recommend you use it only when you really need.

Try to make a patch per a feature

As you may have experienced before, it is very hard to implement a feature with a commit. Even though you succeed in implementing a new feature with a commit perfectly, you may face to touch the implementation again in order to fix a bug or apply new requirements again. In such case your git history will get messier and messier. It will make it difficult to rebase based on the latest opensource. To avoid it, you may have manually merged original implementation with the fixup commits reflected later. But there are two useful git commands for this case – git commit fixup and git rebase –autosquash.

git commit –fixup : Automatically marks your commit as a fix of a previous commit. Construct a commit message for use with git rebase –autosquash.

Example
There is a good article to explain that explains method [1]. If you need to understand further, it would be good if you visit the URL. Let’s assume that we have 3 commits on your local repository.