| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Setting the src of an img to an empty string can crash the browser, so we | 5 // Setting the src of an img to an empty string can crash the browser, so we |
| 6 // use an empty 1x1 gif instead. | 6 // use an empty 1x1 gif instead. |
| 7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' | 7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' |
| 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; | 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; |
| 9 | 9 |
| 10 var g_slideshow_data = null; | 10 var g_slideshow_data = null; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 this.currentButter_ = null; | 51 this.currentButter_ = null; |
| 52 | 52 |
| 53 // True if we should filter out files that start with a dot. | 53 // True if we should filter out files that start with a dot. |
| 54 this.filterFiles_ = true; | 54 this.filterFiles_ = true; |
| 55 | 55 |
| 56 this.commands_ = {}; | 56 this.commands_ = {}; |
| 57 | 57 |
| 58 this.document_ = dialogDom.ownerDocument; | 58 this.document_ = dialogDom.ownerDocument; |
| 59 this.dialogType_ = this.params_.type || FileManager.DialogType.FULL_PAGE; | 59 this.dialogType_ = this.params_.type || FileManager.DialogType.FULL_PAGE; |
| 60 | 60 |
| 61 this.defaultPath_ = this.params_.defaultPath || '/'; | |
| 62 | |
| 63 this.alert = new cr.ui.dialogs.AlertDialog(this.dialogDom_); | 61 this.alert = new cr.ui.dialogs.AlertDialog(this.dialogDom_); |
| 64 this.confirm = new cr.ui.dialogs.ConfirmDialog(this.dialogDom_); | 62 this.confirm = new cr.ui.dialogs.ConfirmDialog(this.dialogDom_); |
| 65 this.prompt = new cr.ui.dialogs.PromptDialog(this.dialogDom_); | 63 this.prompt = new cr.ui.dialogs.PromptDialog(this.dialogDom_); |
| 66 | 64 |
| 67 // TODO(dgozman): This will be changed to LocaleInfo. | 65 // TODO(dgozman): This will be changed to LocaleInfo. |
| 68 this.locale_ = new v8Locale(navigator.language); | 66 this.locale_ = new v8Locale(navigator.language); |
| 69 | 67 |
| 70 // TODO(rginda): 6/22/11: Remove this test when createDateTimeFormat is | 68 // TODO(rginda): 6/22/11: Remove this test when createDateTimeFormat is |
| 71 // available in all chrome trunk builds. | 69 // available in all chrome trunk builds. |
| 72 if ('createDateTimeFormat' in this.locale_) { | 70 if ('createDateTimeFormat' in this.locale_) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 chrome.fileBrowserPrivate.getMountPoints(function(mountPoints) { | 125 chrome.fileBrowserPrivate.getMountPoints(function(mountPoints) { |
| 128 self.mountPoints_ = mountPoints; | 126 self.mountPoints_ = mountPoints; |
| 129 }); | 127 }); |
| 130 | 128 |
| 131 chrome.fileBrowserHandler.onExecute.addListener( | 129 chrome.fileBrowserHandler.onExecute.addListener( |
| 132 this.onFileTaskExecute_.bind(this)); | 130 this.onFileTaskExecute_.bind(this)); |
| 133 | 131 |
| 134 this.initCommands_(); | 132 this.initCommands_(); |
| 135 this.initDom_(); | 133 this.initDom_(); |
| 136 this.initDialogType_(); | 134 this.initDialogType_(); |
| 137 this.initDefaultDirectory_(); | 135 this.initDefaultDirectory_(this.params_.defaultPath); |
| 138 | 136 |
| 139 this.summarizeSelection_(); | 137 this.summarizeSelection_(); |
| 140 this.updatePreview_(); | 138 this.updatePreview_(); |
| 141 | 139 |
| 142 chrome.fileBrowserPrivate.onDiskChanged.addListener( | 140 chrome.fileBrowserPrivate.onDiskChanged.addListener( |
| 143 this.onDiskChanged_.bind(this)); | 141 this.onDiskChanged_.bind(this)); |
| 144 | 142 |
| 145 this.refocus(); | 143 this.refocus(); |
| 146 | 144 |
| 147 // Pass all URLs to the metadata reader until we have a correct filter. | 145 // Pass all URLs to the metadata reader until we have a correct filter. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 160 (function() { | 158 (function() { |
| 161 | 159 |
| 162 // Private variables and helper functions. | 160 // Private variables and helper functions. |
| 163 | 161 |
| 164 /** | 162 /** |
| 165 * Unicode codepoint for 'BLACK RIGHT-POINTING SMALL TRIANGLE'. | 163 * Unicode codepoint for 'BLACK RIGHT-POINTING SMALL TRIANGLE'. |
| 166 */ | 164 */ |
| 167 const RIGHT_TRIANGLE = '\u25b8'; | 165 const RIGHT_TRIANGLE = '\u25b8'; |
| 168 | 166 |
| 169 /** | 167 /** |
| 168 * The DirectoryEntry.fullPath value of the Downloads directory. |
| 169 */ |
| 170 const DOWNLOADS_DIRECTORY = '/Downloads'; |
| 171 |
| 172 /** |
| 170 * The DirectoryEntry.fullPath value of the directory containing externally | 173 * The DirectoryEntry.fullPath value of the directory containing externally |
| 171 * mounted removable storage volumes. | 174 * mounted removable storage volumes. |
| 172 */ | 175 */ |
| 173 const REMOVABLE_DIRECTORY = '/removable'; | 176 const REMOVABLE_DIRECTORY = '/removable'; |
| 174 | 177 |
| 175 /** | 178 /** |
| 176 * The DirectoryEntry.fullPath value of the directory containing externally | 179 * The DirectoryEntry.fullPath value of the directory containing externally |
| 177 * mounted archive file volumes. | 180 * mounted archive file volumes. |
| 178 */ | 181 */ |
| 179 const ARCHIVE_DIRECTORY = '/archive'; | 182 const ARCHIVE_DIRECTORY = '/archive'; |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 (this.currentDirEntry_ && | 778 (this.currentDirEntry_ && |
| 776 this.currentDirEntry_.fullPath != '/'); | 779 this.currentDirEntry_.fullPath != '/'); |
| 777 if (this.copyButton_) | 780 if (this.copyButton_) |
| 778 this.copyButton_.disabled = !event.canExecute; | 781 this.copyButton_.disabled = !event.canExecute; |
| 779 break; | 782 break; |
| 780 | 783 |
| 781 case 'paste': | 784 case 'paste': |
| 782 event.canExecute = | 785 event.canExecute = |
| 783 (this.clipboard_ && | 786 (this.clipboard_ && |
| 784 this.clipboard_.sourceDirEntry.fullPath != | 787 this.clipboard_.sourceDirEntry.fullPath != |
| 785 this.currentDirEntry_.fullPath_ && | 788 this.currentDirEntry_.fullPath && |
| 786 !isSystemDirEntry(this.currentDirEntry_)); | 789 !isSystemDirEntry(this.currentDirEntry_)); |
| 787 if (this.pasteButton_) | 790 if (this.pasteButton_) |
| 788 this.pasteButton_.disabled = !event.canExecute; | 791 this.pasteButton_.disabled = !event.canExecute; |
| 789 break; | 792 break; |
| 790 | 793 |
| 791 case 'rename': | 794 case 'rename': |
| 792 event.canExecute = | 795 event.canExecute = |
| 793 (// Initialized to the point where we have a current directory | 796 (// Initialized to the point where we have a current directory |
| 794 this.currentDirEntry_ && | 797 this.currentDirEntry_ && |
| 795 // Rename not in progress. | 798 // Rename not in progress. |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 this.currentList_.redraw(); | 1029 this.currentList_.redraw(); |
| 1027 } | 1030 } |
| 1028 }; | 1031 }; |
| 1029 | 1032 |
| 1030 FileManager.prototype.resolvePath = function( | 1033 FileManager.prototype.resolvePath = function( |
| 1031 path, resultCallback, errorCallback) { | 1034 path, resultCallback, errorCallback) { |
| 1032 return util.resolvePath(this.filesystem_.root, path, resultCallback, | 1035 return util.resolvePath(this.filesystem_.root, path, resultCallback, |
| 1033 errorCallback); | 1036 errorCallback); |
| 1034 }; | 1037 }; |
| 1035 | 1038 |
| 1036 FileManager.prototype.initDefaultDirectory_ = function() { | 1039 FileManager.prototype.initDefaultDirectory_ = function(path) { |
| 1040 if (!path) { |
| 1041 // No preset given, find a good place to start. |
| 1042 // Check for removable devices, if there are none, go to Downloads. |
| 1043 for (var i = 0; i != this.rootEntries_.length; i++) { |
| 1044 var rootEntry = this.rootEntries_[i]; |
| 1045 if (rootEntry.fullPath == REMOVABLE_DIRECTORY) { |
| 1046 var foundRemovable = false; |
| 1047 var self = this; |
| 1048 util.forEachDirEntry(rootEntry, function(result) { |
| 1049 if (result) { |
| 1050 foundRemovable = true; |
| 1051 } else { // Done enumerating, and we know the answer. |
| 1052 self.initDefaultDirectory_( |
| 1053 foundRemovable ? '/' : DOWNLOADS_DIRECTORY); |
| 1054 } |
| 1055 }); |
| 1056 return; |
| 1057 } |
| 1058 } |
| 1059 |
| 1060 // Removable root directory is missing altogether. |
| 1061 path = DOWNLOADS_DIRECTORY; |
| 1062 } |
| 1063 |
| 1037 // Split the dirname from the basename. | 1064 // Split the dirname from the basename. |
| 1038 var ary = this.defaultPath_.match(/^(.*?)(?:\/([^\/]+))?$/); | 1065 var ary = path.match(/^(.*?)(?:\/([^\/]+))?$/); |
| 1039 if (!ary) { | 1066 if (!ary) { |
| 1040 console.warn('Unable to split default path: ' + path); | 1067 console.warn('Unable to split default path: ' + path); |
| 1041 self.changeDirectory('/', CD_NO_HISTORY); | 1068 self.changeDirectory('/', CD_NO_HISTORY); |
| 1042 return; | 1069 return; |
| 1043 } | 1070 } |
| 1044 | 1071 |
| 1045 var baseName = ary[1]; | 1072 var baseName = ary[1]; |
| 1046 var leafName = ary[2]; | 1073 var leafName = ary[2]; |
| 1047 | 1074 |
| 1048 var self = this; | 1075 var self = this; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1069 self.filenameInput_.value = leafName; | 1096 self.filenameInput_.value = leafName; |
| 1070 if (err = FileError.NOT_FOUND_ERR) { | 1097 if (err = FileError.NOT_FOUND_ERR) { |
| 1071 // Leaf does not exist, it's just a suggested file name. | 1098 // Leaf does not exist, it's just a suggested file name. |
| 1072 self.changeDirectoryEntry(baseDirEntry, CD_NO_HISTORY); | 1099 self.changeDirectoryEntry(baseDirEntry, CD_NO_HISTORY); |
| 1073 } else { | 1100 } else { |
| 1074 console.log('Unexpected error resolving default leaf: ' + err); | 1101 console.log('Unexpected error resolving default leaf: ' + err); |
| 1075 self.changeDirectoryEntry('/', CD_NO_HISTORY); | 1102 self.changeDirectoryEntry('/', CD_NO_HISTORY); |
| 1076 } | 1103 } |
| 1077 } | 1104 } |
| 1078 | 1105 |
| 1079 self.resolvePath(self.defaultPath_, onLeafFound, onLeafError); | 1106 self.resolvePath(path, onLeafFound, onLeafError); |
| 1080 } | 1107 } |
| 1081 | 1108 |
| 1082 function onBaseError(err) { | 1109 function onBaseError(err) { |
| 1083 // Set filename first so OK button will update in changeDirectory. | 1110 // Set filename first so OK button will update in changeDirectory. |
| 1084 self.filenameInput_.value = leafName; | 1111 self.filenameInput_.value = leafName; |
| 1085 console.log('Unexpected error resolving default base "' + | 1112 console.log('Unexpected error resolving default base "' + |
| 1086 baseName + '": ' + err); | 1113 baseName + '": ' + err); |
| 1087 self.changeDirectory('/', CD_NO_HISTORY); | 1114 self.changeDirectory('/', CD_NO_HISTORY); |
| 1088 } | 1115 } |
| 1089 | 1116 |
| (...skipping 1803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2893 | 2920 |
| 2894 if (msg) { | 2921 if (msg) { |
| 2895 console.log('no no no'); | 2922 console.log('no no no'); |
| 2896 this.alert.show(msg, onAccept); | 2923 this.alert.show(msg, onAccept); |
| 2897 return false; | 2924 return false; |
| 2898 } | 2925 } |
| 2899 | 2926 |
| 2900 return true; | 2927 return true; |
| 2901 }; | 2928 }; |
| 2902 })(); | 2929 })(); |
| OLD | NEW |