firefox necko

The Mozilla networking library provides cross-platform networking functionality.

necko Arch:\_Architecture

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


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(“;1”) );
nsCOMPtr<nsIURI> uri;
nsCOMPtr<nsIChannel> chan;

ioserv->NewURI(“”, getter_AddRefs(uri));
ioserv->NewChannel(uri, getter_AddRefs(chan));

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


本文地址: 转载请注明


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