繼續上一次分析到類
WebContents
的
Navigate
函數,在這個函數里通過參數
entry
傳送入來,這樣它只需要根據這個參數去下載網頁回來顯示,應就可以了吧,但到底是怎么樣工作的呢?這需要深入去分析它,才知道它是什么樣的結果。
#001
?
#002
?
bool WebContents::Navigate(const NavigationEntry& entry, bool reload) {
從渲染顯示管理器里獲取當前連接渲染顯示對象。
#003
???
RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
#004
?
設置開始下載計時的時鐘。
#005
???
// Used for page load time metrics.
#006
???
current_load_start_ = TimeTicks::Now();
#007
?
在渲染顯示對象里進行瀏覽處理。
#008
???
// Navigate in the desired RenderViewHost
#009
???
dest_render_view_host->NavigateToEntry(entry, reload);
#010
?
#011
???
if (entry.page_id() == -1) {
#012
?????
// HACK!!
?
This code suppresses javascript: URLs from being added to
#013
?????
// session history, which is what we want to do for javascript: URLs that
#014
?????
// do not generate content.
?
What we really need is a message from the
#015
?????
// renderer telling us that a new page was not created.
?
The same message
#016
?????
// could be used for mailto: URLs and the like.
#017
?????
if (entry.url().SchemeIs("javascript"))
#018
???????
return false;
#019
???
}
#020
?
判斷是否重新加載舊的連接處理。
#021
???
if (reload && !profile()->IsOffTheRecord()) {
#022
?????
HistoryService* history =
#023
?????????
profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
#024
?????
if (history)
#025
???????
history->SetFavIconOutOfDateForPage(entry.url());
#026
???
}
#027
?
#028
???
return true;
#029
?
}
在這個函數最主要的工作,就是調用類
RenderViewHost
函數
NavigateToEntry
,這個函數的代碼如下:
#001
?
void RenderViewHost::NavigateToEntry(const NavigationEntry& entry,
#002
??????????????????????????????????????
bool is_reload) {
創建瀏覽參數。
#003
??
?
ViewMsg_Navigate_Params params;
#004
???
MakeNavigateParams(entry, is_reload, ¶ms);
#005
?
授權渲染進程可以顯示這個連接。
#006
???
RendererSecurityPolicy::GetInstance()->GrantRequestURL(
#007
???????
process()->host_id(), params.url);
#008
?
發送瀏覽下載連接參數給進程處理。
#009
???
DoNavigate(new ViewMsg_Navigate(routing_id_, params));
#010
?
更新列表計數。
#011
???
UpdateBackForwardListCount();
#012
?
}
在這個函數里,主要創建瀏覽參數,然后調用函數
DoNavigate
來發送一個消息
ViewMsg_Navigate
給
RHV
進程,在
UpdateBackForwardListCount
函數里也發送一個消息
ViewMsg_UpdateBackForwardListCount
給
RHV
進程。
繼續分析函數
DoNavigate
:
#001
?
void RenderViewHost::DoNavigate(ViewMsg_Navigate* nav_message) {
#002
???
// Only send the message if we aren't suspended at the start of a cross-site
#003
???
// request.
如果已經掛起,就開始重新復位這個消息。
#004
???
if (navigations_suspended_) {
#005
?????
// Shouldn't be possible to have a second navigation while suspended, since
#006
?????
// navigations will only be suspended during a cross-site request.
?
If a
#007
?????
// second navigation occurs, WebContents will cancel this pending RVH
#008
?
????
// create a new pending RVH.
#009
?????
DCHECK(!suspended_nav_message_.get());
#010
?????
suspended_nav_message_.reset(nav_message);
#011
???
} else {
或者直接發送這個消息出去。
#012
?????
Send(nav_message);
#013
???
}
#014
?
}
函數
UpdateBackForwardListCount
的代碼如下:
#001
?
void RenderViewHost::UpdateBackForwardListCount() {
#002
???
int back_list_count, forward_list_count;
#003
???
delegate_->GetHistoryListCount(&back_list_count, &forward_list_count);
#004
???
Send(new ViewMsg_UpdateBackForwardListCount(
#005
???????
routing_id_, back_list_count, forward_list_count));
#006
?
}
可以從函數
DoNavigate
和
UpdateBackForwardListCount
里看到,最后都把這些事件變成消息,通過類
RenderProcessHost
來發送出去,主要使用
IPC
的通訊機制。具體是怎么樣通訊的呢?下一次再來分析它。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
