I have written several instructions on loading processes, which are from the bottom up, a little bit of a feeling that the trees do not see the forest. After a recent period of study, we have implemented methods that can be summarized and abstracted.
The WebKit loading process is directly related to page composition. A page is the object to be loaded by WebKit. Therefore, the classes that WebKit is responsible for loading also correspond to those that are responsible for page management. Apple's description of WebView clearly shows the MVC structure on the page view:
A page also has its hierarchy from the element and corresponds to the loading class, as shown below:
In terms of Page elements, WebView represents the rendering of a Page, corresponding to a Page. A Page contains one or more frames, one of which is called the Main Frame. Other frames (iframe or HTML introduced by object elements) are called Sub frames. Each Frame has a window and document object from JavaScript.
The Frame, Document, and sub-Resources in the page correspond to the loaded FrameLoader, DocumentLoader, and SubresourceLoader. Frame can perform Navigation operations, that is, loading, reloading, forward, and backward operations. Document indicates a specific HTML Document without Navigation operations.
Several Loaders are loaded logic representation. The actual loading behavior is handed over to ResourceLoader (s), that is, MainResourceLoader and SubresourceLoader, this includes ResourceLoadScheduler ).
ResourceHandle is an important port interface in WebKit. it is adapted to the network layer of each platform and represents a specific network loading task.
Main class relationships
FrameLoader Loading Sequence
We can see from the above that FrameLoader represents the loading behavior of the Frame, and DocumentLoader represents the loading behavior of the Document. To differentiate loading processes, FrameLoader distinguishes loading statuses and converts DocumentLoader to different States. In addition, FrameLoader also uses a state machine to manage the display state (FrameLoaderStateMachine) of Frame loading ).
In addition, FrameLoader also maintains HistoryController to handle the Navigation operation. The detailed project is defined in FrameLoaderTypes. h.
Document Loader
Compared with FrameLoader, DocumentLoader is relatively simple. Its task is to call a MainResourceLoader to load the main document. Because the state conversion is completed in FrameLoader. The loading of sub-resources is managed by DocumentLoader.
Loading sub-Resources
Just as the page element belongs to the Document, the class responsible for loading sub-resources belongs to the Document, and then moved to the DocumentLoader class. The following relationship is formed:
CachedResourceLoader
As for CachedResourceLoader, it is actually an encapsulation class that encapsulates the function of creating various types of CachedResource. Each page element to be loaded inherits from CachedResourceClient, creates CachedResourceRequest, and initiates a request through CachedResourceLoader in DocumentLoader/Document.
The following is the call request initiated by the Script element:
Memory Cache/Application Cache
In order to give users a faster application experience, there is no small cache mechanism. Cached is available in the names of CachedResource/CachedResourceLoader in WebKit because of Cached interaction.
WebKit also provides some algorithm descriptions. For more information, see here.
Resource Load Scheduler
Two lists are stored in HostInformation. One is the list waiting for loading stored in arrays of different priorities, and the other is the list being loaded.
When scheduleServePendingRequests is used to process queued requests, the requests are executed in order of priority. The basic process is as follows:
The above is an overview of the loading process. The process content is missing. You can refer to the following two links:
[WebKit] Design and Implementation of WebCore page loading (2)
[WebKit] Design and Implementation of WebCore page loading (3)
Reprinted please indicate the source: http://blog.csdn.net/horkychen