CINXE.COM
Getting Around the Chromium Source Code Directory Structure
<!DOCTYPE html> <head> <meta charset="utf-8"> <title>Getting Around the Chromium Source Code Directory Structure</title> <link rel="stylesheet" href="/_stylesheets/@docsearch/style.css"> <link rel="stylesheet" href="/_stylesheets/default.css"> </head> <!-- Configure Google Analytics v4 --> <!-- Google tag (gtag.js) --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-24XP4PG02H"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-24XP4PG02H'); </script> <header> <a href="/"> <img alt="the Chromium logo" src="/_assets/icon-chromium-96.png" width="48" height="48"> <h2>The Chromium Projects</h2> </a> <div id="search"></div> </header> <div id="main-wrapper"> <nav id="sidebar-left"> <section> <a href="/chromium-projects">Home</a> <a href="/Home">Chromium</a> <a href="/chromium-os">ChromiumOS</a> </section> <section> <h4>Quick links</h4> <a href="/for-testers/bug-reporting-guidelines">Report bugs</a> <a href="/developers/discussion-groups">Discuss</a> </section> <section> <h4>Other sites</h4> <a href="https://blog.chromium.org/">Chromium Blog</a> <a href="https://developer.chrome.com/extensions">Google Chrome Extensions</a> </section> <section id="license" role="complementary"> Except as otherwise <a href="https://developers.google.com/site-policies.html#restrictions">noted</a>, the content of this page is licensed under a <a href="https://creativecommons.org/licenses/by/2.5/">Creative Commons Attribution 2.5 license</a>, and examples are licensed under the <a href="https://chromium.googlesource.com/chromium/src/+/HEAD/LICENSE">BSD License</a>. </section> <section id="privacy" role="complementary"> <a href="https://policies.google.com/privacy">Privacy</a> </section> <a id="edit-this-page" href="https://edit.chromium.org/edit?repo=chromium/website/main&file=site/developers/how-tos/getting-around-the-chrome-source-code/index.md&ext_google.git=%7B%22repo%22%3A%22chromium%2Fwebsite%22%2C%22ref%22%3A%22main%22%2C%22file%22%3A%22site/developers/how-tos/getting-around-the-chrome-source-code/index.md%22%7D">Edit this page</a> </nav> <main> <div class="breadcrumbs"> <a href="/developers">For Developers</a> > <a href="/developers/how-tos">How-Tos</a> > </div> <h1>Getting Around the Chromium Source Code Directory Structure</h1> <nav class="table-of-contents"><ol><li><a href="#high-level-overview">High-level overview</a></li><li><a href="#top-level-projects">Top-level projects</a></li><li><a href="#quick-reference-for-the-directory-tree-under-content">Quick reference for the directory tree under "content/"</a></li><li><a href="#quick-reference-for-the-directory-tree-under-chrome">Quick reference for the directory tree under "chrome/"</a></li><li><a href="#a-personal-learning-plan">A personal learning plan</a></li><li><a href="#code-paths-for-common-operations">Code paths for common operations</a><ol><li><a href="#application-startup">Application startup</a></li><li><a href="#tab-startup-initial-navigation">Tab startup & initial navigation</a></li><li><a href="#navigating-from-the-url-bar">Navigating from the URL bar</a></li><li><a href="#navigations-and-session-history">Navigations and session history</a></li></ol></li></ol></nav><h2 id="high-level-overview" tabindex="-1"><a class="header-anchor" href="#high-level-overview">High-level overview</a></h2> <p>Chromium is separated into two main parts (excluding other libraries): the browser and the renderer (which includes Blink, the web engine). The browser is the main process and represents all the UI and I/O. The renderer is the (often) per-tab sub-process that is driven by the browser. It embeds Blink to do layout and rendering.</p> <p>You will want to read and become familiar with our <a href="/developers/design-documents/multi-process-architecture">multi-process architecture</a> and <a href="/developers/design-documents/displaying-a-web-page-in-chrome">how Chromium displays web pages</a>.</p> <h2 id="top-level-projects" tabindex="-1"><a class="header-anchor" href="#top-level-projects">Top-level projects</a></h2> <p>When you <a href="https://source.chromium.org/chromium">Browse and Search the Chromium Code</a> or <a href="https://www.chromium.org/developers/how-tos/get-the-code/">Checkout the Chromium Code</a> you will notice a number of top-level directories:</p> <ul> <li><strong>android_webview:</strong> Provides a facade over src/content suitable for integration into the android platform. NOT intended for usage in individual android applications (APK). <a href="https://docs.google.com/document/d/1a_cUP1dGIlRQFUSic8bhAOxfclj4Xzw-yRDljVk1wB0/edit?usp=sharing">More information</a> about the Android WebView source code organization.</li> <li><strong>apps</strong>: <a href="http://developer.chrome.com/apps/about_apps.html">Chrome packaged apps</a>.</li> <li><strong>base</strong>: Common code shared between all sub-projects. This contains things like string manipulation, generic utilities, etc. Add things here only if it must be shared between more than one other top-level project.</li> <li><strong>breakpad</strong>: Google's open source crash reporting project. This is pulled directly from Google Code's Subversion repository.</li> <li><strong>build</strong>: Build-related configuration shared by all projects.</li> <li><strong>cc</strong>: The Chromium compositor implementation.</li> <li><strong>chrome</strong>: The Chromium browser (see below).</li> <li><strong>chrome/test/data</strong>: Data files for running certain tests.</li> <li><strong>components</strong>: directory for components that have the Content Module as the uppermost layer they depend on.</li> <li><strong>content:</strong> The core code needed for a multi-process sandboxed browser (see below). <a href="/developers/content-module">More information</a> about why we have separated out this code.</li> <li><strong>device:</strong> Cross-platform abstractions of common low-level hardware APIs.</li> <li><strong>net</strong>: The networking library developed for Chromium. This can be used separately from Chromium when running our simple test_shell in the <code>webkit</code> repository. See also <code>chrome/common/net</code>.</li> <li><strong>sandbox</strong>: The sandbox project which tries to prevent a hacked renderer from modifying the system.</li> <li><strong>skia + third_party/skia</strong>: Google's Skia graphics library. Our additional classes in ui/gfx wrap Skia.</li> <li><strong>sql:</strong> Our wrap around sqlite.</li> <li><strong>testing</strong>: Contains Google's open-sourced GTest code which we use for unit testing.</li> <li><strong>third_party</strong>: 200+ small and large "external" libraries such as image decoders, compression libraries and the web engine Blink (here because it inherits license limitations from WebKit). <a href="/developers/adding-3rd-party-libraries">Adding new packages</a>. <ul> <li><strong>.../blink/renderer</strong>: The web engine responsible for turning HTML, CSS and scripts into paint commands and other state changes.</li> </ul> </li> <li><strong>tools</strong></li> <li><strong>ui/gfx</strong>: Shared graphics classes. These form the base of Chromium's UI graphics.</li> <li><strong>ui/views</strong>: A simple framework for doing UI development, providing rendering, layout and event handling. Most of the browser UI is implemented in this system. This directory contains the base objects. Some more browser-specific objects are in chrome/browser/ui/views.</li> <li><strong>url</strong>: Google's open source URL parsing and canonicalization library.</li> <li><strong>v8</strong>: The V8 Javascript library. This is pulled directly from Google Code's Subversion repository.</li> </ul> <p>For historical reasons, there are some small top level directories. Going forward, the guidance is that new top level directories are for applications (e.g. Chrome, Android WebView, Ash). Even if these applications have multiple executables, the code should be in subdirectories of the application</p> <p>Here's a slightly dated diagram of the dependencies. In particular, WebKit is replaced by blink/renderer. A module that is lower can't include code from a higher module directly (i.e. content can't include a header from chrome), but talks to it using embedder APIs.</p> <p><a href="/developers/how-tos/getting-around-the-chrome-source-code/Content.png"><img alt="image" src="/developers/how-tos/getting-around-the-chrome-source-code/Content.png"></a></p> <h2 id="quick-reference-for-the-directory-tree-under-content" tabindex="-1"><a class="header-anchor" href="#quick-reference-for-the-directory-tree-under-content">Quick reference for the directory tree under "content/"</a></h2> <ul> <li><strong>browser</strong>: The backend for the application which handles all I/O and communication with the child processes . This talks to the <code>renderer</code> to manage web pages.</li> <li><strong>common:</strong> Files shared between the multiple processes (i.e. browser and renderer, renderer and plugin, etc...). This is the code specific to Chromium (and not applicable to being in base).</li> <li><strong>gpu:</strong> Code for the GPU process, which is used for 3D compositing and 3D APIs.</li> <li><strong>plugin:</strong> Code for running browser plugins in other processes.</li> <li><strong>ppapi_plugin:</strong> Code for the <a href="/developers/design-documents/pepper-plugin-implementation">Pepper </a>plugin process.</li> <li><strong>renderer</strong>: Code for the subprocess in each tab. This embeds WebKit and talks to <code>browser</code> for I/O.</li> <li><strong>utility:</strong> Code for running random operations in a sandboxed process. The browser process uses it when it wants to run an operation on untrusted data.</li> <li><strong>worker:</strong> Code for running HTML5 Web Workers.</li> </ul> <h2 id="quick-reference-for-the-directory-tree-under-chrome" tabindex="-1"><a class="header-anchor" href="#quick-reference-for-the-directory-tree-under-chrome">Quick reference for the directory tree under "chrome/"</a></h2> <ul> <li><strong>app</strong>: The "app" is the most basic level of the program. It is run on startup, and dispatches to either the browser or renderer code depending on which capabilities the current process is in. It contains the projects for <code>chrome.exe</code> and <code>chrome.dll</code>. You won't generally need to change this stuff except for resources like images and strings. <ul> <li><strong>locales</strong>: Projects for building localized DLLs.</li> <li><strong>resources</strong>: Icons and cursors.</li> <li><strong>theme</strong>: Images for the theme of the window.</li> </ul> </li> <li><strong>browser</strong>: The frontend including the main window, UI, and the backend for the application which handles all I/O and storage. This talks to the <code>renderer</code> to manage web pages. <ul> <li><strong>ui</strong> model, view and controller code for UI features and functionality</li> </ul> </li> <li><strong>common</strong>: Files shared between the browser and the renderer that is specific to the Chrome module. <ul> <li><strong>net</strong>: Some Chromium-specific stuff on top of the <code>net</code> top-level module. This should be merged with browser/net.</li> </ul> </li> <li><strong>installer</strong>: Source files and projects for making the installer (MSI package).</li> <li><strong><strong>renderer</strong>: Chrome specific code that runs in the renderer process. This adds Chrome features like autofill, translate etc to the content module.</strong></li> <li><strong>test</strong>: <ul> <li><strong>automation</strong>: Used by tests to drive the browser UI, for example, in <code>test/ui</code>, <code>test/startup</code>, etc. This communicates with <code>browser/automation</code> in the browser.</li> <li><strong>page_cycler</strong>: Code for running page cycler tests (for performance measurement). See <code>tools/perf/dashboard</code>.</li> <li><strong>reliability</strong>: Reliability tests for distributed testing of page loads for reliability metrics and crash finding.</li> <li><strong>selenium</strong>: Code for running the selenium tests, which is a third-party test suite for Ajaxy and JavaScript stuff. See <code>test/third_party/selenium_core</code>.</li> <li><strong>startup</strong>: Tests for measuring startup performance. See <code>tools/perf/dashboard</code> and <code>tools/test/reference_build</code>.</li> <li><strong>ui</strong>: UI tests for poking at the browser UI, opening tabs, etc. It uses <code>test/automation</code> for doing most operations.</li> <li><strong>unit</strong>: The base code for the unit tests. The test code for individual tests is generally alongside the code it is testing in a <code>*_unittest.cc</code> file.</li> </ul> </li> <li><strong>third_party</strong>: Third party libraries that are specific to Chromium. Some other third party libraries are in the top-level <code>third_party</code> library.</li> <li><strong>tools</strong> <ul> <li><strong>build</strong>: Tools and random stuff related to building.</li> <li><strong>memory</strong>: Tools for memory stuff. Currently includes <code>gflags</code> for setting page heap options.</li> <li><strong>perf/dashboard</strong>: Code for converting performance logs (for example <code>test/startup_test</code>) into data and graphs.</li> <li><strong>profiles</strong>: Generator for random history data. Used to make test profiles.</li> </ul> </li> </ul> <h2 id="a-personal-learning-plan" tabindex="-1"><a class="header-anchor" href="#a-personal-learning-plan">A personal learning plan</a></h2> <p>Eventually you鈥檒l have your build setup, and want to get to work. In a perfect world, we would have all the time we needed to read every line of code and understand it before writing our first line of code. In practice, we鈥檇 have a hard time reading just the checkins that happen in one day if we did nothing else, so none of us will ever be able to read all of the code. So, what can we do? We suggest you develop your own plan for learning what you need, here are some suggested starting points.</p> <p>Fortunately for us, Chromium has some top quality design docs <a href="/developers/design-documents">here</a>. While these can go a bit stale (for instance, when following along, you may find references to files that have been moved or renamed or refactored out of existence), it is awesome to be able to comprehend the way that the code fits together overall.</p> <p><strong>Read the most important dev docs</strong></p> <p><a href="/developers/design-documents/multi-process-architecture">multi-process-architecture</a></p> <p><a href="/developers/design-documents/displaying-a-web-page-in-chrome">displaying-a-web-page-in-chrome</a></p> <p><a href="/developers/design-documents/inter-process-communication">inter-process-communication</a></p> <p><a href="/developers/design-documents/threading">threading</a></p> <p><strong>See if your group has any startup docs</strong></p> <p>There may be some docs that people working on the same code will care about while others don鈥檛 need to know as much detail.</p> <p><strong>Learn some of the code idioms:</strong></p> <p><a href="/developers/coding-style/important-abstractions-and-data-structures">important-abstractions-and-data-structures </a></p> <p><a href="/developers/smart-pointer-guidelines">smart-pointer-guidelines</a></p> <p><a href="/developers/chromium-string-usage">chromium-string-usage</a></p> <p>Later, as time permits, skim all the design docs, reading where it seems relevant.</p> <p>Get good at using code search (or your code browsing tool of choice)</p> <p>Learn who to ask how the code works <a href="/developers/finding-somebody-who-knows-how-a-piece-of-code-works">hints here</a>.</p> <p>Debug into the code you need to learn, with a debugger if you can, log statements and grepping if you cannot.</p> <p>Look at the differences in what you need to understand and you currently understand. For instance, if your group does a lot of GUI programming, then maybe you can invest time in learning GTK+, Win32, or Cocoa programming.</p> <p>Use <a href="https://source.chromium.org/">source.chromium.org</a> to search the source code. This can be particularly helpful if code moves around and our documentation is no longer accurate.</p> <h2 id="code-paths-for-common-operations" tabindex="-1"><a class="header-anchor" href="#code-paths-for-common-operations">Code paths for common operations</a></h2> <p>There is additional information and more examples on <a href="/developers/design-documents/displaying-a-web-page-in-chrome">how Chromium displays web pages</a>.</p> <h3 id="application-startup" tabindex="-1"><a class="header-anchor" href="#application-startup">Application startup</a></h3> <ol> <li>Our <code>WinMain</code> function is in <code>chrome/app/main.cc</code>, and is linked in the <code>chrome</code> project.</li> <li><code>WinMain</code> launches the Google Update Client, which is the installer/autoupdater. It will find the subdirectory for the current version, and load <code>chrome.dll</code> from there.</li> <li>It calls <code>ChromeMain</code> in the newly loaded library, which is in <code>chrome_main.cc</code> in the <code>chrome_dll</code> project.</li> <li><code>ChromeMain</code> does initialization for common components, and then forwards to either <code>RendererMain</code> in <code>chrome/renderer/renderer_main.cc</code> if the command line flag indicates that this should be a subprocess, or <code>BrowserMain</code> in <code>chrome/browser/browser_main.cc</code> if not to load a new copy of the application. Since this is startup, we're launching the browser.</li> <li><code>BrowserMain</code> does common browser initialization. It has different modes for running installed webapps, connecting to the automation system if the browser is being tested, etc.</li> <li>It calls <code>LaunchWithProfile</code> in <code>browser_init.cc</code> which creates a new <code>Browser</code> object in <code>chrome/browser/ui/browser.cc</code>. This object encapsulates one toplevel window in the application. The first tab is appended at this time.</li> </ol> <h3 id="tab-startup-initial-navigation" tabindex="-1"><a class="header-anchor" href="#tab-startup-initial-navigation">Tab startup & initial navigation</a></h3> <ol> <li><code>BrowserImpl::AddTab</code> in <code>weblayer/browser/browser_impl.cc</code> is called to append a new tab.</li> <li>It will create a new <code>TabContents</code> object from <code>browser/tab_contents/tab_contents.cc</code></li> <li><code>TabContents</code> creates a <code>RenderViewHost</code> (<code>chrome/browser/renderer_host/render_view_host.cc</code>) via the <code>RenderViewHostManager's</code> Init function in <code>chrome/browser/tab_contents/render_view_host_manager.cc</code>). Depending on the <code>SiteInstance</code>, the <code>RenderViewHost</code> either spawns a new renderer process, or re-uses an existing <code>RenderProcessHost</code>. <code>RenderProcessHost</code> is the object in the browser that represents a single renderer subprocess.</li> <li>The <code>NavigationController</code> in <code>chrome/browser/tab_contents/navigation_controller.cc</code> which is owned by the tab contents, is instructed to navigate to the URL for the new tab in <code>NavigationController::LoadURL</code>. "Navigating from the URL bar" from step 3 onward describes what happens from this point.</li> </ol> <h3 id="navigating-from-the-url-bar" tabindex="-1"><a class="header-anchor" href="#navigating-from-the-url-bar">Navigating from the URL bar</a></h3> <ol> <li>When the user types into or accepts an entry in the URL bar, the autocomplete edit box determines the final target URL and passes that to <code>AutocompleteEdit::OpenURL</code>. (This may not be exactly what the user typed - for example, an URL is generated in the case of a search query.)</li> <li>The navigation controller is instructed to navigate to the URL in <code>NavigationController::LoadURL</code>.</li> <li>The <code>NavigationController</code> calls <code>TabContents::Navigate</code> with the <code>NavigationEntry</code> it created to represent this particular page transition. It will create a new <code>RenderViewHost</code> if necessary, which will cause creation of a <code>RenderView</code> in the renderer process. A <code>RenderView</code> won't exist if this is the first navigation, or if the renderer has crashed, so this will also recover from crashes.</li> <li><code>Navigate</code> forwards to <code>RenderViewHost::NavigateToEntry</code>. The <code>NavigationController</code> stores this navigation entry, but it is marked as "pending" because it doesn't know for sure if the transition will take place (maybe the host can not be resolved).</li> <li><code>RenderViewHost::NavigateToEntry</code> sends a <code>ViewMsg_Navigate</code> to the new <code>RenderView</code> in the renderer process.</li> <li>When told to navigate, <code>RenderView</code> may navigate, it may fail, or it may navigate somewhere else instead (for example, if the user clicks a link). <code>RenderViewHost</code> waits for a <code>ViewHostMsg_FrameNavigate</code> from the <code>RenderView</code>.</li> <li>When the load is "committed" by WebKit (the server responded and is sending us data), the <code>RenderView</code> sends this message, which is handled in <code>RenderViewHost::OnMsgNavigate</code>.</li> <li>The <code>NavigationEntry</code> is updated with the information on the load. In the case of a link click, the browser has never seen this URL before. If the navigation was browser-initiated, as in the startup case, there may have been redirects that have changed the URL.</li> <li>The <code>NavigationController</code> updates its list of navigations to account for this new information.</li> </ol> <h3 id="navigations-and-session-history" tabindex="-1"><a class="header-anchor" href="#navigations-and-session-history">Navigations and session history</a></h3> <p>Each <code>NavigationEntry</code> stores a page ID and a block of history state data. The page ID is used to uniquely identify a page load, so we know which <code>NavigationEntry</code> it corresponds to. It is assigned when the page is committed commit, so a pending <code>NavigationEntry</code> will have a page ID of -1. The history state data is simply a <code>WebCore::HistoryItem</code> serialized to a string. Included on this item are things like the page URL, subframe URLs, and form data.</p> <ol> <li>When the browser initiates the request (typing in the URL bar, or clicking back/forward/reload) <ol> <li>A <code>WebRequest</code> is made representing the navigation, along with extra information like a page ID for bookkeeping. New navigations have an ID of -1. Navigations to old entries have the ID assigned to the <code>NavigationEntry</code> when the page was first visited. This extra information will be queried later when the load commits.</li> <li>The main <code>WebFrame</code> is told to load the new request.</li> </ol> </li> <li>When the renderer initiates the request (user clicks a link, javascript changes the location, etc): <ol> <li><code>WebCore::FrameLoader</code> is told to load the request via one of its bajillion varied load methods.</li> </ol> </li> <li>In either case, when the first packet from the server is received, the load is committed (no longer "pending" or "provisional").</li> <li>If this was a new navigation, <code>WebCore</code> will create a new <code>HistoryItem</code> and add it to the <code>BackForwardList</code>, a <code>WebCore</code> class. In this way, we can differentiate which navigations are new, and which are session history navigations.</li> <li><code>RenderView::DidCommitLoadForFrame</code> handles the commit for the load. Here, the previous page's state is stored in session history, via the <code>ViewHostMsg_UpdateState</code> message. This will tell the browser to update the corresponding <code>NavigationEntry</code> (identified by <code>RenderView's</code> current <code>page ID</code>) with the new history state.</li> <li><code>RenderView's</code> current <code>page ID</code> is updated to reflect the committed page. For a new navigation, a new unique <code>page ID</code> is generated. For a session history navigation, it will be the <code>page ID</code> originally assigned when it was first visited, which we had stored on the <code>WebRequest</code> when initiating the navigation.</li> <li>A <code>ViewHostMsg_FrameNavigate</code> message is sent to the browser, updating the corresponding <code>NavigationEntry</code> (identified by <code>RenderView's</code> newly updated <code>page ID</code>) with the new URL and other information.</li> </ol> </main> </div> <script> // Configure Algolia search. let s = document.createElement('script'); s.src = '/_scripts/@docsearch/index.js'; document.head.append(s); window.addEventListener('load', () => { // Add the Algolia search widget. docsearch({ container: '#search', appId: 'RZDQYCCABX', apiKey: '98b0eabafeb13fe3e1af693d5713d8b4', indexName: 'chromium' }); }); // Configure Google Universal Analytics (the predecessor to GA4, we should // delete this when we don't need it any more). s = document.createElement('script'); s.src = 'https://www.googletagmanager.com/gtag/js?id=UA-5484340-1' s.async = true; document.head.append(s) window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-5484340-1'); // Configure consent bar. s = document.createElement('script'); s.src = 'https://www.gstatic.com/brandstudio/kato/cookie_choice_component/cookie_consent_bar.v3.js' s.dataset.autoloadCookieConsentBar = true; s.dataset.autoloadCookieContentBarIntlCode = ''; document.head.append(s);</script>