nsIIOService
From MDC
The nsIIOService interface provides a set of network utility functions.
This interface duplicates many of the nsIProtocolHandler methods in a protocol handler independent way (e.g., the nsIIOService.newURI() method inspects the scheme in order to delegate creation of the new URI to the appropriate protocol handler).
nsIIOService also provides a set of URL parsing utility functions. These are provided as a convenience to the programmer and in some cases to improve performance by eliminating intermediate data structures and interfaces.
Contents |
nsIIOService is defined in netwerk/base/public/nsIIOService.idl. It is scriptable and
has been frozen since Mozilla 1.2.
See bug 157131 for details.
Inherits from: nsISupports
Implemented by @mozilla.org/network/io-service;1 as a service:
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
nsIIOService may only be used from the main thread.[edit] Method Overview
nsIProtocolHandler getProtocolHandler(in string aScheme);
|
unsigned long getProtocolFlags(in string aScheme);
|
nsIURI newURI(in AUTF8String spec, in string originCharset, in nsIURI baseURI);
|
nsIURI newFileURI(in nsIFile aFile);
|
nsIChannel newChannelFromURI(in nsIURI aURI);
|
nsIChannel newChannel(in AUTF8String aSpec, in string aOriginCharset, in nsIURI aBaseURI);
|
boolean allowPort(in long aPort, in string aScheme);
|
ACString extractScheme(in AUTF8String urlString);
|
[edit] Attributes
| Attribute | Type | Description |
offline
| boolean
| Returns true if networking is in "offline" mode. When in offline mode, attempts to access the network will fail (although this does not necessarily correlate with whether there is actually a network available -- that's hard to detect without causing the dialer to come up). Observers will be notified of changes to this attribute. |
[edit] Methods
[edit] getProtocolHandler()
Returns a protocol handler for a given URI scheme.
nsIProtocolHandler getProtocolHandler( in string aScheme );
[edit] Parameters
- aScheme
The URI scheme for which to get a protocol handler.
[edit] Return value
An nsIProtocolHandler for the scheme.
[edit] getProtocolFlags()
Returns the protocol flags for a given scheme.
unsigned long getProtocolFlags( in string aScheme );
[edit] Parameters
- aScheme
The scheme for which to get the protocol flags.
[edit] Return value
The value of the protocolFlags attribute for the corresponding nsIProtocolHandler.
[edit] newURI()
This method constructs a new URI by determining the scheme of the URI spec, and then delegating the construction of the URI to the protocol handler for that scheme. QueryInterface can be used on the resulting URI object to obtain a more specific type of URI.
nsIURI newURI( in AUTF8String aSpec, in string aOriginCharset, in nsIURI aBaseURI );
[edit] Parameters
- aSpec
The spec for the desired uri.
- aOriginCharset
The charset for the uri. May be null.
- aBaseURI
The base uri for the spec. May be null.
[edit] Return value
An nsIURI object corresponding to aSpec and aBaseURI.
[edit] newFileURI()
Constructs a new nsIURI object from an nsIFile object.
nsIURI newFileURI( in nsIFile aFile );
[edit] Parameters
- aFile
The file whose URI is desired.
[edit] Return value
An nsIURI corresponding to the file.
[edit] newChannelFromURI()
Creates a channel for a given URI.
nsIChannel newChannelFromURI( in nsIURI aURI );
[edit] Parameters
- aURI
The URI for the channel
[edit] Return value
An nsIChannel for the uri.
[edit] newChannel()
A shortcut method to avoid repeated calls of newURI() and newChannelFromURI().
nsIChannel newChannel( in AUTF8String aSpec, in string aOriginCharset, in nsIURI aBaseURI );
For parameter information, see the newURI() method.
[edit] Return value
Returns an nsIChannel based on aSpec and aBaseURI.
[edit] allowPort()
Checks if a port number is banned. This involves consulting a list of unsafe ports, corresponding to network services that may be easily exploitable. If the given port is considered unsafe, then the protocol handler (corresponding to aScheme) will be asked whether it wishes to override the IO service's decision to block the port. This gives the protocol handler ultimate control over its own security policy while ensuring reasonable, default protection.
boolean allowPort( in long aPort, in string aScheme );
[edit] Parameters
- aPort
The port to check
- aScheme
The scheme for the protocol handler that could override the IOService's decision.
[edit] Return value
Returns true if the port is allowed, false otherwise.
See also nsIProtocolHandler::allowPort().
[edit] extractScheme()
Utility method to extract the scheme from a URL string, consistently and according to spec (see RFC 2396).
ACString extractScheme( in AUTF8String urlString );
[edit] Parameters
- urlString
The string for the URL to extract the scheme from
[edit] Return value
A string corresponding to the scheme.
[edit] Notes
The proper way to create a new nsIURI is with newURI() method defined above. Do NOT create a new nsIURI with createInstance().
[edit] See Also
- Auto-generated XULPlanet documentation: nsIIOService.