[WebKit] Design and Implementation of WebCore page loading (2)

Source: Internet
Author: User

It has been more than half a year since I learned how to load WebKit. Now I have time to handle the loading process again. We hope to gradually improve the details and finally have a systematic summary.


First, we can understand the loading logic of WebKit. It involves three main components. HTTP stack is the HTTP protocol module used on each platform, webCore Loaders controls the Loading of different HTML elements based on the page Loading and parsing processes. The Loading Controller specifically controls the Loading of resources:


Although the overall structure of WebKit is not very rigorous, it is helpful to understand the loading process from the perspective of loading. Because HTTP Stack depends on the platform implementation, let's start with the intermediate Loading Controller.


Loading Controller provides two important interface classes: CachedResourceLoader, a class for WebCore to call and load resources, and ResourceHandle for accessing the HTTP module.



1. Load different resources

The difference between loading resources is that the data processing methods are different. For example, if the main Document is to be submitted to the Document Parser for parsing, the image will be displayed, however, their network loading process is the same, so they have different CachedResourceClient implementations, reusing the SubresourceLoader loading process.


You can see how DcoumentLoader and ScriptElement are associated with CachedResource:


Starting to load resources involves two important processes: Creating CachedResource and calling CachedResource: addClient to register a CachedResourceClient instance.


Is the loading sequence diagram of ScriptElement:



CachedResourceHandle can be considered as an encapsulation of CachedResource and is provided to WebCore Loaders.


CachedResourceHandle is a template class

Template <class R> class CachedResourceHandle


CachedResourceLoader provides different interface functions for different types of resources, such as the loading function corresponding to the Script:


CachedResourceHandle <CachedScript> CachedResourceLoader: requestScript (CachedResourceRequest & request)

{

Return static_cast <CachedScript *> (requestResource (CachedResource: Script, request). get ());

}


When receiving the data, the subclass derived from CachedResource will obtain the loaded data in time through the data function, and then complete the corresponding operations through the registered clients.


As mentioned in the previous article, the loading initiation process is as follows:




* When an error occurs, the system calls CachedResource: error ()

It is the processing process after the master document (CachedRawResource) receives data (DocumentLoader is the client of CachedRawResource ):


The following is a code snippet of CachedRawResource: data:

If (incrementalDataLength ){

CachedResourceClientWalker <CachedRawResourceClient> w (m_clients );

While (CachedRawResourceClient * c = w. next ())

C-> dataReceived (this, incrementalData, incrementalDataLength );

}



2. cross-platform ResourceHandle

For more information about the cross-platform mechanism of WebKit, see <WebKit modular analysis> "compatibility-cross-platform solution of WebKit ".

ResourceHandle, ResourceHandleInternal, and NetworkingContext are both defined in the platform/network directory. reourceHandle has different implementations for some functions on different platforms. The implemented unit files are located in the port subdirectory of the specific platform under the platform/network directory.


* In the HTTP Stack used, apart from the implementation of curl and other platforms, the WebKit source code also mentions SOUP, which is also a library that provides HTTP support for GNOME applications. The introduction is as follows:

Soup uses GObjects and the glib main loop, and is designed to work well with Gtk/GNOME applications. this enables GNOME applications to access HTTP servers on the network in a completely asynchronous fashion, very similar to the Gtk + programming model (a synchronous operation mode is also supported for those who want it ).

Reprinted please indicate the source: http://blog.csdn.net/horkychen

Previous articles in this series:

[WebKit] Design and Implementation of WebCore page loading (1)

UML image file (GitHub):

WebKit-Documentation

Related Article

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.