Chromium Code Reviews| Index: chrome/browser/resources/file_manager/js/util.js |
| diff --git a/chrome/browser/resources/file_manager/js/util.js b/chrome/browser/resources/file_manager/js/util.js |
| index eb39b1b8a08c5554754f476fb303f15d3efca309..bf1e8e48b8d492d185eedd78359471f85633df56 100644 |
| --- a/chrome/browser/resources/file_manager/js/util.js |
| +++ b/chrome/browser/resources/file_manager/js/util.js |
| @@ -499,5 +499,99 @@ var util = { |
| */ |
| isOffline: function() { |
| return !navigator.onLine; |
| + }, |
| + |
| + /* |
| + * Tests if |path| references special, internaly used directory in which |
| + * creating new entries is not allowed. |
| + * Currently, only paths used for gdata content search match this description |
| + * (gdata content search root directory and directories that contain gdata |
| + * content search results). |
| + * |
| + * @param path {string} Path which is being tested. |
| + * @return {boolean} Test result. |
| + */ |
| + isSpecialReadonlyDirectory: function(path) { |
| + // If the path is not search root or it's child, we're fine. |
| + if (path.search(this.GDATA_SEARCH_ROOT_PATH) != 0) |
| + return false; |
| + |
| + var pathComponents = path.split('/'); |
| + |
| + // We should not create entries on path if it's either gdata search root, |
| + // or its immediate child. |
| + var lengthDifference = |
| + pathComponents.length - this.GDATA_SEARCH_ROOT_COMPONENTS.length; |
| + return lengthDifference == 0 || lengthDifference == 1; |
| + }, |
| + |
| + /* |
| + * Root path used for displaying gdata content search results. |
| + * Search results will be shown in directory 'GDATA_SEARCH_ROOT_PATH/query'. |
| + * |
| + * @const |
| + * @type {string} |
| + */ |
| + GDATA_SEARCH_ROOT_PATH: '/gdata/.search/', |
| + |
| + /* |
| + * @const |
| + * @type {Array.<string>} |
| + */ |
| + GDATA_SEARCH_ROOT_COMPONENTS: ["", "gdata", ".search"], |
| + |
| + /* |
| + * Creates directory path in which gdata content search results for |query| |
| + * should be displayed. |
| + * |
| + * @param query {string} Search query. |
| + * @return {string} Virtual directory path for search results. |
| + */ |
| + createGDataSearchPath: function(query) { |
| + return this.GDATA_SEARCH_ROOT_PATH + '/' + query; |
|
dgozman
2012/05/04 11:39:36
I'm almost sure that presubmit check will warn abo
tbarzic
2012/05/05 00:56:06
Done.
|
| + }, |
| + |
| + /* |
| + * Tests if the given path is a gdata search result path, and if it is, |
| + * returns file's fileName in virtual search file system, its gdata resourceId |
| + * and the display name that should be used when the file is shown in file |
| + * browser. |
| + * |
| + * @param path {string} The potential gdata search result path. |
| + * @return {object.<string, stringi, string>} Object that will contain file's |
| + * fileName, displayName and resourceId; or null if the path is not gdata |
| + * search result path. |
| + */ |
| + getFileAndDisplayNameForGDataSearchResult: function(path) { |
| + // Nothing to do if the path is not under gdata search root path. |
| + if (path.search(this.GDATA_SEARCH_ROOT_PATH) != 0) |
| + return null; |
| + |
| + var pathComponents = path.split('/'); |
| + |
| + // Search result should be formatted like: |
| + // gdataSearchRoot/query/result |
| + if (pathComponents.length != this.GDATA_SEARCH_ROOT_COMPONENTS.length + 2) |
| + return null; |
| + for (var i = 0; i < this.GDATA_SEARCH_ROOT_COMPONENTS.length; i++) { |
| + if (pathComponents[i] != this.GDATA_SEARCH_ROOT_COMPONENTS[i]) |
| + return null; |
| + } |
| + |
| + // Search result file name should be formatted like: |
| + // resource_id.referenced_file_name |
| + // We should display referenced file name only. |
| + var result = {}; |
| + result.fileName = pathComponents.pop(); |
| + result.displayName = |
| + result.fileName.slice(result.fileName.indexOf('.') + 1); |
| + result.resourceId = |
| + result.fileName.substr(0, result.fileName.indexOf('.')); |
| + |
| + if (result.fileName.length > 0 && result.displayName.length > 0) { |
| + return result; |
| + } else { |
| + return null; |
| + } |
| } |
| }; |