michael@0: /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: // Represents the state of a download. michael@0: // "downloading": The resource is actively transfering. michael@0: // "stopped" : No network tranfer is happening. michael@0: // "succeeded" : The resource has been downloaded successfully. michael@0: // "finalized" : We won't try to download this resource, but the DOM michael@0: // object is still alive. michael@0: enum DownloadState { michael@0: "downloading", michael@0: "stopped", michael@0: "succeeded", michael@0: "finalized" michael@0: }; michael@0: michael@0: // michael@0: // XXXTODO: When we have a generic way to do feature detection in marketplace michael@0: // we will *STOP* using the pref and use the function like DOMDownload michael@0: // and DownloadEvent. michael@0: // michael@0: [NoInterfaceObject, michael@0: NavigatorProperty="mozDownloadManager", michael@0: JSImplementation="@mozilla.org/downloads/manager;1", michael@0: Pref="dom.mozDownloads.enabled"] michael@0: interface DOMDownloadManager : EventTarget { michael@0: // This promise returns an array of downloads with all the current michael@0: // download objects. michael@0: Promise getDownloads(); michael@0: michael@0: // Removes one download from the downloads set. Returns a promise resolved michael@0: // with the finalized download. michael@0: Promise remove(DOMDownload download); michael@0: michael@0: // Removes all the completed downloads from the set. michael@0: Promise clearAllDone(); michael@0: michael@0: // Fires when a new download starts. michael@0: attribute EventHandler ondownloadstart; michael@0: }; michael@0: michael@0: [JSImplementation="@mozilla.org/downloads/download;1", michael@0: Func="Navigator::HasDownloadsSupport"] michael@0: interface DOMDownload : EventTarget { michael@0: // The full size of the resource. michael@0: readonly attribute long long totalBytes; michael@0: michael@0: // The number of bytes that we have currently downloaded. michael@0: readonly attribute long long currentBytes; michael@0: michael@0: // The url of the resource. michael@0: readonly attribute DOMString url; michael@0: michael@0: // The path in local storage where the file will end up once the download michael@0: // is complete. michael@0: readonly attribute DOMString path; michael@0: michael@0: // The state of the download. michael@0: readonly attribute DownloadState state; michael@0: michael@0: // The mime type for this resource. michael@0: readonly attribute DOMString contentType; michael@0: michael@0: // The timestamp this download started. michael@0: readonly attribute Date startTime; michael@0: michael@0: // An opaque identifier for this download. All instances of the same michael@0: // download (eg. in different windows) will have the same id. michael@0: readonly attribute DOMString id; michael@0: michael@0: // A DOM error object, that will be not null when a download is stopped michael@0: // because something failed. michael@0: readonly attribute DOMError? error; michael@0: michael@0: // Pauses the download. michael@0: Promise pause(); michael@0: michael@0: // Resumes the download. This resolves only once the download has michael@0: // succeeded. michael@0: Promise resume(); michael@0: michael@0: // This event is triggered anytime a property of the object changes: michael@0: // - when the transfer progresses, updating currentBytes. michael@0: // - when the state and/or error attributes change. michael@0: attribute EventHandler onstatechange; michael@0: };