Necko walkthrough

Embed Size (px)

Text of Necko walkthrough

  • NECKO WALKTHROUGH

    (Data Protocol)

    Tommy Kuo [:KuoE0] kuoe0@mozilla.com

    2015.04.23 @Mozilla Taiwan

  • Outline Create protocol channel

    Listener interface

    Open protocol channel

    Data transaction

  • Protocol

  • URI Syntax : [ ? ] [ # ]

    http : //google.com/search ? q=Mozilla

    https : //www.facebook.com/pages//871866229523862

    file : ///Downloads/.jpg

    about : config

    mailto : kuoe0@mozilla.com

    data : text/html;charset=utf-8;base64,6YOd56We5aW95bil

    line : //shop/detail/xxx

  • Data Protocol

    data:[][;charset=][;base64],

    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()

  • Protocol Handler

    Internal External

    lookup in /netwerk/protocol/ lookup in about:config

  • 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!