firefox(Mozilla)分析











.Firefox(Mozilla) 框架
層次:
1.0 最底層:跨平臺操作系統實用功能封裝,或稱爲虛擬操作系統(例如OpenOffice)或稱爲操作系統(平臺)適配器。叫什麼沒有關係,基本意思理解就可以了。我認爲對應模塊有:
·NSPR(io,thread,memory等)
·Gecko(?圖形圖象顯示輸出或渲染引擎,GUI模塊--平臺封裝的widget[窗口和控件]+gfx[圖形圖象處理--每個平臺都有其具體實現,包括font,color,image,繪圖原語]),類似cairo圖形庫作用。see NGLayout or layout(依據CSS style layout,but not render html/xml tag contents)|content模塊。
widget:Primitive user interface part (button, menu, radiobutton, etc). There are two kinds of widgets: Native and gfx. Native widgets are implemented differently for each platform, but gfx widgets are implemented using gfx and is thus the same for all platforms.
·Necko[SSL外都是應用層協議如nntp/ldap/about/res/file/ftp/http/pop3/smtp/Imap等協議],ldap sdk在模塊directory中
1.1 中間核心層:XPCOM,類似UNO,COM,Corba等組件模型。我簡單看了看源代碼與OpenOffice的UNO組件相關代碼封裝很類似。
·常見的XPCOM組件爲第三方提供的Add-ons(插件[plug-in,固定實現接口,源碼參見modules/plugin等]和(擴展+主題)[extension+theme,無固定接口要求,通常用來構件不同的UI界面及其相關應用,源碼參見extension目錄])
toolkit(XUL相關東東)xpfe?區別
1.2 Chrome(user GUI統稱):對應文件是各種chrome/*.jar及其xpcom組件(動態庫or js,模塊名稱通常在地址欄中可見:chrome://xxx/content/..xul)-->其中實現射擊技術有:XUL[負責UI界面總體框架,use xul to specify the static layout of the UI elements.Can use "overlays" to add new(or replace) UI elements to existings.use CSS to specify UI elements's format style],XBl[UI界面框架內的基本UI元素]、JS[glue膠合或連接(通過XPConnect--也就是通常說的橋bridge,橋接兩端不同代碼--也可以稱之爲雙向解釋器或編譯器)UI行爲響應到內部XPCOM代碼--多數爲C++代碼.use javascript to spcify how each of the elements interacts]、CSS and RDF(dtd)[表達UI顯示效果]、DOM[html/xml文檔操作接口]等。類似XAML作用,參考MS .NET表現層類庫。
XPConnect:Ability to call C++ implementations of interfaces expressed in IDL from JavaScript and vice versa.
XPFEThe cross-platform front end(toolkit). The part of Mozilla that implements the user interface of Mozilla. Everything that makes a browser except the rendering of pages is considered xpfe (bookmarks, toolbars, menus etc).
2.firefox(Mozilla)開發重要術語
·XP:Cross-Platform。XPCOM:Cross Platform Component Object Model
·cotent node:內容節點。對應html/xml中元素,可由DOM操縱content tree。
·ASN.1--Abstract Syntax Notation One PKCS安全相關--是否也可以用在idl中呢?
·frame--文檔底層佈局對象(所有這些不同層次的frame就代表了一篇佈局好的文檔),負責html/xml節點內容或元素的繪製,通常對應一到多個content node[每個元素在CSS中稱爲box--有元素自身高寬+padding+margin+border,通常這些屬性都不顯示出來,又多數採用div方式使用]-->CSS Box
·webshell:A container that knows how to load and render web pages. Frameset pages has a root webshell and one webshell per frame(注意這個是html frame框架,not前面提到的frame) .應該這個webshell中可以訪問前面提到的所有frame對象(frame heriarchy),?webPage與document區別?
·presentation shell:Presentation shells are the controlling object during the presentation of a document. It owns the document, the frame hierarchy, stylesheets and the presentation context. It also controls and initiates the reflow of the document.
·reflow:The act of laying out the content tree and creating/updating the corresponding frame hierarchy is called reflowing.注意這個update更新--例如DOM寫、修改操作。
·reflow mapped:Reflowing content that already has a framereflow unmapped:Reflowing content that doesn't yet have a frame. see layout模塊
·service:A component that is used as a singleton. That means there exist only one instantiation of the Component, and all request for it returns the same object.這個應該與UNO service基本類似.
·XIF:XML Interchange Format - used internally by NGLayout for all I/O to clipboard, etc. 通用clipboard XML交換格式--封裝所有其他格式到不同的tags?
·XRE:XUL Runtime Engine--init XUL Toolkit?.
此外還需要看看英文版本的幫助文檔--瞭解基本名詞術語等。--例如feed
3.firefox(Mozilla)源碼目錄結構簡述另外參見
·基本結構模式(scheme):首先是頂層產品目錄名如mozilla(TopLevelName--注意下載源碼包後千萬不要將直接將這個目錄下的各種模塊解壓到某個目錄下,否則是無論如何也無法編譯的!也就是這些子模塊的父目錄一定要是這個產品名目錄--稱爲$toplevel);然後是各模塊目錄;各模塊目錄下的目錄遵循原則是能獨立成爲子模塊的就獨立門戶,如此迭代下去。每個模塊下可能存在如下一些常見的目錄名稱:
1.base:該模塊基礎或核心代碼(basic or core source),無法再獨立門戶,大家享用的.--example:docshell模塊。
2.build:編譯特殊模塊所包含的特殊makefile and some sources。--example: intl or docshell等模塊。
3.doc:模塊相關的文檔.example:xpcom|layout模塊。
4.idl+public:基本上是公用頭文件(包括idl間接被編譯後的頭文件),我想public中還混合有idl文件,莫非以後public下的公用頭文件也可能被idl取代之意?example:gfx,editor,dom等模塊。
5.src:cpp,c,h,hxx文件。example:widget模塊。
6.test:該模塊測試代碼或相關html,xul等文件。example:gfx模塊。
7.tools:編譯某些特殊模塊用的工具以及自動產生某些代碼的perl腳本。example:layout模塊
8.平臺相關模塊目錄:windows/mac/gtk/motif/qt/os2+beOS/photon/rhapdody等
9.其他你所見到的目錄名稱基本上都是子模塊名稱+other。
·源碼目錄
browser--firefox可執行程序入口(app/nsBrowserApp.cpp),base/下內容就包含在著名的browser.jar[XUL]中,其中另外一部分在components中。
accessible--輔助功能模塊。例如MS Control Panel's "輔助功能選項"--幫助文檔中也有說明。支持Microsoft Active Accessibility and Sun's ATK accessibility API for Linux.另外請查看該模塊下的accessible-docs.html.非核心模塊。
build+config--相當與openOffice的config_office+solenv兩個模塊,用來搭建編譯環境和提供編譯具體模塊代碼時所需要的信息(如各種通用編譯選項等makefile文件等)。都包含n多perl腳本。firefox(mozilla)的這兩個模塊組織的相對雜亂不容易理解。
calendar--各種日曆應用和擴展。非核心模塊。
caps--webpage安全管理(安全設置和認證)相關模塊.
chrome--chrome://協議、工廠、註冊相關代碼。--toolkit範疇。模塊代碼少。
content+layout--dom所需對象+佈局引擎(依據CSS1+2式樣單來佈置(not render繪製)所有內容(html/xml/xul/xsl/xbl/svg/xtf等文件內容)--對應各自的窗口。即reflow==NGLayout or Gecko)
db--mdb/mork + sqlite3數據庫--郵件+歷史+新聞數據的存儲與訪問。拿來主義--本身跨平臺。openoffice使用berkely DB訪問幫助文檔數據庫文件。also see mozilla mail architecture
directory--ldap C語言SDK及其XPCOM封裝。also see file:draft-ietf-ldapext-ldap-c-api-05.txt. openoffice also support ldap.
docshell->embedding->webshell: 想要將firefox(Mozilla)嵌入在其它應用程序中或定製一個新的瀏覽器請使用接口nsIWebBrowserChrome,而且該瀏覽器窗口還可以是模式(Modal)。

·查找服務html_frames[or iframes: attribute nsIDOMWindow currentSearchFrame/rootSearchFrame;] in the content area.
·JSConsoleService控制檯服務: nsIWindowWatcher->OpenWindow(Parent_nsIDOMWindow,console_chrome_url,"_blank",console_window_options,nsnull,getter_AddRefs(consloeWindow_nsIDOMWindow));
//static const char console_chrome_url[] = "chrome://global/content/console.xul";
//static const char console_window_options[] = "dialog=no,close,chrome,menubar,toolbar,resizable";
·TopLevel(通常可以與nsIWebBrowserChrome互相map--!一對!) Gecko/DOM Windows Watcher or keeper[但不保留對這些窗口的引用--no ownership,only weakReference--當這些窗口create or destory時需要主動通知notify該watcher:注意如果別的應用程序內嵌該瀏覽器時通常該程序不需要做此事]: 有activeWindow屬性;必須在瀏覽器啓動時通過setWindowCreator初始化一個nsIWindowCreator,之後就可以通過它來打開或創建新的各種JS window.open.
::)DOMWindow->ScriptGlobalObject->GetDocShell->items->owner->WebBrowserChrome(Maybe EmbeddingSiteWindow->GetSiteWindow)->BaseWindow->MainWidget->GetNativeData(例如HWND/Window等)
·print打印:PrintDlg[Ex](windows平臺)-LPDEVMODE.
·chrome://global/content/nsHelperAppDlg.xul--打開一個特殊文檔時UI,採用js編寫的XPCOM組件nsHelperAppDlg.js.
·chrome://global/content/nsProgressDialog.xul--自動下載進度控制對話框。nsProgressDialog.js。
IPC--search"進程間通信"
modules--各種壓縮格式庫(Mar--Mozilla Archive,用於更新包,包中文件採用bzip2壓縮,其它jar+zlib,九州的壓寶今後可以加入近來啊);支持的各種圖像庫(png,jpg,bmp[含ico],gif,xbm--x-bitmap)+libprOn+libimg目錄中。還有:
·應用程序配置(或偏好)設置修改訪問模塊preference. about:config即可更改配置文件[*.js文件(一種特殊的javascript腳本文件),位置在grepref+default/pref中*.js,用戶修改後的單獨存儲在用戶配置目錄下的pref.js文件中--分系統和用戶兩部分獨立數據];配置數據範圍很廣:not only選項...中的設置。閱讀這些js文件即可發現。這些配置(或偏好)數據採用tree層次方式管理,入口點preferenceService->prefBranch(訪問各分枝節點數據);還可以增加對這些數據的變動進行動態觀察以反映到不同的窗口等對象中。觀察者和數據訪問對象通常都是弱引用對象[避免loop引用無法釋放]。
gfx(gkgfx.dll等)--2d幾何圖形如矩形(nsRect、nsRegion)、圖象(gfxIImageFrame)、打印設置(PrintSetting)、字體(Font)、設備上下文等對象(此外還包括類似nsColor,nsColorName[s-147個css顏色名稱]等相關對象)及其基本操作(如矩形的交集、合集等基本操作--好象初中就會過其基本概念)----注意它們與os提供的幾何繪圖函數一點關係都沒有。ooo中所有的基本都在vcl中實現(幾何圖形+窗口部件)。
see my mozilla gfx architcture
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章