nsIRequest.idl (12441B)
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 8 %{ C++ 9 #include "nsString.h" 10 %} 11 12 interface nsILoadGroup; 13 14 typedef unsigned long nsLoadFlags; 15 16 /** 17 * nsIRequest 18 */ 19 [scriptable, uuid(ef6bfbd2-fd46-48d8-96b7-9f8f0fd387fe)] 20 interface nsIRequest : nsISupports 21 { 22 /** 23 * The name of the request. Often this is the URI of the request. 24 */ 25 readonly attribute AUTF8String name; 26 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). 34 * 35 * Requests can become pending multiple times during their lifetime. 36 * 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. 41 */ 42 boolean isPending(); 43 44 /** 45 * The error status associated with the request. 46 */ 47 readonly attribute nsresult status; 48 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. 55 * 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. 59 * 60 * Requests that use nsIStreamListener must not call onDataAvailable 61 * anymore after cancel has been called. 62 * 63 * @param aStatus the reason for canceling this request. 64 * 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. 69 */ 70 void cancel(in nsresult aStatus); 71 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. 77 * 78 * Calling cancel() on a suspended request must not send any 79 * notifications (such as onstopRequest) until the request is resumed. 80 * 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. 85 */ 86 void suspend(); 87 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. 92 */ 93 void resume(); 94 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. 99 */ 100 attribute nsILoadGroup loadGroup; 101 102 /** 103 * The load flags of this request. Bits 0-15 are reserved. 104 * 105 * When added to a load group, this request's load flags are merged with 106 * the load flags of the load group. 107 */ 108 attribute nsLoadFlags loadFlags; 109 110 /** 111 * Mask defining the bits reserved for nsIRequest LoadFlags 112 */ 113 const unsigned long LOAD_REQUESTMASK = 0xFFFF; 114 115 /************************************************************************** 116 * Listed below are the various load flags which may be or'd together. 117 */ 118 119 /** 120 * No special load flags: 121 */ 122 const unsigned long LOAD_NORMAL = 0; 123 124 /** 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. 128 */ 129 const unsigned long LOAD_BACKGROUND = 1 << 0; 130 131 /** 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. 135 */ 136 const unsigned long LOAD_HTML_OBJECT_DATA = 1 << 1; 137 138 /** 139 * This flag marks the request as belonging to a document that requires access 140 * to the document.cookies API. 141 */ 142 const unsigned long LOAD_DOCUMENT_NEEDS_COOKIE = 1 << 2; 143 144 cenum TRRMode : 32 { 145 TRR_DEFAULT_MODE = 0, 146 TRR_DISABLED_MODE = 1, 147 TRR_FIRST_MODE = 2, 148 TRR_ONLY_MODE = 3 149 }; 150 151 /** 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. 155 * 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. 165 */ 166 nsIRequest_TRRMode getTRRMode(); 167 void setTRRMode(in nsIRequest_TRRMode mode); 168 169 %{C++ 170 inline TRRMode GetTRRMode() { 171 TRRMode mode = TRR_DEFAULT_MODE; 172 GetTRRMode(&mode); 173 return mode; 174 } 175 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; 182 } 183 *aTRRMode = static_cast<nsIRequest::TRRMode>( 184 (flags & nsIRequest::LOAD_TRR_MASK) >> 3); 185 return NS_OK; 186 } 187 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; 194 } 195 flags = (flags & ~nsIRequest::LOAD_TRR_MASK) | (aTRRMode << 3); 196 return SetLoadFlags(flags); 197 } 198 %} 199 200 /** 201 * These two bits encode the TRR mode. 202 * Do not get/set manually, rather use the getTRRMode/setTRRMode methods. 203 */ 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); 208 209 void cancelWithReason(in nsresult aStatus, in ACString aReason); 210 attribute ACString canceledReason; 211 212 %{C++ 213 protected: 214 nsCString mCanceledReason; 215 216 public: 217 inline nsresult SetCanceledReasonImpl(const nsACString& aReason) { 218 if (mCanceledReason.IsEmpty()) { 219 mCanceledReason.Assign(aReason); 220 } 221 222 return NS_OK; 223 } 224 225 inline nsresult CancelWithReasonImpl(nsresult aStatus, 226 const nsACString& aReason) { 227 SetCanceledReasonImpl(aReason); 228 return Cancel(aStatus); 229 } 230 231 inline nsresult GetCanceledReasonImpl(nsACString& aReason) { 232 aReason.Assign(mCanceledReason); 233 return NS_OK; 234 } 235 %} 236 237 /** 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. 241 */ 242 const long LOAD_ANONYMOUS_ALLOW_CLIENT_CERT = 1 << 5; 243 244 /************************************************************************** 245 * The following flags control the flow of data into the cache. 246 */ 247 248 /** 249 * This flag prevents caching of any kind. It does not, however, prevent 250 * cached content from being used to satisfy this request. 251 */ 252 const unsigned long INHIBIT_CACHING = 1 << 7; 253 254 /** 255 * This flag prevents caching on disk (or other persistent media), which 256 * may be needed to preserve privacy. 257 */ 258 const unsigned long INHIBIT_PERSISTENT_CACHING = 1 << 8; 259 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. 264 */ 265 266 /** 267 * Force an end-to-end download of content data from the origin server. 268 * This flag is used for a shift-reload. 269 */ 270 const unsigned long LOAD_BYPASS_CACHE = 1 << 9; 271 272 /** 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). 276 * 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. 280 * 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. 284 */ 285 const unsigned long LOAD_FROM_CACHE = 1 << 10; 286 287 /** 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. 291 * 292 * VALIDATE_ALWAYS forces validation of any cached content independent of 293 * its expiration time (unless it is https with Cache-Control: immutable) 294 * 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. 298 * 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. 302 * 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. 310 */ 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; 314 315 /** 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. 319 */ 320 const unsigned long LOAD_ANONYMOUS = 1 << 14; 321 322 /** 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. 327 */ 328 const unsigned long LOAD_FRESH_CONNECTION = 1 << 15; 329 330 // Note that all flags are taken, the rest of the flags 331 // are located in nsIChannel and nsICachingChannel 332 };