|
1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
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 file, |
|
4 * You can obtain one at http://mozilla.org/MPL/2.0/. |
|
5 */ |
|
6 |
|
7 // Represents the state of a download. |
|
8 // "downloading": The resource is actively transfering. |
|
9 // "stopped" : No network tranfer is happening. |
|
10 // "succeeded" : The resource has been downloaded successfully. |
|
11 // "finalized" : We won't try to download this resource, but the DOM |
|
12 // object is still alive. |
|
13 enum DownloadState { |
|
14 "downloading", |
|
15 "stopped", |
|
16 "succeeded", |
|
17 "finalized" |
|
18 }; |
|
19 |
|
20 // |
|
21 // XXXTODO: When we have a generic way to do feature detection in marketplace |
|
22 // we will *STOP* using the pref and use the function like DOMDownload |
|
23 // and DownloadEvent. |
|
24 // |
|
25 [NoInterfaceObject, |
|
26 NavigatorProperty="mozDownloadManager", |
|
27 JSImplementation="@mozilla.org/downloads/manager;1", |
|
28 Pref="dom.mozDownloads.enabled"] |
|
29 interface DOMDownloadManager : EventTarget { |
|
30 // This promise returns an array of downloads with all the current |
|
31 // download objects. |
|
32 Promise getDownloads(); |
|
33 |
|
34 // Removes one download from the downloads set. Returns a promise resolved |
|
35 // with the finalized download. |
|
36 Promise remove(DOMDownload download); |
|
37 |
|
38 // Removes all the completed downloads from the set. |
|
39 Promise clearAllDone(); |
|
40 |
|
41 // Fires when a new download starts. |
|
42 attribute EventHandler ondownloadstart; |
|
43 }; |
|
44 |
|
45 [JSImplementation="@mozilla.org/downloads/download;1", |
|
46 Func="Navigator::HasDownloadsSupport"] |
|
47 interface DOMDownload : EventTarget { |
|
48 // The full size of the resource. |
|
49 readonly attribute long long totalBytes; |
|
50 |
|
51 // The number of bytes that we have currently downloaded. |
|
52 readonly attribute long long currentBytes; |
|
53 |
|
54 // The url of the resource. |
|
55 readonly attribute DOMString url; |
|
56 |
|
57 // The path in local storage where the file will end up once the download |
|
58 // is complete. |
|
59 readonly attribute DOMString path; |
|
60 |
|
61 // The state of the download. |
|
62 readonly attribute DownloadState state; |
|
63 |
|
64 // The mime type for this resource. |
|
65 readonly attribute DOMString contentType; |
|
66 |
|
67 // The timestamp this download started. |
|
68 readonly attribute Date startTime; |
|
69 |
|
70 // An opaque identifier for this download. All instances of the same |
|
71 // download (eg. in different windows) will have the same id. |
|
72 readonly attribute DOMString id; |
|
73 |
|
74 // A DOM error object, that will be not null when a download is stopped |
|
75 // because something failed. |
|
76 readonly attribute DOMError? error; |
|
77 |
|
78 // Pauses the download. |
|
79 Promise pause(); |
|
80 |
|
81 // Resumes the download. This resolves only once the download has |
|
82 // succeeded. |
|
83 Promise resume(); |
|
84 |
|
85 // This event is triggered anytime a property of the object changes: |
|
86 // - when the transfer progresses, updating currentBytes. |
|
87 // - when the state and/or error attributes change. |
|
88 attribute EventHandler onstatechange; |
|
89 }; |