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 | 7 |
8 /** | 8 /** |
9 * FileManager constructor. | 9 * FileManager constructor. |
10 * | 10 * |
(...skipping 2197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2208 */ | 2208 */ |
2209 FileManager.prototype.summarizeSelection_ = function() { | 2209 FileManager.prototype.summarizeSelection_ = function() { |
2210 var selection = this.selection = { | 2210 var selection = this.selection = { |
2211 entries: [], | 2211 entries: [], |
2212 urls: [], | 2212 urls: [], |
2213 totalCount: 0, | 2213 totalCount: 0, |
2214 fileCount: 0, | 2214 fileCount: 0, |
2215 directoryCount: 0, | 2215 directoryCount: 0, |
2216 bytes: 0, | 2216 bytes: 0, |
2217 showBytes: false, | 2217 showBytes: false, |
| 2218 allGDataFilesPresent: this.isOnGData(), |
2218 iconType: null, | 2219 iconType: null, |
2219 indexes: this.currentList_.selectionModel.selectedIndexes | 2220 indexes: this.currentList_.selectionModel.selectedIndexes |
2220 }; | 2221 }; |
2221 | 2222 |
2222 if (!selection.indexes.length) { | 2223 if (!selection.indexes.length) { |
2223 this.updateCommonActionButtons_(); | 2224 this.updateCommonActionButtons_(); |
2224 this.updatePreviewPanelVisibility_(); | 2225 this.updatePreviewPanelVisibility_(); |
2225 cr.dispatchSimpleEvent(this, 'selection-summarized'); | 2226 cr.dispatchSimpleEvent(this, 'selection-summarized'); |
2226 return; | 2227 return; |
2227 } | 2228 } |
2228 | 2229 |
2229 this.previewSummary_.textContent = str('COMPUTING_SELECTION'); | 2230 this.previewSummary_.textContent = str('COMPUTING_SELECTION'); |
2230 var thumbnails = this.document_.createDocumentFragment(); | 2231 var thumbnails = this.document_.createDocumentFragment(); |
2231 | 2232 |
2232 var fileCount = 0; | 2233 var fileCount = 0; |
2233 var byteCount = 0; | 2234 var byteCount = 0; |
2234 var pendingFiles = []; | 2235 var pendingFiles = []; |
| 2236 var pendingGDataFiles = []; |
2235 var thumbnailCount = 0; | 2237 var thumbnailCount = 0; |
2236 var thumbnailLoaded = -1; | 2238 var thumbnailLoaded = -1; |
2237 var forcedShowTimeout = null; | 2239 var forcedShowTimeout = null; |
2238 var self = this; | 2240 var self = this; |
2239 | 2241 |
2240 function showThumbnails() { | 2242 function showThumbnails() { |
2241 if (forcedShowTimeout === null) | 2243 if (forcedShowTimeout === null) |
2242 return; | 2244 return; |
2243 clearTimeout(forcedShowTimeout); | 2245 clearTimeout(forcedShowTimeout); |
2244 forcedShowTimeout = null; | 2246 forcedShowTimeout = null; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2298 // Any file that hasn't been rendered may be missing its cachedSize_ | 2300 // Any file that hasn't been rendered may be missing its cachedSize_ |
2299 // property. For example, visit a large file list, and press ctrl-a | 2301 // property. For example, visit a large file list, and press ctrl-a |
2300 // to select all. In this case, we need to asynchronously get the | 2302 // to select all. In this case, we need to asynchronously get the |
2301 // sizes for these files before telling the world the selection has | 2303 // sizes for these files before telling the world the selection has |
2302 // been summarized. See the 'computeNextFile' logic below. | 2304 // been summarized. See the 'computeNextFile' logic below. |
2303 pendingFiles.push(entry); | 2305 pendingFiles.push(entry); |
2304 } else { | 2306 } else { |
2305 selection.bytes += entry.cachedSize_; | 2307 selection.bytes += entry.cachedSize_; |
2306 selection.showBytes |= this.getFileType(entry).type != 'hosted'; | 2308 selection.showBytes |= this.getFileType(entry).type != 'hosted'; |
2307 } | 2309 } |
| 2310 |
| 2311 // Only keep checking if allGDataFilesPresent is not already false. |
| 2312 if (selection.allGDataFilesPresent) { |
| 2313 if (!('gdata_' in entry)) { |
| 2314 pendingGDataFiles.push(entry); |
| 2315 } else { |
| 2316 selection.allGDataFilesPresent = |
| 2317 FileManager.isAvaliableOffline_(entry.gdata_); |
| 2318 } |
| 2319 } |
2308 } else { | 2320 } else { |
2309 selection.directoryCount += 1; | 2321 selection.directoryCount += 1; |
| 2322 // We cannot afford checking every file under this directory so |
| 2323 // we conservatively assume that some files are not present. |
| 2324 selection.allGDataFilesPresent = false; |
2310 } | 2325 } |
2311 } | 2326 } |
2312 | 2327 |
2313 // Now this.selection is complete. Update buttons. | 2328 // Now this.selection is complete. Update buttons. |
2314 this.updateCommonActionButtons_(); | 2329 this.updateCommonActionButtons_(); |
2315 this.updatePreviewPanelVisibility_(); | 2330 this.updatePreviewPanelVisibility_(); |
2316 forcedShowTimeout = setTimeout(showThumbnails, 100); | 2331 forcedShowTimeout = setTimeout(showThumbnails, 100); |
2317 onThumbnailLoaded(); | 2332 onThumbnailLoaded(); |
2318 | 2333 |
| 2334 if (this.fileTransferController_) { |
| 2335 this.fileTransferController_.selectionAvailable = false; |
| 2336 } |
| 2337 |
| 2338 function maybeFireSummarized() { |
| 2339 if (pendingFiles.length == 0 && pendingGDataFiles.length == 0) |
| 2340 self.dispatchEvent(new cr.Event('selection-summarized')); |
| 2341 } |
| 2342 |
2319 function cacheNextFile(fileEntry) { | 2343 function cacheNextFile(fileEntry) { |
2320 if (fileEntry) { | 2344 if (fileEntry) { |
2321 // We're careful to modify the 'selection', rather than 'self.selection' | 2345 // We're careful to modify the 'selection', rather than 'self.selection' |
2322 // here, just in case the selection has changed since this summarization | 2346 // here, just in case the selection has changed since this summarization |
2323 // began. | 2347 // began. |
2324 selection.bytes += fileEntry.cachedSize_; | 2348 selection.bytes += fileEntry.cachedSize_; |
2325 selection.showBytes |= self.getFileType(fileEntry).type != 'hosted'; | 2349 selection.showBytes |= self.getFileType(fileEntry).type != 'hosted'; |
2326 } | 2350 } |
2327 | 2351 |
2328 if (pendingFiles.length) { | 2352 if (pendingFiles.length) { |
2329 cacheEntryDateAndSize(pendingFiles.pop(), cacheNextFile); | 2353 cacheEntryDateAndSize(pendingFiles.pop(), cacheNextFile); |
2330 } else { | 2354 } else { |
2331 self.dispatchEvent(new cr.Event('selection-summarized')); | 2355 maybeFireSummarized(); |
2332 } | 2356 } |
2333 } | 2357 } |
2334 | 2358 |
| 2359 function cacheNextGDataFile(fileEntry) { |
| 2360 // If selection.allGDataFilesPresent is already false we stop checking. |
| 2361 if (selection.allGDataFilesPresent && fileEntry) { |
| 2362 selection.allGDataFilesPresent = |
| 2363 FileManager.isAvaliableOffline_(fileEntry.gdata_); |
| 2364 } |
| 2365 if (selection.allGDataFilesPresent && pendingGDataFiles.length) { |
| 2366 cacheGDataProps(pendingGDataFiles.pop(), cacheNextGDataFile); |
| 2367 } else { |
| 2368 pendingGDataFiles = []; |
| 2369 maybeFireSummarized(); |
| 2370 } |
| 2371 } |
| 2372 |
2335 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { | 2373 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { |
2336 // Some internal tasks cannot be defined in terms of file patterns, | 2374 // Some internal tasks cannot be defined in terms of file patterns, |
2337 // so we pass selection to check for them manually. | 2375 // so we pass selection to check for them manually. |
2338 if (selection.directoryCount == 0 && selection.fileCount > 0) { | 2376 if (selection.directoryCount == 0 && selection.fileCount > 0) { |
2339 // Only files, not directories, are supported for external tasks. | 2377 // Only files, not directories, are supported for external tasks. |
2340 chrome.fileBrowserPrivate.getFileTasks( | 2378 chrome.fileBrowserPrivate.getFileTasks( |
2341 selection.urls, | 2379 selection.urls, |
2342 this.onTasksFound_.bind(this, selection)); | 2380 this.onTasksFound_.bind(this, selection)); |
2343 } else { | 2381 } else { |
2344 // There may be internal tasks for directories. | 2382 // There may be internal tasks for directories. |
2345 this.onTasksFound_(selection, []); | 2383 this.onTasksFound_(selection, []); |
2346 } | 2384 } |
2347 } | 2385 } |
2348 | 2386 |
2349 cacheNextFile(); | 2387 cacheNextFile(); |
| 2388 if (selection.allGDataFilesPresent) |
| 2389 cacheNextGDataFile(); |
2350 }; | 2390 }; |
2351 | 2391 |
2352 /** | 2392 /** |
2353 * Initialize a thumbnail in the bottom pannel to pop up on mouse over. | 2393 * Initialize a thumbnail in the bottom pannel to pop up on mouse over. |
2354 * Image's assumed to be just loaded and not inserted into the DOM. | 2394 * Image's assumed to be just loaded and not inserted into the DOM. |
2355 * | 2395 * |
2356 * @param {HTMLElement} box Element what's going to contain the image. | 2396 * @param {HTMLElement} box Element what's going to contain the image. |
2357 * @param {HTMLElement} img Loaded image. | 2397 * @param {HTMLElement} img Loaded image. |
2358 */ | 2398 */ |
2359 FileManager.prototype.initThumbnailZoom_ = function(box, img, transform) { | 2399 FileManager.prototype.initThumbnailZoom_ = function(box, img, transform) { |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2688 console.log('ONLINE'); | 2728 console.log('ONLINE'); |
2689 this.dialogContainer_.removeAttribute('offline'); | 2729 this.dialogContainer_.removeAttribute('offline'); |
2690 } | 2730 } |
2691 this.directoryModel_.offline = this.isOffline(); | 2731 this.directoryModel_.offline = this.isOffline(); |
2692 }; | 2732 }; |
2693 | 2733 |
2694 FileManager.prototype.isOnGDataOffline = function() { | 2734 FileManager.prototype.isOnGDataOffline = function() { |
2695 return this.isOnGData() && this.isOffline(); | 2735 return this.isOnGData() && this.isOffline(); |
2696 }; | 2736 }; |
2697 | 2737 |
| 2738 /** |
| 2739 * Check if all the files in the current selection are available. The only |
| 2740 * case when files might be not available is when the selection contains |
| 2741 * uncached GData files and the browser is offline. |
| 2742 * @return {boolean} True if all files in the current selection are available. |
| 2743 */ |
| 2744 FileManager.prototype.isSelectionAvailable = function() { |
| 2745 return !this.isOnGDataOffline() || this.selection.allGDataFilesPresent; |
| 2746 }; |
| 2747 |
2698 FileManager.prototype.isOnReadonlyDirectory = function() { | 2748 FileManager.prototype.isOnReadonlyDirectory = function() { |
2699 return this.directoryModel_.readonly; | 2749 return this.directoryModel_.readonly; |
2700 }; | 2750 }; |
2701 | 2751 |
2702 /** | 2752 /** |
2703 * Event handler called when some volume was mounted or unmouted. | 2753 * Event handler called when some volume was mounted or unmouted. |
2704 */ | 2754 */ |
2705 FileManager.prototype.onMountCompleted_ = function(event) { | 2755 FileManager.prototype.onMountCompleted_ = function(event) { |
2706 var self = this; | 2756 var self = this; |
2707 | 2757 |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3226 // TODO(dgozman): change the string to not contain ", $2". | 3276 // TODO(dgozman): change the string to not contain ", $2". |
3227 if (!selection.showBytes) text = text.substring(0, text.lastIndexOf(',')); | 3277 if (!selection.showBytes) text = text.substring(0, text.lastIndexOf(',')); |
3228 } else if (selection.fileCount == 0) { | 3278 } else if (selection.fileCount == 0) { |
3229 text = strf('MANY_DIRECTORIES_SELECTED', selection.directoryCount); | 3279 text = strf('MANY_DIRECTORIES_SELECTED', selection.directoryCount); |
3230 } else { | 3280 } else { |
3231 text = strf('MANY_ENTRIES_SELECTED', selection.totalCount, bytes); | 3281 text = strf('MANY_ENTRIES_SELECTED', selection.totalCount, bytes); |
3232 // TODO(dgozman): change the string to not contain ", $2". | 3282 // TODO(dgozman): change the string to not contain ", $2". |
3233 if (!selection.showBytes) text = text.substring(0, text.lastIndexOf(',')); | 3283 if (!selection.showBytes) text = text.substring(0, text.lastIndexOf(',')); |
3234 } | 3284 } |
3235 this.previewSummary_.textContent = text; | 3285 this.previewSummary_.textContent = text; |
| 3286 |
| 3287 this.updateOkButton_(); |
| 3288 if (this.fileTransferController_) { |
| 3289 this.fileTransferController_.selectionAvailable = |
| 3290 this.isSelectionAvailable(); |
| 3291 } |
3236 }; | 3292 }; |
3237 | 3293 |
3238 /** | 3294 /** |
3239 * Handle a click event on a breadcrumb element. | 3295 * Handle a click event on a breadcrumb element. |
3240 * | 3296 * |
3241 * @param {Event} event The click event. | 3297 * @param {Event} event The click event. |
3242 */ | 3298 */ |
3243 FileManager.prototype.onBreadcrumbClick_ = function(event) { | 3299 FileManager.prototype.onBreadcrumbClick_ = function(event) { |
3244 this.directoryModel_.changeDirectory(event.srcElement.path); | 3300 this.directoryModel_.changeDirectory(event.srcElement.path); |
3245 }; | 3301 }; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3371 this.updateSelectAllCheckboxState_(selectAllCheckbox); | 3427 this.updateSelectAllCheckboxState_(selectAllCheckbox); |
3372 }; | 3428 }; |
3373 | 3429 |
3374 FileManager.prototype.updateOkButton_ = function(event) { | 3430 FileManager.prototype.updateOkButton_ = function(event) { |
3375 var selectable; | 3431 var selectable; |
3376 | 3432 |
3377 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { | 3433 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { |
3378 selectable = this.selection.directoryCount == 1 && | 3434 selectable = this.selection.directoryCount == 1 && |
3379 this.selection.fileCount == 0; | 3435 this.selection.fileCount == 0; |
3380 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { | 3436 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { |
3381 selectable = (this.selection.directoryCount == 0 && | 3437 selectable = (this.isSelectionAvailable() && |
| 3438 this.selection.directoryCount == 0 && |
3382 this.selection.fileCount == 1); | 3439 this.selection.fileCount == 1); |
3383 } else if (this.dialogType_ == | 3440 } else if (this.dialogType_ == |
3384 FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { | 3441 FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { |
3385 selectable = (this.selection.directoryCount == 0 && | 3442 selectable = (this.isSelectionAvailable() && |
| 3443 this.selection.directoryCount == 0 && |
3386 this.selection.fileCount >= 1); | 3444 this.selection.fileCount >= 1); |
3387 } else if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { | 3445 } else if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { |
3388 if (this.isOnReadonlyDirectory()) { | 3446 if (this.isOnReadonlyDirectory()) { |
3389 selectable = false; | 3447 selectable = false; |
3390 } else { | 3448 } else { |
3391 selectable = !!this.filenameInput_.value; | 3449 selectable = !!this.filenameInput_.value; |
3392 } | 3450 } |
3393 } else if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { | 3451 } else if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { |
3394 // No "select" buttons on the full page UI. | 3452 // No "select" buttons on the full page UI. |
3395 selectable = true; | 3453 selectable = true; |
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4428 | 4486 |
4429 chrome.fileBrowserPrivate.setGDataPreferences(changeInfo); | 4487 chrome.fileBrowserPrivate.setGDataPreferences(changeInfo); |
4430 | 4488 |
4431 if (oldValue) { | 4489 if (oldValue) { |
4432 event.target.removeAttribute('checked'); | 4490 event.target.removeAttribute('checked'); |
4433 } else { | 4491 } else { |
4434 event.target.setAttribute('checked', 'checked'); | 4492 event.target.setAttribute('checked', 'checked'); |
4435 } | 4493 } |
4436 }; | 4494 }; |
4437 })(); | 4495 })(); |
OLD | NEW |