| 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 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 * initializing methods. | 571 * initializing methods. |
| 572 * | 572 * |
| 573 * @param {function()} callback Completion callback. | 573 * @param {function()} callback Completion callback. |
| 574 * @private | 574 * @private |
| 575 */ | 575 */ |
| 576 FileManager.prototype.initGeneral_ = function(callback) { | 576 FileManager.prototype.initGeneral_ = function(callback) { |
| 577 // Initialize the application state. | 577 // Initialize the application state. |
| 578 // TODO(mtomasz): Unify window.appState with location.search format. | 578 // TODO(mtomasz): Unify window.appState with location.search format. |
| 579 if (window.appState) { | 579 if (window.appState) { |
| 580 this.params_ = window.appState.params || {}; | 580 this.params_ = window.appState.params || {}; |
| 581 this.initCurrentDirectoryPath_ = window.appState.currentDirectoryPath; | 581 this.initCurrentDirectoryURL_ = window.appState.currentDirectoryURL; |
| 582 this.initSelectionPath_ = window.appState.selectionPath; | 582 this.initSelectionPath_ = window.appState.selectionURL; |
| 583 this.initTargetName_ = window.appState.targetName; | 583 this.initTargetName_ = window.appState.targetName; |
| 584 } else { | 584 } else { |
| 585 // Used by the select dialog only. | 585 // Used by the select dialog only. |
| 586 this.params_ = location.search ? | 586 this.params_ = location.search ? |
| 587 JSON.parse(decodeURIComponent(location.search.substr(1))) : | 587 JSON.parse(decodeURIComponent(location.search.substr(1))) : |
| 588 {}; | 588 {}; |
| 589 this.initCurrentDirectoryPath_ = this.params_.currentDirectoryPath; | 589 this.initCurrentDirectoryURL_ = this.params_.currentDirectoryURL; |
| 590 this.initSelectionPath_ = this.params_.selectionPath; | 590 this.initSelectionURL_ = this.params_.selectionURL; |
| 591 this.initTargetName_ = this.params_.targetName; | 591 this.initTargetName_ = this.params_.targetName; |
| 592 } | 592 } |
| 593 | 593 |
| 594 // Initialize the member variables that depend this.params_. | 594 // Initialize the member variables that depend this.params_. |
| 595 this.dialogType = this.params_.type || DialogType.FULL_PAGE; | 595 this.dialogType = this.params_.type || DialogType.FULL_PAGE; |
| 596 this.startupPrefName_ = 'file-manager-' + this.dialogType; | 596 this.startupPrefName_ = 'file-manager-' + this.dialogType; |
| 597 this.fileTypes_ = this.params_.typeList || []; | 597 this.fileTypes_ = this.params_.typeList || []; |
| 598 | 598 |
| 599 callback(); | 599 callback(); |
| 600 }; | 600 }; |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 | 1400 |
| 1401 // Wait until the volume manager is initialized. | 1401 // Wait until the volume manager is initialized. |
| 1402 queue.run(function(callback) { | 1402 queue.run(function(callback) { |
| 1403 tracker.start(); | 1403 tracker.start(); |
| 1404 this.volumeManager_.ensureInitialized(callback); | 1404 this.volumeManager_.ensureInitialized(callback); |
| 1405 }.bind(this)); | 1405 }.bind(this)); |
| 1406 | 1406 |
| 1407 var nextCurrentDirEntry; | 1407 var nextCurrentDirEntry; |
| 1408 var selectionEntry; | 1408 var selectionEntry; |
| 1409 | 1409 |
| 1410 // Resolve the selectionPath to selectionEntry or to currentDirectoryEntry | 1410 // Resolve the selectionURL to selectionEntry or to currentDirectoryEntry |
| 1411 // in case of being a display root. | 1411 // in case of being a display root. |
| 1412 queue.run(function(callback) { | 1412 queue.run(function(callback) { |
| 1413 // TODO(mtomasz): Migrate to URLs, and stop calling resolveAbsolutePath. | 1413 // TODO(mtomasz): Migrate to URLs, and stop calling resolveAbsoluteURL. |
| 1414 if (!this.initSelectionPath_) { | 1414 if (!this.initSelectionURL_) { |
| 1415 callback(); | 1415 callback(); |
| 1416 return; | 1416 return; |
| 1417 } | 1417 } |
| 1418 this.volumeManager_.resolveAbsolutePath( | 1418 webkitResolveLocalFileSystemURL( |
| 1419 this.initSelectionPath_, | 1419 this.initSelectionURL_, |
| 1420 function(inEntry) { | 1420 function(inEntry) { |
| 1421 var locationInfo = this.volumeManager_.getLocationInfo(inEntry); | 1421 var locationInfo = this.volumeManager_.getLocationInfo(inEntry); |
| 1422 // If the selection is root, then use it as a current directory | 1422 // If the selection is root, then use it as a current directory |
| 1423 // instead. This is because, selecting a root entry is done as | 1423 // instead. This is because, selecting a root entry is done as |
| 1424 // opening it. | 1424 // opening it. |
| 1425 if (locationInfo && locationInfo.isRootEntry) | 1425 if (locationInfo && locationInfo.isRootEntry) |
| 1426 nextCurrentDirEntry = inEntry; | 1426 nextCurrentDirEntry = inEntry; |
| 1427 else | 1427 else |
| 1428 selectionEntry = inEntry; | 1428 selectionEntry = inEntry; |
| 1429 callback(); | 1429 callback(); |
| 1430 }.bind(this), callback); | 1430 }.bind(this), callback); |
| 1431 }.bind(this)); | 1431 }.bind(this)); |
| 1432 // Resolve the currentDirectoryPath to currentDirectoryEntry (if not done | 1432 // Resolve the currentDirectoryURL to currentDirectoryEntry (if not done |
| 1433 // by the previous step). | 1433 // by the previous step). |
| 1434 queue.run(function(callback) { | 1434 queue.run(function(callback) { |
| 1435 if (nextCurrentDirEntry || !this.initCurrentDirectoryPath_) { | 1435 if (nextCurrentDirEntry || !this.initCurrentDirectoryURL_) { |
| 1436 callback(); | 1436 callback(); |
| 1437 return; | 1437 return; |
| 1438 } | 1438 } |
| 1439 // TODO(mtomasz): Migrate to URLs, and stop calling resolveAbsolutePath. | 1439 webkitResolveLocalFileSystemURL( |
| 1440 this.volumeManager_.resolveAbsolutePath( | 1440 this.initCurrentDirectoryURL_, |
| 1441 this.initCurrentDirectoryPath_, | |
| 1442 function(inEntry) { | 1441 function(inEntry) { |
| 1443 nextCurrentDirEntry = inEntry; | 1442 nextCurrentDirEntry = inEntry; |
| 1444 callback(); | 1443 callback(); |
| 1445 }, callback); | 1444 }, callback); |
| 1446 // TODO(mtomasz): Implement reopening on special search, when fake | 1445 // TODO(mtomasz): Implement reopening on special search, when fake |
| 1447 // entries are converted to directory providers. | 1446 // entries are converted to directory providers. |
| 1448 }.bind(this)); | 1447 }.bind(this)); |
| 1449 | 1448 |
| 1450 // If the directory to be changed to is not available, then first fallback | 1449 // If the directory to be changed to is not available, then first fallback |
| 1451 // to the parent of the selection entry. | 1450 // to the parent of the selection entry. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1534 if (util.isFakeEntry(directoryEntry)) { | 1533 if (util.isFakeEntry(directoryEntry)) { |
| 1535 this.directoryModel_.specialSearch(directoryEntry, ''); | 1534 this.directoryModel_.specialSearch(directoryEntry, ''); |
| 1536 } else { | 1535 } else { |
| 1537 this.directoryModel_.changeDirectoryEntry(directoryEntry, function() { | 1536 this.directoryModel_.changeDirectoryEntry(directoryEntry, function() { |
| 1538 if (opt_selectionEntry) | 1537 if (opt_selectionEntry) |
| 1539 this.directoryModel_.selectEntry(opt_selectionEntry); | 1538 this.directoryModel_.selectEntry(opt_selectionEntry); |
| 1540 }.bind(this)); | 1539 }.bind(this)); |
| 1541 } | 1540 } |
| 1542 | 1541 |
| 1543 if (this.dialogType === DialogType.FULL_PAGE) { | 1542 if (this.dialogType === DialogType.FULL_PAGE) { |
| 1544 // In the FULL_PAGE mode if the restored path points to a file we might | 1543 // In the FULL_PAGE mode if the restored URL points to a file we might |
| 1545 // have to invoke a task after selecting it. | 1544 // have to invoke a task after selecting it. |
| 1546 if (this.params_.action === 'select') | 1545 if (this.params_.action === 'select') |
| 1547 return; | 1546 return; |
| 1548 | 1547 |
| 1549 var task = null; | 1548 var task = null; |
| 1550 // Handle restoring after crash, or the gallery action. | 1549 // Handle restoring after crash, or the gallery action. |
| 1551 // TODO(mtomasz): Use the gallery action instead of just the gallery | 1550 // TODO(mtomasz): Use the gallery action instead of just the gallery |
| 1552 // field. | 1551 // field. |
| 1553 if (this.params_.gallery || this.params_.action === 'gallery') { | 1552 if (this.params_.gallery || this.params_.action === 'gallery') { |
| 1554 if (!opt_selectionEntry) { | 1553 if (!opt_selectionEntry) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1567 } else { | 1566 } else { |
| 1568 // TODO(mtomasz): Implement remounting archives after crash. | 1567 // TODO(mtomasz): Implement remounting archives after crash. |
| 1569 // See: crbug.com/333139 | 1568 // See: crbug.com/333139 |
| 1570 } | 1569 } |
| 1571 | 1570 |
| 1572 // If there is a task to be run, run it after the scan is completed. | 1571 // If there is a task to be run, run it after the scan is completed. |
| 1573 if (task) { | 1572 if (task) { |
| 1574 var listener = function() { | 1573 var listener = function() { |
| 1575 if (!util.isSameEntry(this.directoryModel_.getCurrentDirEntry(), | 1574 if (!util.isSameEntry(this.directoryModel_.getCurrentDirEntry(), |
| 1576 directoryEntry)) { | 1575 directoryEntry)) { |
| 1577 // Opened on a different path. Probably fallbacked. Therefore, | 1576 // Opened on a different URL. Probably fallbacked. Therefore, |
| 1578 // do not invoke a task. | 1577 // do not invoke a task. |
| 1579 return; | 1578 return; |
| 1580 } | 1579 } |
| 1581 this.directoryModel_.removeEventListener( | 1580 this.directoryModel_.removeEventListener( |
| 1582 'scan-completed', listener); | 1581 'scan-completed', listener); |
| 1583 task(); | 1582 task(); |
| 1584 }.bind(this); | 1583 }.bind(this); |
| 1585 this.directoryModel_.addEventListener('scan-completed', listener); | 1584 this.directoryModel_.addEventListener('scan-completed', listener); |
| 1586 } | 1585 } |
| 1587 } else if (this.dialogType === DialogType.SELECT_SAVEAS_FILE) { | 1586 } else if (this.dialogType === DialogType.SELECT_SAVEAS_FILE) { |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2278 | 2277 |
| 2279 /** | 2278 /** |
| 2280 * Update the UI when the current directory changes. | 2279 * Update the UI when the current directory changes. |
| 2281 * | 2280 * |
| 2282 * @param {Event} event The directory-changed event. | 2281 * @param {Event} event The directory-changed event. |
| 2283 * @private | 2282 * @private |
| 2284 */ | 2283 */ |
| 2285 FileManager.prototype.onDirectoryChanged_ = function(event) { | 2284 FileManager.prototype.onDirectoryChanged_ = function(event) { |
| 2286 this.selectionHandler_.onFileSelectionChanged(); | 2285 this.selectionHandler_.onFileSelectionChanged(); |
| 2287 this.ui_.searchBox.clear(); | 2286 this.ui_.searchBox.clear(); |
| 2288 // TODO(mtomasz): Use Entry.toURL() instead of fullPath. | |
| 2289 // TODO(mtomasz): Consider remembering the selection. | 2287 // TODO(mtomasz): Consider remembering the selection. |
| 2290 util.updateAppState( | 2288 util.updateAppState( |
| 2291 this.getCurrentDirectoryEntry() ? | 2289 this.getCurrentDirectoryEntry() ? |
| 2292 this.getCurrentDirectoryEntry().fullPath : '', | 2290 this.getCurrentDirectoryEntry().toURL() : '', |
| 2293 '' /* selectionPath */, | 2291 '' /* selectionURL */, |
| 2294 '' /* opt_param */); | 2292 '' /* opt_param */); |
| 2295 | 2293 |
| 2296 if (this.commandHandler) | 2294 if (this.commandHandler) |
| 2297 this.commandHandler.updateAvailability(); | 2295 this.commandHandler.updateAvailability(); |
| 2298 | 2296 |
| 2299 this.updateUnformattedVolumeStatus_(); | 2297 this.updateUnformattedVolumeStatus_(); |
| 2300 this.updateTitle_(); | 2298 this.updateTitle_(); |
| 2301 var newCurrentVolumeInfo = this.volumeManager_.getVolumeInfo( | 2299 var newCurrentVolumeInfo = this.volumeManager_.getVolumeInfo( |
| 2302 event.newDirEntry); | 2300 event.newDirEntry); |
| 2303 | 2301 |
| (...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3682 callback(this.preferences_); | 3680 callback(this.preferences_); |
| 3683 return; | 3681 return; |
| 3684 } | 3682 } |
| 3685 | 3683 |
| 3686 chrome.fileBrowserPrivate.getPreferences(function(prefs) { | 3684 chrome.fileBrowserPrivate.getPreferences(function(prefs) { |
| 3687 this.preferences_ = prefs; | 3685 this.preferences_ = prefs; |
| 3688 callback(prefs); | 3686 callback(prefs); |
| 3689 }.bind(this)); | 3687 }.bind(this)); |
| 3690 }; | 3688 }; |
| 3691 })(); | 3689 })(); |
| OLD | NEW |