Bug 938023 - Implement the download API : Part 1, webidl. r=auswerk
authorFabrice Desré <fabrice@mozilla.com>
Wed, 27 Nov 2013 23:17:39 -0800
changeset 158444 19fbd3fb0373b46b02c6fe79c56a867161255bcb
parent 158443 e0dbabfa3d06a5ac468db615cbd5c0604ab87097
child 158445 4811dfce04077df38979fedab305d5adaa5fb16f
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersauswerk
bugs938023
milestone28.0a1
Bug 938023 - Implement the download API : Part 1, webidl. r=auswerk
b2g/app/b2g.js
dom/webidl/DownloadEvent.webidl
dom/webidl/Downloads.webidl
dom/webidl/moz.build
--- a/b2g/app/b2g.js
+++ b/b2g/app/b2g.js
@@ -833,8 +833,11 @@ pref("gfx.gralloc.fence-with-readpixels"
 // Cell Broadcast API
 pref("ril.cellbroadcast.disabled", false);
 
 // The url of the page used to display network error details.
 pref("b2g.neterror.url", "app://system.gaiamobile.org/net_error.html");
 
 // Enable Web Speech synthesis API
 pref("media.webspeech.synth.enabled", true);
+
+// Downloads API
+pref("dom.mozDownloads.enabled", true);
new file mode 100644
--- /dev/null
+++ b/dom/webidl/DownloadEvent.webidl
@@ -0,0 +1,17 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+[Constructor(DOMString type, optional DownloadEventInit eventInitDict),
+ Pref="dom.mozDownloads.enabled"]
+interface DownloadEvent : Event
+{
+  readonly attribute DOMDownload? download;
+};
+
+dictionary DownloadEventInit : EventInit
+{
+  DOMDownload? download = null;
+};
new file mode 100644
--- /dev/null
+++ b/dom/webidl/Downloads.webidl
@@ -0,0 +1,75 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+[NavigatorProperty="mozDownloadManager",
+ JSImplementation="@mozilla.org/downloads/manager;1",
+ Pref="dom.mozDownloads.enabled"]
+interface DOMDownloadManager : EventTarget {
+  // This promise returns an array of downloads with all the current
+  // download objects.
+  Promise getDownloads();
+
+  // Removes one download from the downloads set. Returns a promise resolved
+  // with the finalized download.
+  Promise remove(DOMDownload download);
+
+  // Removes all the completed downloads from the set.
+  Promise clearAllDone();
+
+  // Fires when a new download starts.
+  attribute EventHandler ondownloadstart;
+};
+
+[JSImplementation="@mozilla.org/downloads/download;1",
+ Pref="dom.mozDownloads.enabled"]
+interface DOMDownload : EventTarget {
+  // The full size of the resource.
+  readonly attribute long totalBytes;
+
+  // The number of bytes that we have currently downloaded.
+  readonly attribute long currentBytes;
+
+  // The url of the resource.
+  readonly attribute DOMString url;
+
+  // The path in local storage where the file will end up once the download
+  // is complete.
+  readonly attribute DOMString path;
+
+  // The state of the download. Can be any of:
+  // "downloading": The resource is actively transfering.
+  // "stopped"    : No network tranfer is happening.
+  // "succeeded"  : The resource has been downloaded successfully.
+  // "finalized"  : We won't try to download this resource, but the DOM
+  //                object is still alive.
+  readonly attribute DOMString state;
+
+  // The mime type for this resource.
+  readonly attribute DOMString contentType;
+
+  // The timestamp this download started.
+  readonly attribute Date startTime;
+
+  // An opaque identifier for this download. All instances of the same
+  // download (eg. in different windows) will have the same id.
+  readonly attribute DOMString id;
+
+  // A DOM error object, that will be not null when a download is stopped
+  // because something failed.
+  readonly attribute DOMError error;
+
+  // Pauses the download.
+  Promise pause();
+
+  // Resumes the download. This resolves only once the download has
+  // succeeded.
+  Promise resume();
+
+  // This event is triggered anytime a property of the object changes:
+  // - when the transfer progresses, updating currentBytes.
+  // - when the state and/or error attributes change.
+  attribute EventHandler onstatechange;
+};
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -81,16 +81,17 @@ WEBIDL_FILES = [
     'DOMParser.webidl',
     'DOMRect.webidl',
     'DOMRectList.webidl',
     'DOMRequest.webidl',
     'DOMSettableTokenList.webidl',
     'DOMStringMap.webidl',
     'DOMTokenList.webidl',
     'DOMTransaction.webidl',
+    'Downloads.webidl',
     'DragEvent.webidl',
     'DummyBinding.webidl',
     'DynamicsCompressorNode.webidl',
     'Element.webidl',
     'Event.webidl',
     'EventHandler.webidl',
     'EventListener.webidl',
     'EventSource.webidl',
@@ -561,16 +562,17 @@ if CONFIG['ENABLE_TESTS']:
     ]
 
 GENERATED_EVENTS_WEBIDL_FILES = [
     'BlobEvent.webidl',
     'CallGroupErrorEvent.webidl',
     'DataStoreChangeEvent.webidl',
     'DeviceLightEvent.webidl',
     'DeviceProximityEvent.webidl',
+    'DownloadEvent.webidl',
     'ErrorEvent.webidl',
     'IccChangeEvent.webidl',
     'MediaStreamEvent.webidl',
     'MozContactChangeEvent.webidl',
     'MozInterAppMessageEvent.webidl',
     'MozStkCommandEvent.webidl',
     'RTCDataChannelEvent.webidl',
     'RTCPeerConnectionIceEvent.webidl',