Backed out 2 changesets (bug 1881078, bug 1879806) for causing dt failures @ devtools...
[gecko.git] / netwerk / base / nsIRequest.idl
blob8fa946213629e3e9e91155c47eb4699af2b77375
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"
8 %{ C++
9 #include "nsString.h"
12 interface nsILoadGroup;
14 typedef unsigned long nsLoadFlags;
16 /**
17 * nsIRequest
19 [scriptable, uuid(ef6bfbd2-fd46-48d8-96b7-9f8f0fd387fe)]
20 interface nsIRequest : nsISupports
22 /**
23 * The name of the request. Often this is the URI of the request.
25 readonly attribute AUTF8String name;
27 /**
28 * Indicates whether the request is pending. nsIRequest::isPending is
29 * true when there is an outstanding asynchronous event that will make
30 * the request no longer be pending. Requests do not necessarily start
31 * out pending; in some cases, requests have to be explicitly initiated
32 * (e.g. nsIChannel implementations are only pending once asyncOpen
33 * returns successfully).
35 * Requests can become pending multiple times during their lifetime.
37 * @return TRUE if the request has yet to reach completion.
38 * @return FALSE if the request has reached completion (e.g., after
39 * OnStopRequest has fired).
40 * @note Suspended requests are still considered pending.
42 boolean isPending();
44 /**
45 * The error status associated with the request.
47 readonly attribute nsresult status;
49 /**
50 * Cancels the current request. This will close any open input or
51 * output streams and terminate any async requests. Users should
52 * normally pass NS_BINDING_ABORTED, although other errors may also
53 * be passed. The error passed in will become the value of the
54 * status attribute.
56 * Implementations must not send any notifications (e.g. via
57 * nsIRequestObserver) synchronously from this function. Similarly,
58 * removal from the load group (if any) must also happen asynchronously.
60 * Requests that use nsIStreamListener must not call onDataAvailable
61 * anymore after cancel has been called.
63 * @param aStatus the reason for canceling this request.
65 * NOTE: most nsIRequest implementations expect aStatus to be a
66 * failure code; however, some implementations may allow aStatus to
67 * be a success code such as NS_OK. In general, aStatus should be
68 * a failure code.
70 void cancel(in nsresult aStatus);
72 /**
73 * Suspends the current request. This may have the effect of closing
74 * any underlying transport (in order to free up resources), although
75 * any open streams remain logically opened and will continue delivering
76 * data when the transport is resumed.
78 * Calling cancel() on a suspended request must not send any
79 * notifications (such as onstopRequest) until the request is resumed.
81 * NOTE: some implementations are unable to immediately suspend, and
82 * may continue to deliver events already posted to an event queue. In
83 * general, callers should be capable of handling events even after
84 * suspending a request.
86 void suspend();
88 /**
89 * Resumes the current request. This may have the effect of re-opening
90 * any underlying transport and will resume the delivery of data to
91 * any open streams.
93 void resume();
95 /**
96 * The load group of this request. While pending, the request is a
97 * member of the load group. It is the responsibility of the request
98 * to implement this policy.
100 attribute nsILoadGroup loadGroup;
103 * The load flags of this request. Bits 0-15 are reserved.
105 * When added to a load group, this request's load flags are merged with
106 * the load flags of the load group.
108 attribute nsLoadFlags loadFlags;
111 * Mask defining the bits reserved for nsIRequest LoadFlags
113 const unsigned long LOAD_REQUESTMASK = 0xFFFF;
115 /**************************************************************************
116 * Listed below are the various load flags which may be or'd together.
120 * No special load flags:
122 const unsigned long LOAD_NORMAL = 0;
125 * Do not deliver status notifications to the nsIProgressEventSink and
126 * do not block the loadgroup from completing (should this load belong to one).
127 * Note: Progress notifications will still be delivered.
129 const unsigned long LOAD_BACKGROUND = 1 << 0;
132 * This flag marks the request as being made to load the data for an html
133 * <object> tag. This means that the LOAD_DOCUMENT_URI flag may be set after
134 * the channel has been provided with the MIME type.
136 const unsigned long LOAD_HTML_OBJECT_DATA = 1 << 1;
139 * This flag marks the request as belonging to a document that requires access
140 * to the document.cookies API.
142 const unsigned long LOAD_DOCUMENT_NEEDS_COOKIE = 1 << 2;
144 cenum TRRMode : 32 {
145 TRR_DEFAULT_MODE = 0,
146 TRR_DISABLED_MODE = 1,
147 TRR_FIRST_MODE = 2,
148 TRR_ONLY_MODE = 3
152 * These methods encode/decode the TRR mode to/from the loadFlags.
153 * Helper methods Get/SetTRRModeImpl are provided so implementations don't
154 * need to duplicate code.
156 * Requests with TRR_DEFAULT_MODE will use the mode indicated by the pref
157 * - see network.trr.mode in all.js
158 * Requests with TRR_DISABLED_MODE will always use native DNS, even if the
159 * pref is set to mode3 (TRR-only).
160 * Requests with TRR_FIRST_MODE will first use TRR then fallback to regular
161 * DNS, unless TRR is disabled by setting the pref to mode5, parental
162 * control being enabled, or the domain being in the exclusion list.
163 * Requests with TRR_ONLY_MODE will only use TRR, unless not allowed by
164 * the same conditions mentioned above.
166 nsIRequest_TRRMode getTRRMode();
167 void setTRRMode(in nsIRequest_TRRMode mode);
169 %{C++
170 inline TRRMode GetTRRMode() {
171 TRRMode mode = TRR_DEFAULT_MODE;
172 GetTRRMode(&mode);
173 return mode;
176 inline nsresult GetTRRModeImpl(nsIRequest::TRRMode* aTRRMode) {
177 NS_ENSURE_ARG_POINTER(aTRRMode);
178 nsLoadFlags flags = nsIRequest::LOAD_NORMAL;
179 nsresult rv = GetLoadFlags(&flags);
180 if (NS_FAILED(rv)) {
181 return rv;
183 *aTRRMode = static_cast<nsIRequest::TRRMode>(
184 (flags & nsIRequest::LOAD_TRR_MASK) >> 3);
185 return NS_OK;
188 inline nsresult SetTRRModeImpl(nsIRequest::TRRMode aTRRMode) {
189 MOZ_ASSERT(aTRRMode <= 3, "invalid value");
190 nsLoadFlags flags = nsIRequest::LOAD_NORMAL;
191 nsresult rv = GetLoadFlags(&flags);
192 if (NS_FAILED(rv)) {
193 return rv;
195 flags = (flags & ~nsIRequest::LOAD_TRR_MASK) | (aTRRMode << 3);
196 return SetLoadFlags(flags);
201 * These two bits encode the TRR mode.
202 * Do not get/set manually, rather use the getTRRMode/setTRRMode methods.
204 const unsigned long LOAD_TRR_MASK = (1 << 3) | (1 << 4);
205 const unsigned long LOAD_TRR_DISABLED_MODE = 1 << 3;
206 const unsigned long LOAD_TRR_FIRST_MODE = 1 << 4;
207 const unsigned long LOAD_TRR_ONLY_MODE = (1 << 3) | (1 << 4);
209 void cancelWithReason(in nsresult aStatus, in ACString aReason);
210 attribute ACString canceledReason;
212 %{C++
213 protected:
214 nsCString mCanceledReason;
216 public:
217 inline nsresult SetCanceledReasonImpl(const nsACString& aReason) {
218 if (mCanceledReason.IsEmpty()) {
219 mCanceledReason.Assign(aReason);
222 return NS_OK;
225 inline nsresult CancelWithReasonImpl(nsresult aStatus,
226 const nsACString& aReason) {
227 SetCanceledReasonImpl(aReason);
228 return Cancel(aStatus);
231 inline nsresult GetCanceledReasonImpl(nsACString& aReason) {
232 aReason.Assign(mCanceledReason);
233 return NS_OK;
238 * This is used for a temporary workaround for a web-compat issue. The flag is
239 * only set on CORS preflight request to allowed sending client certificates
240 * on a connection for an anonymous request.
242 const long LOAD_ANONYMOUS_ALLOW_CLIENT_CERT = 1 << 5;
244 /**************************************************************************
245 * The following flags control the flow of data into the cache.
249 * This flag prevents caching of any kind. It does not, however, prevent
250 * cached content from being used to satisfy this request.
252 const unsigned long INHIBIT_CACHING = 1 << 7;
255 * This flag prevents caching on disk (or other persistent media), which
256 * may be needed to preserve privacy.
258 const unsigned long INHIBIT_PERSISTENT_CACHING = 1 << 8;
260 /**************************************************************************
261 * The following flags control what happens when the cache contains data
262 * that could perhaps satisfy this request. They are listed in descending
263 * order of precidence.
267 * Force an end-to-end download of content data from the origin server.
268 * This flag is used for a shift-reload.
270 const unsigned long LOAD_BYPASS_CACHE = 1 << 9;
273 * Attempt to force a load from the cache, bypassing ALL validation logic
274 * (note: this is stronger than VALIDATE_NEVER, which still validates for
275 * certain conditions).
277 * If the resource is not present in cache, it will be loaded from the
278 * network. Combine this flag with LOAD_ONLY_FROM_CACHE if you wish to
279 * perform cache-only loads without validation checks.
281 * This flag is used when browsing via history. It is not recommended for
282 * normal browsing as it may likely violate reasonable assumptions made by
283 * the server and confuse users.
285 const unsigned long LOAD_FROM_CACHE = 1 << 10;
288 * The following flags control the frequency of cached content validation
289 * when neither LOAD_BYPASS_CACHE or LOAD_FROM_CACHE are set. By default,
290 * cached content is automatically validated if necessary before reuse.
292 * VALIDATE_ALWAYS forces validation of any cached content independent of
293 * its expiration time (unless it is https with Cache-Control: immutable)
295 * VALIDATE_NEVER disables validation of cached content, unless it arrived
296 * with the "Cache: no-store" header, or arrived via HTTPS with the
297 * "Cache: no-cache" header.
299 * VALIDATE_ONCE_PER_SESSION disables validation of expired content,
300 * provided it has already been validated (at least once) since the start
301 * of this session.
303 * NOTE TO IMPLEMENTORS:
304 * These flags are intended for normal browsing, and they should therefore
305 * not apply to content that must be validated before each use. Consider,
306 * for example, a HTTP response with a "Cache-control: no-cache" header.
307 * According to RFC2616, this response must be validated before it can
308 * be taken from a cache. Breaking this requirement could result in
309 * incorrect and potentially undesirable side-effects.
311 const unsigned long VALIDATE_ALWAYS = 1 << 11;
312 const unsigned long VALIDATE_NEVER = 1 << 12;
313 const unsigned long VALIDATE_ONCE_PER_SESSION = 1 << 13;
316 * When set, this flag indicates that no user-specific data should be added
317 * to the request when opened. This means that things like authorization
318 * tokens or cookie headers should not be added.
320 const unsigned long LOAD_ANONYMOUS = 1 << 14;
323 * When set, this flag indicates that caches of network connections,
324 * particularly HTTP persistent connections, should not be used.
325 * Use this together with LOAD_INITIAL_DOCUMENT_URI as otherwise it has no
326 * effect.
328 const unsigned long LOAD_FRESH_CONNECTION = 1 << 15;
330 // Note that all flags are taken, the rest of the flags
331 // are located in nsIChannel and nsICachingChannel