Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

nsIIOService

この翻訳は不完全です。英語から この記事を翻訳 してください。

This interface 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.
継承元: nsISupports 最終更新: Gecko 1.2

This interface duplicates many of the nsIProtocolHandler methods in a protocol handler independent way (For example newURI() inspects the scheme in order to delegate creation of the new URI to the appropriate protocol handler).

註: nsIIOService may only be used from the main thread.

Implemented by @mozilla.org/network/io-service;1 as a service:

var iOService = Components.classes["@mozilla.org/network/io-service;1"]
                .getService(Components.interfaces.nsIIOService);

メソッドの概要

boolean allowPort(in long aPort, in string aScheme);
ACString extractScheme(in AUTF8String urlString);
unsigned long getProtocolFlags(in string aScheme);
nsIProtocolHandler getProtocolHandler(in string aScheme);
nsIChannel newChannel(in AUTF8String aSpec, in string aOriginCharset, in nsIURI aBaseURI); 廃止 Gecko 48
nsIChannel newChannel2(in AUTF8String aSpec, in string aOriginCharset, in nsIURI aBaseURI, in nsIDOMNode aLoadingNode, in nsIPrincipal aLoadingPrincipal, in nsIPrincipal aTriggeringPrincipal, in uint32_t aSecurityFlags, in uint32_t aContentPolicyType);
nsIChannel newChannelFromURI(in nsIURI aURI); 廃止 Gecko 48
nsIChannel newChannelFromURI2(in nsIURI aURI, in nsIDOMNode aLoadingNode, in nsIPrincipal aLoadingPrincipal, in nsIPrincipal aTriggeringPrincipal, in unsigned long aSecurityFlags, in unsigned long aContentPolicyType);
nsIChannel newChannelFromURIWithLoadInfo(in nsIURI aURI, in nsILoadInfo aLoadInfo);
nsIChannel newChannelFromURIWithProxyFlags2(in nsIURI aURI, in nsIURI aProxyURI, in uint32_t aProxyFlags,in nsIDOMNode aLoadingNode, in nsIPrincipal aLoadingPrincipal, in nsIPrincipal aTriggeringPrincipal, in uint32_t aSecurityFlags, in uint32_t aContentPolicyType); Gecko 48 が必要
nsIURI newFileURI(in nsIFile aFile);
nsIURI newURI(in AUTF8String aSpec, in string aOriginCharset, in nsIURI aBaseURI);

属性

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.

メソッド

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.

Is similar to nsIProtocolHandler.allowPort().

boolean allowPort(
  in long aPort,
  in string aScheme
);
Parameters
aPort
The port to check
aScheme
The scheme for the protocol handler that could override the IOService's decision.
Return value

true if the port is allowed, false otherwise.

extractScheme()

Utility to extract the scheme from a URL string, consistently and according to spec (see RFC 3986).

註:  Most URL parsing is done via nsIURI, and in fact the scheme can also be extracted from a URL string via nsIURI. This method is provided purely as an optimization.

ACString extractScheme(
  in AUTF8String urlString
);
Parameters
urlString
The string for the URL to extract the scheme from.
Return value

A string corresponding to the scheme.

Exceptions thrown
NS_ERROR_MALFORMED_URI
If URL string is not of the right form.

getProtocolFlags()

Returns the protocol flags for a given scheme.

unsigned long getProtocolFlags(
  in string aScheme
);
Parameters
aScheme
The scheme for which to get the protocol flags.
Return value

The value of the protocolFlags attribute for the corresponding nsIProtocolHandler.

getProtocolHandler()

Returns a protocol handler for a given URI scheme.

nsIProtocolHandler getProtocolHandler(
  in string aScheme
);
Parameters
aScheme
The URI scheme for which to get a protocol handler.
Return value

An nsIProtocolHandler for the scheme.

newChannel()

廃止 Gecko 48
newURI()newChannelFromURI() の重複した呼び出しを避けるショートカットメソッドです。

nsIChannel newChannel(
  in AUTF8String aSpec,
  in string aOriginCharset,
  in nsIURI aBaseURI
);
Parameters
aSpec
希望するuriのためのスペックです。
aOriginCharset
uriのためのキャラクタセットです。たぶんnullになるでしょう。
aBaseURI
スペックのためベースURLです。たぶんnullになるでしょう。もしaSpecが相対パスだった時このパラメーターは無視されます。
Return value

Returns an nsIChannel based on aSpec and aBaseURI.

newChannel2()

newURI()newChannelFromURI()の再呼び出しを避けるためのショートカットメソッドです。

nsIChannel newChannel2(
   in AUTF8String aSpec,
   in string aOriginCharset,
   in nsIURI aBaseURI,
   in nsIDOMNode aLoadingNode,
   in nsIPrincipal aLoadingPrincipal,
   in nsIPrincipal aTriggeringPrincipal,
   in uint32_t aSecurityFlags,
   in uint32_t aContentPolicyType,

);
Parameters
aSpec

希望するuriのためのスペックです。

aOriginCharset
uriのためのキャラクタセットです。たぶんnullになるでしょう。
aBaseURI
スペックのためベースURLです。たぶんnullになるでしょう。もしaSpecが相対パスだった時このパラメーターは無視されます。
aLoadingNode
チャンネルのloadingDocumentです。この要素やドキュメントがリクエストの結果として使われるでしょう。これはこのリクエストへの結果としてアクセスされる要素やドキュメントです。例として画像をロードする場合、これはイメージがロードされるドキュメントになります。そしてCSSの場合、 レンダリングがこのスタイルシートに影響を与えられるキュメントになります。もし可能なら、ロードが実行される要素を渡します。しかしもしロードが XMLHttpRequestなどのJS API やforなどで複数の要素に渡って合体される場合は代わりにDocumentノードに渡します。ロードがアドオンや内部のブラウザ機能から来るようにロードがどんなドキュメントにも関連していない場合、nullを使います。
aLoadingPrincipal
チャンネルにロードするもののPrincipalです。 リクエストの結果としてこのドキュメントのprincipalが使用されます。 この値のデフォルトは aLoadingNode のprincipalです。そのため、もし aLoadingNode が渡された場合は、nullとして残すことができます。 しかし、aLoadingNode が null としてロードされている場合は、値を渡す必要があります。 例としてWebWorkerからロードする場合を考えてみます。この場合はworkerのprincipalを渡します。アドオンやブラウザ内部からロードする場合は、 system principalを渡します。This principal should almost always be the system principal if aLoadingNode is null. The only exception to this is for loads from WebWorkers since they don't have any nodes to be passed as aLoadingNode. Please note, aLoadingPrincipal is *not* the principal of the resource being loaded. But rather the principal of the context where the resource will be used.
aTriggeringPrincipal
The triggeringPrincipal of the load. The triggeringPrincipal is the principal of the resource that caused this particular URL to be loaded. Most likely the triggeringPrincipal and the loadingPrincipal are identical, in which case the triggeringPrincipal can be left out. In some cases the loadingPrincipal and the triggeringPrincipal are different however, e.g. a stylesheet may import a subresource. In that case the principal of the stylesheet which contains the import command is the triggeringPrincipal, and the principal of the document whose rendering is affected is the loadingPrincipal.
aSecurityFlags
このchannelのsecurityFlagsです。すべてのsecurityFlagsはnsILoadInfoで定義されています。
aContentPolicyType
このchannelのcontentPolicyTypeです。すべてのcontentPolicytypeはnsIContentPolicyで定義されています。
【訳注: アドオン開発者が暫定的に使う場合はTYPE_OTHERを使う。firefox開発者はTYPE_OTHERを使うのは避けるべきです】
【訳注: nsIContentPolicyがincludeしている nsIContentPolicyBase.idl に書いてあるっぽいです】
 
Return value

aSpecやaBaseURIに基づいた nsIChannel を返します

newChannelFromURI()

廃止 Gecko 48

与えられたURIのチャンネルを作成します

nsIChannel newChannelFromURI(
  in nsIURI aURI
);
Parameters
aURI
An nsIURI from which to make a channel.
Return value

An nsIChannel for the uri.

newChannelFromURI2()

Creates a channel for a given URI.

nsIChannel newChannelFromURI2(
  in nsIURI aURI,
  in nsIDOMNode aLoadingNode,
  in nsIPrincipal aLoadingPrincipal,
  in nsIPrincipal aTriggeringPrincipal,
  in unsigned long aSecurityFlags,
  in unsigned long aContentPolicyType
);

Please note, if you provide both a loadingNode and a loadingPrincipal, then loadingPrincipal must be equal to loadingNode->NodePrincipal(). But less error prone is to just supply a loadingNode.

Keep in mind that URIs coming from a webpage should never use the systemPrincipal as the loadingPrincipal.

Parameters
aURI
An nsIURI from which to make a channel.
aLoadingNode
The loadingDocument of the channel.
The element or document where the result of this request will be used. This is the document/element that will get access to the result of this request. For example for an image load, it's the document in which the image will be loaded. And for a CSS stylesheet it's the document whose rendering will be affected by the stylesheet. If possible, pass in the element which is performing the load. But if the load is coming from a JS API (such as XMLHttpRequest) or if the load might be coalesced across multiple elements (such as for <img>) then pass in the Document node instead.

For loads that are not related to any document, such as loads coming from addons or internal browser features, use null here.
aLoadingPrincipal                                                     
The loadingPrincipal of the channel.

The principal of the document where the result of this request will be used.

This defaults to the principal of aLoadingNode, so when aLoadingNode is passed this can be left as null. However for loads where aLoadingNode is null this argument must be passed.  For example for loads from a WebWorker, pass the principal of that worker. For loads from an addon or from internal browser features, pass the system principal. This principal should almost always be the system principal if aLoadingNode is null. The only exception to this is for loads from WebWorkers since they don't have any nodes to be passed as aLoadingNode. Please note, aLoadingPrincipal is *not* the principal of the resource being loaded. But rather the principal of the context here the resource will be used.
aTriggeringPrincipal                                                  
The triggeringPrincipal of the load.

