| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * This object encapsulates everything related to tasks execution. | 6 * This object encapsulates everything related to tasks execution. |
| 7 * @param {FileManager} fileManager FileManager instance. | 7 * @param {FileManager} fileManager FileManager instance. |
| 8 * @param {Array.<string>} urls List of file urls. | 8 * @param {Array.<string>} urls List of file urls. |
| 9 * @param {Array.<string>=} opt_mimeTypes List of MIME types for each | 9 * @param {Array.<string>=} opt_mimeTypes List of MIME types for each |
| 10 * of the files. | 10 * of the files. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 for (var i = 0; i < tasks.length; i++) { | 80 for (var i = 0; i < tasks.length; i++) { |
| 81 var task = tasks[i]; | 81 var task = tasks[i]; |
| 82 | 82 |
| 83 // Skip Drive App if the file is not on Drive. | 83 // Skip Drive App if the file is not on Drive. |
| 84 if (!is_on_drive && task.driveApp) | 84 if (!is_on_drive && task.driveApp) |
| 85 continue; | 85 continue; |
| 86 | 86 |
| 87 // Tweak images, titles of internal tasks. | 87 // Tweak images, titles of internal tasks. |
| 88 var task_parts = task.taskId.split('|'); | 88 var task_parts = task.taskId.split('|'); |
| 89 if (task_parts[0] == id) { | 89 if (task_parts[0] == id && task_parts[1] == 'file') { |
| 90 if (task_parts[1] == 'play') { | 90 if (task_parts[2] == 'play') { |
| 91 // TODO(serya): This hack needed until task.iconUrl is working | 91 // TODO(serya): This hack needed until task.iconUrl is working |
| 92 // (see GetFileTasksFileBrowserFunction::RunImpl). | 92 // (see GetFileTasksFileBrowserFunction::RunImpl). |
| 93 task.iconType = 'audio'; | 93 task.iconType = 'audio'; |
| 94 task.title = loadTimeData.getString('ACTION_LISTEN'); | 94 task.title = loadTimeData.getString('ACTION_LISTEN'); |
| 95 } else if (task_parts[1] == 'mount-archive') { | 95 } else if (task_parts[2] == 'mount-archive') { |
| 96 task.iconType = 'archive'; | 96 task.iconType = 'archive'; |
| 97 task.title = loadTimeData.getString('MOUNT_ARCHIVE'); | 97 task.title = loadTimeData.getString('MOUNT_ARCHIVE'); |
| 98 } else if (task_parts[1] == 'gallery') { | 98 } else if (task_parts[2] == 'gallery') { |
| 99 task.iconType = 'image'; | 99 task.iconType = 'image'; |
| 100 task.title = loadTimeData.getString('ACTION_OPEN'); | 100 task.title = loadTimeData.getString('ACTION_OPEN'); |
| 101 } else if (task_parts[1] == 'watch') { | 101 } else if (task_parts[2] == 'watch') { |
| 102 task.iconType = 'video'; | 102 task.iconType = 'video'; |
| 103 task.title = loadTimeData.getString('ACTION_WATCH'); | 103 task.title = loadTimeData.getString('ACTION_WATCH'); |
| 104 } else if (task_parts[1] == 'open-hosted-generic') { | 104 } else if (task_parts[2] == 'open-hosted-generic') { |
| 105 if (this.urls_.length > 1) | 105 if (this.urls_.length > 1) |
| 106 task.iconType = 'generic'; | 106 task.iconType = 'generic'; |
| 107 else // Use specific icon. | 107 else // Use specific icon. |
| 108 task.iconType = FileType.getIcon(this.urls_[0]); | 108 task.iconType = FileType.getIcon(this.urls_[0]); |
| 109 task.title = loadTimeData.getString('ACTION_OPEN'); | 109 task.title = loadTimeData.getString('ACTION_OPEN'); |
| 110 } else if (task_parts[1] == 'open-hosted-gdoc') { | 110 } else if (task_parts[2] == 'open-hosted-gdoc') { |
| 111 task.iconType = 'gdoc'; | 111 task.iconType = 'gdoc'; |
| 112 task.title = loadTimeData.getString('ACTION_OPEN_GDOC'); | 112 task.title = loadTimeData.getString('ACTION_OPEN_GDOC'); |
| 113 } else if (task_parts[1] == 'open-hosted-gsheet') { | 113 } else if (task_parts[2] == 'open-hosted-gsheet') { |
| 114 task.iconType = 'gsheet'; | 114 task.iconType = 'gsheet'; |
| 115 task.title = loadTimeData.getString('ACTION_OPEN_GSHEET'); | 115 task.title = loadTimeData.getString('ACTION_OPEN_GSHEET'); |
| 116 } else if (task_parts[1] == 'open-hosted-gslides') { | 116 } else if (task_parts[2] == 'open-hosted-gslides') { |
| 117 task.iconType = 'gslides'; | 117 task.iconType = 'gslides'; |
| 118 task.title = loadTimeData.getString('ACTION_OPEN_GSLIDES'); | 118 task.title = loadTimeData.getString('ACTION_OPEN_GSLIDES'); |
| 119 } else if (task_parts[1] == 'view-pdf') { | 119 } else if (task_parts[2] == 'view-pdf') { |
| 120 // Do not render this task if disabled. | 120 // Do not render this task if disabled. |
| 121 if (!loadTimeData.getBoolean('PDF_VIEW_ENABLED')) | 121 if (!loadTimeData.getBoolean('PDF_VIEW_ENABLED')) |
| 122 continue; | 122 continue; |
| 123 task.iconType = 'pdf'; | 123 task.iconType = 'pdf'; |
| 124 task.title = loadTimeData.getString('ACTION_VIEW'); | 124 task.title = loadTimeData.getString('ACTION_VIEW'); |
| 125 } else if (task_parts[1] == 'view-in-browser') { | 125 } else if (task_parts[2] == 'view-in-browser') { |
| 126 task.iconType = 'generic'; | 126 task.iconType = 'generic'; |
| 127 task.title = loadTimeData.getString('ACTION_VIEW'); | 127 task.title = loadTimeData.getString('ACTION_VIEW'); |
| 128 } else if (task_parts[1] == 'install-crx') { | 128 } else if (task_parts[2] == 'install-crx') { |
| 129 task.iconType = 'generic'; | 129 task.iconType = 'generic'; |
| 130 task.title = loadTimeData.getString('INSTALL_CRX'); | 130 task.title = loadTimeData.getString('INSTALL_CRX'); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 if (!task.iconType && task_parts[1] == 'web-intent') { |
| 135 task.iconType = 'generic'; |
| 136 } |
| 137 |
| 134 this.tasks_.push(task); | 138 this.tasks_.push(task); |
| 135 if (this.defaultTask_ == null && task.isDefault) { | 139 if (this.defaultTask_ == null && task.isDefault) { |
| 136 this.defaultTask_ = task; | 140 this.defaultTask_ = task; |
| 137 } | 141 } |
| 138 } | 142 } |
| 139 if (!this.defaultTask_ && this.tasks_.length > 0) { | 143 if (!this.defaultTask_ && this.tasks_.length > 0) { |
| 140 // If we haven't picked a default task yet, then just pick the first one. | 144 // If we haven't picked a default task yet, then just pick the first one. |
| 141 // This is not the preferred way we want to pick this, but better this than | 145 // This is not the preferred way we want to pick this, but better this than |
| 142 // no default at all if the C++ code didn't set one. | 146 // no default at all if the C++ code didn't set one. |
| 143 this.defaultTask_ = this.tasks_[0]; | 147 this.defaultTask_ = this.tasks_[0]; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 * @param {string} taskId Task identifier. | 187 * @param {string} taskId Task identifier. |
| 184 * @param {Array.<string>=} opt_urls Urls to execute on instead of |this.urls_|. | 188 * @param {Array.<string>=} opt_urls Urls to execute on instead of |this.urls_|. |
| 185 * @private | 189 * @private |
| 186 */ | 190 */ |
| 187 FileTasks.prototype.execute_ = function(taskId, opt_urls) { | 191 FileTasks.prototype.execute_ = function(taskId, opt_urls) { |
| 188 var urls = opt_urls || this.urls_; | 192 var urls = opt_urls || this.urls_; |
| 189 this.checkAvailability_(function() { | 193 this.checkAvailability_(function() { |
| 190 chrome.fileBrowserPrivate.executeTask(taskId, urls); | 194 chrome.fileBrowserPrivate.executeTask(taskId, urls); |
| 191 | 195 |
| 192 var task_parts = taskId.split('|'); | 196 var task_parts = taskId.split('|'); |
| 193 if (task_parts[0] == util.getExtensionId()) { | 197 if (task_parts[0] == util.getExtensionId() && task_parts[1] == 'file') { |
| 194 // For internal tasks we do not listen to the event to avoid | 198 // For internal tasks we do not listen to the event to avoid |
| 195 // handling the same task instance from multiple tabs. | 199 // handling the same task instance from multiple tabs. |
| 196 // So, we manually execute the task. | 200 // So, we manually execute the task. |
| 197 this.executeInternalTask_(task_parts[1], urls); | 201 this.executeInternalTask_(task_parts[2], urls); |
| 198 } | 202 } |
| 199 }.bind(this)); | 203 }.bind(this)); |
| 200 }; | 204 }; |
| 201 | 205 |
| 202 /** | 206 /** |
| 203 * Checks whether the remote files are available right now. | 207 * Checks whether the remote files are available right now. |
| 204 * @param {function} callback The callback. | 208 * @param {function} callback The callback. |
| 205 * @private | 209 * @private |
| 206 */ | 210 */ |
| 207 FileTasks.prototype.checkAvailability_ = function(callback) { | 211 FileTasks.prototype.checkAvailability_ = function(callback) { |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 message, | 540 message, |
| 537 items, defaultIdx, | 541 items, defaultIdx, |
| 538 onSuccess); | 542 onSuccess); |
| 539 }; | 543 }; |
| 540 | 544 |
| 541 FileTasks.decorate('display'); | 545 FileTasks.decorate('display'); |
| 542 FileTasks.decorate('updateMenuItem'); | 546 FileTasks.decorate('updateMenuItem'); |
| 543 FileTasks.decorate('execute'); | 547 FileTasks.decorate('execute'); |
| 544 FileTasks.decorate('executeDefault'); | 548 FileTasks.decorate('executeDefault'); |
| 545 | 549 |
| OLD | NEW |