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 // Setting the src of an img to an empty string can crash the browser, so we | 5 // Setting the src of an img to an empty string can crash the browser, so we |
6 // use an empty 1x1 gif instead. | 6 // use an empty 1x1 gif instead. |
7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' | 7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' |
8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; | 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; |
9 | 9 |
10 /** | 10 /** |
(...skipping 2155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2166 | 2166 |
2167 /** | 2167 /** |
2168 * Callback called when tasks for selected files are determined. | 2168 * Callback called when tasks for selected files are determined. |
2169 * @param {Object} selection Selection is passed here, since this.selection | 2169 * @param {Object} selection Selection is passed here, since this.selection |
2170 * can change before tasks were found, and we should be accurate. | 2170 * can change before tasks were found, and we should be accurate. |
2171 * @param {Array.<Task>} tasksList The tasks list. | 2171 * @param {Array.<Task>} tasksList The tasks list. |
2172 */ | 2172 */ |
2173 FileManager.prototype.onTasksFound_ = function(selection, tasksList) { | 2173 FileManager.prototype.onTasksFound_ = function(selection, tasksList) { |
2174 this.taskItems_.clear(); | 2174 this.taskItems_.clear(); |
2175 | 2175 |
| 2176 var tasksCount = 0; |
2176 for (var i = 0; i < tasksList.length; i++) { | 2177 for (var i = 0; i < tasksList.length; i++) { |
2177 var task = tasksList[i]; | 2178 var task = tasksList[i]; |
2178 | 2179 |
2179 // Tweak images, titles of internal tasks. | 2180 // Tweak images, titles of internal tasks. |
2180 var task_parts = task.taskId.split('|'); | 2181 var task_parts = task.taskId.split('|'); |
2181 if (task_parts[0] == this.getExtensionId_()) { | 2182 if (task_parts[0] == this.getExtensionId_()) { |
2182 task.internal = true; | 2183 task.internal = true; |
2183 if (task_parts[1] == 'play') { | 2184 if (task_parts[1] == 'play') { |
2184 // TODO(serya): This hack needed until task.iconUrl is working | 2185 // TODO(serya): This hack needed until task.iconUrl is working |
2185 // (see GetFileTasksFileBrowserFunction::RunImpl). | 2186 // (see GetFileTasksFileBrowserFunction::RunImpl). |
2186 task.iconUrl = | 2187 task.iconUrl = |
2187 chrome.extension.getURL('images/icon_play_16x16.png'); | 2188 chrome.extension.getURL('images/icon_play_16x16.png'); |
2188 task.title = str('PLAY_MEDIA').replace("&", ""); | 2189 task.title = str('PLAY_MEDIA').replace("&", ""); |
2189 this.playTask_ = task; | 2190 this.playTask_ = task; |
2190 } else if (task_parts[1] == 'mount-archive') { | 2191 } else if (task_parts[1] == 'mount-archive') { |
2191 task.iconUrl = | 2192 task.iconUrl = |
2192 chrome.extension.getURL('images/icon_mount_archive_16x16.png'); | 2193 chrome.extension.getURL('images/icon_mount_archive_16x16.png'); |
2193 task.title = str('MOUNT_ARCHIVE'); | 2194 task.title = str('MOUNT_ARCHIVE'); |
2194 } else if (task_parts[1] == 'gallery') { | 2195 } else if (task_parts[1] == 'gallery') { |
2195 task.iconUrl = | 2196 task.iconUrl = |
2196 chrome.extension.getURL('images/icon_preview_16x16.png'); | 2197 chrome.extension.getURL('images/icon_preview_16x16.png'); |
2197 task.title = str('GALLERY'); | 2198 task.title = str('OPEN_ACTION'); |
2198 task.allTasks = tasksList; | 2199 task.allTasks = tasksList; |
2199 this.galleryTask_ = task; | 2200 } else if (task_parts[1] == 'view-pdf') { |
| 2201 // Do not render this task if disabled. |
| 2202 if (str('PDF_VIEW_ENABLED') == 'false') continue; |
| 2203 task.iconUrl = |
| 2204 chrome.extension.getURL('images/icon_preview_16x16.png'); |
| 2205 task.title = str('OPEN_ACTION'); |
| 2206 } else if (task_parts[1] == 'view-txt') { |
| 2207 task.iconUrl = |
| 2208 chrome.extension.getURL('images/icon_preview_16x16.png'); |
| 2209 task.title = str('OPEN_ACTION'); |
| 2210 } else if (task_parts[1] == 'install-crx') { |
| 2211 // TODO(dgozman): change to the right icon. |
| 2212 task.iconUrl = |
| 2213 chrome.extension.getURL('images/icon_preview_16x16.png'); |
| 2214 task.title = str('INSTALL_CRX'); |
2200 } | 2215 } |
2201 } | 2216 } |
2202 this.renderTaskItem_(task); | 2217 this.renderTaskItem_(task); |
| 2218 tasksCount++; |
2203 } | 2219 } |
2204 | 2220 |
2205 this.taskItems_.visible = tasksList.length > 0; | 2221 this.taskItems_.visible = tasksCount > 0; |
2206 | 2222 |
2207 selection.tasksList = tasksList; | 2223 selection.tasksList = tasksList; |
2208 if (selection.dispatchDefault) { | 2224 if (selection.dispatchDefault) { |
2209 // We got a request to dispatch the default task for the selection. | 2225 // We got a request to dispatch the default task for the selection. |
2210 selection.dispatchDefault = false; | 2226 selection.dispatchDefault = false; |
2211 this.dispatchDefaultTask_(selection); | 2227 this.dispatchDefaultTask_(selection); |
2212 } | 2228 } |
2213 // These are done in separate functions, as the checks require | 2229 // These are done in separate functions, as the checks require |
2214 // asynchronous function calls. | 2230 // asynchronous function calls. |
2215 this.maybeRenderFormattingTask_(selection); | 2231 this.maybeRenderFormattingTask_(selection); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2451 var noGallery = []; | 2467 var noGallery = []; |
2452 for (var index = 0; index < details.task.allTasks.length; index++) { | 2468 for (var index = 0; index < details.task.allTasks.length; index++) { |
2453 var task = details.task.allTasks[index]; | 2469 var task = details.task.allTasks[index]; |
2454 if (task.taskId != this.getExtensionId_() + '|gallery') { | 2470 if (task.taskId != this.getExtensionId_() + '|gallery') { |
2455 // Add callback, so gallery can execute the task. | 2471 // Add callback, so gallery can execute the task. |
2456 task.execute = this.dispatchFileTask_.bind(this, task); | 2472 task.execute = this.dispatchFileTask_.bind(this, task); |
2457 noGallery.push(task); | 2473 noGallery.push(task); |
2458 } | 2474 } |
2459 } | 2475 } |
2460 this.openGallery_(urls, noGallery); | 2476 this.openGallery_(urls, noGallery); |
| 2477 } else if (id == 'view-pdf' || id == 'view-txt' || id == 'install-crx') { |
| 2478 chrome.fileBrowserPrivate.viewFiles(urls, 'default', function() {}); |
2461 } | 2479 } |
2462 }; | 2480 }; |
2463 | 2481 |
2464 FileManager.prototype.getDeviceNumber = function(entry) { | 2482 FileManager.prototype.getDeviceNumber = function(entry) { |
2465 if (!entry.isDirectory) return undefined; | 2483 if (!entry.isDirectory) return undefined; |
2466 for (var i = 0; i < this.mountPoints_.length; i++) { | 2484 for (var i = 0; i < this.mountPoints_.length; i++) { |
2467 if (normalizeAbsolutePath(entry.fullPath) == | 2485 if (normalizeAbsolutePath(entry.fullPath) == |
2468 normalizeAbsolutePath(this.mountPoints_[i].mountPath)) { | 2486 normalizeAbsolutePath(this.mountPoints_[i].mountPath)) { |
2469 return i; | 2487 return i; |
2470 } | 2488 } |
(...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3935 }); | 3953 }); |
3936 }, onError); | 3954 }, onError); |
3937 | 3955 |
3938 function onError(err) { | 3956 function onError(err) { |
3939 console.log('Error while checking free space: ' + err); | 3957 console.log('Error while checking free space: ' + err); |
3940 setTimeout(doCheck, 1000 * 60); | 3958 setTimeout(doCheck, 1000 * 60); |
3941 } | 3959 } |
3942 } | 3960 } |
3943 } | 3961 } |
3944 })(); | 3962 })(); |
OLD | NEW |