1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include
"nsISupports.idl"
7 #include
"nsIContentPolicy.idl"
9 interface nsIProtocolHandler
;
13 interface nsIPrincipal
;
14 interface nsILoadInfo
;
15 interface nsIWebTransport
;
20 #include
"mozilla/Maybe.h"
25 class ServiceWorkerDescriptor
;
27 } // namespace mozilla
30 [ref] native const_MaybeClientInfoRef
(const mozilla
::Maybe<mozilla
::dom
::ClientInfo
>);
31 [ref] native const_MaybeServiceWorkerDescriptorRef
(const mozilla
::Maybe<mozilla
::dom
::ServiceWorkerDescriptor
>);
34 * nsIIOService provides a set of network utility functions. This interface
35 * duplicates many of the nsIProtocolHandler methods in a protocol handler
36 * independent way (e.g., NewURI inspects the scheme in order to delegate
37 * creation of the new URI to the appropriate protocol handler). nsIIOService
38 * also provides a set of URL parsing utility functions. These are provided
39 * as a convenience to the programmer and in some cases to improve performance
40 * by eliminating intermediate data structures and interfaces.
42 [scriptable
, builtinclass
, uuid(4286de5a
-b2ea
-446f
-8f70
-e2a461f42694
)]
43 interface nsIIOService
: nsISupports
46 * Returns a protocol handler for a given URI scheme.
48 * @param aScheme the URI scheme
49 * @return reference to corresponding nsIProtocolHandler
51 nsIProtocolHandler getProtocolHandler
(in string aScheme
);
54 * Returns the protocol flags for a given scheme.
56 * @param aScheme the URI scheme
57 * @return protocol flags for the corresponding protocol
59 unsigned long getProtocolFlags
(in string aScheme
);
62 * Returns the dynamic protocol flags for a given URI.
64 * @param aURI the URI to get all dynamic flags for
65 * @return protocol flags for that URI
67 unsigned long getDynamicProtocolFlags
(in nsIURI aURI
);
70 * Returns the default port for a given scheme.
72 * @param aScheme the URI scheme
73 * @return default port for the corresponding protocol
75 long getDefaultPort
(in string aScheme
);
78 * This method constructs a new URI based on the scheme of the URI spec.
79 * QueryInterface can be used on the resulting URI object to obtain a more
80 * specific type of URI.
82 nsIURI newURI
(in AUTF8String aSpec
,
83 [optional] in string aOriginCharset
,
84 [optional] in nsIURI aBaseURI
);
87 * This method constructs a new URI from a nsIFile.
89 * @param aFile specifies the file path
90 * @return reference to a new nsIURI object
92 * Note: in the future, for perf reasons we should allow
93 * callers to specify whether this is a file or directory by
94 * splitting this into newDirURI() and newActualFileURI().
96 nsIURI newFileURI
(in nsIFile aFile
);
99 * Converts an internal URI (e.g. one that has a username and password in
100 * it) into one which we can expose to the user, for example on the URL bar.
102 * @param aURI The URI to be converted.
103 * @return nsIURI The converted, exposable URI.
105 nsIURI createExposableURI
(in nsIURI aURI
);
108 * Creates a channel for a given URI.
111 * nsIURI from which to make a channel
112 * @param aLoadingNode
113 * @param aLoadingPrincipal
114 * @param aTriggeringPrincipal
115 * @param aSecurityFlags
116 * @param aContentPolicyType
117 * These will be used as values for the nsILoadInfo object on the
118 * created channel. For details, see nsILoadInfo in nsILoadInfo.idl
119 * @return reference to the new nsIChannel object
121 * Please note, if you provide both a loadingNode and a loadingPrincipal,
122 * then loadingPrincipal must be equal to loadingNode->NodePrincipal().
123 * But less error prone is to just supply a loadingNode.
125 * Keep in mind that URIs coming from a webpage should *never* use the
126 * systemPrincipal as the loadingPrincipal.
128 nsIChannel newChannelFromURI
(in nsIURI aURI
,
129 in Node aLoadingNode
,
130 in nsIPrincipal aLoadingPrincipal
,
131 in nsIPrincipal aTriggeringPrincipal
,
132 in unsigned long aSecurityFlags
,
133 in nsContentPolicyType aContentPolicyType
);
135 [noscript
, nostdcall
, notxpcom
]
136 nsresult NewChannelFromURIWithClientAndController
(in nsIURI aURI
,
137 in Node aLoadingNode
,
138 in nsIPrincipal aLoadingPrincipal
,
139 in nsIPrincipal aTriggeringPrincipal
,
140 in const_MaybeClientInfoRef aLoadingClientInfo
,
141 in const_MaybeServiceWorkerDescriptorRef aController
,
142 in unsigned long aSecurityFlags
,
143 in nsContentPolicyType aContentPolicyType
,
144 in unsigned long aSandboxFlags
,
145 out nsIChannel aResult
);
148 * Equivalent to newChannelFromURI(aURI, aLoadingNode, ...)
150 nsIChannel newChannelFromURIWithLoadInfo
(in nsIURI aURI
,
151 in nsILoadInfo aLoadInfo
);
154 * Equivalent to newChannelFromURI(newURI(...))
156 nsIChannel newChannel
(in AUTF8String aSpec
,
157 in string aOriginCharset
,
159 in Node aLoadingNode
,
160 in nsIPrincipal aLoadingPrincipal
,
161 in nsIPrincipal aTriggeringPrincipal
,
162 in unsigned long aSecurityFlags
,
163 in nsContentPolicyType aContentPolicyType
);
166 * Creates a WebTransport.
168 nsIWebTransport newWebTransport
();
172 * Calls GetOriginAttributesForNetworkState
173 * see StoragePrincipalHelper.h
176 jsval originAttributesForNetworkState
(in nsIChannel aChannel
);
179 * Returns true if networking is in "offline" mode. When in offline mode,
180 * attempts to access the network will fail (although this does not
181 * necessarily correlate with whether there is actually a network
182 * available -- that's hard to detect without causing the dialer to
185 * Changing this fires observer notifications ... see below.
187 attribute
boolean offline
;
190 * Returns false if there are no interfaces for a network request
192 readonly attribute
boolean connectivity
;
195 * Checks if a port number is banned. This involves consulting a list of
196 * unsafe ports, corresponding to network services that may be easily
197 * exploitable. If the given port is considered unsafe, then the protocol
198 * handler (corresponding to aScheme) will be asked whether it wishes to
199 * override the IO service's decision to block the port. This gives the
200 * protocol handler ultimate control over its own security policy while
201 * ensuring reasonable, default protection.
203 * @see nsIProtocolHandler::allowPort
205 boolean allowPort
(in long aPort
, in string aScheme
);
208 * Utility to extract the scheme from a URL string, consistently and
209 * according to spec (see RFC 2396).
211 * NOTE: Most URL parsing is done via nsIURI, and in fact the scheme
212 * can also be extracted from a URL string via nsIURI. This method
213 * is provided purely as an optimization.
215 * @param aSpec the URL string to parse
216 * @return URL scheme, lowercase
218 * @throws NS_ERROR_MALFORMED_URI if URL string is not of the right form.
220 ACString extractScheme
(in AUTF8String urlString
);
223 * Checks if a URI host is a local IPv4 or IPv6 address literal.
225 * @param nsIURI the URI that contains the hostname to check
226 * @return true if the URI hostname is a local IP address
228 boolean hostnameIsLocalIPAddress
(in nsIURI aURI
);
231 * Checks if a URI host is a shared IPv4 address literal.
233 * @param nsIURI the URI that contains the hostname to check
234 * @return true if the URI hostname is a shared IP address
236 boolean hostnameIsSharedIPAddress
(in nsIURI aURI
);
238 /* Checks if a URI host is a INADDR_ANY
240 * @param nsIURI the URI that contains the hostname to check
241 * @return true if the URI hostname is a INADDR_ANY
243 boolean hostnameIsIPAddressAny
(in nsIURI aURI
);
247 * Checks if characters not allowed in DNS are present in the hostname
248 * and if the hostname ends in a number it also checks if it's a valid
249 * IPv4 address. Any failure indicates that parsing this host will fail at a
250 * later point when using it in the URL parser.
252 * @param AUTF8String hostname is the hostname to validate
253 * @return true if the hostname is valid, else false
255 boolean isValidHostname
(in AUTF8String hostname
);
258 * While this is set, IOService will monitor an nsINetworkLinkService
259 * (if available) and set its offline status to "true" whenever
262 * Applications that want to control changes to the IOService's offline
263 * status should set this to false, watch for network:link-status-changed
264 * broadcasts, and change nsIIOService::offline as they see fit. Note
265 * that this means during application startup, IOService may be offline
266 * if there is no link, until application code runs and can turn off
269 attribute
boolean manageOfflineStatus
;
272 * Creates a channel for a given URI.
275 * nsIURI from which to make a channel
277 * nsIURI to use for proxy resolution. Can be null in which
279 * @param aProxyFlags flags from nsIProtocolProxyService to use
280 * when resolving proxies for this new channel
281 * @param aLoadingNode
282 * @param aLoadingPrincipal
283 * @param aTriggeringPrincipal
284 * @param aSecurityFlags
285 * @param aContentPolicyType
286 * These will be used as values for the nsILoadInfo object on the
287 * created channel. For details, see nsILoadInfo in nsILoadInfo.idl
288 * @return reference to the new nsIChannel object
290 * Please note, if you provide both a loadingNode and a loadingPrincipal,
291 * then loadingPrincipal must be equal to loadingNode->NodePrincipal().
292 * But less error prone is to just supply a loadingNode.
294 nsIChannel newChannelFromURIWithProxyFlags
(in nsIURI aURI
,
296 in unsigned long aProxyFlags
,
297 in Node aLoadingNode
,
298 in nsIPrincipal aLoadingPrincipal
,
299 in nsIPrincipal aTriggeringPrincipal
,
300 in unsigned long aSecurityFlags
,
301 in nsContentPolicyType aContentPolicyType
);
304 * Return true if socket process is launched.
306 readonly attribute
boolean socketProcessLaunched
;
309 * The pid for socket process.
311 readonly attribute
unsigned long long socketProcessId
;
314 * Register a protocol handler at runtime, given protocol flags and a
317 * Statically registered protocol handlers cannot be overridden, and an
318 * error will be returned if that is attempted.
320 * Runtime registered protocol handlers are never QueryInterface-ed into
321 * `nsIProtocolHandlerWithDynamicFlags`, so that interface will be ignored.
323 * @param aScheme the scheme handled by the protocol handler.
324 * @param aHandler the protocol handler instance.
325 * @param aProtocolFlags protocol flags for this protocol, see
326 * nsIProtocolHandler for values.
327 * @param aDefaultPort default port for this scheme, or -1.
329 void registerProtocolHandler
(in ACString aScheme
,
330 in nsIProtocolHandler aHandler
,
331 in unsigned long aProtocolFlags
,
332 in long aDefaultPort
);
335 * Unregister a protocol handler which was previously registered using
336 * registerProtocolHandler.
338 * @param aScheme the scheme to unregister a handler for.
340 void unregisterProtocolHandler
(in ACString aScheme
);
343 * Updates the RemoteSettings-specified portion of the defaultURI bypass
344 * scheme list. The list is then merged with the user-specified pref list
345 * before broadcasting to all alive content processes that may need for URL
348 void setSimpleURIUnknownRemoteSchemes
(in Array
<ACString
> aRemoteSchemes
);
351 * Checks if the provided scheme is in the list of unknown schemes that
352 * should use simpleURI as it's default parser. Where "unknown" scheme means
353 * non-special and otherwise non-common shemes like:
354 * http, about, jar, blob, ssh, etc
355 * See netwerk/base/nsNetUtil.cpp::NS_NewURI for the full list
357 [noscript
] boolean isSimpleURIUnknownScheme
(in ACString aScheme
);
360 * returns an array of the remote-settings specified unknown schemes that
361 * should use SimpleURI parser instead of defaultURI parser.
363 [noscript
] Array
<ACString
> getSimpleURIUnknownRemoteSchemes
();
368 * We send notifications through nsIObserverService with topic
369 * NS_IOSERVICE_GOING_OFFLINE_TOPIC and data NS_IOSERVICE_OFFLINE
370 * when 'offline' has changed from false to true, and we are about
371 * to shut down network services such as DNS. When those
372 * services have been shut down, we send a notification with
373 * topic NS_IOSERVICE_OFFLINE_STATUS_TOPIC and data
374 * NS_IOSERVICE_OFFLINE.
376 * When 'offline' changes from true to false, then after
377 * network services have been restarted, we send a notification
378 * with topic NS_IOSERVICE_OFFLINE_STATUS_TOPIC and data
379 * NS_IOSERVICE_ONLINE.
381 #define NS_IOSERVICE_GOING_OFFLINE_TOPIC
"network:offline-about-to-go-offline"
382 #define NS_IOSERVICE_OFFLINE_STATUS_TOPIC
"network:offline-status-changed"
383 #define NS_IOSERVICE_OFFLINE
"offline"
384 #define NS_IOSERVICE_ONLINE
"online"
388 [uuid(6633c0bf
-d97a
-428f
-8ece
-cb6a655fb95a
)]
389 interface nsIIOServiceInternal
: nsISupports
392 * This is an internal method that should only be called from ContentChild
393 * in order to pass the connectivity state from the chrome process to the
394 * content process. It throws if called outside the content process.
396 void SetConnectivity
(in boolean connectivity
);
399 * An internal method to asynchronously run our notifications that happen
400 * when we wake from sleep