Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: chrome/browser/resources/file_manager/js/file_manager.js

Issue 7057053: Escaping file names correctly. Also fixed a crush in chromeos debug build while saving a web page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed debugging code. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/file_manager/js/file_manager.js
diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js
index 4ecc60e594ca8096e84a4805dc9102edcd289dbd..b4c8ccdb15f2d29e57ee47749ebf73efe8bc347c 100644
--- a/chrome/browser/resources/file_manager/js/file_manager.js
+++ b/chrome/browser/resources/file_manager/js/file_manager.js
@@ -54,6 +54,9 @@ function FileManager(dialogDom, rootEntries, params) {
this.defaultPath_ = this.params_.defaultPath || '/';
+ // Optional list of file types.
+ this.fileTypes_ = this.params_.typeList;
+
this.showCheckboxes_ =
(this.dialogType_ == FileManager.DialogType.FULL_PAGE ||
this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE);
@@ -546,6 +549,29 @@ FileManager.prototype = {
};
/**
+ * "Save a file" dialog is supposed to have a combo box with available
+ * file types. Selecting an item filters files by extension and specifies how
+ * file should be saved.
+ * @return {intener} Index of selected type from this.fileTypes_ + 1. 0
+ * means value is not specified.
+ */
+ FileManager.prototype.getSelectedFilterIndex_= function(fileName) {
+ // TODO(serya): Implement the combo box
+ // For now try to guess choice by file extension.
+ if (!this.fileTypes_ || this.fileTypes_.length == 0) return 0;
+
+ var extension = /\.[^\.]+$/.exec(fileName);
+ extension = extension ? extension[0].substring(1).toLowerCase() : "";
+ var result = 0; // Use first type by default.
+ for (var i = 0; i < this.fileTypes_.length; i++) {
+ if (this.fileTypes_[i].extensions.indexOf(extension)) {
+ result = i;
+ }
+ }
+ return result + 1; // 1-based index.
+ };
+
+ /**
* Force the canExecute events to be dispatched.
*/
FileManager.prototype.updateCommands_ = function() {
@@ -2061,8 +2087,9 @@ FileManager.prototype = {
if (!filename)
throw new Error('Missing filename!');
- chrome.fileBrowserPrivate.selectFile(currentDirUrl + encodeURI(filename),
- 0);
+ chrome.fileBrowserPrivate.selectFile(
+ currentDirUrl + encodeURIComponent(filename),
+ this.getSelectedFilterIndex_(filename));
window.close();
return;
}
@@ -2083,7 +2110,7 @@ FileManager.prototype = {
continue;
}
- ary.push(currentDirUrl + encodeURI(entry.name));
+ ary.push(currentDirUrl + encodeURIComponent(entry.name));
}
// Multi-file selection has no other restrictions.
@@ -2112,7 +2139,8 @@ FileManager.prototype = {
throw new Error('Selected entry is not a file!');
}
- chrome.fileBrowserPrivate.selectFile(ary[0], 0);
+ chrome.fileBrowserPrivate.selectFile(
+ ary[0], this.getSelectedFilterIndex_(ary[0]));
window.close();
};

Powered by Google App Engine
This is Rietveld 408576698