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 2146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2157 | 2157 |
2158 /** | 2158 /** |
2159 * Callback called when tasks for selected files are determined. | 2159 * Callback called when tasks for selected files are determined. |
2160 * @param {Object} selection Selection is passed here, since this.selection | 2160 * @param {Object} selection Selection is passed here, since this.selection |
2161 * can change before tasks were found, and we should be accurate. | 2161 * can change before tasks were found, and we should be accurate. |
2162 * @param {Array.<Task>} tasksList The tasks list. | 2162 * @param {Array.<Task>} tasksList The tasks list. |
2163 */ | 2163 */ |
2164 FileManager.prototype.onTasksFound_ = function(selection, tasksList) { | 2164 FileManager.prototype.onTasksFound_ = function(selection, tasksList) { |
2165 this.taskItems_.clear(); | 2165 this.taskItems_.clear(); |
2166 | 2166 |
2167 var tasksCount = 0; | |
2168 for (var i = 0; i < tasksList.length; i++) { | 2167 for (var i = 0; i < tasksList.length; i++) { |
2169 var task = tasksList[i]; | 2168 var task = tasksList[i]; |
2170 | 2169 |
2171 // Tweak images, titles of internal tasks. | 2170 // Tweak images, titles of internal tasks. |
2172 var task_parts = task.taskId.split('|'); | 2171 var task_parts = task.taskId.split('|'); |
2173 if (task_parts[0] == this.getExtensionId_()) { | 2172 if (task_parts[0] == this.getExtensionId_()) { |
2174 task.internal = true; | 2173 task.internal = true; |
2175 if (task_parts[1] == 'play') { | 2174 if (task_parts[1] == 'play') { |
2176 // TODO(serya): This hack needed until task.iconUrl is working | 2175 // TODO(serya): This hack needed until task.iconUrl is working |
2177 // (see GetFileTasksFileBrowserFunction::RunImpl). | 2176 // (see GetFileTasksFileBrowserFunction::RunImpl). |
2178 task.iconUrl = | 2177 task.iconUrl = |
2179 chrome.extension.getURL('images/icon_play_16x16.png'); | 2178 chrome.extension.getURL('images/icon_play_16x16.png'); |
2180 task.title = str('PLAY_MEDIA').replace("&", ""); | 2179 task.title = str('PLAY_MEDIA').replace("&", ""); |
2181 this.playTask_ = task; | 2180 this.playTask_ = task; |
2182 } else if (task_parts[1] == 'mount-archive') { | 2181 } else if (task_parts[1] == 'mount-archive') { |
2183 task.iconUrl = | 2182 task.iconUrl = |
2184 chrome.extension.getURL('images/icon_mount_archive_16x16.png'); | 2183 chrome.extension.getURL('images/icon_mount_archive_16x16.png'); |
2185 task.title = str('MOUNT_ARCHIVE'); | 2184 task.title = str('MOUNT_ARCHIVE'); |
2186 } else if (task_parts[1] == 'gallery') { | 2185 } else if (task_parts[1] == 'gallery') { |
2187 task.iconUrl = | 2186 task.iconUrl = |
2188 chrome.extension.getURL('images/icon_preview_16x16.png'); | 2187 chrome.extension.getURL('images/icon_preview_16x16.png'); |
2189 task.title = str('OPEN_ACTION'); | 2188 task.title = str('GALLERY'); |
2190 task.allTasks = tasksList; | 2189 task.allTasks = tasksList; |
2191 } else if (task_parts[1] == 'view-pdf') { | 2190 this.galleryTask_ = task; |
2192 // Do not render this task if disabled. | |
2193 if (str('PDF_VIEW_ENABLED') == 'false') continue; | |
2194 task.iconUrl = | |
2195 chrome.extension.getURL('images/icon_preview_16x16.png'); | |
2196 task.title = str('OPEN_ACTION'); | |
2197 } else if (task_parts[1] == 'view-txt') { | |
2198 task.iconUrl = | |
2199 chrome.extension.getURL('images/icon_preview_16x16.png'); | |
2200 task.title = str('OPEN_ACTION'); | |
2201 } else if (task_parts[1] == 'install-crx') { | |
2202 // TODO(dgozman): change to the right icon. | |
2203 task.iconUrl = | |
2204 chrome.extension.getURL('images/icon_preview_16x16.png'); | |
2205 task.title = str('INSTALL_CRX'); | |
2206 } | 2191 } |
2207 } | 2192 } |
2208 this.renderTaskItem_(task); | 2193 this.renderTaskItem_(task); |
2209 tasksCount++; | |
2210 } | 2194 } |
2211 | 2195 |
2212 this.taskItems_.visible = tasksCount > 0; | 2196 this.taskItems_.visible = tasksList.length > 0; |
2213 | 2197 |
2214 selection.tasksList = tasksList; | 2198 selection.tasksList = tasksList; |
2215 if (selection.dispatchDefault) { | 2199 if (selection.dispatchDefault) { |
2216 // We got a request to dispatch the default task for the selection. | 2200 // We got a request to dispatch the default task for the selection. |
2217 selection.dispatchDefault = false; | 2201 selection.dispatchDefault = false; |
2218 this.dispatchDefaultTask_(selection); | 2202 this.dispatchDefaultTask_(selection); |
2219 } | 2203 } |
2220 // These are done in separate functions, as the checks require | 2204 // These are done in separate functions, as the checks require |
2221 // asynchronous function calls. | 2205 // asynchronous function calls. |
2222 this.maybeRenderFormattingTask_(selection); | 2206 this.maybeRenderFormattingTask_(selection); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2454 var noGallery = []; | 2438 var noGallery = []; |
2455 for (var index = 0; index < details.task.allTasks.length; index++) { | 2439 for (var index = 0; index < details.task.allTasks.length; index++) { |
2456 var task = details.task.allTasks[index]; | 2440 var task = details.task.allTasks[index]; |
2457 if (task.taskId != this.getExtensionId_() + '|gallery') { | 2441 if (task.taskId != this.getExtensionId_() + '|gallery') { |
2458 // Add callback, so gallery can execute the task. | 2442 // Add callback, so gallery can execute the task. |
2459 task.execute = this.dispatchFileTask_.bind(this, task); | 2443 task.execute = this.dispatchFileTask_.bind(this, task); |
2460 noGallery.push(task); | 2444 noGallery.push(task); |
2461 } | 2445 } |
2462 } | 2446 } |
2463 this.openGallery_(urls, noGallery); | 2447 this.openGallery_(urls, noGallery); |
2464 } else if (id == 'view-pdf' || id == 'view-txt' || id == 'install-crx') { | |
2465 chrome.fileBrowserPrivate.viewFiles(urls, 'default', function() {}); | |
2466 } | 2448 } |
2467 }; | 2449 }; |
2468 | 2450 |
2469 FileManager.prototype.getDeviceNumber = function(entry) { | 2451 FileManager.prototype.getDeviceNumber = function(entry) { |
2470 if (!entry.isDirectory) return undefined; | 2452 if (!entry.isDirectory) return undefined; |
2471 for (var i = 0; i < this.mountPoints_.length; i++) { | 2453 for (var i = 0; i < this.mountPoints_.length; i++) { |
2472 if (normalizeAbsolutePath(entry.fullPath) == | 2454 if (normalizeAbsolutePath(entry.fullPath) == |
2473 normalizeAbsolutePath(this.mountPoints_[i].mountPath)) { | 2455 normalizeAbsolutePath(this.mountPoints_[i].mountPath)) { |
2474 return i; | 2456 return i; |
2475 } | 2457 } |
(...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3946 }); | 3928 }); |
3947 }, onError); | 3929 }, onError); |
3948 | 3930 |
3949 function onError(err) { | 3931 function onError(err) { |
3950 console.log('Error while checking free space: ' + err); | 3932 console.log('Error while checking free space: ' + err); |
3951 setTimeout(doCheck, 1000 * 60); | 3933 setTimeout(doCheck, 1000 * 60); |
3952 } | 3934 } |
3953 } | 3935 } |
3954 } | 3936 } |
3955 })(); | 3937 })(); |
OLD | NEW |