imgIRequest.idl 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2. *
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #include "nsISupports.idl"
  7. #include "nsIRequest.idl"
  8. interface imgIContainer;
  9. interface imgINotificationObserver;
  10. interface nsIURI;
  11. interface nsIPrincipal;
  12. /**
  13. * imgIRequest interface
  14. *
  15. * @author Stuart Parmenter <stuart@mozilla.com>
  16. * @version 0.1
  17. * @see imagelib2
  18. */
  19. [scriptable, builtinclass, uuid(db0a945c-3883-424a-98d0-2ee0523b0255)]
  20. interface imgIRequest : nsIRequest
  21. {
  22. /**
  23. * the image container...
  24. * @return the image object associated with the request.
  25. * @attention NEED DOCS
  26. */
  27. readonly attribute imgIContainer image;
  28. /**
  29. * Bits set in the return value from imageStatus
  30. * @name statusflags
  31. *
  32. * Meanings:
  33. *
  34. * STATUS_NONE: Nothing to report.
  35. *
  36. * STATUS_SIZE_AVAILABLE: We received enough image data
  37. * from the network or filesystem that we know the width
  38. * and height of the image, and have thus called SetSize()
  39. * on the container.
  40. *
  41. * STATUS_LOAD_COMPLETE: The data has been fully loaded
  42. * to memory, but not necessarily fully decoded.
  43. *
  44. * STATUS_ERROR: An error occurred loading the image.
  45. *
  46. * STATUS_FRAME_COMPLETE: The first frame has been
  47. * completely decoded.
  48. *
  49. * STATUS_DECODE_COMPLETE: The whole image has been decoded.
  50. *
  51. * STATUS_IS_ANIMATED: The image is animated.
  52. *
  53. * STATUS_HAS_TRANSPARENCY: The image is partially or completely transparent.
  54. */
  55. //@{
  56. const long STATUS_NONE = 0x0;
  57. const long STATUS_SIZE_AVAILABLE = 0x1;
  58. const long STATUS_LOAD_COMPLETE = 0x2;
  59. const long STATUS_ERROR = 0x4;
  60. const long STATUS_FRAME_COMPLETE = 0x8;
  61. const long STATUS_DECODE_COMPLETE = 0x10;
  62. const long STATUS_IS_ANIMATED = 0x20;
  63. const long STATUS_HAS_TRANSPARENCY = 0x40;
  64. //@}
  65. /**
  66. * Status flags of the STATUS_* variety.
  67. */
  68. readonly attribute unsigned long imageStatus;
  69. /*
  70. * Actual error code that generated a STATUS_ERROR imageStatus
  71. * (see xpcom/base/ErrorList.h)
  72. */
  73. [noscript] readonly attribute nsresult imageErrorCode;
  74. /**
  75. * The URI the image load was started with. Note that this might not be the
  76. * actual URI for the image (e.g. if HTTP redirects happened during the
  77. * load).
  78. */
  79. readonly attribute nsIURI URI;
  80. /**
  81. * The URI of the resource we ended up loading after all redirects, etc.
  82. */
  83. readonly attribute nsIURI currentURI;
  84. readonly attribute imgINotificationObserver notificationObserver;
  85. readonly attribute string mimeType;
  86. /**
  87. * Clone this request; the returned request will have aObserver as the
  88. * observer. aObserver will be notified synchronously (before the clone()
  89. * call returns) with all the notifications that have already been dispatched
  90. * for this image load.
  91. */
  92. imgIRequest clone(in imgINotificationObserver aObserver);
  93. /**
  94. * The principal gotten from the channel the image was loaded from.
  95. */
  96. readonly attribute nsIPrincipal imagePrincipal;
  97. /**
  98. * Whether the request is multipart (ie, multipart/x-mixed-replace)
  99. */
  100. readonly attribute bool multipart;
  101. /**
  102. * CORS modes images can be loaded with.
  103. *
  104. * By default, all images are loaded with CORS_NONE and cannot be used
  105. * cross-origin in context like WebGL.
  106. *
  107. * If an HTML img element has the crossorigin attribute set, the imgIRequest
  108. * will be validated for cross-origin usage with CORS, and, if successful,
  109. * will have its CORS mode set to the relevant type.
  110. */
  111. //@{
  112. const long CORS_NONE = 1;
  113. const long CORS_ANONYMOUS = 2;
  114. const long CORS_USE_CREDENTIALS = 3;
  115. //@}
  116. /**
  117. * The CORS mode that this image was loaded with.
  118. */
  119. readonly attribute long CORSMode;
  120. /**
  121. * Cancels this request as in nsIRequest::Cancel(); further, also nulls out
  122. * decoderObserver so it gets no further notifications from us.
  123. *
  124. * NOTE: You should not use this in any new code; instead, use cancel(). Note
  125. * that cancel() is asynchronous, which means that some time after you call
  126. * it, the listener/observer will get an OnStopRequest(). This means that, if
  127. * you're the observer, you can't call cancel() from your destructor.
  128. */
  129. void cancelAndForgetObserver(in nsresult aStatus);
  130. /**
  131. * Requests a synchronous decode for the image.
  132. *
  133. * imgIContainer has a startDecoding() method, but callers may want to request
  134. * a decode before the container has necessarily been instantiated. Calling
  135. * startDecoding() on the imgIRequest simply forwards along the request if the
  136. * container already exists, or calls it once the container becomes available
  137. * if it does not yet exist.
  138. */
  139. void startDecoding();
  140. /**
  141. * Locks an image. If the image does not exist yet, locks it once it becomes
  142. * available. The lock persists for the lifetime of the imgIRequest (until
  143. * unlockImage is called) even if the underlying image changes.
  144. *
  145. * If you don't call unlockImage() by the time this imgIRequest goes away, it
  146. * will be called for you automatically.
  147. *
  148. * @see imgIContainer::lockImage for documentation of the underlying call.
  149. */
  150. void lockImage();
  151. /**
  152. * Unlocks an image.
  153. *
  154. * @see imgIContainer::unlockImage for documentation of the underlying call.
  155. */
  156. void unlockImage();
  157. /**
  158. * If this image is unlocked, discard the image's decoded data. If the image
  159. * is locked or is already discarded, do nothing.
  160. */
  161. void requestDiscard();
  162. /**
  163. * If this request is for an animated image, the method creates a new
  164. * request which contains the current frame of the image.
  165. * Otherwise returns the same request.
  166. */
  167. imgIRequest getStaticRequest();
  168. /**
  169. * Requests that the image animate (if it has an animation).
  170. *
  171. * @see Image::IncrementAnimationConsumers for documentation of the
  172. * underlying call.
  173. */
  174. void incrementAnimationConsumers();
  175. /**
  176. * Tell the image it can forget about a request that the image animate.
  177. *
  178. * @see Image::DecrementAnimationConsumers for documentation of the
  179. * underlying call.
  180. */
  181. void decrementAnimationConsumers();
  182. };