Building Google Chrome

来源:互联网 发布:securecrt mac 编辑:程序博客网 时间:2024/05/18 22:46

Building Google Chrome: A first look

GOOGLE'S OPEN SOURCE BROWSER HAS MUCH TO OFFER PROSPECTIVE HACKERS (PROVIDED THEY USE WINDOWS)

Last week I said I would look at Google Chrome "from a developer's perspective." I should have specified what kind. I meant I was considering it from a Web developer's perspective: What does it mean for Web application builders to have yet another browser enter the already-crowded field?

But the more I thought about it, the more I felt it would be worthwhile to look at Chrome from the perspective of the other kind of developer. After all, Chrome is open source, and there's clearly still some work to be done on it. So I decided to take a peek under Chrome's hood and view it through the eyes of the developers who will improve and maintain it in the coming years.

Dude, where's my code?
The first stop on my quest was dev.chromium.org, the Chromium Developer Documentation site, to get a copy of the source code. "Chromium" is the name of the open source version of the Chrome browser, while "Chrome" is Google's official stable release. Get the idea? In real life, chrome is smooth and polished, while chromium is just a raw element.

The Chromium site explains how to download the source code for Linux, Mac OS X, or Windows. Unfortunately, if you're eagerly awaiting a Mac version of Chrome, you shouldn't hold your breath. As the Mac OS X area of the Chromium developer site explains, "Right now, the Mac build is a work in progress that is much closer to the start than the finish." In fact, according tothe latest status report, the Chrome developers have yet to get even the browser core running under Mac OS X. Rendering actual Web pages is still a long way off, to say nothing of a usable Aqua GUI.

Then again, the Linux version is in arguably even worse shape. If you were laboring under the assumption that a new open source browser from Google meant an automatic win for Linux, you'd better think again. The Windows version of Chrome isn't just the first to market; it's also the master mold for all the other versions. You won't see a Linux version until the Chrome developers manage to port the original Win32 codebase over to Linux, with all the headaches that implies.

In short, don't expect a Mac or Linux version of Chrome any time soon. Not even close.

So for my project, Windows was it. But even then, getting the code wasn't as easy as simply clicking a link. Instead, I first had to install a set of scripts to give me access to Chromium's Subversion source code repository. These are command-line tools, but they should feel familiar to anyone with a modicum of development experience. What checking out code from Subversion meant, however, was that I'd be working with the latest, bleeding-edge version of the code. At this early stage of the project, Chromium is definitely a moving target.

It might be helpful to have a book to read while you wait for the source code tree to sync for the first time. The whole thing amounts to around 2.4GB of code, including all the various layout tests used to debug the WebKit rendering engine. Google says the entire download should take about an hour, depending on network activity. In my case it took at least twice that long, despite a 6Mbit broadband connection.

Dissecting a browser
Examination of the source tree reveals some interesting tidbits. Except in cases where code was borrowed from other projects, the source is released under a three-clause BSD-style license, one of the most permissive open source licenses. Google clearly has no qualms about Chromium code being used in commercial settings.

When Chromium does borrow, it's mostly from the expected sources. Besides the WebKit HTML rendering engine, the tree includes the typical libraries for displaying JPEGs, compressing files, and so on. It uses hunspell for its automatic spell-checker -- the same library used by Firefox 3 -- so you can expect that feature to work identically on both browsers.

Overall, the code looks clean and is well organized. Firefox is frequently criticized for its large, Byzantine codebase. By comparison, the Chromium code seems much more accessible to the casual programmer. Comments are plentiful, and they occasionally display some of the humor that makes the best open source projects so much fun. For example, one component of the browser core is a debugging aid dubbed the "jank-o-meter." A comment inside the source explains: "Put break point here if you want to stop threads and look at what caused the jankiness."

Interestingly, Chromium was designed with a certain amount of modularity built in. For example, if for some reason you don't want to use Chromium's ultra-fast V8 JavaScript engine, you can change a few compile-time flags and build it with JavaScriptCore, the engine that ships with WebKit, instead.

What is not immediately evident, however, is any kind of extension mechanism. There is no directory in the source tree called "plug-ins," for example. Building an ad blocker for Chrome might be harder than it sounds.

Putting it all together
Next up: Building the actual browser. To build Chrome for Windows, you'll need Visual Studio 2005 Service Pack 1 (plus some optional patches for improved performance and Vista compatibility) and the current Windows SDK. Neither Visual Studio 2003 nor 2008 are supported currently, due to incompatibility with certain parts of the Chromium codebase.

The folks at Google made it sound as if, once you had the source code, building Chromium was as easy as loading up the solution file in Visual Studio and pressing F7 -- so that's what I did. And you know what? They were right! Fifteen minutes and 51 compiler warnings later, I had my chrome.exe. (For reference, this was on a 2.4GHz Intel Q6600 quad-core workstation running Vista Ultimate, with 4GB of RAM and ample hard drive space.)

Launching the browser brought no real surprises. As the name suggests, Chromium is a rawer, less polished version of Chrome. The UI is mostly identical, with only a few very minor visual differences. All of the same options are available in the pull-down menus on the right. Sites render the same, including Flash sites. The most readily evident difference is the logo, which sheds the Google colors in favor of a subdued blue design.

aboutchromium.jpg

Where it comes to overall ease of use, however, Google has put in a little extra effort to differentiate Chrome from Chromium. Chrome offered to import my Firefox 3 settings automatically on first launch, and the process went without a hitch. I had to do it manually with Chromium, and when I tried, it gagged on my search engine settings and aborted the process. I managed to bring in my bookmarks by importing them separately; but while Chrome organized them just like my Firefox setup, Chromium hid them away in a subfolder.

These minor quibbles aside, however, my initial impression of Chromium is that it is a full-featured, usable browser. Better still, its code is straightforward and well organized, which should make it appealing to would-be browser developers who have shied away from the more daunting Mozilla codebase. I'm looking forward to seeing how it develops as Chrome moves toward its first stable release and beyond.

Posted by Neil McAllister on September 11, 2008 03:00 AM

原创粉丝点击