Servo:the embeddable Browser Engine

Source: Internet
Author: User

Embedding, in the context of this article, is the process of hosting a Web rendering engine inside another application. This engine displays content exactly as a regular web browser would, but allows the application author to customize the US Er ' s experience further than what's possible in the typical display of a normal website. Development time can reduced by keeping part of the content of a application in web-related languages due to the Relat Ive ease of writing web content and the widespread knowledge of HTML5.

The technique of embedding Web content is used in many places by many companies, including:

    • Popular Linux applications such as Rhythmbox, Kate, Eclipse, and Evolution with support for embedding web Conten T.
    • Microsoft Entourage and Apple Mail for Mac OS both utilize embedding for displaying Web content and parts of The UI.
    • Adobe products, including their constantly-running updater, embed full web runtimes.
    • Valve ' s Steam client also depends heavily on embedding web content, as they reuse the content from their online store To display in their native application.
    • Many applications in mobile app stores is simply a native wrapper around a Web browser control and HTML5 resources.

HTML5 have been gaining significant traction in the mobile and embedded world. According to a recent survey HTML5 are a leading platform for application development in all of the, and this figure is Li Kely to increase as the number of mobile platforms grows in the future. Finally, HTML5 is a widely known cross-platform solution which guarantees portability.

The need for A Common, embeddable API

There is very few common APIs for embedding content to applications, and until a couple years ago, the most Prevalen T API Was webkit. This was problematic because WebKit's API is not considered stable, forcing developers to rewrite parts of their applicati On order to keep up with changes in the underlying browser engine. In recent Years, blink was forked from WebKit, creating yet another embeddable API. Unfortunately, in addition to being confined to C + +, Blink ' s embedding API is also not stable, perpetuating the increased Workload for application developers.

One solution for these problems are to use the Chromium Embedded Framework. Launched in +, the project is based on the Blink browser engine but aims to completely insulate it users from Underlyi NG engine changes. It provides a base C API with C + + extensions; Allowing support at the lowest levels of software development. Currently, this API was used extensively by Valve for their Steam client, and by Adobe, for various products.

The Servo Solution

The Servo browser engine aims to be embeddable in order to provide maximum flexibility to developers. To the end, it must provide a stable API and ABI for developers to rely on. It's written in Rust because it provides a API usable from c. Designing yet another embeddable web API is a extremely C Omplex task which requires a tremendous amount of consideration and review. It also requires extensive documentation to being written, frameworks to being tested, and the resulting product to be promoted and accepted into the general usage. Based on this, we decided to take a different approach.

Servo implements the Chromium Embedded Framework api:if It ' s good enough for Valve, it's good enough for us. This means developers who currently use CEF would not need to do any application changes to compare performance between t He Blink and Servo engines, and prospective developers is not having yet another browser API to review and consider. Hopefully, this also means Servo would reach an embeddable state much more quickly.

The methodology for this implementation are twofold:ensure full symbol coverages, and attempt to mimic the exact functional ity of each method call as closely as possible. Since This isn't a common practice, let's break it down a little further. Symbol coverage refers to the externally visible symbols provided by a library. Rust, using the extern "C" keywords, allows any function written in Rust to is directly accessible from C with no extra wo RK needed. So-regard, full-symbol coverage would mean that every CEF-function call is able-be-hooked by Servo ' s embedding Library. It also requires a externally-used struct is allocated, it must match the size and member positioning as a Similar struct allocated by the real CEF.

Pub struct Cef_string_utf8 {   pub str: *mut U8,   pub length:size_t,   pub dtor:extern "C" FN (str: *mut U8),}

Mimicking functionality is a bit trickier. This requires full understanding of all CEF function and how it ties into the browser engine. Then, the same order of operations must is replicated using the underlying Servo browser engine. This can is quite a complex process, as CEF makes internal function calls back and forth between itself and Blink, Sometim ES requiring functions to operate recursively.

The method for implementing and testing the success of this endeavor have been a bit complex. First, a symbol list was needed. Using standard utilities, specifically the NM tool on Linux, we copied the undefined symbols from some of the example CEF Applications. This provided a easy starting point to begin implementing functions and functionality. With the list of target symbols, it became much easier to track the execution of the application through the CEF library A nd determine what is happening in each function call. From this it became a case of using Rust/servo to replicate the expected and observed behavior.

A Few Hitches along the

The process of writing this implementation for embedding have not come very far because it is only recently begun; at p Resent, there is a very small team focusing on it. However, there has been some difficulties, and May is interesting to other developers. One such difficulty that is immediately apparent was tracking the C API ' s execution through the C + + extensions provided B Y CEF. The example applications all use the C + + extensions which required a bit of legwork to understand how they utilize and WRA P The C API and what is going on internally. The solution here is extremely rudimentary, just read a whole bunch of source code. Eventually, even the most high-level wrapper would come down to one or both function calls which could then be written and Tested more thoroughly.

Another difficulty, took quite a while to track down is a byproduct of the testing environment. In order to run the CEF examples with the Servo backend, we needed to use some library preloading hacks (Ld_preload and FR Iends on Linux) so the running environment would inject the Servo embedding symbols for use in the application, Effectivel Y overriding the cef-provided functions. However, as long as the CEF library is used with any function call it would invoke the underlying Blink runtime, which uses T He tcmalloc allocator. The reason this is problematic are because Tcmalloc uses different function calls for allocating memory between C and C + + t Han what are expected, and it complains quite loudly when it detects any deviation from this behavior. As a result, the Servo embedding library needed to provide wrappers to allow calling these functions directly for memory a Llocation, but only when using the preload hack:

PUB fn New (size:size_t)-*mut c_void {   unsafe {      tc_new (size)   }}

The embedding-sufficient-to-run Servo within the Cefsimple application, and a number of tasks are currently Open to improve support in other directions. For more information check out the GitHub page.

Guest Author:lars Bergstrom

Lars Bergstrom is a researcher at Mozilla, currently working on the servo parallel web browser project. He received He Ph.D. from the University of Chicago ' s computer Science department, studying under Dr. John Reppy. His Master's paper was on the implementation of analysis and optimization passes in our parallel compiler, Manticore. His Ph.D. "On" to "add mutation safely and efficiently into a functional parallel programming language. He had also been doing work on a runtime, garbage collector, and most recently some extensions to Control-flow analysis. Before that, he is a manager and a developer at Microsoft in the Visual Studio organization, working on Next-generation s Oftware Development tools technology out at the Redmond, WA offices.

Servo:the embeddable Browser Engine

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.