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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * FileManager constructor. | 8 * FileManager constructor. |
9 * | 9 * |
10 * FileManager objects encapsulate the functionality of the file selector | 10 * FileManager objects encapsulate the functionality of the file selector |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 dm.addEventListener('scan-updated', this.onScanUpdated_.bind(this)); | 298 dm.addEventListener('scan-updated', this.onScanUpdated_.bind(this)); |
299 dm.addEventListener('rescan-completed', | 299 dm.addEventListener('rescan-completed', |
300 this.onRescanCompleted_.bind(this)); | 300 this.onRescanCompleted_.bind(this)); |
301 | 301 |
302 this.directoryTree_.addEventListener('change', function() { | 302 this.directoryTree_.addEventListener('change', function() { |
303 this.ensureDirectoryTreeItemNotBehindPreviewPanel_(); | 303 this.ensureDirectoryTreeItemNotBehindPreviewPanel_(); |
304 }.bind(this)); | 304 }.bind(this)); |
305 | 305 |
306 var stateChangeHandler = | 306 var stateChangeHandler = |
307 this.onPreferencesChanged_.bind(this); | 307 this.onPreferencesChanged_.bind(this); |
308 chrome.fileBrowserPrivate.onPreferencesChanged.addListener( | 308 chrome.fileManagerPrivate.onPreferencesChanged.addListener( |
309 stateChangeHandler); | 309 stateChangeHandler); |
310 stateChangeHandler(); | 310 stateChangeHandler(); |
311 | 311 |
312 var driveConnectionChangedHandler = | 312 var driveConnectionChangedHandler = |
313 this.onDriveConnectionChanged_.bind(this); | 313 this.onDriveConnectionChanged_.bind(this); |
314 this.volumeManager_.addEventListener('drive-connection-changed', | 314 this.volumeManager_.addEventListener('drive-connection-changed', |
315 driveConnectionChangedHandler); | 315 driveConnectionChangedHandler); |
316 driveConnectionChangedHandler(); | 316 driveConnectionChangedHandler(); |
317 | 317 |
318 // Set the initial focus. | 318 // Set the initial focus. |
(...skipping 1448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1767 * Sets the given task as default, when this task is applicable. | 1767 * Sets the given task as default, when this task is applicable. |
1768 * | 1768 * |
1769 * @param {Object} task Task to set as default. | 1769 * @param {Object} task Task to set as default. |
1770 * @private | 1770 * @private |
1771 */ | 1771 */ |
1772 FileManager.prototype.onDefaultTaskDone_ = function(task) { | 1772 FileManager.prototype.onDefaultTaskDone_ = function(task) { |
1773 // TODO(dgozman): move this method closer to tasks. | 1773 // TODO(dgozman): move this method closer to tasks. |
1774 var selection = this.getSelection(); | 1774 var selection = this.getSelection(); |
1775 // TODO(mtomasz): Move conversion from entry to url to custom bindings. | 1775 // TODO(mtomasz): Move conversion from entry to url to custom bindings. |
1776 // crbug.com/345527. | 1776 // crbug.com/345527. |
1777 chrome.fileBrowserPrivate.setDefaultTask( | 1777 chrome.fileManagerPrivate.setDefaultTask( |
1778 task.taskId, | 1778 task.taskId, |
1779 util.entriesToURLs(selection.entries), | 1779 util.entriesToURLs(selection.entries), |
1780 selection.mimeTypes); | 1780 selection.mimeTypes); |
1781 selection.tasks = new FileTasks(this); | 1781 selection.tasks = new FileTasks(this); |
1782 selection.tasks.init(selection.entries, selection.mimeTypes); | 1782 selection.tasks.init(selection.entries, selection.mimeTypes); |
1783 selection.tasks.display(this.taskItems_); | 1783 selection.tasks.display(this.taskItems_); |
1784 this.refreshCurrentDirectoryMetadata_(); | 1784 this.refreshCurrentDirectoryMetadata_(); |
1785 this.selectionHandler_.onFileSelectionChanged(); | 1785 this.selectionHandler_.onFileSelectionChanged(); |
1786 }; | 1786 }; |
1787 | 1787 |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2181 | 2181 |
2182 volumeSpaceInfo.hidden = false; | 2182 volumeSpaceInfo.hidden = false; |
2183 volumeSpaceInfoSeparator.hidden = false; | 2183 volumeSpaceInfoSeparator.hidden = false; |
2184 volumeSpaceInnerBar.setAttribute('pending', ''); | 2184 volumeSpaceInnerBar.setAttribute('pending', ''); |
2185 | 2185 |
2186 if (showLoadingCaption) { | 2186 if (showLoadingCaption) { |
2187 volumeSpaceInfoLabel.innerText = str('WAITING_FOR_SPACE_INFO'); | 2187 volumeSpaceInfoLabel.innerText = str('WAITING_FOR_SPACE_INFO'); |
2188 volumeSpaceInnerBar.style.width = '100%'; | 2188 volumeSpaceInnerBar.style.width = '100%'; |
2189 } | 2189 } |
2190 | 2190 |
2191 chrome.fileBrowserPrivate.getSizeStats( | 2191 chrome.fileManagerPrivate.getSizeStats( |
2192 currentVolumeInfo.volumeId, function(result) { | 2192 currentVolumeInfo.volumeId, function(result) { |
2193 var volumeInfo = this.volumeManager_.getVolumeInfo( | 2193 var volumeInfo = this.volumeManager_.getVolumeInfo( |
2194 this.directoryModel_.getCurrentDirEntry()); | 2194 this.directoryModel_.getCurrentDirEntry()); |
2195 if (currentVolumeInfo !== this.currentVolumeInfo_) | 2195 if (currentVolumeInfo !== this.currentVolumeInfo_) |
2196 return; | 2196 return; |
2197 updateSpaceInfo(result, | 2197 updateSpaceInfo(result, |
2198 volumeSpaceInnerBar, | 2198 volumeSpaceInnerBar, |
2199 volumeSpaceInfoLabel, | 2199 volumeSpaceInfoLabel, |
2200 volumeSpaceOuterBar); | 2200 volumeSpaceOuterBar); |
2201 }.bind(this)); | 2201 }.bind(this)); |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2941 }; | 2941 }; |
2942 | 2942 |
2943 /** | 2943 /** |
2944 * Handle a click of the cancel button. Closes the window. | 2944 * Handle a click of the cancel button. Closes the window. |
2945 * TODO(jamescook): Make unload handler work automatically, crbug.com/104811 | 2945 * TODO(jamescook): Make unload handler work automatically, crbug.com/104811 |
2946 * | 2946 * |
2947 * @param {Event} event The click event. | 2947 * @param {Event} event The click event. |
2948 * @private | 2948 * @private |
2949 */ | 2949 */ |
2950 FileManager.prototype.onCancel_ = function(event) { | 2950 FileManager.prototype.onCancel_ = function(event) { |
2951 chrome.fileBrowserPrivate.cancelDialog(); | 2951 chrome.fileManagerPrivate.cancelDialog(); |
2952 window.close(); | 2952 window.close(); |
2953 }; | 2953 }; |
2954 | 2954 |
2955 /** | 2955 /** |
2956 * Resolves selected file urls returned from an Open dialog. | 2956 * Resolves selected file urls returned from an Open dialog. |
2957 * | 2957 * |
2958 * For drive files this involves some special treatment. | 2958 * For drive files this involves some special treatment. |
2959 * Starts getting drive files if needed. | 2959 * Starts getting drive files if needed. |
2960 * | 2960 * |
2961 * @param {Array.<string>} fileUrls Drive URLs. | 2961 * @param {Array.<string>} fileUrls Drive URLs. |
2962 * @param {function(Array.<string>)} callback To be called with fixed URLs. | 2962 * @param {function(Array.<string>)} callback To be called with fixed URLs. |
2963 * @private | 2963 * @private |
2964 */ | 2964 */ |
2965 FileManager.prototype.resolveSelectResults_ = function(fileUrls, callback) { | 2965 FileManager.prototype.resolveSelectResults_ = function(fileUrls, callback) { |
2966 if (this.isOnDrive()) { | 2966 if (this.isOnDrive()) { |
2967 chrome.fileBrowserPrivate.getDriveFiles( | 2967 chrome.fileManagerPrivate.getDriveFiles( |
2968 fileUrls, | 2968 fileUrls, |
2969 function(localPaths) { | 2969 function(localPaths) { |
2970 callback(fileUrls); | 2970 callback(fileUrls); |
2971 }); | 2971 }); |
2972 } else { | 2972 } else { |
2973 callback(fileUrls); | 2973 callback(fileUrls); |
2974 } | 2974 } |
2975 }; | 2975 }; |
2976 | 2976 |
2977 /** | 2977 /** |
2978 * Closes this modal dialog with some files selected. | 2978 * Closes this modal dialog with some files selected. |
2979 * TODO(jamescook): Make unload handler work automatically, crbug.com/104811 | 2979 * TODO(jamescook): Make unload handler work automatically, crbug.com/104811 |
2980 * @param {Object} selection Contains urls, filterIndex and multiple fields. | 2980 * @param {Object} selection Contains urls, filterIndex and multiple fields. |
2981 * @private | 2981 * @private |
2982 */ | 2982 */ |
2983 FileManager.prototype.callSelectFilesApiAndClose_ = function(selection) { | 2983 FileManager.prototype.callSelectFilesApiAndClose_ = function(selection) { |
2984 var self = this; | 2984 var self = this; |
2985 function callback() { | 2985 function callback() { |
2986 window.close(); | 2986 window.close(); |
2987 } | 2987 } |
2988 if (selection.multiple) { | 2988 if (selection.multiple) { |
2989 chrome.fileBrowserPrivate.selectFiles( | 2989 chrome.fileManagerPrivate.selectFiles( |
2990 selection.urls, this.params_.shouldReturnLocalPath, callback); | 2990 selection.urls, this.params_.shouldReturnLocalPath, callback); |
2991 } else { | 2991 } else { |
2992 var forOpening = (this.dialogType != DialogType.SELECT_SAVEAS_FILE); | 2992 var forOpening = (this.dialogType != DialogType.SELECT_SAVEAS_FILE); |
2993 chrome.fileBrowserPrivate.selectFile( | 2993 chrome.fileManagerPrivate.selectFile( |
2994 selection.urls[0], selection.filterIndex, forOpening, | 2994 selection.urls[0], selection.filterIndex, forOpening, |
2995 this.params_.shouldReturnLocalPath, callback); | 2995 this.params_.shouldReturnLocalPath, callback); |
2996 } | 2996 } |
2997 }; | 2997 }; |
2998 | 2998 |
2999 /** | 2999 /** |
3000 * Tries to close this modal dialog with some files selected. | 3000 * Tries to close this modal dialog with some files selected. |
3001 * Performs preprocessing if needed (e.g. for Drive). | 3001 * Performs preprocessing if needed (e.g. for Drive). |
3002 * @param {Object} selection Contains urls, filterIndex and multiple fields. | 3002 * @param {Object} selection Contains urls, filterIndex and multiple fields. |
3003 * @private | 3003 * @private |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3046 lastPercent = Math.max(lastPercent, percent); | 3046 lastPercent = Math.max(lastPercent, percent); |
3047 progress.style.width = lastPercent + '%'; | 3047 progress.style.width = lastPercent + '%'; |
3048 }.bind(this); | 3048 }.bind(this); |
3049 | 3049 |
3050 var setup = function() { | 3050 var setup = function() { |
3051 this.document_.querySelector('.dialog-container').appendChild(shade); | 3051 this.document_.querySelector('.dialog-container').appendChild(shade); |
3052 setTimeout(function() { shade.setAttribute('fadein', 'fadein') }, 100); | 3052 setTimeout(function() { shade.setAttribute('fadein', 'fadein') }, 100); |
3053 footer.setAttribute('progress', 'progress'); | 3053 footer.setAttribute('progress', 'progress'); |
3054 this.cancelButton_.removeEventListener('click', this.onCancelBound_); | 3054 this.cancelButton_.removeEventListener('click', this.onCancelBound_); |
3055 this.cancelButton_.addEventListener('click', onCancel); | 3055 this.cancelButton_.addEventListener('click', onCancel); |
3056 chrome.fileBrowserPrivate.onFileTransfersUpdated.addListener( | 3056 chrome.fileManagerPrivate.onFileTransfersUpdated.addListener( |
3057 onFileTransfersUpdated); | 3057 onFileTransfersUpdated); |
3058 }.bind(this); | 3058 }.bind(this); |
3059 | 3059 |
3060 var cleanup = function() { | 3060 var cleanup = function() { |
3061 shade.parentNode.removeChild(shade); | 3061 shade.parentNode.removeChild(shade); |
3062 footer.removeAttribute('progress'); | 3062 footer.removeAttribute('progress'); |
3063 this.cancelButton_.removeEventListener('click', onCancel); | 3063 this.cancelButton_.removeEventListener('click', onCancel); |
3064 this.cancelButton_.addEventListener('click', this.onCancelBound_); | 3064 this.cancelButton_.addEventListener('click', this.onCancelBound_); |
3065 chrome.fileBrowserPrivate.onFileTransfersUpdated.removeListener( | 3065 chrome.fileManagerPrivate.onFileTransfersUpdated.removeListener( |
3066 onFileTransfersUpdated); | 3066 onFileTransfersUpdated); |
3067 }.bind(this); | 3067 }.bind(this); |
3068 | 3068 |
3069 var onCancel = function() { | 3069 var onCancel = function() { |
3070 cancelled = true; | 3070 cancelled = true; |
3071 // According to API cancel may fail, but there is no proper UI to reflect | 3071 // According to API cancel may fail, but there is no proper UI to reflect |
3072 // this. So, we just silently assume that everything is cancelled. | 3072 // this. So, we just silently assume that everything is cancelled. |
3073 chrome.fileBrowserPrivate.cancelFileTransfers( | 3073 chrome.fileManagerPrivate.cancelFileTransfers( |
3074 selection.urls, function(response) {}); | 3074 selection.urls, function(response) {}); |
3075 cleanup(); | 3075 cleanup(); |
3076 }.bind(this); | 3076 }.bind(this); |
3077 | 3077 |
3078 var onResolved = function(resolvedUrls) { | 3078 var onResolved = function(resolvedUrls) { |
3079 if (cancelled) return; | 3079 if (cancelled) return; |
3080 cleanup(); | 3080 cleanup(); |
3081 selection.urls = resolvedUrls; | 3081 selection.urls = resolvedUrls; |
3082 // Call next method on a timeout, as it's unsafe to | 3082 // Call next method on a timeout, as it's unsafe to |
3083 // close a window from a callback. | 3083 // close a window from a callback. |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3261 }); | 3261 }); |
3262 }; | 3262 }; |
3263 | 3263 |
3264 /** | 3264 /** |
3265 * Toggle whether mobile data is used for sync. | 3265 * Toggle whether mobile data is used for sync. |
3266 */ | 3266 */ |
3267 FileManager.prototype.toggleDriveSyncSettings = function() { | 3267 FileManager.prototype.toggleDriveSyncSettings = function() { |
3268 // If checked, the sync is disabled. | 3268 // If checked, the sync is disabled. |
3269 var nowCellularDisabled = this.syncButton.hasAttribute('checked'); | 3269 var nowCellularDisabled = this.syncButton.hasAttribute('checked'); |
3270 var changeInfo = {cellularDisabled: !nowCellularDisabled}; | 3270 var changeInfo = {cellularDisabled: !nowCellularDisabled}; |
3271 chrome.fileBrowserPrivate.setPreferences(changeInfo); | 3271 chrome.fileManagerPrivate.setPreferences(changeInfo); |
3272 }; | 3272 }; |
3273 | 3273 |
3274 /** | 3274 /** |
3275 * Toggle whether Google Docs files are shown. | 3275 * Toggle whether Google Docs files are shown. |
3276 */ | 3276 */ |
3277 FileManager.prototype.toggleDriveHostedSettings = function() { | 3277 FileManager.prototype.toggleDriveHostedSettings = function() { |
3278 // If checked, showing drive hosted files is enabled. | 3278 // If checked, showing drive hosted files is enabled. |
3279 var nowHostedFilesEnabled = this.hostedButton.hasAttribute('checked'); | 3279 var nowHostedFilesEnabled = this.hostedButton.hasAttribute('checked'); |
3280 var nowHostedFilesDisabled = !nowHostedFilesEnabled; | 3280 var nowHostedFilesDisabled = !nowHostedFilesEnabled; |
3281 /* | 3281 /* |
3282 var changeInfo = {hostedFilesDisabled: !nowHostedFilesDisabled}; | 3282 var changeInfo = {hostedFilesDisabled: !nowHostedFilesDisabled}; |
3283 */ | 3283 */ |
3284 var changeInfo = {}; | 3284 var changeInfo = {}; |
3285 changeInfo['hostedFilesDisabled'] = !nowHostedFilesDisabled; | 3285 changeInfo['hostedFilesDisabled'] = !nowHostedFilesDisabled; |
3286 chrome.fileBrowserPrivate.setPreferences(changeInfo); | 3286 chrome.fileManagerPrivate.setPreferences(changeInfo); |
3287 }; | 3287 }; |
3288 | 3288 |
3289 /** | 3289 /** |
3290 * Invoked when the search box is changed. | 3290 * Invoked when the search box is changed. |
3291 * | 3291 * |
3292 * @param {Event} event The changed event. | 3292 * @param {Event} event The changed event. |
3293 * @private | 3293 * @private |
3294 */ | 3294 */ |
3295 FileManager.prototype.onSearchBoxUpdate_ = function(event) { | 3295 FileManager.prototype.onSearchBoxUpdate_ = function(event) { |
3296 var searchString = this.searchBox_.value; | 3296 var searchString = this.searchBox_.value; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3421 // search box is resized when it's focused. | 3421 // search box is resized when it's focused. |
3422 this.autocompleteList_.syncWidthAndPositionToInput(); | 3422 this.autocompleteList_.syncWidthAndPositionToInput(); |
3423 | 3423 |
3424 this.autocompleteSuggestionsBusy_ = true; | 3424 this.autocompleteSuggestionsBusy_ = true; |
3425 | 3425 |
3426 var searchParams = { | 3426 var searchParams = { |
3427 'query': query, | 3427 'query': query, |
3428 'types': 'ALL', | 3428 'types': 'ALL', |
3429 'maxResults': 4 | 3429 'maxResults': 4 |
3430 }; | 3430 }; |
3431 chrome.fileBrowserPrivate.searchDriveMetadata( | 3431 chrome.fileManagerPrivate.searchDriveMetadata( |
3432 searchParams, | 3432 searchParams, |
3433 function(suggestions) { | 3433 function(suggestions) { |
3434 this.autocompleteSuggestionsBusy_ = false; | 3434 this.autocompleteSuggestionsBusy_ = false; |
3435 | 3435 |
3436 // Discard results for previous requests and fire a new search | 3436 // Discard results for previous requests and fire a new search |
3437 // for the most recent query. | 3437 // for the most recent query. |
3438 if (query != this.lastAutocompleteQuery_) { | 3438 if (query != this.lastAutocompleteQuery_) { |
3439 this.requestAutocompleteSuggestions_(this.lastAutocompleteQuery_); | 3439 this.requestAutocompleteSuggestions_(this.lastAutocompleteQuery_); |
3440 return; | 3440 return; |
3441 } | 3441 } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3608 * @param {boolean=} opt_update If is's true, don't use the cache and | 3608 * @param {boolean=} opt_update If is's true, don't use the cache and |
3609 * retrieve latest preference. Default is false. | 3609 * retrieve latest preference. Default is false. |
3610 * @private | 3610 * @private |
3611 */ | 3611 */ |
3612 FileManager.prototype.getPreferences_ = function(callback, opt_update) { | 3612 FileManager.prototype.getPreferences_ = function(callback, opt_update) { |
3613 if (!opt_update && this.preferences_ !== undefined) { | 3613 if (!opt_update && this.preferences_ !== undefined) { |
3614 callback(this.preferences_); | 3614 callback(this.preferences_); |
3615 return; | 3615 return; |
3616 } | 3616 } |
3617 | 3617 |
3618 chrome.fileBrowserPrivate.getPreferences(function(prefs) { | 3618 chrome.fileManagerPrivate.getPreferences(function(prefs) { |
3619 this.preferences_ = prefs; | 3619 this.preferences_ = prefs; |
3620 callback(prefs); | 3620 callback(prefs); |
3621 }.bind(this)); | 3621 }.bind(this)); |
3622 }; | 3622 }; |
3623 })(); | 3623 })(); |
OLD | NEW |