接着昨天的代码梳理
m_frame->document()->cancelParsing(); //4
之后出现了 m_stateMachine 这个变量,顾名思义是状态机。
m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocument); //5
m_stateMachine 是 FrameLoader 的一个 FrameLoaderStateMachine 类型成员变量,用来管理 FrameLoader 的状态变迁:
mutable FrameLoaderStateMachine m_stateMachine;
它在FrameLoader构造时调用了默认的构造函数做初始化:
FrameLoaderStateMachine::FrameLoaderStateMachine() : m_state(CreatingInitialEmptyDocument) { }
它有以下几个状态用成员变量 m_state 代表,状态的变迁通过 advanceTo()实现。
// Once a load has been committed, the state may // alternate between CommittedFirstRealLoad and FirstLayoutDone. // Otherwise, the states only go down the list. enum State { CreatingInitialEmptyDocument, DisplayingInitialEmptyDocument, DisplayingInitialEmptyDocumentPostCommit, CommittedFirstRealLoad, FirstLayoutDone };
接下来通过
FrameLoaderClient::createNetworkingContext() 创建网络上下文
m_networkingContext = m_client->createNetworkingContext(); //6真正的实现在
PassRefPtr<FrameNetworkingContext> WebFrameLoaderClient::createNetworkingContext() { RefPtr<WebFrameNetworkingContext> context = WebFrameNetworkingContext::create(m_frame); return context.release(); }
WebFrameLoaderClient 继承了 FrameLoaderClient:
class WebFrameLoaderClient : public WebCore::FrameLoaderClient
接下来创建 FrameProgressTracker:
m_progressTracker = FrameProgressTracker::create(m_frame); //7
FrameProgressTracker 类 用两个方法,progressStarted() 和 progressCompleted(),来维护 m_inProgress 的值,true or false 表示正在加载,和没有在加载。
到这里 FrameLoader::init() 执行结束,之后依次返回 call-stack:
void FrameLoader::init() inline void Frame::init() void WebFrame::init(WebPage* page, const String& frameName, HTMLFrameOwnerElement* ownerElement) PassRefPtr<WebFrame> WebFrame::createMainFrame(WebPage* page)
初始化完成之后WebKit 会等待下次事件的到来,接下来是
加载 TOP 站点
加载Top站点的请求最终传递给
void FrameLoader::load(const FrameLoadRequest& passedRequest) { FrameLoadRequest request(passedRequest); if (m_inStopAllLoaders) return; if (!request.frameName().isEmpty()) { Frame* frame = findFrameForNavigation(request.frameName()); if (frame) { request.setShouldCheckNewWindowPolicy(false); if (frame->loader() != this) { frame->loader()->load(request); return; } } } if (request.shouldCheckNewWindowPolicy()) { policyChecker()->checkNewWindowPolicy(NavigationAction(request.resourceRequest(), NavigationTypeOther), FrameLoader::callContinueLoadAfterNewWindowPolicy, request.resourceRequest(), 0, request.frameName(), this); return; } if (!request.hasSubstituteData()) request.setSubstituteData(defaultSubstituteDataForURL(request.resourceRequest().url())); RefPtr<DocumentLoader> loader = m_client->createDocumentLoader(request.resourceRequest(), request.substituteData()); if (request.lockHistory() && m_documentLoader) loader->setClientRedirectSourceForHistory(m_documentLoader->didCreateGlobalHistoryEntry() ? m_documentLoader->urlForHistory().string() : m_documentLoader->clientRedirectSourceForHistory()); load(loader.get()); }
打印请求的内容,可以看到 url 的值:
(lldb) p request.resourceRequest().url().string().latin1().data()
(const char *) $137 = 0x0000000113620230 "topsites://"