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

Source: Internet
Author: User

This section mainly analyzes the process of loading pages in webcontentprocess, and mainly processes HTTP requests.

Main Structure

Starting from receiving loadurl, webkit2 prepares to try to load network data. Different platforms use different network modules to process HTTP requests. You can briefly describe the following block chart:

* On Mac OS, nsurlconnection is used by default.

* For how to use nsurlconnection, refer to here (the key is its delegate working method ):

How to Use nsurlconnection tutorial

The core class of data loading is centered on WebCore resourcehandle, and resourceloader is an external service interface. First look at the internal relationship:

From left to right, resourceloader implements the resourcehandleclient interface as the caller of resourcehandle. Resourcehandle also uses resourcehandleinternal to package internal data in the form of friends. In actual implementation, resourcehandle is also implemented on different platforms. In Mac OS, nsurlconnection is used for communication processing, while webcoreresourcehandleasdelegate is the nsurlconnection proxy class (implementing nsurlconnectiondelegate), which is used for processing specific loading operations, including HTTP
Request sending control and corresponding error handling.

Let's look at resourceloader's WebCore call direction. The following figure shows the related class:

Resourceloadschedader & subresourceloader & resourceloader constitute the implementation of the loading logic by WebCore. With scheduler, there must be a queue management mechanism:

M_requestspending is a queue. The caller adds new requests through schedulesubresourceload (), and The servependingrequests () processes tasks in the queue.

What's interesting is its queue:

Typedef deque <refptr <Resourceloader>Requestqueue;
Requestqueue m_requestspending[Resourceloadpriorityhighest + 1];
Typedef hashset <refptr <Resourceloader>Requestmap;
Requestmap m_requestsloading;

As the name implies, deque is a bidirectional list. Each element in the list is a resourceloader. In the execution process, as long as the resourceloader is retrieved from the queue, the corresponding loading process is triggered.

There is a clear 1-to-1 relationship (an HTTP resource corresponds to a resourceloader ).

M_requestspending is defined as an array. Different Request queue values are assigned based on different priorities. The following m_requestsloading record adds a request after it is activated when servependingrequesg () is processed, indicating that the request is being loaded.

Loading Process

The loading process has changed somewhat compared with how WebKit loads a web page on the WebKit official website. The key is to merge the processes of the primary and sub-resources. You can compare them with the following:

* Both scriptelement and htmllinkelement are previously defined sub resources.

Attach several sequence diagrams to see some details:

1. Starting from webpage Loading

2. resoureloader Processing

3. Processing resourcehandle

Load the corresponding policy mechanism

WebKit introduces a policy management mechanism to improve the flexibility of some operations. Taking resourceloader as an example, that is, loaderstrategy in, it will decide which resourceloadscheduler to use to manage the download task, and then webplatformstrategies in WebKit will make a specific decision. The callback mechanism is used flexibly in the control process, and further details are discussed.

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

Refer:

WebKit modular Analysis

Analysis of webkit2 multi-process mechanism

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.