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