Commit ecdcfed4 authored by mtomasz@chromium.org's avatar mtomasz@chromium.org

Limit using full paths in the directory model in the Files app.

This patch converts methods getLeadPath, setLeadPath, getSelectedPaths and setSelectedPaths to *Entry/*Entries.

TEST=Tested manually. Partly browser tests.
BUG=320967

Review URL: https://codereview.chromium.org/138033007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245462 0039d316-1c4b-4281-b951-d872f2087c98
parent 3997c300
...@@ -193,64 +193,53 @@ DirectoryModel.prototype.getCurrentDirEntry = function() { ...@@ -193,64 +193,53 @@ DirectoryModel.prototype.getCurrentDirEntry = function() {
}; };
/** /**
* @return {Array.<string>} File paths of selected files. * @return {Array.<Entry>} Array of selected entries..
* @private * @private
*/ */
DirectoryModel.prototype.getSelectedPaths_ = function() { DirectoryModel.prototype.getSelectedEntries_ = function() {
var indexes = this.fileListSelection_.selectedIndexes; var indexes = this.fileListSelection_.selectedIndexes;
var fileList = this.getFileList(); var fileList = this.getFileList();
if (fileList) { if (fileList) {
return indexes.map(function(i) { return indexes.map(function(i) {
return fileList.item(i).fullPath; return fileList.item(i);
}); });
} }
return []; return [];
}; };
/** /**
* @param {Array.<string>} value List of file paths of selected files. * @param {Array.<Entry>} value List of selected entries.
* @private * @private
*/ */
DirectoryModel.prototype.setSelectedPaths_ = function(value) { DirectoryModel.prototype.setSelectedEntries_ = function(value) {
var indexes = []; var indexes = [];
var fileList = this.getFileList(); var fileList = this.getFileList();
var urls = util.entriesToURLs(value);
var safeKey = function(key) {
// The transformation must:
// 1. Never generate a reserved name ('__proto__')
// 2. Keep different keys different.
return '#' + key;
};
var hash = {};
for (var i = 0; i < value.length; i++)
hash[safeKey(value[i])] = 1;
for (var i = 0; i < fileList.length; i++) { for (var i = 0; i < fileList.length; i++) {
if (hash.hasOwnProperty(safeKey(fileList.item(i).fullPath))) if (urls.indexOf(fileList.item(i).toURL()) !== -1)
indexes.push(i); indexes.push(i);
} }
this.fileListSelection_.selectedIndexes = indexes; this.fileListSelection_.selectedIndexes = indexes;
}; };
/** /**
* @return {string} Lead item file path. * @return {Entry} Lead entry.
* @private * @private
*/ */
DirectoryModel.prototype.getLeadPath_ = function() { DirectoryModel.prototype.getLeadEntry_ = function() {
var index = this.fileListSelection_.leadIndex; var index = this.fileListSelection_.leadIndex;
return index >= 0 && this.getFileList().item(index).fullPath; return index >= 0 && this.getFileList().item(index);
}; };
/** /**
* @param {string} value The name of new lead index. * @param {Entry} value The new lead entry.
* @private * @private
*/ */
DirectoryModel.prototype.setLeadPath_ = function(value) { DirectoryModel.prototype.setLeadEntry_ = function(value) {
var fileList = this.getFileList(); var fileList = this.getFileList();
for (var i = 0; i < fileList.length; i++) { for (var i = 0; i < fileList.length; i++) {
if (fileList.item(i).fullPath === value) { if (util.isSameEntry(fileList.item(i), value)) {
this.fileListSelection_.leadIndex = i; this.fileListSelection_.leadIndex = i;
return; return;
} }
...@@ -459,19 +448,19 @@ DirectoryModel.prototype.scan_ = function( ...@@ -459,19 +448,19 @@ DirectoryModel.prototype.scan_ = function(
DirectoryModel.prototype.replaceDirectoryContents_ = function(dirContents) { DirectoryModel.prototype.replaceDirectoryContents_ = function(dirContents) {
cr.dispatchSimpleEvent(this, 'begin-update-files'); cr.dispatchSimpleEvent(this, 'begin-update-files');
this.updateSelectionAndPublishEvent_(this.fileListSelection_, function() { this.updateSelectionAndPublishEvent_(this.fileListSelection_, function() {
var selectedPaths = this.getSelectedPaths_(); var selectedEntries = this.getSelectedEntries_();
var selectedIndices = this.fileListSelection_.selectedIndexes; var selectedIndices = this.fileListSelection_.selectedIndexes;
// Restore leadIndex in case leadName no longer exists. // Restore leadIndex in case leadName no longer exists.
var leadIndex = this.fileListSelection_.leadIndex; var leadIndex = this.fileListSelection_.leadIndex;
var leadPath = this.getLeadPath_(); var leadEntry = this.getLeadEntry_();
this.currentDirContents_ = dirContents; this.currentDirContents_ = dirContents;
dirContents.replaceContextFileList(); dirContents.replaceContextFileList();
this.setSelectedPaths_(selectedPaths); this.setSelectedEntries_(selectedEntries);
this.fileListSelection_.leadIndex = leadIndex; this.fileListSelection_.leadIndex = leadIndex;
this.setLeadPath_(leadPath); this.setLeadEntry_(leadEntry);
// If nothing is selected after update, then select file next to the // If nothing is selected after update, then select file next to the
// latest selection // latest selection
...@@ -719,7 +708,7 @@ DirectoryModel.prototype.resolveDirectory = function( ...@@ -719,7 +708,7 @@ DirectoryModel.prototype.resolveDirectory = function(
}; };
/** /**
* @param {DirectoryEntry} dirEntry The absolute path to the new directory. * @param {DirectoryEntry} dirEntry The entry of the new directory.
* @param {function()=} opt_callback Executed if the directory loads * @param {function()=} opt_callback Executed if the directory loads
* successfully. * successfully.
* @private * @private
...@@ -746,7 +735,7 @@ DirectoryModel.prototype.changeDirectoryEntrySilent_ = function(dirEntry, ...@@ -746,7 +735,7 @@ DirectoryModel.prototype.changeDirectoryEntrySilent_ = function(dirEntry,
* Dispatches the 'directory-changed' event when the directory is successfully * Dispatches the 'directory-changed' event when the directory is successfully
* changed. * changed.
* *
* @param {DirectoryEntry} dirEntry The absolute path to the new directory. * @param {DirectoryEntry} dirEntry The entry of the new directory.
* @param {function()=} opt_callback Executed if the directory loads * @param {function()=} opt_callback Executed if the directory loads
* successfully. * successfully.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment