Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / file_manager / foreground / js / file_operation_manager_wrapper.js
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 'use strict';
6
7 /**
8  * While FileOperationManager is run in the background page, this class is
9  * used to communicate with it.
10  * @param {DOMWindow} backgroundPage Window object of the background page.
11  * @constructor
12  */
13 function FileOperationManagerWrapper(backgroundPage) {
14   this.fileOperationManager_ =
15       backgroundPage.FileOperationManager.getInstance();
16 }
17
18 /**
19  * Create a new instance or get existing instance of FCMW.
20  * @param {DOMWindow} backgroundPage Window object of the background page.
21  * @return {FileOperationManagerWrapper}  FileOperationManagerWrapper instance.
22  */
23 FileOperationManagerWrapper.getInstance = function(backgroundPage) {
24   if (!FileOperationManagerWrapper.instance_)
25     FileOperationManagerWrapper.instance_ =
26         new FileOperationManagerWrapper(backgroundPage);
27
28   return FileOperationManagerWrapper.instance_;
29 };
30
31 /**
32  * @return {boolean} True if there is a running task.
33  */
34 FileOperationManagerWrapper.prototype.isRunning = function() {
35   return this.fileOperationManager_.hasQueuedTasks();
36 };
37
38 /**
39  * Decorates a FileOperationManager method, so it will be executed after
40  * initializing the FileOperationManager instance in background page.
41  * @param {string} method The method name.
42  */
43 FileOperationManagerWrapper.decorateAsyncMethod = function(method) {
44   FileOperationManagerWrapper.prototype[method] = function() {
45     this.fileOperationManager_[method].apply(
46         this.fileOperationManager_, arguments);
47   };
48 };
49
50 FileOperationManagerWrapper.decorateAsyncMethod('paste');
51 FileOperationManagerWrapper.decorateAsyncMethod('deleteEntries');
52 FileOperationManagerWrapper.decorateAsyncMethod('forceDeleteTask');
53 FileOperationManagerWrapper.decorateAsyncMethod('cancelDeleteTask');
54 FileOperationManagerWrapper.decorateAsyncMethod('zipSelection');
55 FileOperationManagerWrapper.decorateAsyncMethod('addEventListener');
56 FileOperationManagerWrapper.decorateAsyncMethod('removeEventListener');