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

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

Issue 7706028: This is UI side unreadable device support. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 4 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 4bcf9cdeedffd4d9397c5a08b20f9a7aa7923465..0e01997d04cdef51a2fb9b3b685e905d489842e1 100644
--- a/chrome/browser/resources/file_manager/js/file_manager.js
+++ b/chrome/browser/resources/file_manager/js/file_manager.js
@@ -206,10 +206,10 @@ FileManager.prototype = {
var localStrings;
/**
- * Map of icon types to regular expressions.
+ * Map of icon types to regular expressions and functions
*
- * The first regexp to match the file name determines the icon type
- * assigned to dom elements for a file. Order of evaluation is not
+ * The first regexp/function to match the entry name determines the icon type
+ * assigned to dom elements for a file. Order of evaluation is not
* defined, so don't depend on it.
*/
const iconTypes = {
@@ -218,13 +218,33 @@ FileManager.prototype = {
'image': /\.(bmp|gif|jpe?g|ico|png|webp)$/i,
'pdf' : /\.(pdf)$/i,
'text': /\.(pod|rst|txt|log)$/i,
- 'video': /\.(3gp|avi|mov|mp4|m4v|mpe?g4?|ogm|ogv|ogx|webm)$/i
+ 'video': /\.(3gp|avi|mov|mp4|m4v|mpe?g4?|ogm|ogv|ogx|webm)$/i,
+ 'device': function(entry) {
+ var deviceNumber = this.getDeviceNumber(entry);
+ if (deviceNumber != undefined)
+ return (this.mountPoints_[deviceNumber].specialData == '');
+ return false;
+ },
+ 'unreadable': function(entry) {
+ var deviceNumber = this.getDeviceNumber(entry);
+ if (deviceNumber != undefined) {
+ return this.mountPoints_[deviceNumber].specialData ==
+ 'unreadable_unknown_filesystem' ||
+ this.mountPoints_[deviceNumber].specialData ==
+ 'unreadable_unsupported_filesystem';
+ }
+ return false;
+ }
};
const previewArt = {
'audio': 'images/filetype_large_audio.png',
+ // TODO(sidor): Find better icon here.
+ 'device': 'images/filetype_large_folder.png',
'folder': 'images/filetype_large_folder.png',
'unknown': 'images/filetype_large_generic.png',
+ // TODO(sidor): Find better icon here.
+ 'unreadable': 'images/filetype_large_folder.png',
'video': 'images/filetype_large_video.png'
};
@@ -292,50 +312,19 @@ FileManager.prototype = {
return parent;
}
- /**
- * Get the icon type for a given Entry.
- *
- * @param {Entry} entry An Entry subclass (FileEntry or DirectoryEntry).
- * @return {string} One of the keys from FileManager.iconTypes, or
- * 'unknown'.
- */
- function getIconType(entry) {
- if (entry.cachedIconType_)
- return entry.cachedIconType_;
-
- var rv = 'unknown';
-
- if (entry.isDirectory) {
- rv = 'folder';
- } else {
- for (var name in iconTypes) {
- var value = iconTypes[name];
-
- if (value instanceof RegExp) {
- if (value.test(entry.name)) {
- rv = name;
- break;
- }
- } else if (typeof value == 'function') {
- try {
- if (value(entry)) {
- rv = name;
- break;
- }
- } catch (ex) {
- console.error('Caught exception while evaluating iconType: ' +
- name, ex);
- }
- } else {
- console.log('Unexpected value in iconTypes[' + name + ']: ' + value);
- }
- }
- }
-
- entry.cachedIconType_ = rv;
- return rv;
+ /**
+ * Normalizes path not to start with /
+ *
+ * @param {string} path The file path.
+ */
+ function normalize(x) {
rginda 2011/08/23 20:23:30 normalizePath please.
rginda 2011/08/23 20:25:12 Actually, it would probably be cleaner to call thi
sidor 2011/08/23 23:18:47 So according to Toni, this should be removing / at
sidor 2011/08/23 23:18:47 Path name changed.
+ if (x[0] == '/')
+ return x.slice(1);
+ else
+ return x;
}
+
/**
* Call an asynchronous method on dirEntry, batching multiple callers.
*
@@ -493,7 +482,7 @@ FileManager.prototype = {
* icon type is known.
*/
function cacheEntryIconType(entry, successCallback) {
rginda 2011/08/23 20:23:30 If this is going to be invoked as a method, it sho
sidor 2011/08/23 23:18:47 Done.
- getIconType(entry);
+ this.getIconType(entry);
if (successCallback)
setTimeout(function() { successCallback(entry) }, 0);
}
@@ -658,6 +647,47 @@ FileManager.prototype = {
};
/**
+ * Get the icon type for a given Entry.
+ *
+ * @param {Entry} entry An Entry subclass (FileEntry or DirectoryEntry).
+ * @return {string} One of the keys from FileManager.iconTypes, or
+ * 'unknown'.
+ */
+ FileManager.prototype.getIconType = function(entry) {
+ if (entry.cachedIconType_)
+ return entry.cachedIconType_;
+
+ var rv = 'unknown';
+ if (entry.isDirectory)
+ rv = 'folder';
+ for (var name in iconTypes) {
+ var value = iconTypes[name];
+
+ if (value instanceof RegExp) {
+ if (value.test(entry.name)) {
+ rv = name;
+ break;
+ }
+ } else if (typeof value == 'function') {
+ try {
+ var isThisIconForThatEntry = value.bind(this);
rginda 2011/08/23 20:23:30 Please just pass in the FileManager instance as a
sidor 2011/08/23 23:18:47 Done.
+ if (isThisIconForThatEntry(entry)) {
+ rv = name;
+ break;
+ }
+ } catch (ex) {
+ console.error('Caught exception while evaluating iconType: ' +
+ name, ex);
+ }
+ } else {
+ console.log('Unexpected value in iconTypes[' + name + ']: ' + value);
+ }
+ }
+ entry.cachedIconType_ = rv;
+ return rv;
+ };
+
+ /**
* Compare by mtime first, then by name.
*/
FileManager.prototype.compareMtime_ = function(a, b) {
@@ -1243,7 +1273,7 @@ FileManager.prototype = {
} else if (field == 'cachedSize_') {
cacheFunction = cacheEntrySize;
} else if (field == 'cachedIconType_') {
- cacheFunction = cacheEntryIconType;
+ cacheFunction = cacheEntryIconType.bind(this);
} else {
callback();
return;
@@ -1350,7 +1380,7 @@ FileManager.prototype = {
var icon = this.document_.createElement('div');
icon.className = 'detail-icon';
- entry.cachedIconType_ = getIconType(entry);
+ entry.cachedIconType_ = this.getIconType(entry);
icon.setAttribute('iconType', entry.cachedIconType_);
div.appendChild(icon);
@@ -1485,9 +1515,9 @@ FileManager.prototype = {
selection.urls.push(entry.toURL());
if (selection.iconType == null) {
- selection.iconType = getIconType(entry);
+ selection.iconType = this.getIconType(entry);
} else if (selection.iconType != 'unknown') {
- var iconType = getIconType(entry);
+ var iconType = this.getIconType(entry);
if (selection.iconType != iconType)
selection.iconType = 'unknown';
}
@@ -1706,18 +1736,10 @@ FileManager.prototype = {
var self = this;
function onMountPointsFound(mountPoints) {
self.mountPoints_ = mountPoints;
-
- function normalize(x) {
- if (x[0] == '/')
- return x.slice(1);
- else
- return x;
- }
-
function onVolumeMetadataFound(volumeMetadata) {
if (volumeMetadata.deviceType == "flash") {
- if (selection.entries.length != 1 ||
- normalize(selection.entries[0].fullPath) !=
+ if (self.selection.entries.length != 1 ||
+ normalize(self.selection.entries[0].fullPath) !=
normalize(volumeMetadata.mountPath)) {
return;
}
@@ -1789,9 +1811,16 @@ FileManager.prototype = {
return;
}
+ var rescanDirectory = (event.status == 'success');
+ for (var i = 0; i < mountPoints.length; i++) {
+ if (event.sourceUrl == mountPoints[i].sourceUrl &&
+ mountPoints[i].specialData != '') {
+ rescanDirectory = true;
+ }
+ }
// TODO(dgozman): rescan directory, only if it contains mounted points,
// when mounts location will be decided.
- if (event.status == 'success')
+ if (rescanDirectory)
self.rescanDirectory_();
});
};
@@ -1826,6 +1855,17 @@ FileManager.prototype = {
}
};
+ FileManager.prototype.getDeviceNumber = function(entry) {
+ if (!entry.isDirectory) return false;
+ for (var i = 0; i < this.mountPoints_.length; i++) {
+ if (normalize(entry.fullPath) ==
+ normalize(this.mountPoints_[i].mountPath)) {
+ return i;
+ }
+ }
+ return undefined;
+ }
+
FileManager.prototype.openImageEditor_ = function(entry) {
var self = this;
@@ -1930,7 +1970,7 @@ FileManager.prototype = {
this.previewFilename_.textContent = previewName;
- var iconType = getIconType(this.selection.leadEntry);
+ var iconType = this.getIconType(this.selection.leadEntry);
if (iconType == 'image') {
if (fileManager.selection.totalCount > 1)
this.previewImage_.classList.add('multiple-selected');
@@ -2087,7 +2127,7 @@ FileManager.prototype = {
if (!entry)
return;
- var iconType = getIconType(entry);
+ var iconType = this.getIconType(entry);
this.cacheMetadata_(entry, function (metadata) {
var url = metadata.thumbnailURL;
@@ -2487,9 +2527,21 @@ FileManager.prototype = {
return;
}
- if (entry.isDirectory)
- return this.changeDirectory(entry.fullPath);
-
+ if (entry.isDirectory) {
+ var deviceNumber = this.getDeviceNumber(entry);
+
+ if (deviceNumber != undefined &&
+ this.mountPoints_[deviceNumber].specialData ==
+ 'unreadable_unknown_filesystem') {
+ return this.showButter(str('UNKNOWN_FILESYSTEM_WARNING'));
+ } else if (deviceNumber != undefined &&
+ this.mountPoints_[deviceNumber].specialData ==
+ 'unreadable_unsupported_filesystem') {
+ return this.showButter(str('UNSUPPORTED_FILESYSTEM_WARNING'));
+ } else {
+ return this.changeDirectory(entry.fullPath);
+ }
+ }
if (!this.okButton_.disabled)
this.onOk_();

Powered by Google App Engine
This is Rietveld 408576698