| 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 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 * initializing methods. | 568 * initializing methods. |
| 569 * | 569 * |
| 570 * @param {function()} callback Completion callback. | 570 * @param {function()} callback Completion callback. |
| 571 * @private | 571 * @private |
| 572 */ | 572 */ |
| 573 FileManager.prototype.initGeneral_ = function(callback) { | 573 FileManager.prototype.initGeneral_ = function(callback) { |
| 574 // Initialize the application state. | 574 // Initialize the application state. |
| 575 // TODO(mtomasz): Unify window.appState with location.search format. | 575 // TODO(mtomasz): Unify window.appState with location.search format. |
| 576 if (window.appState) { | 576 if (window.appState) { |
| 577 this.params_ = window.appState.params || {}; | 577 this.params_ = window.appState.params || {}; |
| 578 this.initCurrentDirectoryPath_ = window.appState.currentDirectoryPath; | 578 this.initCurrentDirectoryURL_ = window.appState.currentDirectoryURL; |
| 579 this.initSelectionPath_ = window.appState.selectionPath; | 579 this.initSelectionPath_ = window.appState.selectionURL; |
| 580 this.initTargetName_ = window.appState.targetName; | 580 this.initTargetName_ = window.appState.targetName; |
| 581 } else { | 581 } else { |
| 582 // Used by the select dialog only. | 582 // Used by the select dialog only. |
| 583 this.params_ = location.search ? | 583 this.params_ = location.search ? |
| 584 JSON.parse(decodeURIComponent(location.search.substr(1))) : | 584 JSON.parse(decodeURIComponent(location.search.substr(1))) : |
| 585 {}; | 585 {}; |
| 586 this.initCurrentDirectoryPath_ = this.params_.currentDirectoryPath; | 586 this.initCurrentDirectoryURL_ = this.params_.currentDirectoryURL; |
| 587 this.initSelectionPath_ = this.params_.selectionPath; | 587 this.initSelectionURL_ = this.params_.selectionURL; |
| 588 this.initTargetName_ = this.params_.targetName; | 588 this.initTargetName_ = this.params_.targetName; |
| 589 } | 589 } |
| 590 | 590 |
| 591 // Initialize the member variables that depend this.params_. | 591 // Initialize the member variables that depend this.params_. |
| 592 this.dialogType = this.params_.type || DialogType.FULL_PAGE; | 592 this.dialogType = this.params_.type || DialogType.FULL_PAGE; |
| 593 this.startupPrefName_ = 'file-manager-' + this.dialogType; | 593 this.startupPrefName_ = 'file-manager-' + this.dialogType; |
| 594 this.fileTypes_ = this.params_.typeList || []; | 594 this.fileTypes_ = this.params_.typeList || []; |
| 595 | 595 |
| 596 callback(); | 596 callback(); |
| 597 }; | 597 }; |
| (...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 | 1394 |
| 1395 // Wait until the volume manager is initialized. | 1395 // Wait until the volume manager is initialized. |
| 1396 queue.run(function(callback) { | 1396 queue.run(function(callback) { |
| 1397 tracker.start(); | 1397 tracker.start(); |
| 1398 this.volumeManager_.ensureInitialized(callback); | 1398 this.volumeManager_.ensureInitialized(callback); |
| 1399 }.bind(this)); | 1399 }.bind(this)); |
| 1400 | 1400 |
| 1401 var nextCurrentDirEntry; | 1401 var nextCurrentDirEntry; |
| 1402 var selectionEntry; | 1402 var selectionEntry; |
| 1403 | 1403 |
| 1404 // Resolve the selectionPath to selectionEntry or to currentDirectoryEntry | 1404 // Resolve the selectionURL to selectionEntry or to currentDirectoryEntry |
| 1405 // in case of being a display root. | 1405 // in case of being a display root. |
| 1406 queue.run(function(callback) { | 1406 queue.run(function(callback) { |
| 1407 // TODO(mtomasz): Migrate to URLs, and stop calling resolveAbsolutePath. | 1407 // TODO(mtomasz): Migrate to URLs, and stop calling resolveAbsoluteURL. |
| 1408 if (!this.initSelectionPath_) { | 1408 if (!this.initSelectionURL_) { |
| 1409 callback(); | 1409 callback(); |
| 1410 return; | 1410 return; |
| 1411 } | 1411 } |
| 1412 this.volumeManager_.resolveAbsolutePath( | 1412 this.volumeManager_.resolveAbsoluteURL( |
| 1413 this.initSelectionPath_, | 1413 this.initSelectionURL_, |
| 1414 function(inEntry) { | 1414 function(inEntry) { |
| 1415 var locationInfo = this.volumeManager_.getLocationInfo(inEntry); | 1415 var locationInfo = this.volumeManager_.getLocationInfo(inEntry); |
| 1416 // If the selection is root, then use it as a current directory | 1416 // If the selection is root, then use it as a current directory |
| 1417 // instead. This is because, selecting a root entry is done as | 1417 // instead. This is because, selecting a root entry is done as |
| 1418 // opening it. | 1418 // opening it. |
| 1419 if (locationInfo && locationInfo.isRootEntry) | 1419 if (locationInfo && locationInfo.isRootEntry) |
| 1420 nextCurrentDirEntry = inEntry; | 1420 nextCurrentDirEntry = inEntry; |
| 1421 else | 1421 else |
| 1422 selectionEntry = inEntry; | 1422 selectionEntry = inEntry; |
| 1423 callback(); | 1423 callback(); |
| 1424 }.bind(this), callback); | 1424 }.bind(this), callback); |
| 1425 }.bind(this)); | 1425 }.bind(this)); |
| 1426 // Resolve the currentDirectoryPath to currentDirectoryEntry (if not done | 1426 // Resolve the currentDirectoryURL to currentDirectoryEntry (if not done |
| 1427 // by the previous step). | 1427 // by the previous step). |
| 1428 queue.run(function(callback) { | 1428 queue.run(function(callback) { |
| 1429 if (nextCurrentDirEntry || !this.initCurrentDirectoryPath_) { | 1429 if (nextCurrentDirEntry || !this.initCurrentDirectoryURL_) { |
| 1430 callback(); | 1430 callback(); |
| 1431 return; | 1431 return; |
| 1432 } | 1432 } |
| 1433 // TODO(mtomasz): Migrate to URLs, and stop calling resolveAbsolutePath. | 1433 webkitResolveLocalFileSystemURL( |
| 1434 this.volumeManager_.resolveAbsolutePath( | 1434 this.initCurrentDirectoryURL_, |
| 1435 this.initCurrentDirectoryPath_, | |
| 1436 function(inEntry) { | 1435 function(inEntry) { |
| 1437 nextCurrentDirEntry = inEntry; | 1436 nextCurrentDirEntry = inEntry; |
| 1438 callback(); | 1437 callback(); |
| 1439 }, callback); | 1438 }, callback); |
| 1440 // TODO(mtomasz): Implement reopening on special search, when fake | 1439 // TODO(mtomasz): Implement reopening on special search, when fake |
| 1441 // entries are converted to directory providers. | 1440 // entries are converted to directory providers. |
| 1442 }.bind(this)); | 1441 }.bind(this)); |
| 1443 | 1442 |
| 1444 // If the directory to be changed to is not available, then first fallback | 1443 // If the directory to be changed to is not available, then first fallback |
| 1445 // to the parent of the selection entry. | 1444 // to the parent of the selection entry. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 if (util.isFakeEntry(directoryEntry)) { | 1527 if (util.isFakeEntry(directoryEntry)) { |
| 1529 this.directoryModel_.specialSearch(directoryEntry, ''); | 1528 this.directoryModel_.specialSearch(directoryEntry, ''); |
| 1530 } else { | 1529 } else { |
| 1531 this.directoryModel_.changeDirectoryEntry(directoryEntry, function() { | 1530 this.directoryModel_.changeDirectoryEntry(directoryEntry, function() { |
| 1532 if (opt_selectionEntry) | 1531 if (opt_selectionEntry) |
| 1533 this.directoryModel_.selectEntry(opt_selectionEntry); | 1532 this.directoryModel_.selectEntry(opt_selectionEntry); |
| 1534 }.bind(this)); | 1533 }.bind(this)); |
| 1535 } | 1534 } |
| 1536 | 1535 |
| 1537 if (this.dialogType === DialogType.FULL_PAGE) { | 1536 if (this.dialogType === DialogType.FULL_PAGE) { |
| 1538 // In the FULL_PAGE mode if the restored path points to a file we might | 1537 // In the FULL_PAGE mode if the restored URL points to a file we might |
| 1539 // have to invoke a task after selecting it. | 1538 // have to invoke a task after selecting it. |
| 1540 if (this.params_.action === 'select') | 1539 if (this.params_.action === 'select') |
| 1541 return; | 1540 return; |
| 1542 | 1541 |
| 1543 var task = null; | 1542 var task = null; |
| 1544 // Handle restoring after crash, or the gallery action. | 1543 // Handle restoring after crash, or the gallery action. |
| 1545 // TODO(mtomasz): Use the gallery action instead of just the gallery | 1544 // TODO(mtomasz): Use the gallery action instead of just the gallery |
| 1546 // field. | 1545 // field. |
| 1547 if (this.params_.gallery || this.params_.action === 'gallery') { | 1546 if (this.params_.gallery || this.params_.action === 'gallery') { |
| 1548 if (!opt_selectionEntry) { | 1547 if (!opt_selectionEntry) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1561 } else { | 1560 } else { |
| 1562 // TODO(mtomasz): Implement remounting archives after crash. | 1561 // TODO(mtomasz): Implement remounting archives after crash. |
| 1563 // See: crbug.com/333139 | 1562 // See: crbug.com/333139 |
| 1564 } | 1563 } |
| 1565 | 1564 |
| 1566 // If there is a task to be run, run it after the scan is completed. | 1565 // If there is a task to be run, run it after the scan is completed. |
| 1567 if (task) { | 1566 if (task) { |
| 1568 var listener = function() { | 1567 var listener = function() { |
| 1569 if (!util.isSameEntry(this.directoryModel_.getCurrentDirEntry(), | 1568 if (!util.isSameEntry(this.directoryModel_.getCurrentDirEntry(), |
| 1570 directoryEntry)) { | 1569 directoryEntry)) { |
| 1571 // Opened on a different path. Probably fallbacked. Therefore, | 1570 // Opened on a different URL. Probably fallbacked. Therefore, |
| 1572 // do not invoke a task. | 1571 // do not invoke a task. |
| 1573 return; | 1572 return; |
| 1574 } | 1573 } |
| 1575 this.directoryModel_.removeEventListener( | 1574 this.directoryModel_.removeEventListener( |
| 1576 'scan-completed', listener); | 1575 'scan-completed', listener); |
| 1577 task(); | 1576 task(); |
| 1578 }.bind(this); | 1577 }.bind(this); |
| 1579 this.directoryModel_.addEventListener('scan-completed', listener); | 1578 this.directoryModel_.addEventListener('scan-completed', listener); |
| 1580 } | 1579 } |
| 1581 } else if (this.dialogType === DialogType.SELECT_SAVEAS_FILE) { | 1580 } else if (this.dialogType === DialogType.SELECT_SAVEAS_FILE) { |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2214 | 2213 |
| 2215 /** | 2214 /** |
| 2216 * Update the UI when the current directory changes. | 2215 * Update the UI when the current directory changes. |
| 2217 * | 2216 * |
| 2218 * @param {Event} event The directory-changed event. | 2217 * @param {Event} event The directory-changed event. |
| 2219 * @private | 2218 * @private |
| 2220 */ | 2219 */ |
| 2221 FileManager.prototype.onDirectoryChanged_ = function(event) { | 2220 FileManager.prototype.onDirectoryChanged_ = function(event) { |
| 2222 this.selectionHandler_.onFileSelectionChanged(); | 2221 this.selectionHandler_.onFileSelectionChanged(); |
| 2223 this.ui_.searchBox.clear(); | 2222 this.ui_.searchBox.clear(); |
| 2224 // TODO(mtomasz): Use Entry.toURL() instead of fullPath. | |
| 2225 // TODO(mtomasz): Consider remembering the selection. | 2223 // TODO(mtomasz): Consider remembering the selection. |
| 2226 util.updateAppState( | 2224 util.updateAppState( |
| 2227 this.getCurrentDirectoryEntry() ? | 2225 this.getCurrentDirectoryEntry() ? |
| 2228 this.getCurrentDirectoryEntry().fullPath : '', | 2226 this.getCurrentDirectoryEntry().toURL() : '', |
| 2229 '' /* selectionPath */, | 2227 '' /* selectionURL */, |
| 2230 '' /* opt_param */); | 2228 '' /* opt_param */); |
| 2231 | 2229 |
| 2232 // If the current directory is moved from the device's volume, do not | 2230 // If the current directory is moved from the device's volume, do not |
| 2233 // automatically close the window on device removal. | 2231 // automatically close the window on device removal. |
| 2234 if (event.previousDirEntry && | 2232 if (event.previousDirEntry && |
| 2235 PathUtil.getRootPath(event.previousDirEntry.fullPath) != | 2233 PathUtil.getRootPath(event.previousDirEntry.fullPath) != |
| 2236 PathUtil.getRootPath(event.newDirEntry.fullPath)) | 2234 PathUtil.getRootPath(event.newDirEntry.fullPath)) |
| 2237 this.closeOnUnmount_ = false; | 2235 this.closeOnUnmount_ = false; |
| 2238 | 2236 |
| 2239 if (this.commandHandler) | 2237 if (this.commandHandler) |
| (...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3618 callback(this.preferences_); | 3616 callback(this.preferences_); |
| 3619 return; | 3617 return; |
| 3620 } | 3618 } |
| 3621 | 3619 |
| 3622 chrome.fileBrowserPrivate.getPreferences(function(prefs) { | 3620 chrome.fileBrowserPrivate.getPreferences(function(prefs) { |
| 3623 this.preferences_ = prefs; | 3621 this.preferences_ = prefs; |
| 3624 callback(prefs); | 3622 callback(prefs); |
| 3625 }.bind(this)); | 3623 }.bind(this)); |
| 3626 }; | 3624 }; |
| 3627 })(); | 3625 })(); |
| OLD | NEW |