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

Side by Side Diff: chrome/browser/resources/file_manager/js/path_util.js

Issue 12716015: filemanager: Files App change necessary to use "drive/root". It still works with "drive". (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 /** 5 /**
6 * Type of a root directory. 6 * Type of a root directory.
7 * @enum 7 * @enum
8 */ 8 */
9 var RootType = { 9 var RootType = {
10 DOWNLOADS: 'downloads', 10 DOWNLOADS: 'downloads',
11 ARCHIVE: 'archive', 11 ARCHIVE: 'archive',
12 REMOVABLE: 'removable', 12 REMOVABLE: 'removable',
13 DRIVE: 'drive', 13 DRIVE: 'drive',
14 DRIVE_OFFLINE: 'drive_offline' // A fake root. Not the actual filesystem. 14 DRIVE_OFFLINE: 'drive_offline' // A fake root. Not the actual filesystem.
15 }; 15 };
16 16
17 /** 17 /**
18 * Top directory for each root type. 18 * Top directory for each root type.
19 * @type {Object.<RootType,string>} 19 * @type {Object.<RootType,string>}
20 */ 20 */
21 var RootDirectory = { 21 var RootDirectory = {
22 DOWNLOADS: '/Downloads', 22 DOWNLOADS: '/Downloads',
23 ARCHIVE: '/archive', 23 ARCHIVE: '/archive',
24 REMOVABLE: '/removable', 24 REMOVABLE: '/removable',
25 DRIVE: '/drive', 25 DRIVE: '/drive',
26 DRIVE_OFFLINE: '/drive_offline' // A fake root. Not the actual filesystem. 26 DRIVE_OFFLINE: '/drive_offline' // A fake root. Not the actual filesystem.
27 }; 27 };
28 28
29 /**
30 * Sub root directory for Drive. "root" and "other".
yoshiki 2013/03/15 06:26:58 nit: This seems not to be used now. Please add som
Haruki Sato 2013/03/15 06:49:47 Done. Thanks.
31 * @enum
32 */
33 var DriveSubRootDirectory = {
34 ROOT: 'root',
35 OTHER: 'other',
36 };
37
29 var PathUtil = {}; 38 var PathUtil = {};
30 39
31 /** 40 /**
32 * @param {string} path Path starting with '/'. 41 * @param {string} path Path starting with '/'.
33 * @return {string} Root directory (starting with '/'). 42 * @return {string} Top directory (starting with '/').
34 */ 43 */
35 PathUtil.getRootDirectory = function(path) { 44 PathUtil.getTopDirectory = function(path) {
36 var i = path.indexOf('/', 1); 45 var i = path.indexOf('/', 1);
37 return i === -1 ? path.substring(0) : path.substring(0, i); 46 return i === -1 ? path : path.substring(0, i);
38 }; 47 };
39 48
40 /** 49 /**
41 * @param {string} path Any unix-style path (may start or not start from root). 50 * @param {string} path Any unix-style path (may start or not start from root).
42 * @return {Array.<string>} Path components. 51 * @return {Array.<string>} Path components.
43 */ 52 */
44 PathUtil.split = function(path) { 53 PathUtil.split = function(path) {
45 var fromRoot = false; 54 var fromRoot = false;
46 if (path[0] === '/') { 55 if (path[0] === '/') {
47 fromRoot = true; 56 fromRoot = true;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 path += components[i]; 94 path += components[i];
86 } 95 }
87 return path; 96 return path;
88 }; 97 };
89 98
90 /** 99 /**
91 * @param {string} path Path starting with '/'. 100 * @param {string} path Path starting with '/'.
92 * @return {RootType} RootType.DOWNLOADS, RootType.DRIVE etc. 101 * @return {RootType} RootType.DOWNLOADS, RootType.DRIVE etc.
93 */ 102 */
94 PathUtil.getRootType = function(path) { 103 PathUtil.getRootType = function(path) {
95 var rootDir = PathUtil.getRootDirectory(path); 104 var rootDir = PathUtil.getTopDirectory(path);
96 for (var type in RootDirectory) { 105 for (var type in RootDirectory) {
97 if (rootDir === RootDirectory[type]) 106 if (rootDir === RootDirectory[type])
98 return RootType[type]; 107 return RootType[type];
99 } 108 }
100 }; 109 };
101 110
102 /** 111 /**
103 * @param {string} path Any path. 112 * @param {string} path Any path.
104 * @return {string} The root path. 113 * @return {string} The root path.
105 */ 114 */
106 PathUtil.getRootPath = function(path) { 115 PathUtil.getRootPath = function(path) {
107 var type = PathUtil.getRootType(path); 116 var type = PathUtil.getRootType(path);
108 117
118 // TODO(haruki): Add support for "drive/root" and "drive/other".
109 if (type == RootType.DOWNLOADS || type == RootType.DRIVE || 119 if (type == RootType.DOWNLOADS || type == RootType.DRIVE ||
110 type == RootType.DRIVE_OFFLINE) 120 type == RootType.DRIVE_OFFLINE)
111 return PathUtil.getRootDirectory(path); 121 return PathUtil.getTopDirectory(path);
112 122
113 if (type == RootType.ARCHIVE || type == RootType.REMOVABLE) { 123 if (type == RootType.ARCHIVE ||
124 type == RootType.REMOVABLE) {
114 var components = PathUtil.split(path); 125 var components = PathUtil.split(path);
115 if (components.length > 1) { 126 if (components.length > 1) {
116 return PathUtil.join(components[0], components[1]); 127 return PathUtil.join(components[0], components[1]);
117 } else { 128 } else {
118 return components[0]; 129 return components[0];
119 } 130 }
120 } 131 }
121 132
122 return '/'; 133 return '/';
123 }; 134 };
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 if (path === RootDirectory.ARCHIVE) 176 if (path === RootDirectory.ARCHIVE)
166 return str('ARCHIVE_DIRECTORY_LABEL'); 177 return str('ARCHIVE_DIRECTORY_LABEL');
167 if (PathUtil.isParentPath(RootDirectory.ARCHIVE, path)) 178 if (PathUtil.isParentPath(RootDirectory.ARCHIVE, path))
168 return path.substring(RootDirectory.ARCHIVE.length + 1); 179 return path.substring(RootDirectory.ARCHIVE.length + 1);
169 180
170 if (path === RootDirectory.REMOVABLE) 181 if (path === RootDirectory.REMOVABLE)
171 return str('REMOVABLE_DIRECTORY_LABEL'); 182 return str('REMOVABLE_DIRECTORY_LABEL');
172 if (PathUtil.isParentPath(RootDirectory.REMOVABLE, path)) 183 if (PathUtil.isParentPath(RootDirectory.REMOVABLE, path))
173 return path.substring(RootDirectory.REMOVABLE.length + 1); 184 return path.substring(RootDirectory.REMOVABLE.length + 1);
174 185
186 // TODO(haruki): Add support for "drive/root" and "drive/other".
175 if (path === RootDirectory.DRIVE) 187 if (path === RootDirectory.DRIVE)
176 return str('DRIVE_DIRECTORY_LABEL'); 188 return str('DRIVE_DIRECTORY_LABEL');
177 189
178 if (path === RootDirectory.DRIVE_OFFLINE) 190 if (path === RootDirectory.DRIVE_OFFLINE)
179 return str('DRIVE_OFFLINE_COLLECTION_LABEL'); 191 return str('DRIVE_OFFLINE_COLLECTION_LABEL');
180 192
181 return path; 193 return path;
182 }; 194 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698