necko walkthrough
TRANSCRIPT
Outline• Create protocol channel
• Listener interface
• Open protocol channel
• Data transaction
Protocol
URI Syntax<scheme name> : <hierarchical part> [ ? <query> ] [ # <fragment> ]
http : //google.com/search ? q=Mozilla
https : //www.facebook.com/pages/郝神好神/871866229523862
file : ///Downloads/郝神好帥.jpg
about : config
mailto : [email protected]
data : text/html;charset=utf-8;base64,6YOd56We5aW95bil
line : //shop/detail/xxx
Data Protocol
data:[<MIME-type>][;charset=<encoding>][;base64],<data>
A very simple protocol.
data:text/html;charset=utf-8;base64,6YOd56We5aW95bil
data:text/html;charset=utf-8;base64,6YOd56We5aW95bil
After base64 decoding…
Create Protocol Channel
handleCommand
openUILinkIn
openLinkIn
loadURIWithFlags (tabbrowser)
loadURIWithFlags (browser)
LoadURI(char16_t*, …)
LoadURIWithOptions
LoadURI(nsIURI*, …)
InternalLoad
DoURILoad
DoChannelLoad
NS_NewURI
NS_NewChannelInternal
Browser UI (XUL)
DocShell Necko
GetProtocolHandler
GetProtocolHandler
nsIURI
nsIChannel
NewURI
NewChannel2
GetProtocolHandler
1. Get protocol handler if it is cached.
2. Lookup in ‘about:config’ to check internal support.
3. For internal protocol, get internal protocol hander service and cache it.
4. For external protocol, get default external protocol handler service.
netwerk/base/nsIOService.cpp#406
data:text/html;charset=utf-8;base64,6YOd56We5aW95bil
GetProtocolHandler
nsDataHandler
nsSimpleURI nsDataChannel
NewURI() NewChannel2()
Protocol Handler API
Format the URI Create the channel Get flags
NewChannel2(…)
NewProxiedChannel2(…)
NewURI(…) GetProtocolFlags(…)
Internal protocol handler in /netwerk/protocol/
External protocol handler in about:config
Listener Interface
nsIStreamListener• onStartRequest()
• Called to signify the beginning of an asynchronous request.
• onStopRequest()
• Called to signify the end of an asynchronous request.
• onDataAvailable()
• This method is called when the next chunk of data for the ongoing request may be read without blocking the calling thread.
nsInputStreamPump… nsDataChannelnsHtml5StreamParser
OnStartRequest
OnStartRequest
OnStartRequest
OnDataAvailable
OnDataAvailable
OnDataAvailable
Read / ReadSegment
OnStopRequest
OnStopRequest
OnStopRequest
Open Protocol Channel
Initialize & Start
nsDataChannel
nsPipeInputStreamInitialize Stream & Pump
nsInputStreamPump
(event dispatcher)
(data source) notify on ready
create create
nsDocumentOpenInfo
nsDataChannel
nsInputStreamPump
Setup Listener Chain
listen
listen
notify
notify
Start Waiting nsInputStreamPump
nsDataChannel
nsPipeInputStream
AsyncRead()
AsyncWait()OnInputStreamReady()
Data Transaction
IDLE START
STOP TRANSFER
State of nsInputStreamPump
Must be in main thread!!
OnStateStart
OnStateStart
Create Content Viewer
nsDocShell
nsHTMLDocument
nsDocumentViewer
load
Set Content Listener
nsHtml5StreamParser
nsHtml5StreamListener
nsDocumentOpenInfo
listen
listen
notify
notify
nsDocumentOpenInfoCall OnStartRequest()
nsDataChannel
nsInputStreamPump
nsHtml5StreamParser
nsHtml5StreamListener
listen notify
listen notify
listen notify
listen notify
OnStateTransfer
OnStateTransfer
nsDocumentOpenInfoCall OnDataAvailable()
nsDataChannel
nsInputStreamPump
nsHtml5StreamParser
nsHtml5StreamListener
listen notify
listen notify
listen notify
listen notify
Read Data
nsPipeInputStream
Read/ReadSegment
nsHtml5StreamParser
nsPipeInputStream
data segment
nsHtml5StreamParser
parser buffer
temporal buffer
Call Read() in Main Thread
copy
dispatch to parser thread
nsPipeInputStream
data segment
nsHtml5StreamParser
parser buffer
Call ReadSegment() in Parser Thread
copy
OnStateStop
OnStateStop
nsDocumentOpenInfoCall OnStopRequest()
nsDataChannel
nsInputStreamPump
nsHtml5StreamParser
nsHtml5StreamListener
listen notify
listen notify
listen notify
listen notify
Thank you!