nsIDownloadManager.idl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. // Keeps track of ongoing downloads, in the form of nsIDownload's.
  6. #include "nsISupports.idl"
  7. interface nsIURI;
  8. interface nsIFile;
  9. interface nsIDownload;
  10. interface nsICancelable;
  11. interface nsIMIMEInfo;
  12. interface nsIDownloadProgressListener;
  13. interface nsISimpleEnumerator;
  14. interface mozIStorageConnection;
  15. [scriptable, function, uuid(0c07ffeb-791b-49f3-ae38-2c331fd55a52)]
  16. interface nsIDownloadManagerResult : nsISupports {
  17. /**
  18. * Process an asynchronous result from getDownloadByGUID.
  19. *
  20. * @param aStatus The result code of the operation:
  21. * * NS_OK: an item was found. No other success values are returned.
  22. * * NS_ERROR_NOT_AVAILABLE: no such item was found.
  23. * * Other error values are possible, but less well-defined.
  24. */
  25. void handleResult(in nsresult aStatus, in nsIDownload aDownload);
  26. };
  27. [scriptable, uuid(b29aac15-7ec4-4ab3-a53b-08f78aed3b34)]
  28. interface nsIDownloadManager : nsISupports {
  29. /**
  30. * Download type for generic file download.
  31. */
  32. const short DOWNLOAD_TYPE_DOWNLOAD = 0;
  33. /**
  34. * Download state for uninitialized download object.
  35. */
  36. const short DOWNLOAD_NOTSTARTED = -1;
  37. /**
  38. * Download is currently transferring data.
  39. */
  40. const short DOWNLOAD_DOWNLOADING = 0;
  41. /**
  42. * Download completed including any processing of the target
  43. * file. (completed)
  44. */
  45. const short DOWNLOAD_FINISHED = 1;
  46. /**
  47. * Transfer failed due to error. (completed)
  48. */
  49. const short DOWNLOAD_FAILED = 2;
  50. /**
  51. * Download was canceled by the user. (completed)
  52. */
  53. const short DOWNLOAD_CANCELED = 3;
  54. /**
  55. * Transfer was paused by the user.
  56. */
  57. const short DOWNLOAD_PAUSED = 4;
  58. /**
  59. * Download is active but data has not yet been received.
  60. */
  61. const short DOWNLOAD_QUEUED = 5;
  62. /**
  63. * Transfer request was blocked by parental controls proxies. (completed)
  64. */
  65. const short DOWNLOAD_BLOCKED_PARENTAL = 6;
  66. /**
  67. * Transferred download is being scanned by virus scanners.
  68. */
  69. const short DOWNLOAD_SCANNING = 7;
  70. /**
  71. * A virus was detected in the download. The target will most likely
  72. * no longer exist. (completed)
  73. */
  74. const short DOWNLOAD_DIRTY = 8;
  75. /**
  76. * Win specific: Request was blocked by zone policy settings.
  77. * (see bug #416683) (completed)
  78. */
  79. const short DOWNLOAD_BLOCKED_POLICY = 9;
  80. /**
  81. * Creates an nsIDownload and adds it to be managed by the download manager.
  82. *
  83. * @param aSource The source URI of the transfer. Must not be null.
  84. *
  85. * @param aTarget The target URI of the transfer. Must not be null.
  86. *
  87. * @param aDisplayName The user-readable description of the transfer.
  88. * Can be empty.
  89. *
  90. * @param aMIMEInfo The MIME info associated with the target,
  91. * including MIME type and helper app when appropriate.
  92. * This parameter is optional.
  93. *
  94. * @param startTime Time when the download started
  95. *
  96. * @param aTempFile The location of a temporary file; i.e. a file in which
  97. * the received data will be stored, but which is not
  98. * equal to the target file. (will be moved to the real
  99. * target by the DownloadManager, when the download is
  100. * finished). This will be null for all callers except for
  101. * nsExternalHelperAppHandler. Addons should generally pass
  102. * null for aTempFile. This will be moved to the real target
  103. * by the download manager when the download is finished,
  104. * and the action indicated by aMIMEInfo will be executed.
  105. *
  106. * @param aCancelable An object that can be used to abort the download.
  107. * Must not be null.
  108. *
  109. * @param aIsPrivate Used to determine the privacy status of the new download.
  110. * If true, the download is stored in a manner that leaves
  111. * no permanent trace outside of the current private session.
  112. *
  113. * @return The newly created download item with the passed-in properties.
  114. *
  115. * @note This does not actually start a download. If you want to add and
  116. * start a download, you need to create an nsIWebBrowserPersist, pass it
  117. * as the aCancelable object, call this method, set the progressListener
  118. * as the returned download object, then call saveURI.
  119. */
  120. nsIDownload addDownload(in short aDownloadType,
  121. in nsIURI aSource,
  122. in nsIURI aTarget,
  123. in AString aDisplayName,
  124. in nsIMIMEInfo aMIMEInfo,
  125. in PRTime aStartTime,
  126. in nsIFile aTempFile,
  127. in nsICancelable aCancelable,
  128. in boolean aIsPrivate);
  129. /**
  130. * Retrieves a download managed by the download manager. This can be one that
  131. * is in progress, or one that has completed in the past and is stored in the
  132. * database.
  133. *
  134. * @param aID The unique ID of the download.
  135. * @return The download with the specified ID.
  136. * @throws NS_ERROR_NOT_AVAILABLE if the download is not in the database.
  137. */
  138. nsIDownload getDownload(in unsigned long aID);
  139. /**
  140. * Retrieves a download managed by the download manager. This can be one that
  141. * is in progress, or one that has completed in the past and is stored in the
  142. * database. The result of this method is returned via an asynchronous callback,
  143. * the parameter of which will be an nsIDownload object, or null if none exists
  144. * with the provided GUID.
  145. *
  146. * @param aGUID The unique GUID of the download.
  147. * @param aCallback The callback to invoke with the result of the search.
  148. */
  149. void getDownloadByGUID(in ACString aGUID, in nsIDownloadManagerResult aCallback);
  150. /**
  151. * Cancels the download with the specified ID if it's currently in-progress.
  152. * This calls cancel(NS_BINDING_ABORTED) on the nsICancelable provided by the
  153. * download.
  154. *
  155. * @param aID The unique ID of the download.
  156. * @throws NS_ERROR_FAILURE if the download is not in-progress.
  157. */
  158. void cancelDownload(in unsigned long aID);
  159. /**
  160. * Removes the download with the specified id if it's not currently
  161. * in-progress. Whereas cancelDownload simply cancels the transfer, but
  162. * retains information about it, removeDownload removes all knowledge of it.
  163. *
  164. * Also notifies observers of the "download-manager-remove-download-guid"
  165. * topic with the download guid as the subject to allow any DM consumers to
  166. * react to the removal.
  167. *
  168. * Also may notify observers of the "download-manager-remove-download" topic
  169. * with the download id as the subject, if the download removed is public
  170. * or if global private browsing mode is in use. This notification is deprecated;
  171. * the guid notification should be relied upon instead.
  172. *
  173. * @param aID The unique ID of the download.
  174. * @throws NS_ERROR_FAILURE if the download is active.
  175. */
  176. void removeDownload(in unsigned long aID);
  177. /**
  178. * Removes all inactive downloads that were started inclusively within the
  179. * specified time frame.
  180. *
  181. * @param aBeginTime
  182. * The start time to remove downloads by in microseconds.
  183. * @param aEndTime
  184. * The end time to remove downloads by in microseconds.
  185. */
  186. void removeDownloadsByTimeframe(in long long aBeginTime,
  187. in long long aEndTime);
  188. /**
  189. * Pause the specified download.
  190. *
  191. * @param aID The unique ID of the download.
  192. * @throws NS_ERROR_FAILURE if the download is not in-progress.
  193. */
  194. void pauseDownload(in unsigned long aID);
  195. /**
  196. * Resume the specified download.
  197. *
  198. * @param aID The unique ID of the download.
  199. * @throws NS_ERROR_FAILURE if the download is not in-progress.
  200. */
  201. void resumeDownload(in unsigned long aID);
  202. /**
  203. * Retries a failed download.
  204. *
  205. * @param aID The unique ID of the download.
  206. * @throws NS_ERROR_NOT_AVAILALE if the download id is not known.
  207. * @throws NS_ERROR_FAILURE if the download is not in the following states:
  208. * nsIDownloadManager::DOWNLOAD_CANCELED
  209. * nsIDownloadManager::DOWNLOAD_FAILED
  210. */
  211. void retryDownload(in unsigned long aID);
  212. /**
  213. * The database connection to the downloads database.
  214. */
  215. readonly attribute mozIStorageConnection DBConnection;
  216. readonly attribute mozIStorageConnection privateDBConnection;
  217. /**
  218. * Whether or not there are downloads that can be cleaned up (removed)
  219. * i.e. downloads that have completed, have failed or have been canceled.
  220. * In global private browsing mode, this reports the status of the relevant
  221. * private or public downloads. In per-window mode, it only reports for
  222. * public ones.
  223. */
  224. readonly attribute boolean canCleanUp;
  225. /**
  226. * Whether or not there are private downloads that can be cleaned up (removed)
  227. * i.e. downloads that have completed, have failed or have been canceled.
  228. */
  229. readonly attribute boolean canCleanUpPrivate;
  230. /**
  231. * Removes completed, failed, and canceled downloads from the list.
  232. * In global private browsing mode, this operates on the relevant
  233. * private or public downloads. In per-window mode, it only operates
  234. * on public ones.
  235. *
  236. * Also notifies observers of the "download-manager-remove-download-gui"
  237. * and "download-manager-remove-download" topics with a null subject to
  238. * allow any DM consumers to react to the removals.
  239. */
  240. void cleanUp();
  241. /**
  242. * Removes completed, failed, and canceled downloads from the list
  243. * of private downloads.
  244. *
  245. * Also notifies observers of the "download-manager-remove-download-gui"
  246. * and "download-manager-remove-download" topics with a null subject to
  247. * allow any DM consumers to react to the removals.
  248. */
  249. void cleanUpPrivate();
  250. /**
  251. * The number of files currently being downloaded.
  252. *
  253. * In global private browsing mode, this reports the status of the relevant
  254. * private or public downloads. In per-window mode, it only reports public
  255. * ones.
  256. */
  257. readonly attribute long activeDownloadCount;
  258. /**
  259. * The number of private files currently being downloaded.
  260. */
  261. readonly attribute long activePrivateDownloadCount;
  262. /**
  263. * An enumeration of active nsIDownloads
  264. *
  265. * In global private browsing mode, this reports the status of the relevant
  266. * private or public downloads. In per-window mode, it only reports public
  267. * ones.
  268. */
  269. readonly attribute nsISimpleEnumerator activeDownloads;
  270. /**
  271. * An enumeration of active private nsIDownloads
  272. */
  273. readonly attribute nsISimpleEnumerator activePrivateDownloads;
  274. /**
  275. * Adds a listener to the download manager. It is expected that this
  276. * listener will only access downloads via their deprecated integer id attribute,
  277. * and when global private browsing compatibility mode is disabled, this listener
  278. * will receive no notifications for downloads marked private.
  279. */
  280. void addListener(in nsIDownloadProgressListener aListener);
  281. /**
  282. * Adds a listener to the download manager. This listener must be able to
  283. * understand and use the guid attribute of downloads for all interactions
  284. * with the download manager.
  285. */
  286. void addPrivacyAwareListener(in nsIDownloadProgressListener aListener);
  287. /**
  288. * Removes a listener from the download manager.
  289. */
  290. void removeListener(in nsIDownloadProgressListener aListener);
  291. /**
  292. * Returns the platform default downloads directory.
  293. */
  294. readonly attribute nsIFile defaultDownloadsDirectory;
  295. /**
  296. * Returns the user configured downloads directory.
  297. * The path is dependent on two user configurable prefs
  298. * set in preferences:
  299. *
  300. * browser.download.folderList
  301. * Indicates the location users wish to save downloaded
  302. * files too.
  303. * Values:
  304. * 0 - The desktop is the default download location.
  305. * 1 - The system's downloads folder is the default download location.
  306. * 2 - The default download location is elsewhere as specified in
  307. * browser.download.dir. If invalid, userDownloadsDirectory
  308. * will fallback on defaultDownloadsDirectory.
  309. *
  310. * browser.download.dir -
  311. * A local path the user may have selected at some point
  312. * where downloaded files are saved. The use of which is
  313. * enabled when folderList equals 2.
  314. */
  315. readonly attribute nsIFile userDownloadsDirectory;
  316. };