nsIChannel.idl 15 KB

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