O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

2

Compartilhar

Baixar para ler offline

Necko walkthrough

Baixar para ler offline

Necko walkthrough: take data protocol as example

Audiolivros relacionados

Gratuito durante 30 dias do Scribd

Ver tudo

Necko walkthrough

  1. 1. NECKO WALKTHROUGH (Data Protocol) Tommy Kuo [:KuoE0] kuoe0@mozilla.com 2015.04.23 @Mozilla Taiwan
  2. 2. Outline • Create protocol channel • Listener interface • Open protocol channel • Data transaction
  3. 3. Protocol
  4. 4. 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 : kuoe0@mozilla.com data : text/html;charset=utf-8;base64,6YOd56We5aW95bil line : //shop/detail/xxx
  5. 5. Data Protocol data:[<MIME-type>][;charset=<encoding>][;base64],<data> A very simple protocol.
  6. 6. data:text/html;charset=utf-8;base64,6YOd56We5aW95bil
  7. 7. data:text/html;charset=utf-8;base64,6YOd56We5aW95bil After base64 decoding…
  8. 8. Create Protocol Channel
  9. 9. 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
  10. 10. 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
  11. 11. data:text/html;charset=utf-8;base64,6YOd56We5aW95bil GetProtocolHandler nsDataHandler nsSimpleURI nsDataChannel NewURI() NewChannel2()
  12. 12. Protocol Handler API Format the URI Create the channel Get flags NewChannel2(…) NewProxiedChannel2(…) NewURI(…) GetProtocolFlags(…)
  13. 13. Protocol Handler Internal External lookup in /netwerk/protocol/ lookup in about:config
  14. 14. Internal protocol handler in /netwerk/protocol/
  15. 15. External protocol handler in about:config
  16. 16. Listener Interface
  17. 17. 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.
  18. 18. nsInputStreamPump… nsDataChannelnsHtml5StreamParser OnStartRequest OnStartRequest OnStartRequest OnDataAvailable OnDataAvailable OnDataAvailable Read / ReadSegment OnStopRequest OnStopRequest OnStopRequest
  19. 19. Open Protocol Channel
  20. 20. Initialize & Start
  21. 21. nsDataChannel nsPipeInputStreamInitialize Stream & Pump nsInputStreamPump (event dispatcher) (data source) notify on ready create create
  22. 22. nsDocumentOpenInfo nsDataChannel nsInputStreamPump Setup Listener Chain listen listen notify notify
  23. 23. Start Waiting nsInputStreamPump nsDataChannel nsPipeInputStream AsyncRead() AsyncWait()OnInputStreamReady()
  24. 24. Data Transaction
  25. 25. IDLE START STOP TRANSFER State of nsInputStreamPump Must be in main thread!!
  26. 26. OnStateStart
  27. 27. OnStateStart
  28. 28. Create Content Viewer nsDocShell nsHTMLDocument nsDocumentViewer load
  29. 29. Set Content Listener nsHtml5StreamParser nsHtml5StreamListener nsDocumentOpenInfo listen listen notify notify
  30. 30. nsDocumentOpenInfoCall OnStartRequest() nsDataChannel nsInputStreamPump nsHtml5StreamParser nsHtml5StreamListener listen notify listen notify listen notify listen notify
  31. 31. OnStateTransfer
  32. 32. OnStateTransfer
  33. 33. nsDocumentOpenInfoCall OnDataAvailable() nsDataChannel nsInputStreamPump nsHtml5StreamParser nsHtml5StreamListener listen notify listen notify listen notify listen notify
  34. 34. Read Data nsPipeInputStream Read/ReadSegment nsHtml5StreamParser
  35. 35. nsPipeInputStream data segment nsHtml5StreamParser parser buffer temporal buffer Call Read() in Main Thread copy dispatch to parser thread
  36. 36. nsPipeInputStream data segment nsHtml5StreamParser parser buffer Call ReadSegment() in Parser Thread copy
  37. 37. OnStateStop
  38. 38. OnStateStop
  39. 39. nsDocumentOpenInfoCall OnStopRequest() nsDataChannel nsInputStreamPump nsHtml5StreamParser nsHtml5StreamListener listen notify listen notify listen notify listen notify
  40. 40. Thank you!
  • FarmerTseng

    Apr. 26, 2016
  • YiFanLiao

    Apr. 18, 2016

Necko walkthrough: take data protocol as example

Vistos

Vistos totais

969

No Slideshare

0

De incorporações

0

Número de incorporações

5

Ações

Baixados

7

Compartilhados

0

Comentários

0

Curtir

2

×