`
sole
  • 浏览: 141538 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

编译Google浏览器

阅读更多

 

        Google一直传言要做自己的浏览器,上周三终于出了Windows环境下的Beta版。Google总是提供免费的午餐,这次也不例外,不是指免费使用google浏览器,而是指代码完全开源。

 

本来还没开始编译,先Copy在这:http://sites.google.com/a/chromium.org/dev/developers/how-tos/getting-started

Getting Started

If you're serious about learning how Chromium works, this is the page for you. You'll get the Chromium code and build it. Then you'll use the Visual Studio 2005 debugger to see how the browser works — in particular, how it responds to common user actions.


Note: This page is aimed at developers and testers who have Windows and want to inspect running code. If you're not ready to set up a build environment, you can read the documentation . If you don't have Windows, check out the build instructions for Mac and Linux .

Get the software you need

  • Windows XP (SP2 or later) or Windows Vista
  • Microsoft Visual Studio 2005 (8.0)

Additional (free) downloads

Once Visual Studio is installed, you need to download and install some more software.

  1. Download and install Microsoft Visual Studio 2005 Service Pack 1 .
    Depending on your computer, installation can take about an hour, and you might need to reboot.

  2. Download and install the Microsoft Windows SDK .
    You might need to reboot. You can save space by not installing the documentation and code samples.

    Note:
    Although the SDK says it's for Vista, it works on both XP and Vista. If you already have the Microsoft 2008 SDK, you don't need to install a new one.

  3. Integrate the SDK with Visual Studio:

    Start > All Programs > Microsoft Windows SDK > Visual Studio Registration > Integrate Windows SDK with Visual Studio 2005


  4. Get the Chromium depot_tools :
    1. Download depot_tools.zip .

    2. Unzip the file.
      Note: If you have Cygwin installed, don't use its unzip tool; it will mess up the permissions.

    3. Add the depot tools directory to your PATH. Example: C:\bin\depot_tools
      Note: By default, the depot_tools will automatically update to the latest version every time you run gclient . See the depot_tools page if you want to disable this behavior.


Chromium code

The Chromium codebase consists of hundreds of thousands of files, which means that a checkout straight from the Subversion (SVN) repository can take a long time. To speed up the process, we have provided a tarball that you can use to bootstrap the download. Alternatively, you can skip the tarball and download straight from SVN (not recommended).

Note: There is no advantage to checking out straight from SVN. The tarball includes SVN directories so that after you unpack the tarball, you can get up to the latest revision by using gclient sync .

If you only want to look at the source code, you'll need at least 1.6 GB of hard drive space available. If you want to build it, you will need just under 10 GB of space, including all the object files and executables.

To bootstrap using the tarball:
  1. Make sure that you have a program that can untar .tar.gz files. Examples include the open-source 7-Zip archiver, the free BsdTar utility (part of LibArchive ), and WinZip.

  2. Download the source tarball .

  3. Choose a directory to hold your source code. Example: c:\chromiumtrunk

    Important:
    Make sure the directory path has no spaces .

  4. Untar the source tarball into the directory you've chosen. Example: If you're using LibArchive, issue the following command:

    "C:\Program Files\GnuWin32\bin\bsdtar.exe" -xzf chromium.tgz


  5. Optionally, sync to the latest revision of Chromium:

    1. Visit the Chromium Buildbot waterfall to see the state of the tree. [Note: If this part of the infrastructure is not yet working, please check the topic of the #chromium IRC channel on irc.freenode.net instead.] If the top of the waterfall says:

      OPEN
      - The tree is in a good state and you should be able to compile the code. Go to the next step.

      CLOSED
      - There might be compile or test failures. You can download the code, but you'll get those same failures when you try to compile or run tests. Best to check back later.

    2. In a shell window, execute the following commands:

      cd c:\chromiumtrunk
      gclient sync

      The gclient tool is included in the depot tools described above. The first time you execute gclient, there will be a delay (a minute or so) while it updates the depot tools.
To check out directly from SVN:

You'll use the gclient depot tool to download the Chromium code from its SVN repository.
  1. Create a directory to hold your source code. Example: c:\chromiumtrunk

    Important:
    Make sure the directory path has no spaces .

  2. Visit the Chromium Buildbot waterfall to see the state of the tree. [Note: If this part of the infrastructure is not yet working, please check the topic of the #chromium IRC channel on irc.freenode.net instead.] If the top of the waterfall says:

    OPEN
    - The tree is in a good state and you should be able to compile the code. Go to the next step.

    CLOSED
    - There might be compile or test failures. You can download the code, but you'll get those same failures when you try to compile or run tests. Best to check back later.

  3. In a shell window, execute the following commands:

    cd c:\chromiumtrunk

    gclient config http://src.chromium.org/svn/trunk/src
    gclient sync

    The first time you execute gclient , there will be a delay (a minute or so) while it updates the depot tools. Downloading the Chromium code takes about an hour.

Build and launch Chromium

Once you have all the software and code, you can build Chromium and launch it in debug mode.
  1. Launch Visual Studio.

  2. Choose File > Open Project/Solution... , go to the src\chrome directory (under c:\chromiumtrunk or wherever you put the Chromium files), and open the file chrome.sln .

  3. In the Solution Explorer, go to the App directory, right-click chrome_exe , and choose Set as StartUp Project .

  4. Set the user profile used by your build of Chromium:

    1. Right-click chrome_exe , and choose Properties .

    2. In the left column, choose Configuration Properties > Debugging .

    3. In the right column, change the value of Command Arguments to something like this:

      --user-data-dir=c:\tmp\DebugProfile


      Click Ok . Chromium creates the specified profile directory (c:\tmp\DebugProfile in the previous example) if the directory doesn't already exist.

      Note:
      If you don't set the profile, then if you try to launch Chromium when Google Chrome or Chromium is already running, a new window comes up in the already running browser . This behavior ensures exclusive access to the user profile, but it means that you can't debug your version of Chromium!

      Warning: If the latest build of Chromium has a new profile format, Google Chrome and older versions of Chromium might not be able to read that format. Unless you set the profile, you could lose your Google Chrome profile data.

  5. Press F5 , which builds the chrome_exe solution and launches Chromium in debug mode. When you're asked whether to build out-of-date projects, choose Yes .

  6. Building takes 15-40 minutes. When the build completes, a browser window appears on your desktop.

    If the build fails or a new browser window does not appear, go to
    Build Instructions (Windows) for help.

Take the tour

The easiest way to start getting familiar with Chromium is to follow what it does in response to user actions.

User action: Entering URLs

You can easily find the code that's executed when the user enters a URL at the address bar.

  1. Open (Ctrl+O ) the file src\chrome\browser\autocomplete\autocomplete_edit.cc .

  2. Place a breakpoint at the AutocompleteEdit::AcceptInput method.
    The AcceptInput method is called whenever the user enters a URL.

  3. Go to your Chromium browser window, type in a web address such as google.com , and press Return. The UI should freeze when the breakpoint is hit.

    Note: If the UI doesn't freeze, then you probably didn't set the profile used by your build of Chromium. Please do so (see Step 4 of
    Build and launch Chromium ) or close all Google Chrome and Chromium windows on your desktop. Then go back to Visual Studio and press F5 again to run the browser within the debugger.

  4. Take a look at the call stack (Debug > Windows > Call Stack ). It shows you the path that the event took from the window system to the Chromium code that starts processing the user-entered URL.

  5. Step through the code (F10 ), looking at the Locals tab to see the values of variables such as url , until you reach the line that invokes the OpenURL method.

  6. Look at the code and the Locals tab to see the values of the arguments to OpenURL . You can see that the URL has been fleshed out (from "google.com" to "http://google.com/", for example), the transition is set to 1 (PageTransition::LINK ), and so on. Because you entered the URL by typing, rather than clicking an item in the drop-down, the next-to-last variable is set to AutocompletePopup::kNoMatch .

  7. To find out more about page transitions, select the word PageTransition , right-click, and choose Go To Definition . You'll see the definition of PageTransition in src\chrome\common\page_transition_types.h . As the source code and comments show, page transitions describe what triggered the page visit. Transitions include clicks on links, typed-in URLs (like the one in this case), form submissions, reloads, and more.

  8. Go back to the autocomplete_edit.cc tab, and step into the OpenURL method (F11 ). When you find yourself looking at code that's too low level, step out (Shift-F11 ) and step again (F11 ). Continue stepping through the code to follow what happens as the page is loaded.

  9. When you're ready to go on, press F5 to continue executing the browser.

  10. Optional: Try other ways of entering a URL. For example:
  • Start typing in a URL, but instead of pressing Enter, use the mouse to click a URL from the drop-down. Compare the call stack and variable values to the ones that you saw previously.

  • Enter one character or word -- one you haven't used before, such as x -- into the URL field. Note that the variable alternative_nav_url soon has a value, such as http://x/ . Also note that the transition is 5, indicating that the URL has been generated (PageTransition::GENERATED ).

  • Drag a URL into the browser. Note that the call stack is different, since AcceptInput is called by a drop event handler.

For more information, see the Navigating from the URL bar section of Getting Around the Chromium Source Code .

User action: Clicking links

The browser's response to clicks on links is a bit complicated, due to Chromium's multi-process, multi-threaded architecture.

  1. Open (Ctrl+O) the file src\chrome\browser\browser.cc .

  2. Place a breakpoint at the Browser::NavigationStateChanged method.

  3. Click a link in any page. You'll hit the breakpoint.

  4. Look at the call stack. You'll see method calls related to message passing between threads in the same process (such as MessageLoop::QueueOrRunTask ; see Threading ) and between processes (such as RenderViewHost::OnMessageReceived ; see Multi-process Architecture and Inter-process Communication ).

  5. Press F5 to start executing again. You'll immediately hit another breakpoint, as the tab redraws itself.

Feature: Browser commands

Often, the user can request an operation in more than one way. For example, the user can reload a page by pressing the Reload button or by pressing F5. To avoid duplicating code, many operations are handled by common code, in the form of commands .

  1. Open (Ctrl+O) the file src\chrome\browser\browser_commands.cc .

  2. Place a breakpoint at the Browser::ExecuteCommand method.

  3. In the browser, press the star button to the left of the address bar. You'll hit the breakpoint.

  4. Look at the call stack. It includes a chain of mouse-release event handlers, including BaseButton::OnMouseReleased .

  5. In the Locals tab, look at the value of id . It identifies the operation that the user requested.

  6. Step into the case statement (IDC_STAR ) that handles this operation. Note that the action is being recorded into user metrics, and then the code to perform the action is called.

  7. Select IDC_STAR , right-click, and choose Go To Definition. You'll see its definition (and those of many other commands) in chrome_dll_resource.h .

  8. Press F5 to continue executing the browser.

  9. Press Ctrl+D , the keyboard alternative for star. You'll hit the breakpoint again.

  10. Look at the call stack. This time, it contains mostly calls related to inter-process and thread-to-thread communication. The only keyboard event handler that's visible in the call stack is WebContents::HandleKeyboardEvent .

  11. Note that the value of id is the same as before, so the same code will be executed as when you used the star button.

  12. Optional: Look at other browser commands, including some menu commands. For example:
  • Ctrl+T and the New tab menu item
  • Reload button and F5

What next?

Now that you've built Chromium and stepped through some of its code, here are some suggestions for what you might want to do now.

 

分享到:
评论

相关推荐

    谷歌浏览器Json格式化插件,浏览器接口调试json

    标题中的“谷歌浏览器Json格式化插件,浏览器接口调试json”指的是在Google Chrome浏览器中用于解析和美化JSON数据的扩展程序。JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,广泛应用于Web服务和...

    google_chrome浏览器编译过程

    ### Google Chrome 浏览器编译过程详解 #### 一、搭建编译环境 Google Chrome 是一款由 Google 开发的免费开源网页浏览器,基于 Chromium 项目。为了编译 Google Chrome,首先需要准备合适的编译环境。 ##### 1. ...

    使用AOSP项目编译的Android系统,会发现在部分APP使用系统自带的浏览器内核来加载网页时会出现报错,加载不出网页的情况

    WebView是Android系统中的一个核心组件,用于在应用程序内部展示网页内容,许多APP都会依赖这个内置的浏览器内核来加载网页。当使用AOSP编译的系统时,可能会发现一些APP在尝试使用系统内置的WebView加载网页时出现...

    Google 浏览器Chrome 那么多进程怎么办?.docx

    Google 浏览器 Chrome 解决多进程问题 Google Chrome 浏览器在每次打开新标签页时,会在系统进程中加入一个新的 Chrome.exe 进程,这使得任务栏管理器中显示许多 Chrome.exe 进程,占用了很多内存空间。下面将介绍...

    Java嵌入谷歌内核简单浏览器

    Java嵌入谷歌内核简单浏览器是一种技术实现,它允许开发者在Java应用程序中集成谷歌的Chromium Embedded Framework(CEF),从而创建具有现代Web浏览功能的应用。CEF是一个开源项目,它为各种编程语言提供了一个轻量...

    谷歌51核浏览器源码

    谷歌51核浏览器源码是谷歌浏览器开发过程中的一部分,它揭示了浏览器的内核机制,为开发者提供了深入理解网络浏览器工作原理的宝贵资料。51核通常指的是Chromium项目的一个特定版本,Chromium是Google Chrome浏览器...

    C#封装的chorme内核浏览器_demo

    在**压缩包子文件的文件名称列表**中,"C#_封装chorme内核浏览器__最新版"可能包含有源代码、编译好的可执行文件、示例代码、配置文件等资源。开发者可以通过查看这些文件来了解具体实现细节,学习如何在自己的项目...

    最新google浏览器85.0.4183.121_chrome.zip

    "最新google浏览器85.0.4183.121_chrome.zip" 提供的是Chrome浏览器的特定版本——85.0.4183.121,这表明这是一个官方更新版本,旨在提供最新的功能和安全修复。 Chrome浏览器的核心特性包括: 1. **Blink渲染引擎...

    qt调用cef编译的库版本的浏览器作者臧传凯_浏览器_CEF_qt+cef_QT_QTCEF_

    要使用QT调用CEF编译的库版本的浏览器,首先需要在本地环境中安装谷歌浏览器,因为CEF是基于谷歌Chromium内核构建的。安装谷歌浏览器可以确保获得最新的Web渲染引擎,提供更好的兼容性和性能。同时,还需要下载并...

    谷歌Chrome浏览器x86版APK低版本Android4.4可用浏览器版本是72.0

    这款“谷歌Chrome浏览器x86版APK低版本Android4.4可用浏览器版本是72.0”是专为使用x86架构设备的用户设计的,如某些平板电脑和安卓模拟器。对于那些在Android 4.4(KitKat)系统上运行的设备,这是一个理想的解决...

    谷歌嵌入式浏览器(cef)源码

    谷歌嵌入式浏览器(CEF,Chromium Embedded Framework)是一个开源项目,它允许开发者将Google Chrome浏览器的核心组件嵌入到他们的应用程序中,以实现强大的网络功能和现代Web界面。CEF源码是理解其工作原理和...

    qt+cef嵌入浏览器

    这里我们关注的是“qt+cef嵌入浏览器”,这是一个利用Qt框架与CEF(Chromium Embedded Framework)相结合来创建一个具备谷歌浏览器内核功能的桌面应用。Qt是一个跨平台的C++图形用户界面库,而CEF则是一个开源项目,...

    Chromium核心的简单多标签浏览器源码

    首先,Chromium是Google Chrome浏览器的基础,它是一个开源的、高性能的Web渲染引擎。CEF则是一个用C++编写的框架,允许开发者将Chromium内核嵌入到各种应用程序中,实现自定义的浏览器功能。在本项目中,开发者使用...

    水星浏览器

    这个工具使得开发者能够使用易语言,这种简洁明了的编程语言,来调用谷歌内核的浏览器框架,从而实现对网页的各类操作和自定义功能。其核心价值在于降低了使用谷歌浏览器引擎进行开发的技术门槛,让易语言用户也能...

    CEF嵌入google chrome内核的浏览器

    在Windows平台上,通过CEF接口将Google Chrome内核嵌入到Win32程序中,开发者可以创建自定义的浏览器应用,这些应用不仅具有与Chrome浏览器类似的性能,还能根据具体需求进行定制和扩展。例如,你可以调整界面布局、...

    谷歌编译之后的插件

    标题中提到的“谷歌编译之后的插件”可能指的是Vue DevTools在被编译并打包后,形成的适用于Chrome浏览器的扩展程序。这个过程通常包括将源代码转换为浏览器可理解的格式,例如通过Babel将ES6+语法转译成ES5,以及...

    pb 浏览器源代码

    4. **JavaScript引擎**:执行JavaScript代码,如V8引擎(Google Chrome使用的引擎)或SpiderMonkey(Firefox的引擎)。这部分源码涵盖了编译、优化和垃圾回收机制。 5. **用户界面**:包括地址栏、书签、历史记录等...

    google 浏览器非应用商店扩展程序安装

    标题 "google 浏览器非应用商店扩展程序安装" 涉及到的是谷歌浏览器(Google Chrome)如何安装不在Chrome网上应用店中的扩展程序。这是一个常见的需求,因为有些扩展可能由于各种原因没有在官方商店发布,或者用户...

    gwt浏览器插件 谷歌 火狐 ie

    GWT(Google Web Toolkit)是谷歌推出的一款开源的JavaScript开发框架,它允许开发者使用Java语言来编写Web应用程序,然后自动生成优化过的JavaScript代码,以在各种浏览器上运行。GWT浏览器插件是GWT框架的一部分,...

    buildroot静态编译Android平台程序

    Bionic库是Google为Android设计的轻量级C库,它不完全兼容glibc,所以直接将使用glibc编译的程序移植到Android上可能会遇到问题。 以下是使用Buildroot进行静态编译的步骤: 1. **配置Buildroot**:打开Buildroot...

Global site tag (gtag.js) - Google Analytics