Chromium源码目录结构简介入门必备。

High-level overview

高级概述

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.
Chromium分为两个重要部分:browser和renderer。
browser是主进程并且代表了所有的UI和I/O。
renderer是有browser驱动的选项卡子进程,他嵌入blink去做布局和渲染工作。

You will want to read and become familiar with our multi-process architecture and how Chromium displays web pages.
您需要阅读并熟悉我们的多进程体系结构以及Chromium如何显示网页。

Top-level projects

顶级项目

When you check out Chromium, you will notice a number of top-level directories. These projects are as follows:
当你下载chromium代码后,你可以看到顶层目录,包含以下内容:

  • android_webview: Provides a facade over src/content suitable for integration into the android platform. NOT intended for usage in individual android applications (APK). More information about the Android WebView source code organization.
  • apps: Chrome packaged apps.
  • apps: Chrome 打包应用。
  • base: 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.
  • base: 所有子项目之间共享的通用代码。其中包含字符串操作、通用实用程序等内容。仅当必须在多个其他顶级项目之间共享时,才在此处添加这些内容。
  • breakpad: Google’s open source crash reporting project. This is pulled directly from Google Code’s Subversion repository.
  • breakpad:谷歌的开源崩溃报告项目。这是直接从谷歌代码的Subversion存储库中提取的。
  • build: Build-related configuration shared by all projects.
  • build: 所有项目共享的编译相关配置。
  • cc: The Chromium compositor implementation.
  • chrome: The Chromium browser (see below).
  • chrome/test/data: Data files for running certain tests.
  • components: directory for components that have the Content Module as the uppermost layer they depend on.
  • **components:**将内容模块作为其所依赖的最上层的组件的目录。
  • content: The core code needed for a multi-process sandboxed browser (see below). More information about why we have separated out this code.
  • content: 多进程沙盒浏览器所需的核心代码(见下文)。关于我们为什么要分离此代码可以通过以下链接查看更多信息。
  • device: Cross-platform abstractions of common low-level hardware APIs.
  • net: The networking library developed for Chromium. This can be used separately from Chromium when running our simple test_shell in the webkit repository. See also chrome/common/net.
    + net: 为Chromium开发的网络库。在webkit存储库中运行我们的简单测试shell时,这可以与Chromium分开使用。另请参见chrome/common/net。
  • sandbox: The sandbox project which tries to prevent a hacked renderer from modifying the system.
  • skia + third_party/skia: Google’s Skia graphics library. Our additional classes in ui/gfx wrap Skia.
  • sql: Our wrap around sqlite.
  • testing: Contains Google’s open-sourced GTest code which we use for unit testing.
  • third_party: 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). Adding new packages.
    • …/blink/renderer: The web engine responsible for turning HTML, CSS and scripts into paint commands and other state changes.
      tools
  • ui/gfx: Shared graphics classes. These form the base of Chromium’s UI graphics.
  • ui/gfx: 共享图形类,这些构成了Chromium UI图形的基础。
  • ui/views: 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.
  • ui/views: 用于进行UI开发的简单框架,提供渲染、布局和事件处理。大部分浏览器用户界面都是在这个系统中实现的。此目录包含基本对象。chrome/browser/ui/views中还有一些特定于浏览器的对象。
  • url: Google’s open source URL parsing and canonicalization library.
  • **url:**谷歌的开源URL解析和规范化库。
  • v8: The V8 Javascript library. This is pulled directly from Google Code’s Subversion repository.

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。
由于历史原因,有一些小的顶级目录。展望未来,指南是新的顶级目录用于应用程序(如Chrome、Android WebView、Ash)。即使这些应用程序有多个可执行文件,代码也应该位于应用程序的子目录中

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.
这是一个稍微过时的依赖关系图。特别是,WebKit被blink/renderer所取代。较低的模块不能直接包含来自较高模块的代码(即内容不能包含来自chrome的标题),而是使用嵌入式API与之对话。

Quick reference for the directory tree under “content/”

  • browser: The backend for the application which handles all I/O and communication with the child processes . This talks to the renderer to manage web pages.
  • browser: 应用程序的后端,处理所有I/O和与子进程的通信。这将与渲染器对话以管理网页。
  • common: 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).
  • gpu: Code for the GPU process, which is used for 3D compositing and 3D APIs.
  • plugin: Code for running browser plugins in other processes.
  • ppapi_plugin: Code for the Pepper plugin process.
  • renderer: Code for the subprocess in each tab. This embeds WebKit and talks to browser for I/O.
  • renderer: 每个选项卡中的子流程代码。这嵌入WebKit并与browser对话以进行I/O。
  • utility: Code for running random operations in a sandboxed process. The browser process uses it when it wants to run an operation on untrusted data.
  • utility: 用于在沙盒进程中运行随机操作的代码。browser进程在希望对不受信任的数据运行操作时使用它.
  • worker: Code for running HTML5 Web Workers.

