CINXE.COM

How Chromium Displays Web Pages

<!DOCTYPE html> <head> <meta charset="utf-8"> <title>How Chromium Displays Web Pages</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&amp;file=site/developers/design-documents/displaying-a-web-page-in-chrome/index.md&ext_google.git=%7B%22repo%22%3A%22chromium%2Fwebsite%22%2C%22ref%22%3A%22main%22%2C%22file%22%3A%22site/developers/design-documents/displaying-a-web-page-in-chrome/index.md%22%7D">Edit this page</a> </nav> <main> <div class="breadcrumbs"> <a href="/developers">For Developers</a> &gt; <a href="/developers/design-documents">Design Documents</a> &gt; </div> <h1>How Chromium Displays Web Pages</h1> <p>This document describes how web pages are displayed in Chromium from the bottom up. Be sure you have read the <a href="/developers/design-documents/multi-process-architecture">multi-process architecture</a> design document. You will especially want to understand the block diagram of major components. You may also be interested in <a href="/developers/design-documents/multi-process-resource-loading">multi-process resource loading</a> for how pages are fetched from the network.</p> <h2 id="conceptual-application-layers" tabindex="-1"><a class="header-anchor" href="#conceptual-application-layers">Conceptual application layers</a></h2> <p><a href="https://docs.google.com/drawings/pub?id=1gdSTfvLxbJDbX8oiWo5LTwAmXmdMQvjoUhYEhfhj0-k&amp;w=473&amp;h=204"><img alt="image" src="https://docs.google.com/drawings/pub?id=1gdSTfvLxbJDbX8oiWo5LTwAmXmdMQvjoUhYEhfhj0-k&w=473&h=211"></a></p> <p>(The original Google Doc for this illustration is http://goo.gl/MsEJX which is open for editing by any @chromium.org)</p> <p>Each box represents a conceptual application layer. No layer should have knowledge of or dependencies on any higher-level layers.</p> <ul> <li><strong>WebKit:</strong> Rendering engine shared between Safari, Chromium, and all other WebKit-based browsers. The <strong>Port</strong> is a part of WebKit that integrates with platform dependent system services such as resource loading and graphics.</li> <li><strong>Glue:</strong> Converts WebKit types to Chromium types. This is our &quot;WebKit embedding layer.&quot; It is the basis of two browsers, Chromium, and test_shell (which allows us to test WebKit).</li> <li><strong>Renderer / Render host:</strong> This is Chromium's &quot;multi-process embedding layer.&quot; It proxies notifications and commands across the process boundary.</li> <li><strong>WebContents:</strong> A reusable component that is the main class of the Content module. It's easily embeddable to allow multiprocess rendering of HTML into a view. See the <a href="/developers/content-module">content module pages</a> for more information.</li> <li><strong>Browser:</strong> Represents the browser window, it contains multiple WebContentses.</li> <li><strong>Tab Helpers</strong>: Individual objects that can be attached to a WebContents (via the WebContentsUserData mixin). The Browser attaches an assortment of them to the WebContentses that it holds (one for favicons, one for infobars, etc).</li> </ul> <h2 id="webkit" tabindex="-1"><a class="header-anchor" href="#webkit">WebKit</a></h2> <p>We use the <a href="http://webkit.org/">WebKit</a> open-source project to lay out web pages. This code is pulled from Apple and stored in the /third_party/WebKit directory. WebKit consists primarily of &quot;WebCore&quot; which represents the core layout functionality, and &quot;JavaScriptCore&quot; which runs JavaScript. We only run JavaScriptCore for testing purposes, normally we replace it with our high performance V8 JavaScript engine. We do not actually use the layer that Apple calls &quot;WebKit,&quot; which is the embedding API between WebCore and OS X applications such as Safari. We normally refer to the code from Apple generically as &quot;WebKit&quot; for convenience.</p> <h3 id="the-webkit-port" tabindex="-1"><a class="header-anchor" href="#the-webkit-port">The WebKit port</a></h3> <p>At the lowest level we have our WebKit &quot;port.&quot; This is our implementation of required platform-specific functionality that interfaces with the platform-independent WebCore code. These files are located in the WebKit tree, typically in chromium directories or as Chromium-suffixed files. Much of our port is not actually OS-specific: you could think of it as the &quot;Chromium port&quot; of WebCore. Some parts, like font rendering, must be handled differently for each platform.</p> <ul> <li>Network traffic is handled by our <a href="/developers/design-documents/multi-process-resource-loading">multi-process resource loading</a> system rather than being handed off to the OS directly from the render process.</li> <li>Graphics uses the Skia graphics library developed for Android. This is a cross-platform graphics library and handles all images and graphics primitives except for text. Skia is located in /third_party/skia. The main entrypoint for graphics operations is /webkit/port/platform/graphics/GraphicsContextSkia.cpp. It uses many other files in the same directory as well as from /base/gfx.</li> </ul> <h3 id="the-webkit-glue" tabindex="-1"><a class="header-anchor" href="#the-webkit-glue">The WebKit glue</a></h3> <p>The Chromium application uses different types, coding styles, and code layout than the third-party WebKit code. The WebKit &quot;glue&quot; provides a more convenient embedding API for WebKit using Google coding conventions and types (for example, we use std::string instead of WebCore::String and GURL instead of KURL). The glue code is located in /webkit/glue. The glue objects are typically named similar to the WebKit objects, but with &quot;Web&quot; at the beginning. For example, WebCore::Frame becomes WebFrame.</p> <p>The WebKit &quot;glue&quot; layer insulates the rest of the Chromium code base from WebCore data types to help minimize the impact of WebCore changes on the Chromium code base. As such, WebCore data types are never used directly by Chromium. APIs are added to the WebKit &quot;glue&quot; for the benefit of Chromium when it needs to poke at some WebCore object.</p> <p>The &quot;test shell&quot; application is a bare-bones web browser for testing our WebKit port and glue code. It uses the same glue interface for communicating with WebKit as Chromium does. It provides a simpler way for developers to test new code without having many complicated browser features, threads, and processes. This application is also used to run the automated WebKit tests. However, the downside of the &quot;test shell&quot; is that it doesn't exercise WebKit as Chromium does, in a multi-process way. The content module is embedded in an application called &quot;content shell&quot; which will soon be running the tests instead.</p> <h2 id="the-render-process" tabindex="-1"><a class="header-anchor" href="#the-render-process">The render process</a></h2> <p><a href="/developers/design-documents/displaying-a-web-page-in-chrome/Renderingintherenderer-v2.png"><img alt="image" src="/developers/design-documents/displaying-a-web-page-in-chrome/Renderingintherenderer-v2.png"></a></p> <p>Chromium's render process embeds our WebKit port using the glue interface. It does not contain very much code: its job is primarily to be the renderer side of the <a href="/developers/design-documents/inter-process-communication">IPC</a> channel to the browser..</p> <p>The most important class in the renderer is the RenderView, located in /content/renderer/render_view_impl.cc. This object represents a web page. It handles all navigation-related commands to and from the browser process. It derives from RenderWidget which provides painting and input event handling. The RenderView communicates with the browser process via the global (per render process) RenderProcess object.</p> <p>FAQ: What's the difference between RenderWidget and RenderView? RenderWidget maps to one WebCore::Widget object by implementing the abstract interface in the glue layer called WebWidgetDelegate.. This is basically a Window on the screen that receives input events and that we paint into. A RenderView inherits from RenderWidget and is the contents of a tab or popup Window. It handles navigational commands in addition to the painting and input events of the widget. There is only one case where a RenderWidget exists without a RenderView, and that's for select boxes on the web page. These are the boxes with the down arrows that pop up a list of options. The select boxes must be rendered using a native window so that they can appear above everything else, and pop out of the frame if necessary. These windows need to paint and receive input, but there isn't a separate &quot;web page&quot; (RenderView) for them.</p> <h3 id="threads-in-the-renderer" tabindex="-1"><a class="header-anchor" href="#threads-in-the-renderer">Threads in the renderer</a></h3> <p>Each renderer has two threads (see the <a href="/developers/design-documents/multi-process-architecture">multi-process architecture</a> page for a diagram, or <a href="/developers/design-documents/threading">threading in Chromium</a> for how to program with them). The render thread is where the main objects such as the RenderView and all WebKit code run. When it communicates to the browser, messages are first sent to the main thread, which in turn dispatches the message to the browser process. Among other things, this allows us to send messages synchronously from the renderer to the browser. This happens for a small set of operations where a result from the browser is required to continue. An example is getting the cookies for a page when requested by JavaScript. The renderer thread will block, and the main thread will queue all messages that are received until the correct response is found. Any messages received in the meantime are subsequently posted to the renderer thread for normal processing.</p> <h2 id="the-browser-process" tabindex="-1"><a class="header-anchor" href="#the-browser-process">The browser process</a></h2> <p><a href="/developers/design-documents/displaying-a-web-page-in-chrome/rendering%20browser.png"><img alt="image" src="/developers/design-documents/displaying-a-web-page-in-chrome/rendering%20browser.png"></a></p> <h3 id="low-level-browser-process-objects" tabindex="-1"><a class="header-anchor" href="#low-level-browser-process-objects">Low-level browser process objects</a></h3> <p>All <a href="/developers/design-documents/inter-process-communication">IPC</a> communication with the render processes is done on the I/O thread of the browser. This thread also handles all <a href="/developers/design-documents/multi-process-resource-loading">network communication</a> which keeps it from interfering with the user interface.</p> <p>When a RenderProcessHost is initialized on the main thread (where the user interface runs), it creates the new renderer process and a ChannelProxy <a href="/developers/design-documents/inter-process-communication">IPC</a> object with a named pipe to the renderer. This object runs on the I/O thread of the browser, listening to the named pipe to the renderer, and automatically forwards all messages back to the RenderProcessHost on the UI thread. A ResourceMessageFilter will be installed in this channel which will filter out certain messages that can be handled directly on the I/O thread such as network requests. This filtering happens in ResourceMessageFilter::OnMessageReceived.</p> <p>The RenderProcessHost on the UI thread is responsible for dispatching all view-specific messages to the appropriate RenderViewHost (it handles a limited number of non-view-specific messages itself). This dispatching happens in RenderProcessHost::OnMessageReceived.</p> <h3 id="high-level-browser-process-objects" tabindex="-1"><a class="header-anchor" href="#high-level-browser-process-objects">High-level browser process objects</a></h3> <p>View-specific messages come into RenderViewHost::OnMessageReceived. Most of the messages are handled here, and the rest get forwarded to the RenderWidgetHost base class. These two objects map to the RenderView and the RenderWidget in the renderer (see &quot;The Render Process&quot; above for what these mean). Each platform has a view class (RenderWidgetHostView[Aura|Gtk|Mac|Win]) to implement integration into the native view system.</p> <p>Above the RenderView/Widget is the WebContents object, and most of the messages actually end up as function calls on that object. A WebContents represents the contents of a webpage. It is the top-level object in the content module, and has the responsibility of displaying a web page in a rectangular view. See the <a href="/developers/content-module">content module pages</a> for more information.</p> <p>The WebContents object is contained in a TabContentsWrapper. That is in chrome/ and is responsible for a tab.</p> <p><strong>Illustrative examples</strong></p> <p>Additional examples covering navigation and startup are in <a href="/developers/how-tos/getting-around-the-chrome-source-code">Getting Around the Chromium Source Code</a>.</p> <h3 id="life-of-a-set-cursor-message" tabindex="-1"><a class="header-anchor" href="#life-of-a-set-cursor-message">Life of a &quot;set cursor&quot; message</a></h3> <p>Setting the cursor is an example of a typical message that is sent from the renderer to the browser. In the renderer, here is what happens.</p> <ul> <li>Set cursor messages are generated by WebKit internally, typically in response to an input event. The set cursor message will start out in RenderWidget::SetCursor in content/renderer/render_widget.cc.</li> <li>It will call RenderWidget::Send to dispatch the message. This method is also used by RenderView to send messages to the browser. It will call RenderThread::Send.</li> <li>This will call the IPC::SyncChannel which will internally proxy the message to the main thread of the renderer and post it to the named pipe for sending to the browser.</li> </ul> <p>Then the browser takes control:</p> <ul> <li>The IPC::ChannelProxy in the RenderProcessHost receives all message on the I/O thread of the browser. It first sends them through the ResourceMessageFilter that dispatches network requests and related messages directly on the I/O thread. Since our message is not filtered out, it continues on to the UI thread of the browser (the IPC::ChannelProxy does this internally).</li> <li>RenderProcessHost::OnMessageReceived in content/browser/renderer_host/render_process_host_impl.cc gets the messages for all views in the corresponding render process. It handles several types of messages directly, and for the rest forwards to the appropriate RenderViewHost corresponding to the source RenderView that sent the message.</li> <li>The message arrives at RenderViewHost::OnMessageReceived in content/browser/renderer_host/render_view_host_impl.cc. Many messages are handled here, but ours is not because it's a message sent from the RenderWidget and handled by the RenderWidgetHost.</li> <li>All unhandled messages in RenderViewHost are automatically forwarded to the RenderWidgetHost, including our set cursor message.</li> <li>The message map in content/browser/renderer_host/render_view_host_impl.cc finally receives the message in RenderWidgetHost::OnMsgSetCursor and calls the appropriate UI function to set the mouse cursor.</li> </ul> <h3 id="life-of-a-mouse-click-message" tabindex="-1"><a class="header-anchor" href="#life-of-a-mouse-click-message">Life of a &quot;mouse click&quot; message</a></h3> <p>Sending a mouse click is a typical example of a message going from the browser to the renderer.</p> <ul> <li>The Windows message is received on the UI thread of the browser by RenderWidgetHostViewWin::OnMouseEvent which then calls ForwardMouseEventToRenderer in the same class.</li> <li>The forwarder function packages the input event into a cross-platform WebMouseEvent and ends up sending it to the RenderWidgetHost it is associated with.</li> <li>RenderWidgetHost::ForwardInputEvent creates an IPC message ViewMsg_HandleInputEvent, serializes the WebInputEvent to it, and calls RenderWidgetHost::Send.</li> <li>This just forwards to the owning RenderProcessHost::Send function, which in turn gives the message to the IPC::ChannelProxy.</li> <li>Internally, the IPC::ChannelProxy will proxy the message to the I/O thread of the browser and write it to the named pipe of the corresponding renderer.</li> </ul> <p>Note that many other types of messages are created in the WebContents, especially navigational ones. These follow a similar path from the WebContents to the RenderViewHost.</p> <p>Then the renderer takes control:</p> <ul> <li>IPC::Channel on the main thread of the renderer reads the message sent by the browser, and IPC::ChannelProxy proxies to the renderer thread.</li> <li>RenderView::OnMessageReceived gets the message. Many types messages are handled here directly. Since the click message is not, it falls through (with all other unhandled messages) to RenderWidget::OnMessageReceived which in turn forwards it to RenderWidget::OnHandleInputEvent.</li> <li>The input event is given to WebWidgetImpl::HandleInputEvent where it is converted to a WebKit PlatformMouseEvent class and given to the WebCore::Widget class inside WebKit.</li> </ul> </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>

Pages: 1 2 3 4 5 6 7 8 9 10