firefox necko

The Mozilla networking library provides cross-platform networking functionality.

https://developer.mozilla.org/en-US/docs/Necko

necko Arch:

https://developer.mozilla.org/en-US/docs/Necko\_Architecture

下面这个文档比较清楚的介绍了necko的结构。life of a request.

以下摘自上面的这篇PPT:

A channel is constructed from an URI. It represents a logical connection to the URI.

A client “opens” a channel to fetch its URI (nsIChannel::asyncOpen).

nsIIOService provides mapping from scheme to registered nsIProtocolHandler.

Each protocol has a nsIProtocolHandler implementation (per scheme), which provides:

interface nsIProtocolHandler {
nsIURI newURI(in string spec, in nsIURI baseURI);
nsIChannel newChannel(in nsIURI uri);
};
Client passes their nsIStreamListener impl to asyncOpen(), StreanListerner 看起来是这样:

interface nsIStreamListener {
void onStartRequest(…);
void onDataAvailable(…, in nsIInputStream data, …);
void onStopRequest(…, in nsresult status);
};

fetch URL sample:
class MyListener : public nsIStreamListener { /* … */ }
nsCOMPtr<nsIIOService> ioserv(
do_GetService(“@mozilla.org/network/io-service;1”) );
nsCOMPtr<nsIURI> uri;
nsCOMPtr<nsIChannel> chan;

ioserv->NewURI(“http://www.mozilla.org/”, getter_AddRefs(uri));
ioserv->NewChannel(uri, getter_AddRefs(chan));

chan->AsyncOpen(new MyListener(), nsnull);

 



本文地址: http://www.bagualu.net/wordpress/archives/3474 转载请注明




发表评论

电子邮件地址不会被公开。 必填项已用*标注