Quick reference for the directory tree under “chrome/”

  • app: 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 chrome.exe and chrome.dll. You won’t generally need to change this stuff except for resources like images and strings.

    • locales: Projects for building localized DLLs.
    • resources: Icons and cursors.
    • theme: Images for the theme of the window.
  • browser: The frontend including the main window, UI, and the backend for the application which handles all I/O and storage. This talks to the renderer to manage web pages.
    • ui model, view and controller code for UI features and functionality
    • ui模块,view和controller的UI界面和功能代码
  • common: Files shared between the browser and the renderer that is specific to the Chrome module.
    • net: Some Chromium-specific stuff on top of the net top-level module. This should be merged with browser/net.
  • installer: Source files and projects for making the installer (MSI package).
  • renderer: Chrome specific code that runs in the renderer process. This adds Chrome features like autofill, translate etc to the content module.
  • test:
    • automation: Used by tests to drive the browser UI, for example, in test/ui, test/startup, etc. This communicates with browser/automation in the browser.
    • **page_cycler: Code for running page cycler tests (for performance measurement). See tools/perf/dashboard.
    • reliability: Reliability tests for distributed testing of page loads for reliability metrics and crash finding.
    • selenium: Code for running the selenium tests, which is a third-party test suite for Ajaxy and JavaScript stuff. See test/third_party/selenium_core.
    • startup: Tests for measuring startup performance. See tools/perf/dashboard and tools/test/reference_build.
    • ui: UI tests for poking at the browser UI, opening tabs, etc. It uses test/automation for doing most operations.
    • unit: The base code for the unit tests. The test code for individual tests is generally alongside the code it is testing in a *_unittest.cc file.
  • third_party: Third party libraries that are specific to Chromium. Some other third party libraries are in the top-level third_party library.
  • tools:
    • build: Tools and random stuff related to building.
    • memory: Tools for memory stuff. Currently includes gflags for setting page heap options.
    • perf/dashboard: Code for converting performance logs (for example test/startup_test) into data and graphs.
    • profiles: Generator for random history data. Used to make test profiles.

A personal learning plan

开发者学习计划

Eventually you’ll 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’d 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.
最终,您将拥有构建设置,并希望开始工作。换句话说,在编写第一行代码之前,我们将有足够的时间阅读每一行代码并理解它。实际上,如果我们什么都不做,我们很难只读取一天内发生的签入,因此我们中的任何人都无法读取所有代码,我们建议你制定自己的学习计划,以下是一些建议的起点。

Fortunately for us, Chromium has some top quality design docs here. 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.
幸运的是,Chromium在这里有一些高质量的设计文档。虽然这些文件可能会变得有点过时(例如,在后续操作中,您可能会发现对已被移动、重命名或重构而不存在的文件的引用),但能够理解代码的整体组合方式是非常棒的。

  • Read the most important dev docs
  • 阅读重要的开发文档
  • multi-process-architecture
  • 多进程框架
  • displaying-a-web-page-in-chrome
  • 在chrome中展示一个web面
  • inter-process-communication
  • 进程内通信
  • threading
  • 线程

See if your group has any startup docs。There may be some docs that people working on the same code will care about while others don’t need to know as much detail.
查看您的团队是否有启动文档。可能有一些文档是使用相同代码的人会关心的,而其他人不需要知道太多细节。

Learn some of the code idioms:
学习一些代码习惯用法:

  • important-abstractions-and-data-structures
  • 重要的抽象以及数据结构
  • smart-pointer-guidelines
  • 指针指针准则
  • chromium-string-usage
  • chromium的string用法

Later, as time permits, skim all the design docs, reading where it seems relevant.
稍后,如果时间允许,浏览所有的设计文档,在相关的地方阅读。

Get good at using code search (or your code browsing tool of choice)
善于使用代码搜索

Learn who to ask how the code works hints here.
学会咨询代码的工作原理提示如下。

Debug into the code you need to learn, with a debugger if you can, log statements and grepping if you cannot.

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.
看看你需要理解的内容与你目前理解的内容之间的差异。例如,如果您的团队进行大量GUI编程,那么您可以投入时间学习GTK+、Win32或Cocoa编程。

Use source.chromium.org to search the source code. This can be particularly helpful if code moves around and our documentation is no longer accurate.

Code paths for common operations

There is additional information and more examples on how Chromium displays web pages.
还有更多关于Chromium如何显示网页的信息和示例。

