[datacontrol][common] Simplify instance methods registration (2)
[platform/core/api/webapi-plugins.git] / src / download / download_api.js
index 20536ea..5ea0cf7 100755 (executable)
@@ -47,7 +47,6 @@ function DownloadManagerChangeCallback(result) {
         } else if (result.status == 'canceled') {
             if (callback.oncanceled) {
                 callback.oncanceled(result.downloadId);
-                delete callbacks[result.downloadId];
             }
         } else if (result.status == 'completed') {
             if (callback.oncompleted) {
@@ -58,7 +57,6 @@ function DownloadManagerChangeCallback(result) {
         } else if (result.status == 'error') {
             if (callback.onfailed) {
                 callback.onfailed(result.downloadId, new WebAPIException(result.error));
-                delete callbacks[result.downloadId];
             }
         }
     }, 0);
@@ -78,7 +76,8 @@ var DownloadState = {
     PAUSED: 'PAUSED',
     CANCELED: 'CANCELED',
     COMPLETED: 'COMPLETED',
-    FAILED: 'FAILED'
+    FAILED: 'FAILED',
+    ABANDONED: 'ABANDONED'
 };
 
 var DownloadNetworkType = {
@@ -188,7 +187,7 @@ DownloadManager.prototype.start = function() {
         this.setListener(nativeParam.downloadId, args.downloadCallback);
     }
 
-    var result = native_.callSync('DownloadManager_start', nativeParam);
+    var result = native_.callSync('DownloadManagerStart', nativeParam);
 
     if (native_.isFailure(result)) {
         if ('NetworkError' === result.error.name) {
@@ -217,7 +216,7 @@ DownloadManager.prototype.cancel = function() {
             'the identifier does not match any download operation in progress'
         );
 
-    var result = native_.callSync('DownloadManager_cancel', nativeParam);
+    var result = native_.callSync('DownloadManagerCancel', nativeParam);
 
     if (native_.isFailure(result)) {
         throw native_.getErrorObject(result);
@@ -239,13 +238,37 @@ DownloadManager.prototype.pause = function() {
             'the identifier does not match any download operation in progress'
         );
 
-    var result = native_.callSync('DownloadManager_pause', nativeParam);
+    var result = native_.callSync('DownloadManagerPause', nativeParam);
 
     if (native_.isFailure(result)) {
         throw native_.getErrorObject(result);
     }
 };
 
+DownloadManager.prototype.abandon = function() {
+    var args = validator_.validateArgs(arguments, [
+        { name: 'downloadId', type: types_.LONG, nullable: false, optional: false }
+    ]);
+
+    var nativeParam = {
+        downloadId: args.downloadId
+    };
+
+    if (typeof requests[args.downloadId] === 'undefined')
+        throw new WebAPIException(
+            WebAPIException.INVALID_VALUES_ERR,
+            'the identifier does not match any download operation in progress'
+        );
+
+    var result = native_.callSync('DownloadManagerAbandon', nativeParam);
+
+    if (native_.isFailure(result)) {
+        throw native_.getErrorObject(result);
+    }
+
+    delete callbacks[args.downloadId];
+};
+
 DownloadManager.prototype.resume = function() {
     var args = validator_.validateArgs(arguments, [
         { name: 'downloadId', type: types_.LONG, nullable: false, optional: false }
@@ -261,7 +284,7 @@ DownloadManager.prototype.resume = function() {
             'the identifier does not match any download operation in progress'
         );
 
-    var result = native_.callSync('DownloadManager_resume', nativeParam);
+    var result = native_.callSync('DownloadManagerResume', nativeParam);
 
     if (native_.isFailure(result)) {
         throw native_.getErrorObject(result);
@@ -283,7 +306,7 @@ DownloadManager.prototype.getState = function() {
             'the identifier does not match any download operation in progress'
         );
 
-    var result = native_.callSync('DownloadManager_getState', nativeParam);
+    var result = native_.callSync('DownloadManagerGetState', nativeParam);
 
     if (native_.isSuccess(result)) {
         return native_.getResultObject(result);
@@ -321,7 +344,7 @@ DownloadManager.prototype.getMIMEType = function() {
             'the identifier does not match any download operation in progress'
         );
 
-    var result = native_.callSync('DownloadManager_getMIMEType', nativeParam);
+    var result = native_.callSync('DownloadManagerGetMimeType', nativeParam);
 
     if (native_.isSuccess(result)) {
         return native_.getResultObject(result);