# How to submit a Chromium patch to libchromiumcontent

libchromiumcontent is a shared library build of Chromium’s Content module used by Electron (Atom Shell).

This project contains a set of git diff patches that it applies to Chromium’s source during the build phase. This blog post is about writing and testing such patches, and not about submitting a change to the Chromium project itself.

## Clone Chromium’s source

Since we’re building a git diff patch, we need to work with a full git checkout of the Chromium project. You can do so with the following command:

git clone https://chromium.googlesource.com/chromium/src chromium


Notice the repository is huge (~7.8 GiB), so it might take a good while depending on your internet connection.

## Checkout the correct tag

libchromiumcontent contains a file in the root of the project called VERSION, which contains a string that corresponds to a git tag from Chromium’s repository. To avoid conflicts later on, we’ll checkout the tag specified in the file before making any change, which at the time of this writing is 47.0.2526.110:

git checkout 47.0.2526.110


## Create the patch

You can now make the changes that you like without staging them, and create the patch with git diff:

git diff > my-patch.patch


An example patch looks like this:

diff — git a/sandbox/linux/services/credentials.cc b/sandbox/linux/services/credentials.cc
index dd26472..6324ef5 100644
-—- a/sandbox/linux/services/credentials.cc
+++ b/sandbox/linux/services/credentials.cc
@@ -324,8 +324,6 @@ pid_t Credentials::ForkAndDropCapabilitiesInChild() {
return pid;
}

—   // Since we just forked, we are single threaded.
return 0;
}


You can then move the resulting patch to libchromiumcontent/patches, and commit your changes.

## Build libchromiumcontent

Now that the patch is in place, we have to build libchromiumcontent and create a distributable release that we can then make use of to test our changes with Electron. Head over to where you initially cloned libchromiumcontent and do:

./scripts/bootstrap
./scripts/update


The patches will be applied during the update script. Afterwards, so might want to check libchromiumcontent/vendor/chromium/src to ensure your patch applied correctly.

If something happened and your patch didn’t apply cleanly, you can easily test your patch by going to libchromiumcontent/vendor/chromium/src and trying to apply the patch yourself, to see what conflicts you get:

git apply path/to/my-patch.patch


Once you’re ready to go, compile and package libchromiumcontent with the following commands:

./script/build
./script/create-dist


Notice this might take several hours, even on a decently fast computer.

After the build is done, take note of the hash from the libchromiumcontent commit that includes your patch and perform the following commands, replacing your operating system and architecture as appropriate:

# Use either win|linux|osx to reference the platform
mkdir -p osx/x64/<commit>
mv libchromiumcontent* osx/x64/<commit>


## Build Electron with our custom libchromiumcontent

Now that our libchromiumcontent changes are ready to be tested, we’re going to build Electron against it.

Clone Electron if you haven’t already:

git clone https://github.com/electron/electron && cd electron


Bootstrap Electron with our custom libchromiumcontent:

./script/bootstrap.py -v --url file:///path/to/libchromiumcontent


And finally build Electron:

./script/build.py -c D


## Run Electron

You can finally run your custom Electron build with your libchromiumcontent changes:

./out/D/electron path/to/your/electron/app