WebKit의 핵심 시퀀스를 요약하면 아마 다음과 같을 것이다.
- URL 문서를 loading 하는 시퀀스
- loading한 문서를 parsing 하는 시퀀스
- parsing된 내용의 layout을 결정하는 시퀀스
- 구성한 화면을 출력하는 시퀀스
이들중 "URL 문서를 loading하는 시퀀스"를 분석하게 됐다.
WebKit을 갖고 일하는 개발자들에게 조금이라도 보탬이 되면 좋겠다. 혹시나 분석한 내용에 오류가 있다면, 댓글이나 트랙백으로 가르침 주시기 바란다. 분석에 사용한 WebKit은 작년말(2008년 12월) 버전이며 (rev. 39476), cURL을 사용하는 win32 port를 기준으로 하고 있다.
URL을 load 하는 시퀀스를 분석하면서 WebKit에 존재하는 수 많은 종류의 loader들 때문에 골치 아팠다. 대강의 내용을 정리하면 다음과 같다 (클래스 다이어그램에 메모박스로 주석 달아 놓았다).
- FrameLoader : URL-load 과정을 총괄하는 loader (1개의 frame에는 여러개의 web-page가 load될 수 있다).
- DocumentLoader : 1개의 web-page load를 책임지는 loader.
- MainResourceLoader : base-document (HTML 문서) load를 책임지는 loader.
- ResourceLoader : sub-document (CSS, js, image, ...) load를 책임지는 loader.
분석한 내용을 다음 2장의 UML 다이어그램으로 정리한다. 이미지를 클릭하면 원본 크기로 볼 수 있다.
<<URL load 과정에 참여하는 Class 들>>
<<URL load 간단 시퀀스 (HTML 파일 1개로만 이루어진 페이지 load 시퀀스)>>
분석을 위해 다음과 같은 뉴스그룹 기사들을 참고했다. 다른 사람들에게도 참고가 되기를 바라며, 해석 없이 그대로 올린다.
"문서 load 시퀀스"
from http://osdir.com/ml/opendarwin.webkit.devel/2006-10/msg00041.html
======================================================================
Main resource loaded, started from app via API:
[ WebFrame ] (ObjC, WebKit)
[ FrameLoader ] (C++, WebCore) ---> [ FrameLoaderClient ] (C++ abstract base class, implemented in webkit to deliver delegates)
[ DocumentLoader ] (C++, WebCore)
[ MainResourceLoader ] (C++, WebCore)
[ ResourceLoader ] (C++, WebCore)
[ FrameLoader ] (C++, WebCore)
Main resource loaded, started from engine via link click or form submission:
[ FrameLoader ] (C++, WebCore) ---> [ FrameLoaderClient ] (C++ abstract base class, implemented in webkit to deliver delegates)
[ DocumentLoader ] (C++, WebCore)
[ MainResourceLoader ] (C++, WebCore)
[ ResourceLoader ] (C++, WebCore)
[ FrameLoader ] (C++, WebCore)
Subresource load:
[ DocumentLoader ] (C++, WebCore)
[ Cache ] (C++, WebCore)
[ FrameLoader ] (C++, WebCore) ---> [ FrameLoaderClient ] (C++ abstract base class, implemented in webkit to deliver delegates)
[ SubresourceLoader ] (C++, WebCore)
[ ResourceLoader ] (C++, WebCore)
[ Cache ] (C++, WebCore)
[ CachedResource ] (C++ WebCore)
"Loader의 종류 및 역할"
from http://www.nabble.com/Role-of-all-loaders-to22115931.html#a22172592
========================================================================
Re: Role of all loaders
by Darin Adler Feb 24, 2009; 08:28am :: Rate this Message: (use ratings to moderate[?])
> FrameLoader
Controls the process of loading web pages into a frame. Contains all
the loading-related functions and data instead of having them all on
Frame itself. There’s one of these for each frame.
> DocumentLoader
Controls the process of loading one particular web page into a frame.
When a new page is loaded, the frame loader creates a new document
loader and then later destroys the old one.
> DocLoader
Part of the caching machinery. Manages the cached loading for a
particular document. May be merged with DocumentLoader at some point
in the future, or perhaps renamed.
> MainResourceLoader
FrameLoader and DocumentLoader use ResourceLoader objects to load
individual resources. The main resource is the HTML file (or SVG file
or whatever). The ResourceLoader for the main resource is a
MainResourceLoader.
> Sub resource Loader
The ResourceLoader objects for subresources such as images, scripts,
and CSS style sheets are SubresourceLoader objects.
-- Darin
"URL loading중 발생하는 frameLoaderClient를 통한 이벤트"
from http://www.nabble.com/FrameLoaderClient-notifications-to16025970.html#a16030339
=====================================================================================
Re: FrameLoaderClient notifications
by Darin Adler Mar 14, 2008; 02:37am :: Rate this Message: (use ratings to moderate[?])
> I suppose the following order of loading events for a page with a
> single frame (please, correct me, if I'm wrong):
>
> page load started
> main document load started
> title received
> icon received
> * main document load finished
> ** resource load started
> resource load finished
> page load finished
...[show rest of quote]
The the FrameLoaderClient functions about the frame (not the ones that
take DocumentLoader*) are what you want. They are all about this
cycle. dispatchDidStartProvisionalLoad is the one that goes first, and
then there are quite a few others, ending with dispatchDidFinishLoad,
dispatchDidFailLoad or dispatchDidFailProvisionalLoad.
> OK, I see. Is there any other load process other than provisional?
All loads start provisional.
>> dispatchWillSendRequest will be called repeatedly with different
>> URLs when a server does redirection. This is normal. How it should
>> be handled depends on what API you've devised.
>
> Is there any separate notification about redirection, or this method
> is enough?
There is
dispatchDidReceiveServerRedirectForProvisionalLoad for loads of the
main resource of a frame, but dispatchWillSendRequest alone is all
that's needed for arbitrary resource loads.
> One more question: is there any method about starting loading of an
> external resource? Is it dispatchWillSendRequest?
> dispatchDidReceiveResponse?
assignIdentifierToInitialRequest and dispatchWillSendRequest
-- Darin
"HTTP 스택은 누가 처리하나?"
from http://www.nabble.com/Complicated-Loaders-to18706606.html#a18724848
========================================================================
The sequence of FrameLoader and DocumentLoader functions is indeed complicated
and overloaded. This is slowly being improved over time, little by little.
And no, there is no documentation at this time.
I'm not sure of the exact motivation for your question, but you did end on
a very specific note so this might be of use. The question of "how WebKit is
invoking the HTTP stack" is much simpler - the ResourceRequest, ResourceHandle,
and ResourceResponse classes are all fairly encapsulated and represent
HTTP connections.
~Brady