Application startup

  1. Our WinMain function is in chrome/app/main.cc, and is linked in the chrome project.
  2. 我们的WinMain方法在chrome/app/main.cc文件中,并且链接在chrome项目中.
  3. WinMain launches the Google Update Client, which is the installer/autoupdater. It will find the subdirectory for the current version, and load chrome.dll from there.
  4. It calls ChromeMain in the newly loaded library, which is in chrome_main.cc in the chrome_dll project.
  5. 它在新加载的库中调用ChromeMain,该库位于chrome_dll项目的chrome_main.cc中
  6. ChromeMain does initialization for common components, and then forwards to either RendererMain in chrome/renderer/renderer_main.cc if the command line flag indicates that this should be a subprocess, or BrowserMain in chrome/browser/browser_main.cc if not to load a new copy of the application. Since this is startup, we’re launching the browser.
  7. ChromeMain对常用组件进行初始化,然后转发到chrome/renderer/renderer_main.cc中的RenderMain(如果命令行标志指示这应该是子流程),或者如果不加载应用程序的新副本,则转发到chrome/browser/browser_main.cc中的BrowserMain。由于这是启动,我们正在启动浏览器。
  8. BrowserMain does common browser initialization. It has different modes for running installed webapps, connecting to the automation system if the browser is being tested, etc.
  9. It calls LaunchWithProfile in browser_init.cc which creates a new Browser object in chrome/browser/ui/browser.cc. This object encapsulates one toplevel window in the application. The first tab is appended at this time.

Tab startup & initial navigation

选项卡启动和初始导航

BrowserImpl::AddTab in weblayer/browser/browser_impl.cc is called to append a new tab.It will create a new TabContents object from browser/tab_contents/tab_contents.cc TabContents creates a RenderViewHost (chrome/browser/renderer_host/render_view_host.cc) via the RenderViewHostManager’s Init function in (chrome/browser/tab_contents/render_view_host_manager.cc).
在 weblayer/browser/browser_impl.cc is 调用BrowserImpl::AddTab函数以附加新选项卡。

Depending on the SiteInstance, the RenderViewHost either spawns a new renderer process, or re-uses an existing RenderProcessHost. RenderProcessHost is the object in the browser that represents a single renderer subprocess.
The NavigationController in chrome/browser/tab_contents/navigation_controller.cc which is owned by the tab contents, is instructed to navigate to the URL for the new tab in NavigationController::LoadURL. “Navigating from the URL bar” from step 3 onward describes what happens from this point.

Navigating from the URL bar

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 AutocompleteEdit::OpenURL. (This may not be exactly what the user typed - for example, an URL is generated in the case of a search query.)
The navigation controller is instructed to navigate to the URL in NavigationController::LoadURL.
The NavigationController calls TabContents::Navigate with the NavigationEntry it created to represent this particular page transition. It will create a new RenderViewHost if necessary, which will cause creation of a RenderView in the renderer process. A RenderView won’t exist if this is the first navigation, or if the renderer has crashed, so this will also recover from crashes.
Navigate forwards to RenderViewHost::NavigateToEntry. The NavigationController 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).
RenderViewHost::NavigateToEntry sends a ViewMsg_Navigate to the new RenderView in the renderer process.
When told to navigate, RenderView may navigate, it may fail, or it may navigate somewhere else instead (for example, if the user clicks a link). RenderViewHost waits for a ViewHostMsg_FrameNavigate from the RenderView.
When the load is “committed” by WebKit (the server responded and is sending us data), the RenderView sends this message, which is handled in RenderViewHost::OnMsgNavigate.
The NavigationEntry 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.
The NavigationController updates its list of navigations to account for this new information.

Navigations and session history

Each NavigationEntry 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 NavigationEntry it corresponds to. It is assigned when the page is committed commit, so a pending NavigationEntry will have a page ID of -1. The history state data is simply a WebCore::HistoryItem serialized to a string. Included on this item are things like the page URL, subframe URLs, and form data.
When the browser initiates the request (typing in the URL bar, or clicking back/forward/reload)
A WebRequest 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 NavigationEntry when the page was first visited. This extra information will be queried later when the load commits.
The main WebFrame is told to load the new request.
When the renderer initiates the request (user clicks a link, javascript changes the location, etc):
WebCore::FrameLoader is told to load the request via one of its bajillion varied load methods.
In either case, when the first packet from the server is received, the load is committed (no longer “pending” or “provisional”).
If this was a new navigation, WebCore will create a new HistoryItem and add it to the BackForwardList, a WebCore class. In this way, we can differentiate which navigations are new, and which are session history navigations.
RenderView::DidCommitLoadForFrame handles the commit for the load. Here, the previous page’s state is stored in session history, via the ViewHostMsg_UpdateState message. This will tell the browser to update the corresponding NavigationEntry (identified by RenderView’s current page ID) with the new history state.
RenderView’s current page ID is updated to reflect the committed page. For a new navigation, a new unique page ID is generated. For a session history navigation, it will be the page ID originally assigned when it was first visited, which we had stored on the WebRequest when initiating the navigation.
A ViewHostMsg_FrameNavigate message is sent to the browser, updating the corresponding NavigationEntry (identified by RenderView’s newly updated page ID) with the new URL and other information.

