WebKit Kernel source code Analysis (iv)

Source: Internet
Author: User
WebKit Kernel source code Analysis (iv)

Red Sweet potato (tomorrow.cyz@gmail.com)

Absrtact: This article describes how Loader modules in webcore load resources, and the class relationships of Loader modules are analyzed by the primary resource and the derived resource.

Key words: Webkit,loader,network,resouceloader,subresourceloader One, class structure and interface

The Loader module is a customer of the network module. The network module provides the ability to acquire and upload specified resources, which may be obtained from a network, local file, or cache. The adaptation to different HTTP implementations is done at the network layer, so Loader is basically exposed to network layer interfaces that are independent of the OS and HTTP implementations.


As above is the class diagram between Loader and network, Resourcehandleclient is a Resourcehandle customer, which defines a series of virtual functions that are resoucehandle callbacks, and inherit classes that implement these interfaces.

The Resoucehandleclient interface is closely related to the process of network transmission, which is generally a callback for a network event. Here are some of these interfaces.

In general, call before initiating a network request, you can set a specific Http

The head, such as the user agent, will be automatically tuned when the request is redirected.

Use

void Willsendrequest (resourcehandle*, resourcerequest&, const

resourceresponse&)

When uploading data, when the TCP Wrtie event, send the data to the other side

When called, loader can display the upload progress according to this callback.

void Didsenddata (resourcehandle*, unsigned long long

/*bytessent*/, unsigned long long/*totalbytestobesent*/)

The first response packet is received, at least the HTTP part of the header has been resolved (e.g.

Status code), loader to determine whether the request was successful based on the header information of the response

Wait

void Didreceiveresponse (resourcehandle*,

Const resourceresponse&)

Receive HTTP response data, similar to TCP read event, to HTTP response data

, the network design mechanism is to come up with a piece of data to upload a piece of data.

void Didreceivedata (resourcehandle*, const char*, int,

int/*lengthreceived*/)

Load complete, data is aligned.

void Didfinishloading (resourcehandle*, double/*finishtime*/)

Load failed

void Didfail (resourcehandle*, const resourceerror&)

Require user authentication

void Didreceiveauthenticationchallenge (resourcehandle*,

Const authenticationchallenge&)

WebCore the resources to be loaded into two categories, such as the main resource, such as HTML pages, or downloads, and a derived resource, such as an embedded image or script link in an HTML page. These two types of resources for the processing of callbacks are very different, for example, the same download failed, the main resource may need to complain to the user, derived resources such as a picture of the page download failed, may be the figure does not show or show instead of the description text, not to the user error. So with the Mainresourceloader and Subresourceloader. Their common base class Resourceloader completes some of the two resource downloads, such as telling the load process to the upper application via a callback.

Resourceloader passes the callback to the Frameloaderclient class through the Resourcenotifier class.


The load of the primary resource is immediately initiated, and the derived resource may be waiting in the queue to optimize the network (the immediate launch here is loader level, not network level). Resourcescheduler This class is used to manage the scheduling of resource loads. The primary scheduling object is the derived resource, which affects the order in which the resource is loaded, depending on the host.

There is also a difference between the loading of primary and derived resources, where the primary resource is currently not cached, and the derived resource has a caching mechanism. The cache here refers to the resouce cache, used to save raw data (such as CSS, JS, etc.), as well as decoded image data, through Resource cache can save network requests and image decoding time. Unlike page cache, page cache is the data structure of the DOM tree and the Render tree, which is used to quickly display the page as it moves backwards. second, loading process

The following figure is a normal loading process when the HTML page is loaded.

third, the main resource loading process

1. Documentloader calls Mainresourceloader::load to loader to initiate a request

2. Call Mainresourceloader::loadnow

3. Call Mainresourceloader::willsendrequest

4. Call the Resourceloader::willsendrequest and transmit callback through Resourcenotifier to Frameloaderclient. The Client can manipulate resourcerequest in the callback, such as setting the request header.

5. Call Policychecker::checknavigationpolicy to filter out duplicate requests, etc.

6. Loader calls Resourcehandle::create to launch a load request to network

7. Receive the first HTTP response packet, network callback Mainresourceloader::d idreceiveresponse, mainly processing HTTP headers.

8. Call Policychecker:: Checkcontentpolicy, and finally through Frameloaderclient Dispatchdecidepolicyformimetype to determine whether the download request (existence "C Ontent-disposition "HTTP header)

9. Call Mainresourceloader::continueaftercontentpolicy and detect if an error occurs according to Resourceresponse.

10. Call Resourceloader::d Idreceiveresponse, will callback through Resourcenotifier conduction to frameloaderclient.

11. HTTP body Data received, call Mainresourceloader::d idreceivedata

12. Call Resourceloader::d Idreceivedata, transmit callback through Resourcenotifier to Frameloaderclient

13. Call Mainresourceloader::adddata

14. Call Documentloader::receiveddata

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.