1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/webidl/Downloads.webidl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,89 @@ 1.4 +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. 1.8 + */ 1.9 + 1.10 +// Represents the state of a download. 1.11 +// "downloading": The resource is actively transfering. 1.12 +// "stopped" : No network tranfer is happening. 1.13 +// "succeeded" : The resource has been downloaded successfully. 1.14 +// "finalized" : We won't try to download this resource, but the DOM 1.15 +// object is still alive. 1.16 +enum DownloadState { 1.17 + "downloading", 1.18 + "stopped", 1.19 + "succeeded", 1.20 + "finalized" 1.21 +}; 1.22 + 1.23 +// 1.24 +// XXXTODO: When we have a generic way to do feature detection in marketplace 1.25 +// we will *STOP* using the pref and use the function like DOMDownload 1.26 +// and DownloadEvent. 1.27 +// 1.28 +[NoInterfaceObject, 1.29 + NavigatorProperty="mozDownloadManager", 1.30 + JSImplementation="@mozilla.org/downloads/manager;1", 1.31 + Pref="dom.mozDownloads.enabled"] 1.32 +interface DOMDownloadManager : EventTarget { 1.33 + // This promise returns an array of downloads with all the current 1.34 + // download objects. 1.35 + Promise getDownloads(); 1.36 + 1.37 + // Removes one download from the downloads set. Returns a promise resolved 1.38 + // with the finalized download. 1.39 + Promise remove(DOMDownload download); 1.40 + 1.41 + // Removes all the completed downloads from the set. 1.42 + Promise clearAllDone(); 1.43 + 1.44 + // Fires when a new download starts. 1.45 + attribute EventHandler ondownloadstart; 1.46 +}; 1.47 + 1.48 +[JSImplementation="@mozilla.org/downloads/download;1", 1.49 + Func="Navigator::HasDownloadsSupport"] 1.50 +interface DOMDownload : EventTarget { 1.51 + // The full size of the resource. 1.52 + readonly attribute long long totalBytes; 1.53 + 1.54 + // The number of bytes that we have currently downloaded. 1.55 + readonly attribute long long currentBytes; 1.56 + 1.57 + // The url of the resource. 1.58 + readonly attribute DOMString url; 1.59 + 1.60 + // The path in local storage where the file will end up once the download 1.61 + // is complete. 1.62 + readonly attribute DOMString path; 1.63 + 1.64 + // The state of the download. 1.65 + readonly attribute DownloadState state; 1.66 + 1.67 + // The mime type for this resource. 1.68 + readonly attribute DOMString contentType; 1.69 + 1.70 + // The timestamp this download started. 1.71 + readonly attribute Date startTime; 1.72 + 1.73 + // An opaque identifier for this download. All instances of the same 1.74 + // download (eg. in different windows) will have the same id. 1.75 + readonly attribute DOMString id; 1.76 + 1.77 + // A DOM error object, that will be not null when a download is stopped 1.78 + // because something failed. 1.79 + readonly attribute DOMError? error; 1.80 + 1.81 + // Pauses the download. 1.82 + Promise pause(); 1.83 + 1.84 + // Resumes the download. This resolves only once the download has 1.85 + // succeeded. 1.86 + Promise resume(); 1.87 + 1.88 + // This event is triggered anytime a property of the object changes: 1.89 + // - when the transfer progresses, updating currentBytes. 1.90 + // - when the state and/or error attributes change. 1.91 + attribute EventHandler onstatechange; 1.92 +};