Chromium源码目录结构简介相关推荐

  1. chromium 源码目录结构

    Chromium 一级目录(src/)的层次结构如下图所示: 一级目录中,android_webview 和 content 两个目录被 Android WebView 开发人员接触最多. webvi ...

  2. Android 8.0学习(32)---Android 8.0源码目录结构详解

    Android 8.0源码目录结构详解 android的移植按如下流程:     (1)android linux 内核的普通驱动移植,让内核可以在目标平台上运行起来.     (2)正确挂载文件系统 ...

  3. 【Busybox】Busybox源码分析-01 | 源码目录结构和程序入口

    文章目录 一.Busybox简介 (1-1)开源项目 (1-2)程序本体较小 (1-3)使用简单 二.Busybox源码目录结构 三.Busybox程序主体 四.Busybox程序运行剖析

  4. asterisk源码目录结构

    版本:asterisk-1.8.7.1 下载地址:asterisk-1.8.7.1.tar.gz main函数所在文件:main/asterisk.c (3182行) 文件夹: addons :ast ...

  5. 【原创】【专栏】《Linux设备驱动程序》--- LDD3源码目录结构和源码分析经典链接

    http://blog.csdn.net/geng823/article/details/37567557 [原创][专栏]<Linux设备驱动程序>--- LDD3源码目录结构和源码分析 ...

  6. RTOS之uCOS-II源码下载及源码目录结构、常见的RTOS!

    RTOS有众多种,用得最火的是FreeRTOS,因为它即使用于商业途径,也是开源免费的:其次是就是uCOS-II和uCOS-III.uCOS-II用于商业途径是需要付费的,但是对于学习研究却是免费的. ...

  7. linux与安卓系统目录,android系统架构及源码目录结构

    1. android系统架构: android系统架构采用了分层架构的思想,如下图所示,从上到下共4层,分别为:应用程序层.应用程序框架层.系统库和android运行时层.linux内核层. 每层功能 ...

  8. 【lLinux驱动】linux内核源码目录结构

    linux内核源码目录结构 代码目录结构 在阅读源码之前,还应知道Linux内核源码的整体分布情况.现代的操作系统一般由进程管理.内存管理.文件系统.驱动程序和网络等组成.Linux内核源码的各个目录 ...

  9. Pixhawk飞控源码目录结构及编译流程分析

     http://blog.csdn.net/xlb7679/article/details/51658956 (PS:这是第一次写博客,以前也有记录一些经验总结心得什么的,不过都是手写笔记或者记在 ...

最新文章

  1. 设置log缓存_带你搞明白什么是缓存穿透、缓存击穿、缓存雪崩
  2. Serverless 实战——使用 Rendertron 搭建 Headless Chrome 渲染解决方案
  3. python中字符串的几种表达方式(用什么方式表示字符串)
  4. 算法训练 字符串编辑c语言
  5. how to create BRF application via code
  6. java中 wait()和sleep()的差异
  7. 怎么hold住版本质量
  8. rnn神经网络模型_ICLR 2019 | 与胶囊网络异曲同工:Bengio等提出四元数循环神经网络...
  9. SpringBoot整合Shiro实现登录认证授权操作
  10. 大数据_Flink_流式处理_简介_流数据处理的应用行业---Flink工作笔记0003
  11. C# textBox框实现输入像百度搜索出现下拉列表的格式
  12. linux文件描述符、软硬连接、输入输出重定向
  13. Winform读报工具
  14. display:block jquery.sort()
  15. 大型WEB系统架构的那些组成
  16. final可以修饰哪些java名词_Java关键知识点 - Java final关键字到底修饰了什么?
  17. 双层pdf解析 java_java转双层pdf
  18. 三读《UNIX编程艺术》——UNIX哲学
  19. 从零开始设计一款APP之如何做原型图
  20. 一个节拍都不错过——dfuse 2019年第三季度回顾

热门文章

  1. 用OpenGL码一艘战舰~哈哈
  2. python 中使用breast_cancer数据画图
  3. leetcode 剑指 Offer 46. 把数字翻译成字符串
  4. 该内存不能为written
  5. SQL学习-2.7 SQL聚合
  6. 西工大-软件学院-2021复试-面试题目
  7. 冀教版五年级计算机教学计划,冀教版信息技术五年级下册教学计划.pdf
  8. ERP是什么?ERP管理系统怎么用?
  9. 基于Proteus学习单片机系列(七)——AD转换及其应用--ADC0832
  10. Nervos:链外扩容 + Layer 2才是区块链的未来(下)