Open-Source Wikis

/

Gecko

/

Primitives

/

Channel and Request

mozilla/gecko-dev

Channel and Request

The unifying primitive for "a network fetch in progress" is nsIChannel plus its base interface nsIRequest. Every network operation, from HTTP fetches to data: URLs to extension-injected resources, is a channel.

The interfaces

Interface File Role
nsIRequest netwerk/base/nsIRequest.idl Base type with name, status, suspend/resume
nsIChannel netwerk/base/nsIChannel.idl Adds URI, contentType, contentLength, async open
nsIHttpChannel netwerk/protocol/http/nsIHttpChannel.idl HTTP-specific (headers, method)
nsIStreamListener netwerk/base/nsIStreamListener.idl Receives OnStartRequest/OnDataAvailable/OnStopRequest

Lifecycle

sequenceDiagram
    participant Client
    participant Channel as nsIChannel
    participant Listener as nsIStreamListener
    Client->>Channel: AsyncOpen(listener)
    Channel-->>Listener: OnStartRequest
    Channel-->>Listener: OnDataAvailable(stream, offset, count) (×N)
    Channel-->>Listener: OnStopRequest(status)

Creating a channel

nsCOMPtr<nsIIOService> ios = mozilla::services::GetIOService();
nsCOMPtr<nsIChannel> channel;
ios->NewChannel(uri, /* loadingPrincipal */, /* securityFlags */,
                /* contentPolicyType */, getter_AddRefs(channel));
channel->AsyncOpen(listener);

The nsIIOService figures out which protocol handler creates the right channel.

LoadInfo

Every channel has an nsILoadInfo carrying provenance metadata: who triggered the load, the loading principal, the security flags, the content policy type, the cookie behavior. This is the security context for the request and is propagated cross-process.

Cross-process

A channel can be initiated in a content process; necko transparently shifts the heavy work to the parent or socket process. The IPC plumbing (PNeckoChild, PNeckoParent, HttpChannelChild, HttpChannelParent) lives under netwerk/ipc/ and netwerk/protocol/http/.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Channel and Request – Gecko wiki | Factory