netwerk/base/public/nsIChannel.idl

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "nsIRequest.idl"
michael@0 7
michael@0 8 interface nsIURI;
michael@0 9 interface nsIInterfaceRequestor;
michael@0 10 interface nsIInputStream;
michael@0 11 interface nsIStreamListener;
michael@0 12
michael@0 13 /**
michael@0 14 * The nsIChannel interface allows clients to construct "GET" requests for
michael@0 15 * specific protocols, and manage them in a uniform way. Once a channel is
michael@0 16 * created (via nsIIOService::newChannel), parameters for that request may
michael@0 17 * be set by using the channel attributes, or by QI'ing to a subclass of
michael@0 18 * nsIChannel for protocol-specific parameters. Then, the URI can be fetched
michael@0 19 * by calling nsIChannel::open or nsIChannel::asyncOpen.
michael@0 20 *
michael@0 21 * After a request has been completed, the channel is still valid for accessing
michael@0 22 * protocol-specific results. For example, QI'ing to nsIHttpChannel allows
michael@0 23 * response headers to be retrieved for the corresponding http transaction.
michael@0 24 *
michael@0 25 * This interface must be used only from the XPCOM main thread.
michael@0 26 */
michael@0 27 [scriptable, uuid(2a8a7237-c1e2-4de7-b669-2002af29e42d)]
michael@0 28 interface nsIChannel : nsIRequest
michael@0 29 {
michael@0 30 /**
michael@0 31 * The original URI used to construct the channel. This is used in
michael@0 32 * the case of a redirect or URI "resolution" (e.g. resolving a
michael@0 33 * resource: URI to a file: URI) so that the original pre-redirect
michael@0 34 * URI can still be obtained. This is never null. Attempts to
michael@0 35 * set it to null must throw.
michael@0 36 *
michael@0 37 * NOTE: this is distinctly different from the http Referer (referring URI),
michael@0 38 * which is typically the page that contained the original URI (accessible
michael@0 39 * from nsIHttpChannel).
michael@0 40 */
michael@0 41 attribute nsIURI originalURI;
michael@0 42
michael@0 43 /**
michael@0 44 * The URI corresponding to the channel. Its value is immutable.
michael@0 45 */
michael@0 46 readonly attribute nsIURI URI;
michael@0 47
michael@0 48 /**
michael@0 49 * The owner, corresponding to the entity that is responsible for this
michael@0 50 * channel. Used by the security manager to grant or deny privileges to
michael@0 51 * mobile code loaded from this channel.
michael@0 52 *
michael@0 53 * NOTE: this is a strong reference to the owner, so if the owner is also
michael@0 54 * holding a strong reference to the channel, care must be taken to
michael@0 55 * explicitly drop its reference to the channel.
michael@0 56 */
michael@0 57 attribute nsISupports owner;
michael@0 58
michael@0 59 /**
michael@0 60 * The notification callbacks for the channel. This is set by clients, who
michael@0 61 * wish to provide a means to receive progress, status and protocol-specific
michael@0 62 * notifications. If this value is NULL, the channel implementation may use
michael@0 63 * the notification callbacks from its load group. The channel may also
michael@0 64 * query the notification callbacks from its load group if its notification
michael@0 65 * callbacks do not supply the requested interface.
michael@0 66 *
michael@0 67 * Interfaces commonly requested include: nsIProgressEventSink, nsIPrompt,
michael@0 68 * and nsIAuthPrompt/nsIAuthPrompt2.
michael@0 69 *
michael@0 70 * When the channel is done, it must not continue holding references to
michael@0 71 * this object.
michael@0 72 *
michael@0 73 * NOTE: A channel implementation should take care when "caching" an
michael@0 74 * interface pointer queried from its notification callbacks. If the
michael@0 75 * notification callbacks are changed, then a cached interface pointer may
michael@0 76 * become invalid and may therefore need to be re-queried.
michael@0 77 */
michael@0 78 attribute nsIInterfaceRequestor notificationCallbacks;
michael@0 79
michael@0 80 /**
michael@0 81 * Transport-level security information (if any) corresponding to the channel.
michael@0 82 */
michael@0 83 readonly attribute nsISupports securityInfo;
michael@0 84
michael@0 85 /**
michael@0 86 * The MIME type of the channel's content if available.
michael@0 87 *
michael@0 88 * NOTE: the content type can often be wrongly specified (e.g., wrong file
michael@0 89 * extension, wrong MIME type, wrong document type stored on a server, etc.),
michael@0 90 * and the caller most likely wants to verify with the actual data.
michael@0 91 *
michael@0 92 * Setting contentType before the channel has been opened provides a hint
michael@0 93 * to the channel as to what the MIME type is. The channel may ignore this
michael@0 94 * hint in deciding on the actual MIME type that it will report.
michael@0 95 *
michael@0 96 * Setting contentType after onStartRequest has been fired or after open()
michael@0 97 * is called will override the type determined by the channel.
michael@0 98 *
michael@0 99 * Setting contentType between the time that asyncOpen() is called and the
michael@0 100 * time when onStartRequest is fired has undefined behavior at this time.
michael@0 101 *
michael@0 102 * The value of the contentType attribute is a lowercase string. A value
michael@0 103 * assigned to this attribute will be parsed and normalized as follows:
michael@0 104 * 1- any parameters (delimited with a ';') will be stripped.
michael@0 105 * 2- if a charset parameter is given, then its value will replace the
michael@0 106 * the contentCharset attribute of the channel.
michael@0 107 * 3- the stripped contentType will be lowercased.
michael@0 108 * Any implementation of nsIChannel must follow these rules.
michael@0 109 */
michael@0 110 attribute ACString contentType;
michael@0 111
michael@0 112 /**
michael@0 113 * The character set of the channel's content if available and if applicable.
michael@0 114 * This attribute only applies to textual data.
michael@0 115 *
michael@0 116 * The value of the contentCharset attribute is a mixedcase string.
michael@0 117 */
michael@0 118 attribute ACString contentCharset;
michael@0 119
michael@0 120 /**
michael@0 121 * The length of the data associated with the channel if available. A value
michael@0 122 * of -1 indicates that the content length is unknown. Note that this is a
michael@0 123 * 64-bit value and obsoletes the "content-length" property used on some
michael@0 124 * channels.
michael@0 125 */
michael@0 126 attribute int64_t contentLength;
michael@0 127
michael@0 128 /**
michael@0 129 * Synchronously open the channel.
michael@0 130 *
michael@0 131 * @return blocking input stream to the channel's data.
michael@0 132 *
michael@0 133 * NOTE: nsIChannel implementations are not required to implement this
michael@0 134 * method. Moreover, since this method may block the calling thread, it
michael@0 135 * should not be called on a thread that processes UI events. Like any
michael@0 136 * other nsIChannel method it must not be called on any thread other
michael@0 137 * than the XPCOM main thread.
michael@0 138 *
michael@0 139 * NOTE: Implementations should throw NS_ERROR_IN_PROGRESS if the channel
michael@0 140 * is reopened.
michael@0 141 */
michael@0 142 nsIInputStream open();
michael@0 143
michael@0 144 /**
michael@0 145 * Asynchronously open this channel. Data is fed to the specified stream
michael@0 146 * listener as it becomes available. The stream listener's methods are
michael@0 147 * called on the thread that calls asyncOpen and are not called until
michael@0 148 * after asyncOpen returns. If asyncOpen returns successfully, the
michael@0 149 * channel promises to call at least onStartRequest and onStopRequest.
michael@0 150 *
michael@0 151 * If the nsIRequest object passed to the stream listener's methods is not
michael@0 152 * this channel, an appropriate onChannelRedirect notification needs to be
michael@0 153 * sent to the notification callbacks before onStartRequest is called.
michael@0 154 * Once onStartRequest is called, all following method calls on aListener
michael@0 155 * will get the request that was passed to onStartRequest.
michael@0 156 *
michael@0 157 * If the channel's and loadgroup's notification callbacks do not provide
michael@0 158 * an nsIChannelEventSink when onChannelRedirect would be called, that's
michael@0 159 * equivalent to having called onChannelRedirect.
michael@0 160 *
michael@0 161 * If asyncOpen returns successfully, the channel is responsible for
michael@0 162 * keeping itself alive until it has called onStopRequest on aListener or
michael@0 163 * called onChannelRedirect.
michael@0 164 *
michael@0 165 * Implementations are allowed to synchronously add themselves to the
michael@0 166 * associated load group (if any).
michael@0 167 *
michael@0 168 * NOTE: Implementations should throw NS_ERROR_ALREADY_OPENED if the
michael@0 169 * channel is reopened.
michael@0 170 *
michael@0 171 * @param aListener the nsIStreamListener implementation
michael@0 172 * @param aContext an opaque parameter forwarded to aListener's methods
michael@0 173 * @see nsIChannelEventSink for onChannelRedirect
michael@0 174 */
michael@0 175 void asyncOpen(in nsIStreamListener aListener, in nsISupports aContext);
michael@0 176
michael@0 177 /**************************************************************************
michael@0 178 * Channel specific load flags:
michael@0 179 *
michael@0 180 * Bits 23-31 are reserved for future use by this interface or one of its
michael@0 181 * derivatives (e.g., see nsICachingChannel).
michael@0 182 */
michael@0 183
michael@0 184 /**
michael@0 185 * Set (e.g., by the docshell) to indicate whether or not the channel
michael@0 186 * corresponds to a document URI.
michael@0 187 */
michael@0 188 const unsigned long LOAD_DOCUMENT_URI = 1 << 16;
michael@0 189
michael@0 190 /**
michael@0 191 * If the end consumer for this load has been retargeted after discovering
michael@0 192 * its content, this flag will be set:
michael@0 193 */
michael@0 194 const unsigned long LOAD_RETARGETED_DOCUMENT_URI = 1 << 17;
michael@0 195
michael@0 196 /**
michael@0 197 * This flag is set to indicate that this channel is replacing another
michael@0 198 * channel. This means that:
michael@0 199 *
michael@0 200 * 1) the stream listener this channel will be notifying was initially
michael@0 201 * passed to the asyncOpen method of some other channel
michael@0 202 *
michael@0 203 * and
michael@0 204 *
michael@0 205 * 2) this channel's URI is a better identifier of the resource being
michael@0 206 * accessed than this channel's originalURI.
michael@0 207 *
michael@0 208 * This flag can be set, for example, for redirects or for cases when a
michael@0 209 * single channel has multiple parts to it (and thus can follow
michael@0 210 * onStopRequest with another onStartRequest/onStopRequest pair, each pair
michael@0 211 * for a different request).
michael@0 212 */
michael@0 213 const unsigned long LOAD_REPLACE = 1 << 18;
michael@0 214
michael@0 215 /**
michael@0 216 * Set (e.g., by the docshell) to indicate whether or not the channel
michael@0 217 * corresponds to an initial document URI load (e.g., link click).
michael@0 218 */
michael@0 219 const unsigned long LOAD_INITIAL_DOCUMENT_URI = 1 << 19;
michael@0 220
michael@0 221 /**
michael@0 222 * Set (e.g., by the URILoader) to indicate whether or not the end consumer
michael@0 223 * for this load has been determined.
michael@0 224 */
michael@0 225 const unsigned long LOAD_TARGETED = 1 << 20;
michael@0 226
michael@0 227 /**
michael@0 228 * If this flag is set, the channel should call the content sniffers as
michael@0 229 * described in nsNetCID.h about NS_CONTENT_SNIFFER_CATEGORY.
michael@0 230 *
michael@0 231 * Note: Channels may ignore this flag; however, new channel implementations
michael@0 232 * should only do so with good reason.
michael@0 233 */
michael@0 234 const unsigned long LOAD_CALL_CONTENT_SNIFFERS = 1 << 21;
michael@0 235
michael@0 236 /**
michael@0 237 * This flag tells the channel to use URI classifier service to check
michael@0 238 * the URI when opening the channel.
michael@0 239 */
michael@0 240 const unsigned long LOAD_CLASSIFY_URI = 1 << 22;
michael@0 241
michael@0 242 /**
michael@0 243 * If this flag is set and a server's response is Content-Type
michael@0 244 * application/octet-steam, the server's Content-Type will be ignored and
michael@0 245 * the channel content will be sniffed as though no Content-Type had been
michael@0 246 * passed.
michael@0 247 */
michael@0 248 const unsigned long LOAD_TREAT_APPLICATION_OCTET_STREAM_AS_UNKNOWN = 1 << 23;
michael@0 249
michael@0 250 /**
michael@0 251 * Set to let explicitely provided credentials be used over credentials
michael@0 252 * we have cached previously. In some situations like form login using HTTP
michael@0 253 * auth via XMLHttpRequest we need to let consumers override the cached
michael@0 254 * credentials explicitely. For form login 403 response instead of 401 is
michael@0 255 * usually used to prevent an auth dialog. But any code other then 401/7
michael@0 256 * will leave original credentials in the cache and there is then no way
michael@0 257 * to override them for the same user name.
michael@0 258 */
michael@0 259 const unsigned long LOAD_EXPLICIT_CREDENTIALS = 1 << 24;
michael@0 260
michael@0 261 /**
michael@0 262 * Access to the type implied or stated by the Content-Disposition header
michael@0 263 * if available and if applicable. This allows determining inline versus
michael@0 264 * attachment.
michael@0 265 *
michael@0 266 * Setting contentDisposition provides a hint to the channel about the
michael@0 267 * disposition. If a normal Content-Disposition header is present its
michael@0 268 * value will always be used. If it is missing the hinted value will
michael@0 269 * be used if set.
michael@0 270 *
michael@0 271 * Implementations should throw NS_ERROR_NOT_AVAILABLE if the header either
michael@0 272 * doesn't exist for this type of channel or is empty, and return
michael@0 273 * DISPOSITION_ATTACHMENT if an invalid/noncompliant value is present.
michael@0 274 */
michael@0 275 attribute unsigned long contentDisposition;
michael@0 276 const unsigned long DISPOSITION_INLINE = 0;
michael@0 277 const unsigned long DISPOSITION_ATTACHMENT = 1;
michael@0 278
michael@0 279 /**
michael@0 280 * Access to the filename portion of the Content-Disposition header if
michael@0 281 * available and if applicable. This allows getting the preferred filename
michael@0 282 * without having to parse it out yourself.
michael@0 283 *
michael@0 284 * Setting contentDispositionFilename provides a hint to the channel about
michael@0 285 * the disposition. If a normal Content-Disposition header is present its
michael@0 286 * value will always be used. If it is missing the hinted value will be
michael@0 287 * used if set.
michael@0 288 *
michael@0 289 * Implementations should throw NS_ERROR_NOT_AVAILABLE if the header doesn't
michael@0 290 * exist for this type of channel, if the header is empty, if the header
michael@0 291 * doesn't contain a filename portion, or the value of the filename
michael@0 292 * attribute is empty/missing.
michael@0 293 */
michael@0 294 attribute AString contentDispositionFilename;
michael@0 295
michael@0 296 /**
michael@0 297 * Access to the raw Content-Disposition header if available and applicable.
michael@0 298 *
michael@0 299 * Implementations should throw NS_ERROR_NOT_AVAILABLE if the header either
michael@0 300 * doesn't exist for this type of channel or is empty.
michael@0 301 *
michael@0 302 * @deprecated Use contentDisposition/contentDispositionFilename instead.
michael@0 303 */
michael@0 304 readonly attribute ACString contentDispositionHeader;
michael@0 305 };

mercurial