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/. */
5
6#include "nsISupports.idl"
7
8interface nsIProtocolHandler;
9interface nsIChannel;
10interface nsIURI;
11interface nsIFile;
12interface nsIDOMNode;
13interface nsIPrincipal;
14interface nsILoadInfo;
15
16%{C++
17#include "mozilla/Maybe.h"
18
19namespace mozilla {
20namespace dom {
21class ClientInfo;
22class ServiceWorkerDescriptor;
23} // namespace dom
24} // namespace mozilla
25%}
26
27[ref] native const_MaybeClientInfoRef(const mozilla::Maybe<mozilla::dom::ClientInfo>);
28[ref] native const_MaybeServiceWorkerDescriptorRef(const mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor>);
29
30/**
31 * nsIIOService provides a set of network utility functions.  This interface
32 * duplicates many of the nsIProtocolHandler methods in a protocol handler
33 * independent way (e.g., NewURI inspects the scheme in order to delegate
34 * creation of the new URI to the appropriate protocol handler).  nsIIOService
35 * also provides a set of URL parsing utility functions.  These are provided
36 * as a convenience to the programmer and in some cases to improve performance
37 * by eliminating intermediate data structures and interfaces.
38 */
39[scriptable, uuid(4286de5a-b2ea-446f-8f70-e2a461f42694)]
40interface nsIIOService : nsISupports
41{
42    /**
43     * Returns a protocol handler for a given URI scheme.
44     *
45     * @param aScheme the URI scheme
46     * @return reference to corresponding nsIProtocolHandler
47     */
48    nsIProtocolHandler getProtocolHandler(in string aScheme);
49
50    /**
51     * Returns the protocol flags for a given scheme.
52     *
53     * @param aScheme the URI scheme
54     * @return value of corresponding nsIProtocolHandler::protocolFlags
55     */
56    unsigned long getProtocolFlags(in string aScheme);
57
58    /**
59     * This method constructs a new URI by determining the scheme of the
60     * URI spec, and then delegating the construction of the URI to the
61     * protocol handler for that scheme. QueryInterface can be used on
62     * the resulting URI object to obtain a more specific type of URI.
63     *
64     * @see nsIProtocolHandler::newURI
65     */
66    nsIURI newURI(in AUTF8String aSpec,
67                  [optional] in string aOriginCharset,
68                  [optional] in nsIURI aBaseURI);
69
70    /**
71     * This method constructs a new URI from a nsIFile.
72     *
73     * @param aFile specifies the file path
74     * @return reference to a new nsIURI object
75     *
76     * Note: in the future, for perf reasons we should allow
77     * callers to specify whether this is a file or directory by
78     * splitting this  into newDirURI() and newActualFileURI().
79     */
80    nsIURI newFileURI(in nsIFile aFile);
81
82    /**
83     * Creates a channel for a given URI.
84     *
85     * @param aURI
86     *        nsIURI from which to make a channel
87     * @param aLoadingNode
88     * @param aLoadingPrincipal
89     * @param aTriggeringPrincipal
90     * @param aSecurityFlags
91     * @param aContentPolicyType
92     *        These will be used as values for the nsILoadInfo object on the
93     *        created channel. For details, see nsILoadInfo in nsILoadInfo.idl
94     * @return reference to the new nsIChannel object
95     *
96     * Please note, if you provide both a loadingNode and a loadingPrincipal,
97     * then loadingPrincipal must be equal to loadingNode->NodePrincipal().
98     * But less error prone is to just supply a loadingNode.
99     *
100     * Keep in mind that URIs coming from a webpage should *never* use the
101     * systemPrincipal as the loadingPrincipal.
102     */
103    nsIChannel newChannelFromURI2(in nsIURI aURI,
104                                  in nsIDOMNode aLoadingNode,
105                                  in nsIPrincipal aLoadingPrincipal,
106                                  in nsIPrincipal aTriggeringPrincipal,
107                                  in unsigned long aSecurityFlags,
108                                  in unsigned long aContentPolicyType);
109
110    [noscript, nostdcall, notxpcom]
111    nsresult NewChannelFromURIWithClientAndController(in nsIURI aURI,
112                                                      in nsIDOMNode aLoadingNode,
113                                                      in nsIPrincipal aLoadingPrincipal,
114                                                      in nsIPrincipal aTriggeringPrincipal,
115                                                      in const_MaybeClientInfoRef aLoadingClientInfo,
116                                                      in const_MaybeServiceWorkerDescriptorRef aController,
117                                                      in unsigned long aSecurityFlags,
118                                                      in unsigned long aContentPolicyType,
119                                                      out nsIChannel aResult);
120
121    /**
122     * Equivalent to newChannelFromURI2(aURI, aLoadingNode, ...)
123     */
124    nsIChannel newChannelFromURIWithLoadInfo(in nsIURI aURI,
125                                             in nsILoadInfo aLoadInfo);
126
127    /**
128     * Equivalent to newChannelFromURI2(newURI(...))
129     */
130    nsIChannel newChannel2(in AUTF8String aSpec,
131                           in string aOriginCharset,
132                           in nsIURI aBaseURI,
133                           in nsIDOMNode aLoadingNode,
134                           in nsIPrincipal aLoadingPrincipal,
135                           in nsIPrincipal aTriggeringPrincipal,
136                           in unsigned long aSecurityFlags,
137                           in unsigned long aContentPolicyType);
138
139    /**
140     * ***** DEPRECATED *****
141     * Please use NewChannelFromURI2()
142     *
143     * Creates a channel for a given URI.
144     *
145     * @param aURI nsIURI from which to make a channel
146     * @return reference to the new nsIChannel object
147     */
148    nsIChannel newChannelFromURI(in nsIURI aURI);
149
150    /**
151     * ***** DEPRECATED *****
152     * Please use newChannel2().
153     *
154     * Equivalent to newChannelFromURI(newURI(...))
155     */
156    nsIChannel newChannel(in AUTF8String aSpec,
157                          in string aOriginCharset,
158                          in nsIURI aBaseURI);
159
160
161    /**
162     * Returns true if networking is in "offline" mode. When in offline mode,
163     * attempts to access the network will fail (although this does not
164     * necessarily correlate with whether there is actually a network
165     * available -- that's hard to detect without causing the dialer to
166     * come up).
167     *
168     * Changing this fires observer notifications ... see below.
169     */
170    attribute boolean offline;
171
172    /**
173     * Returns false if there are no interfaces for a network request
174     */
175    readonly attribute boolean connectivity;
176
177    /**
178     * Checks if a port number is banned. This involves consulting a list of
179     * unsafe ports, corresponding to network services that may be easily
180     * exploitable. If the given port is considered unsafe, then the protocol
181     * handler (corresponding to aScheme) will be asked whether it wishes to
182     * override the IO service's decision to block the port. This gives the
183     * protocol handler ultimate control over its own security policy while
184     * ensuring reasonable, default protection.
185     *
186     * @see nsIProtocolHandler::allowPort
187     */
188    boolean allowPort(in long aPort, in string aScheme);
189
190    /**
191     * Utility to extract the scheme from a URL string, consistently and
192     * according to spec (see RFC 2396).
193     *
194     * NOTE: Most URL parsing is done via nsIURI, and in fact the scheme
195     * can also be extracted from a URL string via nsIURI.  This method
196     * is provided purely as an optimization.
197     *
198     * @param aSpec the URL string to parse
199     * @return URL scheme, lowercase
200     *
201     * @throws NS_ERROR_MALFORMED_URI if URL string is not of the right form.
202     */
203    ACString extractScheme(in AUTF8String urlString);
204
205    /**
206     * Checks if a URI host is a local IPv4 or IPv6 address literal.
207     *
208     * @param nsIURI the URI that contains the hostname to check
209     * @return true if the URI hostname is a local IP address
210     */
211    boolean hostnameIsLocalIPAddress(in nsIURI aURI);
212
213    /**
214     * While this is set, IOService will monitor an nsINetworkLinkService
215     * (if available) and set its offline status to "true" whenever
216     * isLinkUp is false.
217     *
218     * Applications that want to control changes to the IOService's offline
219     * status should set this to false, watch for network:link-status-changed
220     * broadcasts, and change nsIIOService::offline as they see fit. Note
221     * that this means during application startup, IOService may be offline
222     * if there is no link, until application code runs and can turn off
223     * this management.
224     */
225    attribute boolean manageOfflineStatus;
226
227    /**
228     * Creates a channel for a given URI.
229     *
230     * @param aURI
231     *        nsIURI from which to make a channel
232     * @param aProxyURI
233     *        nsIURI to use for proxy resolution. Can be null in which
234     *        case aURI is used
235     * @param aProxyFlags flags from nsIProtocolProxyService to use
236     *        when resolving proxies for this new channel
237     * @param aLoadingNode
238     * @param aLoadingPrincipal
239     * @param aTriggeringPrincipal
240     * @param aSecurityFlags
241     * @param aContentPolicyType
242     *        These will be used as values for the nsILoadInfo object on the
243     *        created channel. For details, see nsILoadInfo in nsILoadInfo.idl
244     * @return reference to the new nsIChannel object
245     *
246     * Please note, if you provide both a loadingNode and a loadingPrincipal,
247     * then loadingPrincipal must be equal to loadingNode->NodePrincipal().
248     * But less error prone is to just supply a loadingNode.
249     */
250    nsIChannel newChannelFromURIWithProxyFlags2(in nsIURI aURI,
251                                                in nsIURI aProxyURI,
252                                                in unsigned long aProxyFlags,
253                                                in nsIDOMNode aLoadingNode,
254                                                in nsIPrincipal aLoadingPrincipal,
255                                                in nsIPrincipal aTriggeringPrincipal,
256                                                in unsigned long aSecurityFlags,
257                                                in unsigned long aContentPolicyType);
258};
259
260%{C++
261/**
262 * We send notifications through nsIObserverService with topic
263 * NS_IOSERVICE_GOING_OFFLINE_TOPIC and data NS_IOSERVICE_OFFLINE
264 * when 'offline' has changed from false to true, and we are about
265 * to shut down network services such as DNS. When those
266 * services have been shut down, we send a notification with
267 * topic NS_IOSERVICE_OFFLINE_STATUS_TOPIC and data
268 * NS_IOSERVICE_OFFLINE.
269 *
270 * When 'offline' changes from true to false, then after
271 * network services have been restarted, we send a notification
272 * with topic NS_IOSERVICE_OFFLINE_STATUS_TOPIC and data
273 * NS_IOSERVICE_ONLINE.
274 */
275#define NS_IOSERVICE_GOING_OFFLINE_TOPIC  "network:offline-about-to-go-offline"
276#define NS_IOSERVICE_OFFLINE_STATUS_TOPIC "network:offline-status-changed"
277#define NS_IOSERVICE_OFFLINE              "offline"
278#define NS_IOSERVICE_ONLINE               "online"
279
280%}
281
282[builtinclass, uuid(6633c0bf-d97a-428f-8ece-cb6a655fb95a)]
283interface nsIIOServiceInternal : nsISupports
284{
285    /**
286     * This is an internal method that should only be called from ContentChild
287     * in order to pass the connectivity state from the chrome process to the
288     * content process. It throws if called outside the content process.
289     */
290    void SetConnectivity(in boolean connectivity);
291
292    /**
293     * An internal method to asynchronously run our notifications that happen
294     * when we wake from sleep
295     */
296    void NotifyWakeup();
297};
298