上一次說(shuō)到類
RenderThread
和類
RenderView
把消息處理,那么這兩個(gè)類是怎么樣處理消息的呢?又是怎么樣處理瀏覽的消息呢?現(xiàn)在就帶著這兩個(gè)問(wèn)題去分析它的源碼,理解它處理消息的方法。類
RenderThread
處理消息的代碼如下:
#001
?
void RenderThread::OnMessageReceived(const IPC::Message& msg) {
#002
???
// NOTE: We could subclass router_ to intercept OnControlMessageReceived, but
#003
???
// it seems simpler to just process any control messages that we care about
#004
???
// up-front and then send the rest of the messages onto router_.
#005
?
下面判斷是控制消息,如果是控制消息就在本類里處理,否則就分發(fā)到別的地方處理,主要是轉(zhuǎn)到類
RenderView
處理。
#006
???
if (msg.routing_id() == MSG_ROUTING_CONTROL) {
#007
?????
IPC_BEGIN_MESSAGE_MAP(RenderThread, msg)
#008
???????
IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_NewTable, OnUpdateVisitedLinks)
#009
???????
IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID)
#010
???????
IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView)
#011
???????
IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities)
#012
???????
IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats,
#013
???????????????????????????
OnGetCacheResourceStats)
#014
???????
// send the rest to the router
#015
???????
IPC_MESSAGE_UNHANDLED(router_.OnMessageReceived(msg))
#016
?????
IPC_END_MESSAGE_MAP()
#017
???
} else {
這里是分發(fā)消息到別的地方處理。
#018
?????
router_.OnMessageReceived(msg);
#019
???
}
#020
?
}
在瀏覽器里,消息分為兩大類:控制消息和路由消息。像使用
IPC_MESSAGE_CONTROL
宏定義的消息,就是控制消息;使用
IPC_MESSAGE_ROUTED
宏定義的消息,就是路由消息。
路由消息分發(fā)是由類
MessageRouter
來(lái)負(fù)責(zé)的,主要處理的代碼如下:
#001
?
#002
?
void MessageRouter::OnMessageReceived(const IPC::Message& msg) {
#003
???
if (msg.routing_id() == MSG_ROUTING_CONTROL) {
#004
?????
OnControlMessageReceived(msg);
#005
???
} else {
#006
?????
RouteMessage(msg);
#007
???
}
#008
?
}
在這里又分為
MSG_ROUTING_CONTROL
消息和其它路由消息,再一次通過(guò)函數(shù)
RouteMessage
分發(fā)之后,如下:
#001
?
bool MessageRouter::RouteMessage(const IPC::Message& msg) {
#002
???
IPC::Channel::Listener* listener = routes_.Lookup(msg.routing_id());
#003
???
if (!listener)
#004
?????
return false;
#005
?
#006
???
listener->OnMessageReceived(msg);
#007
???
return true;
#008
?
}
上面這個(gè)函數(shù)里又把消息通過(guò)發(fā)送到
listener
里去,其實(shí)
listener
是根據(jù)消息的目標(biāo)
routing_id
來(lái)選擇的,那么就是說(shuō)它是選擇發(fā)送到不同的窗口里去,因?yàn)槊總€(gè)
TAB
一個(gè)窗口。消息經(jīng)過(guò)這樣的處理之后,就到達(dá)了終點(diǎn)地
---
RenderView::OnMessageReceived
函數(shù)。下一次再來(lái)分析
RenderView::OnMessageReceived
函數(shù)的代碼和后繼處理。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

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