The triggeringPrincipal is the principal of the resource that caused this particular URL to be loaded. Most likely the triggeringPrincipal and the loadingPrincipal are identical, in which case the triggeringPrincipal can be left out. In some cases the loadingPrincipal and the triggeringPrincipal are different however, e.g. a stylesheet may import a subresource. In that case the principal of the stylesheet which contains the import command is the triggeringPrincipal, and the principal of the document whose rendering is affected is the loadingPrincipal.
aSecurityFlags                                                        
The securityFlags of the channel. Any of the securityflags defined in nsILoadInfo.idl
aContentPolicyType                                                        
The contentPolicyType of the channel. Any of the content types defined in nsIContentPolicy.idl              
Return value

An nsIChannel for the uri.

newChannelFromURIWithLoadInfo()

Creates a channel for a given URI. Equivalent to newChannelFromURI2(aURI, aLoadingNode, ...)

nsIChannel newChannelFromURIWithLoadInfo(
  in nsIURI aURI,
  in nsILoadInfo aLoadInfo
);
Parameters
aURI
An nsIURI from which to make a channel.
aLoadInfo
A load info object.
Return value

An nsIChannel for the uri.

newChannelFromURIWithProxyFlags2()

Gecko 48 が必要
Creates a channel for a given URI. Equivalent to newChannelFromURI2(aURI, aLoadingNode, ...)

nsIChannel newChannelFromURIWithProxyFlags2(
  in nsIURI aURI,
  in nsIURI aProxyURI,
  in uint32_t aProxyFlags,
  in nsIDOMNode aLoadingNode,
  in nsIPrincipal aLoadingPrincipal,
  in nsIPrincipal aTriggeringPrincipal,
  in uint32_t aSecurityFlags,
  in uint32_t aContentPolicyType
);
Parameters
aURI
An nsIURI from which to make a channel.
aProxyURI
nsIURI to use for proxy resolution. Can be null in which case aURI is used.
aPorxyFlags
Flags from nsIProtocolProxyService to use when resolving proxies for this new channel.
aLoadingNode
The loadingDocument of the channel. The element or document where the result of this request will be used. This is the document/element that will get access to the result of this request. For example for an image load, it's the document in which the image will be loaded. And for a CSS stylesheet it's the document whose rendering will be affected by the stylesheet. If possible, pass in the element which is performing the load. But if the load is coming from a JS API (such as XMLHttpRequest) or if the load might be coalesced across multiple elements (such as for ) then pass in the Document node instead. For loads that are not related to any document, such as loads coming from addons or internal browser features, use null here.
aLoadingPrincipal
The loadingPrincipal of the channel. The principal of the document where the result of this request will be used. This defaults to the principal of aLoadingNode, so when aLoadingNode is passed this can be left as null. However for loads where aLoadingNode is null this argument must be passed. For example for loads from a WebWorker, pass the principal of that worker. For loads from an addon or from internal browser features, pass the system principal. This principal should almost always be the system principal if aLoadingNode is null. The only exception to this is for loads from WebWorkers since they don't have any nodes to be passed as aLoadingNode. Please note, aLoadingPrincipal is *not* the principal of the resource being loaded. But rather the principal of the context where the resource will be used.
aTriggeringPrincipal
The triggeringPrincipal of the load. The triggeringPrincipal is the principal of the resource that caused this particular URL to be loaded. Most likely the triggeringPrincipal and the loadingPrincipal are identical, in which case the triggeringPrincipal can be left out. In some cases the loadingPrincipal and the triggeringPrincipal are different however, e.g. a stylesheet may import a subresource. In that case the principal of the stylesheet which contains the import command is the triggeringPrincipal, and the principal of the document whose rendering is affected is the loadingPrincipal.
aSecurityFlags
The securityFlags of the channel. Any of the securityflags defined in nsILoadInfo.
aContentPolicyType
The contentPolicyType of the channel. Any of the content types defined in nsIContentPolicy.
Return value

An nsIChannel for the uri.

newFileURI()

This method constructs a new URI from a nsIFile.

nsIURI newFileURI(
  in nsIFile aFile
);
Parameters
aFile
The nsIFile whose URI is desired.
Return value

An nsIURI corresponding to the file.

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
);
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. If aSpec is an absolute URL, this parameter is ignored.
Return value

An nsIURI object corresponding to aSpec and aBaseURI.

Exceptions thrown
NS_ERROR_MALFORMED_URI
If URI does not begin with a valid scheme (as defined by RFC 3986) followed by a colon.

備考

註:  The proper way to create a new nsIURI is with newURI() method defined above. Do NOT create a new nsIURI with createInstance().

This was a frozen interface see バグ 157131 for details. From Gecko 2.0 interfaces are no longer frozen.

関連項目

ドキュメントのタグと貢献者

タグ: 
 このページの貢献者: lv7777
 最終更新者: lv7777,